You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-dev@incubator.apache.org by Scott Boyd <sc...@gmail.com> on 2008/05/07 01:02:21 UTC

absolute paths

Xappers,

Its a common load balancing technique to put images in different servers.
If you set the image attribute on a label with an absolute path, you end up
with a wierd path:

http://server:port/context/http://server:port/context/file

I did a bit of digging, and noticed that when the image attribute is set, we
call getAttributeAsUrl.  Are we restricting absolute paths for a reason
(e.g. security), or do we need to check the string in getAttributeAsUrl to
see if it already has a protocol and server portion of a URL?

LabelBridge.js
xap.bridges.xap.LabelBridge.prototype.setImageAttribute = function(imgURL) {
    //we need this to be relative to the page it was fed from
    //if it was set from an XML page. If the page was 3 folders deep
    //and the url is ../../../ we expect that to be relative to the original
    //folder
    this.getPeer().setImg(this.getElement().getAttributeAsUrl("image"));
}


XapElement.js
/**
 * Returns the attribute interpreted as a url. That url will be properly
 * qualified based on information stored within this element and attribute.
 * @param name {String} Attribute name
 * @return //TODO why do we need it?
 */
xap.xml.dom.XapElement.prototype.getAttributeAsUrl = function( name ) {
    var att = null;

    for (var i = 0; i < this.attributes.length; ++i) {
        if (this.attributes[i].nodeName == name) {
          att =  this.attributes[i];
        }
    }

    if (att === null){
        return null;
    }

    var attValue = att.nodeValue;

    var baseUrl = att.baseUrl;

    baseUrl = baseUrl || this.baseUrl || "";
    return (baseUrl + attValue);
};

-Scott B