[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jakarta-commons-dev
Subject:    cvs commit: jakarta-commons/jxpath/src/test/org/apache/commons/jxpath JXPathTestCase.java Test.prope
From:       dmitri () apache ! org
Date:       2001-09-26 1:21:55
[Download RAW message or body]

dmitri      01/09/25 18:21:55

  Modified:    jxpath/src/java/org/apache/commons/jxpath JXPathContext.java
               jxpath/src/java/org/apache/commons/jxpath/ri
                        EvalContext.java JXPathContextReferenceImpl.java
               jxpath/src/java/org/apache/commons/jxpath/ri/axes
                        RootContext.java
               jxpath/src/java/org/apache/commons/jxpath/ri/pointers
                        BeanPointer.java ContainerPointer.java
                        DOMNodePointer.java DynamicPointer.java
                        NodePointer.java NullPointer.java
                        PropertyOwnerPointer.java
               jxpath/src/test/org/apache/commons/jxpath
                        JXPathTestCase.java Test.properties
  Added:       jxpath/src/java/org/apache/commons/jxpath/ri/pointers
                        BeanAttributeIterator.java
                        LangAttributePointer.java
  Log:
  Implemented lang() and @xml:lang
  
  Revision  Changes    Path
  1.3       +27 -4     \
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContext.java  
  Index: JXPathContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JXPathContext.java	2001/09/08 20:59:58	1.2
  +++ JXPathContext.java	2001/09/26 01:21:54	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContext.java,v \
                1.2 2001/09/08 20:59:58 dmitri Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/09/08 20:59:58 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContext.java,v \
1.3 2001/09/26 01:21:54 dmitri Exp $  + * $Revision: 1.3 $
  + * $Date: 2001/09/26 01:21:54 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -63,6 +63,7 @@
   
   import java.util.List;
   import org.w3c.dom.Node;
  +import java.util.Locale;
   
   /**
    * JXPathContext provides APIs for the traversal of graphs of JavaBeans using
  @@ -383,13 +384,14 @@
    * See <a href="http://www.w3.org/TR/xpath">XML Path Language (XPath) Version 1.0 \
                </a>
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.2 $ $Date: 2001/09/08 20:59:58 $
  + * @version $Revision: 1.3 $ $Date: 2001/09/26 01:21:54 $
    */
   public abstract class JXPathContext {
       protected JXPathContext parentContext;
       protected Object contextBean;
       protected Variables vars;
       protected Functions functions;
  +    protected Locale locale;
   
       /**
        * Creates a new JXPathContext with the specified bean as the root node.
  @@ -453,6 +455,27 @@
       public Functions getFunctions(){
           // TBD: default lib
           return functions;
  +    }
  +
  +    /**
  +     * Set the locale for this context.  The value of the "lang"
  +     * attribute as well as the the lang() function will be
  +     * affected by the locale.  By default, JXPath uses
  +     * <code>Locale.getDefault()</code>
  +     */
  +    public void setLocale(Locale locale){
  +        this.locale = locale;
  +    }
  +
  +    /**
  +     * Returns the locale set with setLocale or Locale.getDefault()
  +     * by default.
  +     */
  +    protected Locale getLocale(){
  +        if (locale == null){
  +            locale = Locale.getDefault();
  +        }
  +        return locale;
       }
   
       /**
  
  
  
  1.4       +15 -6     \
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/EvalContext.java  
  Index: EvalContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/EvalContext.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- EvalContext.java	2001/09/21 23:22:43	1.3
  +++ EvalContext.java	2001/09/26 01:21:54	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/EvalContext.java,v \
                1.3 2001/09/21 23:22:43 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/09/21 23:22:43 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/EvalContext.java,v \
1.4 2001/09/26 01:21:54 dmitri Exp $  + * $Revision: 1.4 $
  + * $Date: 2001/09/26 01:21:54 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -79,7 +79,7 @@
    * implement behavior of various XPath axes: "child::", "parent::" etc.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2001/09/21 23:22:43 $
  + * @version $Revision: 1.4 $ $Date: 2001/09/26 01:21:54 $
    */
   public abstract class EvalContext implements ExpressionContext {
       protected EvalContext parentContext;
  @@ -922,8 +922,7 @@
               case Compiler.FUNCTION_LAST:                return \
                functionLast(function);
               case Compiler.FUNCTION_POSITION:            return \
                functionPosition(function);
               case Compiler.FUNCTION_COUNT:               return \
                functionCount(function);
  -
  -            case Compiler.FUNCTION_LANG:
  +            case Compiler.FUNCTION_LANG:                return \
functionLang(function);  case Compiler.FUNCTION_ID:
               {
                   System.err.println("UNIMPLEMENTED: " + function);
  @@ -1007,6 +1006,16 @@
               count = 1;
           }
           return new Double(count);
  +    }
  +
  +    protected Object functionLang(CoreFunction function){
  +        assertArgCount(function, 1);
  +        String lang = stringValue(eval(function.getArg1()));
  +        NodePointer pointer = (NodePointer)getContextNodePointer();
  +        if (pointer == null){
  +            return Boolean.FALSE;
  +        }
  +        return pointer.isLanguage(lang) ? Boolean.TRUE: Boolean.FALSE;
       }
   
       protected Object functionNamespaceURI(CoreFunction function){
  
  
  
  1.5       +7 -7      \
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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JXPathContextReferenceImpl.java	2001/09/21 23:22:43	1.4
  +++ JXPathContextReferenceImpl.java	2001/09/26 01:21:54	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java,v \
                1.4 2001/09/21 23:22:43 dmitri Exp $
  - * $Revision: 1.4 $
  - * $Date: 2001/09/21 23:22:43 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java,v \
1.5 2001/09/26 01:21:54 dmitri Exp $  + * $Revision: 1.5 $
  + * $Date: 2001/09/26 01:21:54 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -81,7 +81,7 @@
   
   /**
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.4 $ $Date: 2001/09/21 23:22:43 $
  + * @version $Revision: 1.5 $ $Date: 2001/09/26 01:21:54 $
    */
   public class JXPathContextReferenceImpl extends JXPathContext
   {
  @@ -212,7 +212,7 @@
               return (Pointer)result;
           }
           else {
  -            return NodePointer.createNodePointer(null, result);
  +            return NodePointer.createNodePointer(null, result, getLocale());
           }
       }
   
  @@ -255,14 +255,14 @@
               list.add((Pointer)result);
           }
           else {
  -            list.add(NodePointer.createNodePointer(null, result));
  +            list.add(NodePointer.createNodePointer(null, result, getLocale()));
           }
           return list;
       }
   
       private Object eval(String xpath, boolean firstMatchLookup) {
           Expression expr = compile(xpath);
  -        NodePointer pointer = NodePointer.createNodePointer(new QName(null, \
"root"), getContextBean());  +        NodePointer pointer = \
NodePointer.createNodePointer(new QName(null, "root"), getContextBean(), \
getLocale());  EvalContext ctx = new RootContext(this, pointer);
   //        System.err.println("XPATH = " + xpath);
           return ctx.eval(expr, firstMatchLookup);
  
  
  
  1.3       +5 -5      \
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/RootContext.java  
  Index: RootContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/RootContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RootContext.java	2001/09/21 23:22:44	1.2
  +++ RootContext.java	2001/09/26 01:21:54	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/RootContext.java,v \
                1.2 2001/09/21 23:22:44 dmitri Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/09/21 23:22:44 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/axes/RootContext.java,v \
1.3 2001/09/26 01:21:54 dmitri Exp $  + * $Revision: 1.3 $
  + * $Date: 2001/09/26 01:21:54 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -73,7 +73,7 @@
    * EvalContext that is used to hold the root node for the path traversal.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.2 $ $Date: 2001/09/21 23:22:44 $
  + * @version $Revision: 1.3 $ $Date: 2001/09/26 01:21:54 $
    */
   public class RootContext extends EvalContext {
       private boolean startedSet = false;
  @@ -124,7 +124,7 @@
       }
   
       public EvalContext getConstantContext(Object constant){
  -        NodePointer pointer = NodePointer.createNodePointer(new QName(null, ""), \
constant);  +        NodePointer pointer = NodePointer.createNodePointer(new \
QName(null, ""), constant, null);  return new InitialContext(new RootContext(parent, \
pointer));  }
   
  
  
  
  1.4       +9 -6      \
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/BeanPointer.java
  
  Index: BeanPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/BeanPointer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BeanPointer.java	2001/09/21 23:22:45	1.3
  +++ BeanPointer.java	2001/09/26 01:21:54	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/BeanPointer.java,v \
                1.3 2001/09/21 23:22:45 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/09/21 23:22:45 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/BeanPointer.java,v \
1.4 2001/09/26 01:21:54 dmitri Exp $  + * $Revision: 1.4 $
  + * $Date: 2001/09/26 01:21:54 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -74,7 +74,7 @@
    * a path, following elements will by of type PropertyPointer.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2001/09/21 23:22:45 $
  + * @version $Revision: 1.4 $ $Date: 2001/09/26 01:21:54 $
    */
   public class BeanPointer extends PropertyOwnerPointer {
       private QName name;
  @@ -83,8 +83,11 @@
       private PropertyDescriptor propertyDescriptors[];
       private String[] names;
   
  -    public BeanPointer(QName name, Object bean, JXPathBeanInfo beanInfo){
  -        this(null, name, bean, beanInfo);
  +    public BeanPointer(QName name, Object bean, JXPathBeanInfo beanInfo, Locale \
locale){  +        super(null, locale);
  +        this.name = name;
  +        this.bean = bean;
  +        this.beanInfo = beanInfo;
       }
   
       /**
  
  
  
  1.3       +7 -6      \
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/ContainerPointer.java
  
  Index: ContainerPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/ContainerPointer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ContainerPointer.java	2001/09/21 23:22:45	1.2
  +++ ContainerPointer.java	2001/09/26 01:21:54	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/ContainerPointer.java,v \
                1.2 2001/09/21 23:22:45 dmitri Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/09/21 23:22:45 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/ContainerPointer.java,v \
1.3 2001/09/26 01:21:54 dmitri Exp $  + * $Revision: 1.3 $
  + * $Date: 2001/09/26 01:21:54 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -76,14 +76,15 @@
    * itself.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.2 $ $Date: 2001/09/21 23:22:45 $
  + * @version $Revision: 1.3 $ $Date: 2001/09/26 01:21:54 $
    */
   public class ContainerPointer extends NodePointer {
       private Container container;
       private NodePointer valuePointer;
   
  -    public ContainerPointer(Container container){
  -        this(null, container);
  +    public ContainerPointer(Container container, Locale locale){
  +        super(null, locale);
  +        this.container = container;
       }
   
       public ContainerPointer(NodePointer parent, Container container){
  
  
  
  1.3       +34 -6     \
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/DOMNodePointer.java
  
  Index: DOMNodePointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/DOMNodePointer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DOMNodePointer.java	2001/09/21 23:22:45	1.2
  +++ DOMNodePointer.java	2001/09/26 01:21:54	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/DOMNodePointer.java,v \
                1.2 2001/09/21 23:22:45 dmitri Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/09/21 23:22:45 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/DOMNodePointer.java,v \
1.3 2001/09/26 01:21:54 dmitri Exp $  + * $Revision: 1.3 $
  + * $Date: 2001/09/26 01:21:54 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -74,7 +74,7 @@
    * A Pointer that points to a DOM node.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.2 $ $Date: 2001/09/21 23:22:45 $
  + * @version $Revision: 1.3 $ $Date: 2001/09/26 01:21:54 $
    */
   public class DOMNodePointer extends NodePointer {
       private Node node;
  @@ -84,8 +84,8 @@
       public static final String XML_NAMESPACE_URI = \
                "http://www.w3.org/XML/1998/namespace";
       public static final String XMLNS_NAMESPACE_URI = \
"http://www.w3.org/2000/xmlns/";  
  -    public DOMNodePointer(Node node){
  -        super(null);
  +    public DOMNodePointer(Node node, Locale locale){
  +        super(null, locale);
           this.node = node;
       }
   
  @@ -281,6 +281,34 @@
   
       public boolean isLeaf(){
           return !node.hasChildNodes();
  +    }
  +
  +    /**
  +     * Returns true if the xml:lang attribute for the current node
  +     * or its parent has the specified prefix <i>lang</i>.
  +     * If no node has this prefix, calls <code>super.isLanguage(lang)</code>.
  +     */
  +    public boolean isLanguage(String lang){
  +        String current = getLanguage();
  +        if (current == null){
  +            return super.isLanguage(lang);
  +        }
  +        return current.toUpperCase().startsWith(lang.toUpperCase());
  +    }
  +
  +    protected String getLanguage(){
  +        Node n = node;
  +        while (n != null){
  +            if (n.getNodeType() == Node.ELEMENT_NODE){
  +                Element e = (Element)n;
  +                String attr = e.getAttribute("xml:lang");
  +                if (attr != null && !attr.equals("")){
  +                    return attr;
  +                }
  +            }
  +            n = n.getParentNode();
  +        }
  +        return null;
       }
   
       /**
  
  
  
  1.4       +9 -6      \
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/DynamicPointer.java
  
  Index: DynamicPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/DynamicPointer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DynamicPointer.java	2001/09/21 23:22:45	1.3
  +++ DynamicPointer.java	2001/09/26 01:21:54	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/DynamicPointer.java,v \
                1.3 2001/09/21 23:22:45 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/09/21 23:22:45 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/DynamicPointer.java,v \
1.4 2001/09/26 01:21:54 dmitri Exp $  + * $Revision: 1.4 $
  + * $Date: 2001/09/26 01:21:54 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -74,7 +74,7 @@
    * for the first element of a path; following elements will by of type \
                PropertyPointer.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2001/09/21 23:22:45 $
  + * @version $Revision: 1.4 $ $Date: 2001/09/26 01:21:54 $
    */
   public class DynamicPointer extends PropertyOwnerPointer {
       private QName name;
  @@ -82,8 +82,11 @@
       private DynamicPropertyHandler handler;
       private String[] names;
   
  -    public DynamicPointer(QName name, Object bean, DynamicPropertyHandler \
                handler){
  -        this(null, name, bean, handler);
  +    public DynamicPointer(QName name, Object bean, DynamicPropertyHandler handler, \
Locale locale){  +        super(null, locale);
  +        this.name = name;
  +        this.bean = bean;
  +        this.handler = handler;
       }
   
       public DynamicPointer(NodePointer parent, QName name, Object bean, \
DynamicPropertyHandler handler){  
  
  
  1.4       +35 -10    \
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/NodePointer.java
  
  Index: NodePointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/NodePointer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NodePointer.java	2001/09/21 23:22:45	1.3
  +++ NodePointer.java	2001/09/26 01:21:54	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/NodePointer.java,v \
                1.3 2001/09/21 23:22:45 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/09/21 23:22:45 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/NodePointer.java,v \
1.4 2001/09/26 01:21:54 dmitri Exp $  + * $Revision: 1.4 $
  + * $Date: 2001/09/26 01:21:54 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -74,7 +74,7 @@
    * Common superclass for Poitners of all kinds.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2001/09/21 23:22:45 $
  + * @version $Revision: 1.4 $ $Date: 2001/09/26 01:21:54 $
    */
   public abstract class NodePointer implements Pointer, Cloneable {
   
  @@ -82,24 +82,24 @@
       protected int index = WHOLE_COLLECTION;
       public static String UNKNOWN_NAMESPACE = "<<unknown namespace>>";
   
  -    public static NodePointer createNodePointer(QName name, Object bean){
  +    public static NodePointer createNodePointer(QName name, Object bean, Locale \
locale){  if (bean == null){
  -            return new NullPointer(name);
  +            return new NullPointer(name, locale);
           }
           if (bean instanceof Node){
  -            return new DOMNodePointer((Node)bean);
  +            return new DOMNodePointer((Node)bean, locale);
           }
           if (bean instanceof Container){
  -            return new ContainerPointer((Container)bean);
  +            return new ContainerPointer((Container)bean, locale);
           }
   
           JXPathBeanInfo bi = JXPathIntrospector.getBeanInfo(bean.getClass());
           if (bi.isDynamic()){
               DynamicPropertyHandler handler = \
                PropertyAccessHelper.getDynamicPropertyHandler(bi.getDynamicPropertyHandlerClass());
                
  -            return new DynamicPointer(name, bean, handler);
  +            return new DynamicPointer(name, bean, handler, locale);
           }
           else {
  -            return new BeanPointer(name, bean, bi);
  +            return new BeanPointer(name, bean, bi, locale);
           }
       }
   
  @@ -201,11 +201,17 @@
       }
   
       protected NodePointer parent;
  +    protected Locale locale;
   
       protected NodePointer(NodePointer parent){
           this.parent = parent;
       }
   
  +    protected NodePointer(NodePointer parent, Locale locale){
  +        this.parent = parent;
  +        this.locale = locale;
  +    }
  +
       public NodePointer getParent(){
           return parent;
       }
  @@ -247,6 +253,25 @@
       public abstract Object getBaseValue();
       public abstract void setValue(Object value);
       public abstract boolean testNode(NodeTest nodeTest);
  +
  +    public Locale getLocale(){
  +        if (locale == null){
  +            if (parent != null){
  +                locale = parent.getLocale();
  +            }
  +        }
  +        return locale;
  +    }
  +
  +    /**
  +     * Returns true if the selected locale name starts
  +     * with the specified prefix <i>lang</i>, case-insensitive.
  +     */
  +    public boolean isLanguage(String lang){
  +        Locale loc = getLocale();
  +        String name = loc.toString().replace('_', '-');
  +        return name.toUpperCase().startsWith(lang.toUpperCase());
  +    }
   
       public String asPath(){
           StringBuffer buffer = new StringBuffer();
  
  
  
  1.4       +7 -6      \
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/NullPointer.java
  
  Index: NullPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/NullPointer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NullPointer.java	2001/09/21 23:22:45	1.3
  +++ NullPointer.java	2001/09/26 01:21:54	1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/NullPointer.java,v \
                1.3 2001/09/21 23:22:45 dmitri Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/09/21 23:22:45 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/NullPointer.java,v \
1.4 2001/09/26 01:21:54 dmitri Exp $  + * $Revision: 1.4 $
  + * $Date: 2001/09/26 01:21:54 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -71,13 +71,14 @@
   
   /**
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.3 $ $Date: 2001/09/21 23:22:45 $
  + * @version $Revision: 1.4 $ $Date: 2001/09/26 01:21:54 $
    */
   public class NullPointer extends PropertyOwnerPointer {
       private QName name;
   
  -    public NullPointer(QName name){
  -        this(null, name);
  +    public NullPointer(QName name, Locale locale){
  +        super(null, locale);
  +        this.name = name;
       }
   
       /**
  
  
  
  1.3       +12 -4     \
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/PropertyOwnerPointer.java
  
  Index: PropertyOwnerPointer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/PropertyOwnerPointer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PropertyOwnerPointer.java	2001/09/21 23:22:45	1.2
  +++ PropertyOwnerPointer.java	2001/09/26 01:21:54	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/PropertyOwnerPointer.java,v \
                1.2 2001/09/21 23:22:45 dmitri Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/09/21 23:22:45 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/PropertyOwnerPointer.java,v \
1.3 2001/09/26 01:21:54 dmitri Exp $  + * $Revision: 1.3 $
  + * $Date: 2001/09/26 01:21:54 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -75,7 +75,7 @@
    * a collection.
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.2 $ $Date: 2001/09/21 23:22:45 $
  + * @version $Revision: 1.3 $ $Date: 2001/09/26 01:21:54 $
    */
   public abstract class PropertyOwnerPointer extends NodePointer {
   
  @@ -153,7 +153,15 @@
           return true;
       }
   
  +    public NodeIterator attributeIterator(QName name){
  +        return new BeanAttributeIterator(this, name);
  +    }
  +
       public static int UNSPECIFIED_PROPERTY = Integer.MIN_VALUE;
  +
  +    protected PropertyOwnerPointer(NodePointer parent, Locale locale){
  +        super(parent, locale);
  +    }
   
       protected PropertyOwnerPointer(NodePointer parent){
           super(parent);
  
  
  
  1.1                  \
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/BeanAttributeIterator.java
  
  Index: BeanAttributeIterator.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/BeanAttributeIterator.java,v \
                1.1 2001/09/26 01:21:54 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2001/09/26 01:21:54 $
   *
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 2001, Plotnix, Inc,
   * <http://www.plotnix.com/>.
   * For more information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.pointers;
  
  import org.apache.commons.jxpath.*;
  import org.apache.commons.jxpath.ri.Compiler;
  import org.apache.commons.jxpath.ri.compiler.*;
  
  import java.lang.reflect.*;
  import java.util.*;
  import java.beans.*;
  import org.w3c.dom.*;
  
  /**
   * An iterator of attributes of a JavaBean. Currently supports only one
   * attribute - "lang".
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2001/09/26 01:21:54 $
   */
  public class BeanAttributeIterator implements NodeIterator {
      private NodePointer parent;
      private QName name;
      private int position = 0;
  
      public BeanAttributeIterator(NodePointer parent, QName name){
          this.parent = parent;
          this.name = name;
      }
  
      public NodePointer getNodePointer(){
          return new LangAttributePointer(parent);
      }
  
      public int getPosition(){
          return position;
      }
  
      public boolean setPosition(int position){
          this.position = position;
          return position == 1 && name.getPrefix() != null && \
                name.getPrefix().equals("xml") &&
              (name.getName().equals("lang") || name.getName().equals("*"));
      }
  }
  
  
  1.1                  \
jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/LangAttributePointer.java
  
  Index: LangAttributePointer.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/pointers/LangAttributePointer.java,v \
                1.1 2001/09/26 01:21:54 dmitri Exp $
   * $Revision: 1.1 $
   * $Date: 2001/09/26 01:21:54 $
   *
   * ====================================================================
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 2001, Plotnix, Inc,
   * <http://www.plotnix.com/>.
   * For more information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.commons.jxpath.ri.pointers;
  
  import org.apache.commons.jxpath.*;
  import org.apache.commons.jxpath.ri.Compiler;
  import org.apache.commons.jxpath.ri.compiler.*;
  
  import java.lang.reflect.*;
  import java.util.*;
  import java.beans.*;
  import org.w3c.dom.*;
  
  /**
   * A Pointer that points to the "lang" attribute of a JavaBean. The value
   * of the attribute is based on the locale supplied to it in the constructor.
   *
   * @author Dmitri Plotnikov
   * @version $Revision: 1.1 $ $Date: 2001/09/26 01:21:54 $
   */
  public class LangAttributePointer extends NodePointer {
      public LangAttributePointer(NodePointer parent){
          super(parent);
      }
  
      public QName getName(){
          return new QName(null, "lang");
      }
  
      public QName getExpandedName(){
          return getName();
      }
  
      public String getNamespaceURI(){
          return null;
      }
  
      public Object getBaseValue(){
          return parent.getLocale().toString().replace('_', '-');
      }
  
      public Object getValue(){
          return getBaseValue();
      }
  
      public boolean isLeaf(){
          return true;
      }
  
      /**
       * Throws UnsupportedOperationException.
       */
      public void setValue(Object value){
          throw new UnsupportedOperationException("Cannot change locale using the \
'lang' attribute");  }
  
      /**
       */
      public String asPath(){
          StringBuffer buffer = new StringBuffer();
          if (parent != null){
              buffer.append(parent.asPath());
              buffer.append('/');
          }
          buffer.append("@xml:lang");
          return buffer.toString();
      }
  
      public int hashCode(){
          return 0;
      }
  
      public boolean equals(Object object){
          if (object == this){
              return true;
          }
  
          if (!(object instanceof LangAttributePointer)){
              return false;
          }
  
          return true;
      }
  
      public boolean testNode(NodeTest test){
          return false;
      }
  }
  
  
  1.8       +18 -7     \
jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java  
  Index: JXPathTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JXPathTestCase.java	2001/09/21 23:30:32	1.7
  +++ JXPathTestCase.java	2001/09/26 01:21:54	1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java,v \
                1.7 2001/09/21 23:30:32 dmitri Exp $
  - * $Revision: 1.7 $
  - * $Date: 2001/09/21 23:30:32 $
  + * $Header: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/JXPathTestCase.java,v \
1.8 2001/09/26 01:21:54 dmitri Exp $  + * $Revision: 1.8 $
  + * $Date: 2001/09/26 01:21:54 $
    *
    * ====================================================================
    * The Apache Software License, Version 1.1
  @@ -93,7 +93,7 @@
    * </p>
    *
    * @author Dmitri Plotnikov
  - * @version $Revision: 1.7 $ $Date: 2001/09/21 23:30:32 $
  + * @version $Revision: 1.8 $ $Date: 2001/09/26 01:21:54 $
    */
   
   public class JXPathTestCase extends TestCase
  @@ -181,7 +181,7 @@
       }
   
       private void testIndividual(int relativePropertyIndex, int offset, boolean \
                useStartLocation, boolean reverse, int expected){
  -        PropertyOwnerPointer root = \
(PropertyOwnerPointer)NodePointer.createNodePointer(new QName(null, "root"), bean);  \
+        PropertyOwnerPointer root = \
(PropertyOwnerPointer)NodePointer.createNodePointer(new QName(null, "root"), bean, \
Locale.getDefault());  NodeIterator it;
   
           if (useStartLocation){
  @@ -219,7 +219,7 @@
       }
   
       private void testMultiple(int propertyIndex, int offset, boolean \
                useStartLocation, boolean reverse, int expected){
  -        PropertyOwnerPointer root = \
(PropertyOwnerPointer)NodePointer.createNodePointer(new QName(null, "root"), bean);  \
+        PropertyOwnerPointer root = \
(PropertyOwnerPointer)NodePointer.createNodePointer(new QName(null, "root"), bean, \
Locale.getDefault());  NodeIterator it;
   
           if (useStartLocation){
  @@ -471,6 +471,7 @@
       }
   
       public void testParser(JXPathContext ctx, boolean ignorePath){
  +        ctx.setLocale(Locale.US);
           ctx.getVariables().declareVariable("a", new Double(1));
           ctx.getVariables().declareVariable("b", new Double(1));
           ctx.getVariables().declareVariable("nan", new Double(Double.NaN));
  @@ -618,7 +619,7 @@
           test("count(set)", new Double(3)),
           test("boolean", Boolean.FALSE),
           testEval("foo:boolean", list()),
  -        test("@*", null),
  +        test("count(@*)", new Double(0)),
           testPath("boolean", "/boolean"),
           testEvalPath("boolean", list("/boolean")),
           test("nestedBean/name", "Name 0"),
  @@ -764,7 +765,13 @@
           test("round(1.5)", new Double(2)),
           test("round(-1.5)", new Double(-1)),
           test("null()", null),
  +        test("@xml:lang", "en-US"),
  +        test("count(@xml:*)", new Double(1)),
  +        test("@foo", null),
  +        test("lang('en')", Boolean.TRUE),
  +        test("lang('fr')", Boolean.FALSE),
   
  +
           // Extension functions
           test("string(test:new())", "foo=0; bar=null"),
           test("string(jxpathtest:TestFunctions.new())", "foo=0; bar=null"),
  @@ -865,6 +872,7 @@
               XMLDocumentContainer docCtr = new \
XMLDocumentContainer(getClass().getResource("Test.properties"));  Document doc = \
                (Document)docCtr.getValue();
               JXPathContext ctx = \
JXPathContextFactory.newInstance().newContext(null, doc);  +            \
ctx.setLocale(Locale.US);  ctx.getVariables().declareVariable("dom", doc);
               ctx.getVariables().declareVariable("object", docCtr);
               TestBeanWithDOM tbwdom = new TestBeanWithDOM();
  @@ -936,6 +944,9 @@
           testPath("//nsnode/processing-instruction('do')", \
"/vendor[1]/nsnode[1]/processing-instruction('do')[1]"),  \
test("name(//nsnode/processing-instruction()[1])", "go"),  
  +        test("//nsnode/baz/@xml:lang", "fr"),
  +        test("//nsnode/baz[lang('fr')]", "BAZ"),
  +        test("//nsnode/foo:x[lang('en')]/y", "why"),
           test("vendor/location/@blank", ""),
           test("vendor/location/@missing", null),
           test("count(vendor/location[1]/@*)", new Double(3)),
  
  
  
  1.3       +1 -1      \
jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/Test.properties  
  Index: Test.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/Test.properties,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Test.properties	2001/09/21 23:22:45	1.2
  +++ Test.properties	2001/09/26 01:21:54	1.3
  @@ -14,7 +14,7 @@
     <nsnode xmlns="somenamespace" xmlns:foo="foonamespace" xmlns:zoo="foonamespace">
        text
        <foo:bar foo:attr="A" attr="B">BAR</foo:bar>
  -     <baz>BAZ</baz>
  +     <baz xml:lang="fr">BAZ</baz>
        <foo:x>
           <y>why</y>
        </foo:x>
  
  
  


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic