001    
002    package railo.runtime.functions.xml;
003    
004    import org.w3c.dom.Node;
005    
006    import railo.runtime.PageContext;
007    import railo.runtime.ext.function.Function;
008    import railo.runtime.text.xml.XMLNodeList;
009    import railo.runtime.text.xml.XMLUtil;
010    
011    /**
012     * Implements the Cold Fusion Function xmlchildpos
013     */
014    public final class XmlChildPos implements Function {
015            public static double call(PageContext pc , Node node, String name, double index) {
016                    XMLNodeList xmlNodeList = new XMLNodeList(node,false);
017                    int len=xmlNodeList.getLength();
018                    // if(index<1)throw new FunctionException(pc,"XmlChildPos","second","index","attribute must be 1 or greater");
019                    int count=1;
020                    for(int i=0;i<len;i++) {
021                            Node n=xmlNodeList.item(i);
022                            if(XMLUtil.nameEqual(n,name,XMLUtil.isCaseSensitve(n)) && count++==index) return i+1;
023                    }
024                    return -1;
025            }
026    }