Return-Path: Delivered-To: apmail-jakarta-taglibs-dev-archive@apache.org Received: (qmail 67547 invoked from network); 9 May 2003 00:16:21 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 9 May 2003 00:16:21 -0000 Received: (qmail 10153 invoked by uid 97); 9 May 2003 00:18:32 -0000 Delivered-To: qmlist-jakarta-archive-taglibs-dev@nagoya.betaversion.org Received: (qmail 10145 invoked from network); 9 May 2003 00:18:31 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 9 May 2003 00:18:31 -0000 Received: (qmail 67205 invoked by uid 500); 9 May 2003 00:16:17 -0000 Mailing-List: contact taglibs-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tag Libraries Developers List" Reply-To: "Tag Libraries Developers List" Delivered-To: mailing list taglibs-dev@jakarta.apache.org Received: (qmail 67194 invoked by uid 500); 9 May 2003 00:16:17 -0000 Received: (qmail 67191 invoked from network); 9 May 2003 00:16:17 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 9 May 2003 00:16:17 -0000 Received: (qmail 74408 invoked by uid 1003); 9 May 2003 00:16:16 -0000 Date: 9 May 2003 00:16:16 -0000 Message-ID: <20030509001616.74407.qmail@icarus.apache.org> From: pierred@apache.org To: jakarta-taglibs-cvs@apache.org Subject: cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/xml XPathUtil.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N pierred 2003/05/08 17:16:16 Modified: standard/src/org/apache/taglibs/standard/tag/common/xml XPathUtil.java Log: Patch from Ramesh to properly handle NodeLists. Revision Changes Path 1.13 +60 -30 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/xml/XPathUtil.java Index: XPathUtil.java =================================================================== RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/xml/XPathUtil.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- XPathUtil.java 1 May 2003 00:02:54 -0000 1.12 +++ XPathUtil.java 9 May 2003 00:16:16 -0000 1.13 @@ -443,6 +443,23 @@ } return null; } + + static Document getDummyDocumentWithoutRoot( ) { + try { + if ( dbf == null ) { + dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware( true ); + dbf.setValidating( false ); + } + db = dbf.newDocumentBuilder(); + + d = db.newDocument(); + return d; + } catch ( Exception e ) { + e.printStackTrace(); + } + return null; + } // The following variable is used for holding the modified xpath string // when adapting parameter for Xalan XPath engine, where we need to have @@ -633,6 +650,7 @@ modifiedXPath = xpath; String origXPath = xpath ; + boolean whetherOrigXPath = true; // If contextNode is not null then just pass the values to Xalan XPath if ( n != null ) { @@ -657,6 +675,7 @@ xpath = xpath.substring( xpath.indexOf("/")); } else { xpath = "/*"; + whetherOrigXPath = false; } @@ -675,48 +694,59 @@ //System.out.println("Creating a Dummy document to pass " + // " onto as context node " ); - if ( Class.forName("org.apache.taglibs.standard.tag.common.xml.JSTLNodeList").isInstance( - varObject ) ) { + if ( Class.forName("org.apache.taglibs.standard.tag.common.xml.JSTLNodeList").isInstance( varObject ) ) { Document newDocument = getDummyDocument(); JSTLNodeList jstlNodeList = (JSTLNodeList)varObject; - if ( ( jstlNodeList.getLength() == 1 ) && - (!Class.forName("org.w3c.dom.Node").isInstance( jstlNodeList.elementAt(0) ) ) ) { - - //Nodelist with primitive type - Object myObject = jstlNodeList.elementAt(0); - - //p("Single Element of primitive type"); - //p("Type => " + myObject.getClass()); - - xpath = myObject.toString(); - - //p("String value ( xpathwould be this) => " + xpath); - boundDocument = newDocument; + if ( jstlNodeList.getLength() == 1 ) { + if ( Class.forName("org.w3c.dom.Node").isInstance( + jstlNodeList.elementAt(0) ) ) { + Node node = (Node)jstlNodeList.elementAt(0); + Document doc = getDummyDocumentWithoutRoot(); + Node importedNode = doc.importNode( node, true); + doc.appendChild (importedNode ); + boundDocument = doc; + if ( whetherOrigXPath ) { + xpath="/*" + xpath; + } + + } else { + + //Nodelist with primitive type + Object myObject = jstlNodeList.elementAt(0); + + //p("Single Element of primitive type"); + //p("Type => " + myObject.getClass()); + + xpath = myObject.toString(); + + //p("String value ( xpathwould be this) => " + xpath); + boundDocument = newDocument; + } } else { Element dummyroot = newDocument.getDocumentElement(); - for ( int i=0; i< jstlNodeList.getLength(); i++ ) { - Node currNode = (Node)jstlNodeList.item(i); + for ( int i=0; i< jstlNodeList.getLength(); i++ ) { + Node currNode = (Node)jstlNodeList.item(i); - Node importedNode = newDocument.importNode( - currNode, true ); + Node importedNode = newDocument.importNode( + currNode, true ); - //printDetails ( newDocument); + //printDetails ( newDocument); - dummyroot.appendChild( importedNode ); + dummyroot.appendChild( importedNode ); - //p( "Details of the document After importing " ); - //printDetails ( newDocument); - } - boundDocument = newDocument; - // printDetails ( boundDocument ); - // Verify : As we are adding Document element we need to - // change the xpath expression. Hopefully this won't - // change the result + //p( "Details of the document After importing"); + //printDetails ( newDocument); + } + boundDocument = newDocument; + // printDetails ( boundDocument ); + //Verify :As we are adding Document element we need + // to change the xpath expression.Hopefully this + // won't change the result - xpath = "/*" + xpath; + xpath = "/*" + xpath; } } else if ( Class.forName("org.w3c.dom.Node").isInstance( varObject ) ) { --------------------------------------------------------------------- To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org