cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: cocoon-2.1/src/java/org/apache/cocoon/components/xpointer/parser XPointerFrameworkParser.java XPointerFrameworkParserTokenManager.java xpointer-fw.jj
Date Fri, 04 Jul 2003 09:43:36 GMT
bruno       2003/07/04 02:43:36

  Modified:    src/java/org/apache/cocoon/components/xpointer/parser
                        XPointerFrameworkParser.java
                        XPointerFrameworkParserTokenManager.java
                        xpointer-fw.jj
  Log:
  Updated parser to support elementpath xpointer scheme, meanwhile made scheme names namespace-aware.
  
  Revision  Changes    Path
  1.2       +32 -15    cocoon-2.1/src/java/org/apache/cocoon/components/xpointer/parser/XPointerFrameworkParser.java
  
  Index: XPointerFrameworkParser.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/xpointer/parser/XPointerFrameworkParser.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XPointerFrameworkParser.java	20 May 2003 11:57:14 -0000	1.1
  +++ XPointerFrameworkParser.java	4 Jul 2003 09:43:35 -0000	1.2
  @@ -2,12 +2,14 @@
     package org.apache.cocoon.components.xpointer.parser;
   
     import org.apache.cocoon.components.xpointer.*;
  +  import java.util.HashMap;
   
     public class XPointerFrameworkParser implements XPointerFrameworkParserConstants {
       private XPointer xpointer = new XPointer();
  +    private HashMap namespaces = new HashMap();
   
       public static void main(String [] args) throws Exception {
  -      System.out.println("zal dit parsen: " + args[0]);
  +      System.out.println("will parse this: " + args[0]);
         XPointerFrameworkParser xfp = new XPointerFrameworkParser(new java.io.StringReader(args[0]));
         xfp.pointer();
       }
  @@ -126,8 +128,20 @@
         // when going outside the scheme data, swith back to the default lexical state
         token_source.SwitchTo(DEFAULT);
   
  +      // parse schemeName in prefix and localName
  +      String schemeNamespace = null, schemeLocalName = null;
  +      int colonPos = schemeName.indexOf(':');
  +      if (colonPos != -1) {
  +         String schemePrefix = schemeName.substring(0, colonPos);
  +         schemeNamespace = (String)namespaces.get(schemePrefix);
  +         schemeLocalName = schemeName.substring(colonPos + 1);
  +       } else {
  +         schemeLocalName = schemeName;
  +       }
  +
  +
         // add the pointer part
  -      if (schemeName.equals("xmlns")) {
  +      if (schemeNamespace == null && schemeLocalName.equals("xmlns")) {
           int eqPos = schemeData.indexOf("=");
           if (eqPos == -1)
             {if (true) throw new ParseException("xmlns scheme data should contain an equals
sign");}
  @@ -137,8 +151,11 @@
           String prefix = schemeData.substring(0, eqPos).trim();
           String namespace = schemeData.substring(eqPos + 1, schemeData.length()).trim();
           xpointer.addPart(new XmlnsPart(prefix, namespace));
  -      } else if (schemeName.equals("xpointer")) {
  +        namespaces.put(prefix, namespace);
  +      } else if (schemeNamespace == null && schemeLocalName.equals("xpointer"))
{
           xpointer.addPart(new XPointerPart(schemeData));
  +      } else if ("http://apache.org/cocoon/xpointer".equals(schemeNamespace) &&
schemeLocalName.equals("elementpath")) {
  +        xpointer.addPart(new ElementPathPart(schemeData));
         } else {
           xpointer.addPart(new UnsupportedPart(schemeName));
         }
  @@ -213,18 +230,6 @@
       return retval;
     }
   
  -  final private boolean jj_3R_7() {
  -    if (jj_scan_token(QName)) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
  -  final private boolean jj_3_1() {
  -    if (jj_3R_4()) return true;
  -    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  -    return false;
  -  }
  -
     final private boolean jj_3R_6() {
       if (jj_scan_token(NCName)) return true;
       if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  @@ -246,6 +251,18 @@
       if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
       } else if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
       if (jj_scan_token(LBRACE)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3R_7() {
  +    if (jj_scan_token(QName)) return true;
  +    if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
  +    return false;
  +  }
  +
  +  final private boolean jj_3_1() {
  +    if (jj_3R_4()) return true;
       if (jj_la == 0 && jj_scanpos == jj_lastpos) return false;
       return false;
     }
  
  
  
  1.3       +2 -0      cocoon-2.1/src/java/org/apache/cocoon/components/xpointer/parser/XPointerFrameworkParserTokenManager.java
  
  Index: XPointerFrameworkParserTokenManager.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/xpointer/parser/XPointerFrameworkParserTokenManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XPointerFrameworkParserTokenManager.java	23 May 2003 07:29:57 -0000	1.2
  +++ XPointerFrameworkParserTokenManager.java	4 Jul 2003 09:43:36 -0000	1.3
  @@ -1,5 +1,7 @@
   /* Generated By:JavaCC: Do not edit this line. XPointerFrameworkParserTokenManager.java
*/
   package org.apache.cocoon.components.xpointer.parser;
  +import org.apache.cocoon.components.xpointer.*;
  +import java.util.HashMap;
   
   public class XPointerFrameworkParserTokenManager implements XPointerFrameworkParserConstants
   {
  
  
  
  1.2       +20 -3     cocoon-2.1/src/java/org/apache/cocoon/components/xpointer/parser/xpointer-fw.jj
  
  Index: xpointer-fw.jj
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/xpointer/parser/xpointer-fw.jj,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- xpointer-fw.jj	20 May 2003 11:57:14 -0000	1.1
  +++ xpointer-fw.jj	4 Jul 2003 09:43:36 -0000	1.2
  @@ -66,12 +66,14 @@
     package org.apache.cocoon.components.xpointer.parser;
   
     import org.apache.cocoon.components.xpointer.*;
  +  import java.util.HashMap;
   
     public class XPointerFrameworkParser {
       private XPointer xpointer = new XPointer();
  +    private HashMap namespaces = new HashMap();
   
       public static void main(String [] args) throws Exception {
  -      System.out.println("zal dit parsen: " + args[0]);
  +      System.out.println("will parse this: " + args[0]);
         XPointerFrameworkParser xfp = new XPointerFrameworkParser(new java.io.StringReader(args[0]));
         xfp.pointer();
       }
  @@ -266,8 +268,20 @@
         // when going outside the scheme data, swith back to the default lexical state
         token_source.SwitchTo(DEFAULT);
   
  +      // parse schemeName in prefix and localName
  +      String schemeNamespace = null, schemeLocalName = null;
  +      int colonPos = schemeName.indexOf(':');
  +      if (colonPos != -1) {
  +         String schemePrefix = schemeName.substring(0, colonPos);
  +         schemeNamespace = (String)namespaces.get(schemePrefix);
  +         schemeLocalName = schemeName.substring(colonPos + 1);
  +       } else {
  +         schemeLocalName = schemeName;
  +       }
  +
  +
         // add the pointer part
  -      if (schemeName.equals("xmlns")) {
  +      if (schemeNamespace == null && schemeLocalName.equals("xmlns")) {
           int eqPos = schemeData.indexOf("=");
           if (eqPos == -1)
             throw new ParseException("xmlns scheme data should contain an equals sign");
  @@ -277,8 +291,11 @@
           String prefix = schemeData.substring(0, eqPos).trim();
           String namespace = schemeData.substring(eqPos + 1, schemeData.length()).trim();
           xpointer.addPart(new XmlnsPart(prefix, namespace));
  -      } else if (schemeName.equals("xpointer")) {
  +        namespaces.put(prefix, namespace);
  +      } else if (schemeNamespace == null && schemeLocalName.equals("xpointer"))
{
           xpointer.addPart(new XPointerPart(schemeData));
  +      } else if ("http://apache.org/cocoon/xpointer".equals(schemeNamespace) &&
schemeLocalName.equals("elementpath")) {
  +        xpointer.addPart(new ElementPathPart(schemeData));
         } else {
           xpointer.addPart(new UnsupportedPart(schemeName));
         }
  
  
  

Mime
View raw message