FileDocCategorySizeDatePackage
ConfigXPathHelper.javaAPI DocGlassfish v2 API5047Fri May 04 22:31:20 BST 2007com.sun.enterprise.config.util

ConfigXPathHelper

public final class ConfigXPathHelper extends Object
Helper methods are provided to generate valid xpaths that are needed by config api.

Fields Summary
public static final String
XPATH_SEPARATOR
private static char
SEPARATOR_CHAR
private static char
OPENBRACKET_CHAR
private static char
CLOSEBRACKET_CHAR
private static char
ESCAPE_CHAR
Constructors Summary
Methods Summary
private static intbypassBrackets(java.lang.String xPath, int idx)

        char ch;
        while(idx>=0 && ((ch=xPath.charAt(idx))!=OPENBRACKET_CHAR || isEscapedChar(xPath,idx))) {
            idx--;
        }
        return idx-1;
    
public static java.lang.StringgetAbsoluteIdXpathExpression(java.lang.String childTagName, java.lang.String nameId, java.lang.String valueId)

param
childTagName
param
nameId
param
valueId

    
                    
             
        if(childTagName.startsWith(XPATH_SEPARATOR))
            return childTagName + "[@" + nameId + "='" + valueId + "']";
        else
            return XPATH_SEPARATOR + childTagName + "[@" + nameId + "='" + valueId + "']";
    
public static java.lang.StringgetLastNodeName(java.lang.String xPath)

  
    /* 
     *  returns element's tag name extracting from its xpath
     */
         
        //FIXME: it is supposed that open bracket should be escaped if its part of name or value
        // FIXME no error handling
        
        int idx = xPath.length()-1;
        char ch;
        int idxEnd = -1;
        if(idx>=0 && (ch=xPath.charAt(idx))==CLOSEBRACKET_CHAR) {
            idxEnd = bypassBrackets(xPath, --idx);
            idx = idxEnd;
        }
     
        while(idx>=0 && ((ch=xPath.charAt(idx))!=SEPARATOR_CHAR || isEscapedChar(xPath,idx))) {
                idx--;
        }
        idx++;
        if(idxEnd<=0 || idxEnd==xPath.length()-1)
            return xPath.substring(idx);
        else
            return xPath.substring(idx, idxEnd+1);
    
public static java.lang.StringgetParentXPath(java.lang.String xPath)

        //FIXME: it is supposed that open bracket should be escaped if its part of name or value
        // FIXME no error handling
        
        int idx = xPath.length()-1;
        char ch;
        if(idx>=0 && (ch=xPath.charAt(idx))==CLOSEBRACKET_CHAR) {
            idx = bypassBrackets(xPath, --idx);
        }
     
        while(idx>=0 && ((ch=xPath.charAt(idx))!=SEPARATOR_CHAR || isEscapedChar(xPath,idx))) {
                idx--;
        }
        if(idx<=0)
            return "/";
        return xPath.substring(0, idx);
    
private static booleanisEscapedChar(java.lang.String xPath, int idx)

        if(idx<=0)
            return false;
        int count = 0;
        while(--idx>=0 && xPath.charAt(idx)==ESCAPE_CHAR)
            count++;
        return ((count%2)==1);