commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmi...@apache.org
Subject cvs commit: jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/dom DOMModelTest.java
Date Tue, 02 Mar 2004 01:32:20 GMT
dmitri      2004/03/01 17:32:20

  Modified:    jxpath/src/java/org/apache/commons/jxpath/ri
                        JXPathContextReferenceImpl.java
               jxpath/src/test/org/apache/commons/jxpath/ri/model
                        XMLModelTestCase.java
               jxpath/src/test/org/apache/commons/jxpath/ri/model/dom
                        DOMModelTest.java
  Log:
  Fix for bug #26899.   See http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26899
  
  Revision  Changes    Path
  1.39      +74 -2     jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java
  
  Index: JXPathContextReferenceImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- JXPathContextReferenceImpl.java	29 Feb 2004 14:17:45 -0000	1.38
  +++ JXPathContextReferenceImpl.java	2 Mar 2004 01:32:20 -0000	1.39
  @@ -39,6 +39,7 @@
   import org.apache.commons.jxpath.ri.axes.RootContext;
   import org.apache.commons.jxpath.ri.compiler.Expression;
   import org.apache.commons.jxpath.ri.compiler.LocationPath;
  +import org.apache.commons.jxpath.ri.compiler.Path;
   import org.apache.commons.jxpath.ri.compiler.TreeCompiler;
   import org.apache.commons.jxpath.ri.model.NodePointer;
   import org.apache.commons.jxpath.ri.model.NodePointerFactory;
  @@ -240,11 +241,82 @@
        * types are wrapped into objects.
        */
       public Object getValue(String xpath) {
  -        return getValue(xpath, compileExpression(xpath));
  +        Expression expression = compileExpression(xpath);
  +// TODO: (work in progress) - trying to integrate with Xalan
  +//        Object ctxNode = getNativeContextNode(expression);
  +//        if (ctxNode != null) {
  +//            System.err.println("WILL USE XALAN: " + xpath);
  +//            CachedXPathAPI api = new CachedXPathAPI();
  +//            try {
  +//                if (expression instanceof Path) {
  +//                    Node node = api.selectSingleNode((Node)ctxNode, xpath);
  +//                    System.err.println("NODE: " + node);
  +//                    if (node == null) {
  +//                        return null;
  +//                    }
  +//                    return new DOMNodePointer(node, null).getValue();
  +//                }
  +//                else {
  +//                    XObject object = api.eval((Node)ctxNode, xpath);
  +//                    switch (object.getType()) {
  +//                    case XObject.CLASS_STRING: return object.str();
  +//                    case XObject.CLASS_NUMBER: return new Double(object.num());
  +//                    case XObject.CLASS_BOOLEAN: return new Boolean(object.bool());
  +//                    default:
  +//                        System.err.println("OTHER TYPE: " + object.getTypeString());
  +//                    }
  +//                }
  +//            }
  +//            catch (TransformerException e) {
  +//                // TODO Auto-generated catch block
  +//                e.printStackTrace();
  +//            }
  +//            return
  +//        }
  +        
  +        return getValue(xpath, expression);
       }
   
  +//    private Object getNativeContextNode(Expression expression) {
  +//        Object node = getNativeContextNode(getContextBean());
  +//        if (node == null) {
  +//            return null;
  +//        }
  +//        
  +//        List vars = expression.getUsedVariables();
  +//        if (vars != null) {
  +//            return null;
  +//        }
  +//        
  +//        return node;
  +//    }
  +
  +//    private Object getNativeContextNode(Object bean) {
  +//        if (bean instanceof Number || bean instanceof String || bean instanceof Boolean)
{
  +//            return bean;
  +//        }
  +//        if (bean instanceof Node) {
  +//            return (Node)bean;            
  +//        }
  +//        
  +//        if (bean instanceof Container) {
  +//            bean = ((Container)bean).getValue();
  +//            return getNativeContextNode(bean);
  +//        }
  +//        
  +//        return null;
  +//    }
  +
       public Object getValue(String xpath, Expression expr) {
           Object result = expr.computeValue(getEvalContext());
  +        if (result == null) {
  +            if (expr instanceof Path) {
  +                if (!isLenient()) {
  +                    throw new JXPathException("No value for xpath: " + xpath);
  +                }
  +            }
  +            return null;
  +        }
           if (result instanceof EvalContext) {
               EvalContext ctx = (EvalContext) result;
               result = ctx.getSingleNodePointer();
  
  
  
  1.20      +24 -1     jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java
  
  Index: XMLModelTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- XMLModelTestCase.java	29 Feb 2004 14:17:45 -0000	1.19
  +++ XMLModelTestCase.java	2 Mar 2004 01:32:20 -0000	1.20
  @@ -18,6 +18,7 @@
   import org.apache.commons.jxpath.AbstractFactory;
   import org.apache.commons.jxpath.IdentityManager;
   import org.apache.commons.jxpath.JXPathContext;
  +import org.apache.commons.jxpath.JXPathException;
   import org.apache.commons.jxpath.JXPathTestCase;
   import org.apache.commons.jxpath.Pointer;
   import org.apache.commons.jxpath.Variables;
  @@ -321,6 +322,28 @@
   
           // default namespace does not affect search
           assertXPathValue(context, "vendor/product/prix", "934.99");
  +        
  +        assertXPathValue(context, "/vendor/contact[@name='jim']", "Jim");
  +        
  +        boolean nsv = false;
  +        try {
  +            context.setLenient(false);
  +            context.getValue("/vendor/contact[@name='jane']");
  +        }
  +        catch (JXPathException ex) {
  +            nsv = true;
  +        }
  +        assertTrue("No such value: /vendor/contact[@name='jim']", nsv);
  +                
  +        nsv = false;
  +        try {
  +            context.setLenient(false);
  +            context.getValue("/vendor/contact[@name='jane']/*");
  +        }
  +        catch (JXPathException ex) {
  +            nsv = true;
  +        }
  +        assertTrue("No such value: /vendor/contact[@name='jane']/*", nsv);
           
           // child:: with a wildcard
           assertXPathValue(
  
  
  
  1.13      +1 -2      jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/dom/DOMModelTest.java
  
  Index: DOMModelTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/model/dom/DOMModelTest.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- DOMModelTest.java	29 Feb 2004 14:17:46 -0000	1.12
  +++ DOMModelTest.java	2 Mar 2004 01:32:20 -0000	1.13
  @@ -19,7 +19,6 @@
   import junit.framework.TestSuite;
   
   import org.apache.commons.jxpath.AbstractFactory;
  -import org.apache.commons.jxpath.JXPathContext;
   import org.apache.commons.jxpath.ri.model.XMLModelTestCase;
   import org.apache.commons.jxpath.xml.DocumentContainer;
   import org.w3c.dom.Attr;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message