Skip to content

Commit

Permalink
ticket 140: new api getcwd, and move envjs.uri from rhino to core
Browse files Browse the repository at this point in the history
  • Loading branch information
client9 committed Mar 31, 2010
1 parent f01167f commit f1bb85d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 47 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
</filterchain>
<fileset dir="${SRC_DIR}" includes="platform/core/__global__.js" />
<fileset dir="${SRC_DIR}" includes="common/intro.js" />
<fileset dir="${SRC_DIR}" includes="common/urlparse.js" />
<fileset dir="${SRC_DIR}" includes="platform/core/console.js" />
<fileset dir="${SRC_DIR}" includes="platform/core/dom.js" />
<fileset dir="${SRC_DIR}" includes="platform/core/event.js" />
Expand Down Expand Up @@ -150,7 +151,6 @@
<fileset dir="${SRC_DIR}" includes="platform/rhino/__global__.js" />
<fileset dir="${SRC_DIR}" includes="common/intro.js" />
<fileset dir="${SRC_DIR}" includes="common/__extend__.js" />
<fileset dir="${SRC_DIR}" includes="common/urlparse.js" />
<fileset dir="${SRC_DIR}" includes="platform/rhino/console.js" />
<fileset dir="${SRC_DIR}" includes="platform/rhino/dom.js" />
<fileset dir="${SRC_DIR}" includes="platform/rhino/event.js" />
Expand Down
54 changes: 50 additions & 4 deletions src/platform/core/xhr.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,56 @@

/**
* resolves location relative to base or window location
* @param {Object} path
* @param {Object} base
* getcwd - named after posix call of same name (see 'man 2 getcwd')
*
*/
Envjs.uri = function(path, base){};
Envjs.getcwd = function() {
return '.';
}

/**
* resolves location relative to doc location
*
* @param {Object} path Relative or absolute URL
* @param {Object} base (semi-optional) The base url used in resolving "path" above
*/
Envjs.uri = function(path, base) {
//console.log('constructing uri from path %s and base %s', path, base);

// Semi-common trick is to make an iframe with src='javascript:false'
// (or some equivalent). By returning '', the load is skipped
if (path.indexOf('javascript') === 0) {
return '';
}

// if path is absolute, then just normalize and return
if (path.match('^[a-zA-Z]+://')) {
return urlparse.urlnormalize(path);
}

// if base not passed in, try to get it from document
// Ideally I would like the caller to pass in document.baseURI to
// make this more self-sufficient and testable
if (!base && document) {
base = document.baseURI;
}

// about:blank doesn't count
if (base === 'about:blank'){
base = '';
}

// if base is still empty, then we are in QA mode loading local
// files. Get current working directory
if (!base) {
base = 'file://' + Envjs.getcwd() + '/';
}
// handles all cases if path is abosulte or relative to base
// 3rd arg is "false" --> remove fragments
var newurl = urlparse.urlnormalize(urlparse.urljoin(base, path, false));

return newurl;
};


/**
* Used in the XMLHttpRquest implementation to run a
Expand Down
46 changes: 4 additions & 42 deletions src/platform/rhino/xhr.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,10 @@

/**
* resolves location relative to doc location
*
* @param {Object} path Relative or absolute URL
* @param {Object} base (semi-optional) The base url used in resolving "path" above
* Get 'Current Working Directory'
*/
Envjs.uri = function(path, base){
//console.log('constructing uri from path %s and base %s', path, base);

// Semi-common trick is to make an iframe with src='javascript:false'
// (or some equivalent). By returning '', the load is skipped
if (path.indexOf('javascript') === 0) {
return '';
}

// if path is absolute, then just normalize and return
if (path.match('^[a-zA-Z]+://')) {
return urlparse.urlnormalize(path);
}

// if base not passed in, try to get it from document
// Ideally I would like the caller to pass in document.baseURI to
// make this more self-sufficient and testable
if (!base && document) {
base = document.baseURI;
}

// about:blank doesn't count
if (base === 'about:blank'){
base = '';
}

// if base is still empty, then we are in QA mode loading local
// files. Get current working directory
if (!base) {
base = 'file://' + java.lang.System.getProperty("user.dir") + '/';
}
// handles all cases if path is abosulte or relative to base
// 3rd arg is "false" --> remove fragments
var newurl = urlparse.urlnormalize(urlparse.urljoin(base, path, false));

// console.log('New url is: %s', newurl);
return newurl;
};
Envjs.getcwd = function() {
return java.lang.System.getProperty('user.dir');
}

/**
*
Expand Down

0 comments on commit f1bb85d

Please sign in to comment.