You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by aw...@apache.org on 2007/03/15 21:37:43 UTC

svn commit: r518760 - in /incubator/adffaces/trunk/plugins/maven-xrts-plugin: ./ src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/

Author: awiner
Date: Thu Mar 15 14:37:42 2007
New Revision: 518760

URL: http://svn.apache.org/viewvc?view=rev&rev=518760
Log:
ADFFACES-411: xrts plugin should support metadata content
- Element content within <resource> will now just be ignored
- Deleted all of the unused <set> and <values> parsing code, and matching hooks in RTSWriter
- Some code cleanup (Dictionary -> Map, etc.) for code that was written back in the JDK 1.1 days

Removed:
    incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/OrderedDictionary.java
Modified:
    incubator/adffaces/trunk/plugins/maven-xrts-plugin/pom.xml
    incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/AbstractGenerateSourcesMojo.java
    incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/GenerateSourcesMojo.java
    incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/GenerateTestSourcesMojo.java
    incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/ListRTSWriter.java
    incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/RTSWriter.java
    incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/XRTSGenerator.java
    incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/XRTSParser.java

Modified: incubator/adffaces/trunk/plugins/maven-xrts-plugin/pom.xml
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/plugins/maven-xrts-plugin/pom.xml?view=diff&rev=518760&r1=518759&r2=518760
==============================================================================
--- incubator/adffaces/trunk/plugins/maven-xrts-plugin/pom.xml (original)
+++ incubator/adffaces/trunk/plugins/maven-xrts-plugin/pom.xml Thu Mar 15 14:37:42 2007
@@ -32,6 +32,25 @@
   <packaging>maven-plugin</packaging>
   <name>Apache Trinidad Maven XRTS Plugin</name>
 
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <inherited>true</inherited>
+          <configuration>
+            <source>1.5</source>
+            <target>1.5</target>
+            <showWarnings>true</showWarnings>
+            <compilerArgument>-Xlint:all,-serial,-fallthrough</compilerArgument>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+
   <dependencies>
     <dependency>
       <groupId>org.apache.maven</groupId>

Modified: incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/AbstractGenerateSourcesMojo.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/AbstractGenerateSourcesMojo.java?view=diff&rev=518760&r1=518759&r2=518760
==============================================================================
--- incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/AbstractGenerateSourcesMojo.java (original)
+++ incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/AbstractGenerateSourcesMojo.java Thu Mar 15 14:37:42 2007
@@ -24,8 +24,8 @@
 import java.io.InputStream;
 
 import java.util.Arrays;
-import java.util.Dictionary;
-import java.util.Hashtable;
+import java.util.Map;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -93,7 +93,7 @@
       if (xrtsFiles.length > 0)
       {
         RTSWriter writer = getRTSWriter();
-        Dictionary params = new Hashtable();
+        Map params = new HashMap();
 
         List dirtyXRTS = new LinkedList(Arrays.asList(xrtsFiles));
         SAXParserFactory factory = SAXParserFactory.newInstance();

Modified: incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/GenerateSourcesMojo.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/GenerateSourcesMojo.java?view=diff&rev=518760&r1=518759&r2=518760
==============================================================================
--- incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/GenerateSourcesMojo.java (original)
+++ incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/GenerateSourcesMojo.java Thu Mar 15 14:37:42 2007
@@ -63,7 +63,7 @@
 
   protected String[] getExcludes()
   {
-	return excludes;
+    return excludes;
   }
 
   protected void addCompileSourceRoot() throws IOException

Modified: incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/GenerateTestSourcesMojo.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/GenerateTestSourcesMojo.java?view=diff&rev=518760&r1=518759&r2=518760
==============================================================================
--- incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/GenerateTestSourcesMojo.java (original)
+++ incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/GenerateTestSourcesMojo.java Thu Mar 15 14:37:42 2007
@@ -63,7 +63,7 @@
 
   protected String[] getExcludes()
   {
-	return testExcludes;
+    return testExcludes;
   }
 
   protected void addCompileSourceRoot() throws IOException

Modified: incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/ListRTSWriter.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/ListRTSWriter.java?view=diff&rev=518760&r1=518759&r2=518760
==============================================================================
--- incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/ListRTSWriter.java (original)
+++ incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/ListRTSWriter.java Thu Mar 15 14:37:42 2007
@@ -22,7 +22,7 @@
 import java.io.File;
 import java.io.FileWriter;
 import java.io.PrintWriter;
-import java.util.Dictionary;
+import java.util.Map;
 //import java.util.StringTokenizer;
 
 
@@ -50,11 +50,11 @@
    * <code>RTSWriter</code> method implementation to write the header of the
    * <code>ListResourceBundle</code> file.
    *
-   * @param parms a <code>Dictionary</code> of command line parameters.
-   * @param meta a <code>Dictionary</code> of parsed non-resource data
+   * @param parms a <code>Map</code> of command line parameters.
+   * @param meta a <code>Map</code> of parsed non-resource data
    * (e.g., authors).
    */
-  public void startBundle(Dictionary parms, Dictionary meta)
+  public void startBundle(Map parms, Map meta)
     throws Throwable
   {
     File outFile = (File)parms.get("outFile");
@@ -107,66 +107,29 @@
     _pw.println("  static final Object[][] contents = {");
   }
 
-  protected void writeImports(Dictionary parms, Dictionary meta)
+  protected void writeImports(Map parms, Map meta)
      throws Throwable
   {
   }
 
-  public void writeString(Dictionary parms, Dictionary meta, String key,
-    String value, Dictionary attr) throws Throwable
+  public void writeString(Map parms, Map meta, String key,
+    String value) throws Throwable
   {
     _pw.println("    {\"" + UnicodeEscapes.convert(key) + "\", \"" +
                 UnicodeEscapes.convert(value) + "\"},");
-
-// Comments can be preserved with RTS.  The commented out code below
-// was for demonstrating that this worked properly.  As comments are
-// not required in the ListResourceBundle, this code is here only to guide
-// developers in their RTSWriter interface implementation.
-//      String comments = rts.getComment(key);
-//      if (comments.length() > 0 )
-//      {
-//        StringTokenizer st = new StringTokenizer(comments, "\n");
-//        while (st.hasMoreTokens())
-//          _pw.println("// " + st.nextToken());
-//      }
-
   }
 
 
-  public void writeStringArray(Dictionary parms, Dictionary meta, String key,
-   String[] strArr, Dictionary[] attrs) throws Throwable
-  {
-    _pw.println("    {\"" + key + "\",");
-    _pw.println("       new String[] {");
-
-    for (int i = 0; i < (strArr.length - 1); i++)
-      _pw.println("           \"" + UnicodeEscapes.convert(strArr[i]) + "\",");
-    // the last line of the string array shouldn't have a comma
-
-    _pw.println("           \"" +
-                UnicodeEscapes.convert(strArr[strArr.length-1]) + "\"");
-    _pw.println("       }");
-    _pw.println("    },");
-  }
-
-  public void writeDictionary(Dictionary parms, Dictionary meta, String key,
-    Dictionary kvps, Dictionary attrs) throws Throwable
-  {
-    System.err.println("Dictionary \'" + key + "\' was found in XML-based " +
-      "RTS, but is not supported by ListResourceBundle.  Use XRTSMakeBundle " +
-      "subkey instead.");
-  }
-
   /**
    * <code>RTSWriter</code> method implementation to close the file stream
    * required for the <code>ListResourceBundle</code>.  Before closing, this
    * method also writes the footer portions of the file.  The footer portions
    * consist of little more than closing braces.
    *
-   * @param meta a <code>Dictionary</code> of parsed non-resource data
+   * @param meta a <code>Map</code> of parsed non-resource data
    * (e.g., authors).
    */
-  public void endBundle(Dictionary parms, Dictionary meta) throws Throwable
+  public void endBundle(Map parms, Map meta) throws Throwable
   {
     _pw.println("  };");
     _pw.println("}");

Modified: incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/RTSWriter.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/RTSWriter.java?view=diff&rev=518760&r1=518759&r2=518760
==============================================================================
--- incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/RTSWriter.java (original)
+++ incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/RTSWriter.java Thu Mar 15 14:37:42 2007
@@ -18,8 +18,7 @@
  */
 package org.apache.myfaces.trinidadbuild.plugin.xrts;
 
-import java.util.Dictionary;
-import java.util.Enumeration;
+import java.util.Map;
 
 /**
  * The <code>RTSWriter</code> interface defines methods for writing the
@@ -28,71 +27,13 @@
  * The methods <code>startBundle</code> and <code>endBundle</code> write the
  * header and footer portions to the output.  The methods for writing the
  * body are <code>writeString</code>, <code>writeStringArray</code>, and
- * <code>writeDictionary</code>. These methods are supplied with data parsed
+ * <code>writeMap</code>. These methods are supplied with data parsed
  * by the XML-based RTS file <code>XRTSParser</code> or the
  * <code>RTSProperties</code> parser.<p>
  *
- * RTS provides two basic implementations of RTSWriter --
- * <code>ListRTSWriter</code> and <code>DefaultSubkeyRTSWriter</code>. <p>
- *
- * <code>ListRTSWriter</code> writes parsed data into a Sun
- * <code>ListResourceBundle</code> file.  It utilizes the <code>writeString</code>
- * and <code>writeStringArray</code> methods.  Data stored in Dictionary format
- * cannot be processed by <code>ListResourceBundle</code>s and
- * <code>ListRTSWriter</code> will throw an exception. <p>
- *
- * Those consumers with a requirement to store and process
- * <code>Dictionary</code> format information should use
- * <code>DefaultSubkeyResourceBundle</code>. <code>DefaultSubkeyRTSWriter</code>
- * writes parsed data to an Oracle RTS <code>DefaultSubkeyResourceBundle</code>
- * file. <code>DefaultSubkeyResourceBundle</code> is capable of storing not only
- * <code>String</code> and <code>String</code> array data as
- * <code>ListResourceBundle</code>, but also <code>Dictionary</code> data that
- * is stored as subkey/value pairs as well. <p>
- *
- * These two implementations of <code>RTSWriter</code> provided by RTS only
- * write Java output files.  However, <code>RTSWriter</code> is an extremely
- * powerful interface and is designed to support the output of any file type.
- * That is, RTS consumers can write their own implementations of
- * <code>RTSWriter</code> to output files type such as HTML, XSL, CSS, XML, etc.
- * Moreover, the output of <code>RTSWriter</code> is not limited to just
- * files.  For example, <code>RTSWriter</code> could be used to implement
- * writing parsed data to the database using SQLJ, JDBC, or even a SQL loader.
- * <p>
- *
- * Consumers developing their own implementations of <code>RTSWriter</code> will
- * need to make sure that the implementation is registered in the Config.txt
- * file.  By default, Config.txt contains registrations for the list and subkey
- * implementations.  The format of Config.txt matches that of a text-based RTS
- * file.  That is, a key, followed by an equal sign '=', followed by the value.
- * The key is the command line parameter that XXXMakeBundle calls.  The value is
- * the fully qualified class name of the <code>RTSWriter</code> implementation.
- *  The following is the text contained in the default Config.txt:
- * <blockquote>
- * <pre>
- * subkey = oracle.bali.rts.tools.DefaultSubkeyRTSWriter
- * list = oracle.bali.rts.tools.ListRTSWriter
- * </pre>
- * </blockquote>
- *
- * Each method in this interface includes a <code>parms</code> and
- * <code>meta Dictionary</code>.  The <code>parms dictionary</code> contains
- * <code>String</code> keys and values representing the command line parameters
- * for the make tool. <p>
- *
- * In this release, the <code>meta Dictionary</code> is not fully utilized.  It
- * is intended to contain information that contained in the XML-based RTS source
- * file, but external to the resource element information.  The final release of
- * RTS 2.0 will better define this structure's contents.
- *
  * @see ListRTSWriter
- * @see DefaultSubkeyRTSWriter
- * @see RTSMakeBundle
- * @see XRTSMakeBundle
  *
  * @version $Name:  $ ($Revision: 1.7 $) $Date: 2001/04/09 23:22:22 $
- * @author Craig R. Cummings (crcummin@us.oracle.com)
- * @since RTS 1.5
  */
 public interface RTSWriter
 {
@@ -100,11 +41,11 @@
   /**
    * Writes the <file or other output header(s).
    *
-   * @param parms a <code>Dictionary</code> of command line parameters.
-   * @param meta a <code>Dictionary</code> of parsed non-resource data
+   * @param parms a <code>Map</code> of command line parameters.
+   * @param meta a <code>Map</code> of parsed non-resource data
    * (e.g., package).
    */
-  public void startBundle(Dictionary parms, Dictionary meta)
+  public void startBundle(Map parms, Map meta)
     throws Throwable;
 
   /**
@@ -113,98 +54,29 @@
    * This is the typical case use.  A single <code>String</code> key associated
    * with a single <code>String</code> value forming a key/value pair (kvp).
    * Note that the other two body methods, <code>writeStringArray</code> and
-   * <code>writeDictionary</code> both support a single <code>String</code>
+   * <code>writeMap</code> both support a single <code>String</code>
    * key associated with multiple values. <p>
    *
    * A key/value pair may have associated attributes in the RTS file.
    * In this method, these are received from the XML parser as a
-   * <code>Dictionary</code>. <p>
+   * <code>Map</code>. <p>
    *
-   * @param parms a <code>Dictionary</code> of command line parameters
-   * @param meta a <code>Dictionary</code> of parsed non-resource data
+   * @param parms a <code>Map</code> of command line parameters
+   * @param meta a <code>Map</code> of parsed non-resource data
    * (e.g., package).
    * @param key a <code>String</code> key.
    * @param value a <code>String</code> value.
-   * @param attr a <code>Dictionary</code> containing any XML attributes
-   * assciated with the resource element.
-   *
-   * The <code>attr Dictionary</code> contains a <code>String</code> key which
-   * is the attribute name and a <code>String</code> value for the given
-   * attribute name (typically the text in the source RTS file that
-   * appears to the right of the equals '=' sign of an attribute key).
-   */
-  public void writeString(Dictionary parms, Dictionary meta, String key,
-    String value, Dictionary attr) throws Throwable;
-
-  /**
-   * Writes an array of <code>String</code> to the implementation body output.
-   * <p>
-   *
-   * If the <code>String</code> array <code>kvpArr</code> has n values then the
-   * array of <code>Dictionary attrs</code> will have n+1 values.  Each
-   * <code>Dictionary</code> in the array with an index from 0-n will be
-   * the attributes for the <code>String</code> in the <code>String</code> array
-   * of the same index.  The <code>Dictionary</code> of attributes at index n+1
-   * will be that of the 'values' element from the RTS file. <p>
-   *
-   * @param parms a <code>Dictionary</code> of command line parameters
-   * @param meta a <code>Dictionary</code> of parsed non-resource data
-   * (e.g., package).
-   * @param key a <code>String</code> key.
-   * @param kvpArr an array of <code>String</code> values
-   * pairs.
-   * @param attrs an array of <code>Dictionary</code> where each
-   * <code>Dictionary</code> contains any XML attributes assciated with a
-   * given <code>String</code> in the kvpArr array.
-   *
-   * The contents of each attribute <code>Dictionary</code> in the array is
-   * a <code>String</code> key which is the attribute name and a value which is
-   * the <code>String</code> value for the given attribute name (typically the
-   * text that appears to the right of the equals '=' sign of an attribute key.
-   */
-  public void writeStringArray(Dictionary parms, Dictionary meta, String key,
-    String[] kvpArr, Dictionary[] attrs) throws Throwable;
-
-  /**
-   * Writes a <code>Dictionary</code> to the implementation body output. <p>
-   *
-   * If the <code>Dictionary kvps</code> contains subkeys which are
-   * <code>String</code> element names of the child elements of 'set' in the
-   * RTS file.  The <code>Dictionary kvps</code> also contains values
-   * associated the the various subkeys which are <code>String</code> values
-   * from the XML file -- the string that appears between child start and end
-   * elements. <p>
-   *
-   * @param parms a <code>Dictionary</code> of command line parameters.
-   * @param meta a <code>Dictionary</code> of parsed non-resource data
-   * (e.g., package).
-   * @param key a <code>String</code> key.
-   * @param kvps a <code>Dictionary</code> with ordered subkey/
-   * <code>String</code> value pairs.
-   * @param attrs a <code>Dictionary</code> of XML attributes assciated with a
-   * given subkey. 
-   *
-   * The contents of the <code>attrs Dictionary</code> are keys that match the
-   * name of the child elements or subkey.  The values of the
-   * <code>attrs Dictionary</code> are <code>Dictionary</code> objects
-   * themselves.  These nested Dictionary value objects contain key/value pairs.
-   * The key is a <code>String</code> attribute name and the value is a
-   * <code>String</code> the value for the given attribute name.
-   *
-   * Typical use cases will probably not require attributes for any of
-   * the child elements.  Just the same, RTS is able to support attributes for
-   * these subkey/child elements.
    */
-  public void writeDictionary(Dictionary parms, Dictionary meta, String key,
-    Dictionary kvps, Dictionary attrs) throws Throwable;
+  public void writeString(Map parms, Map meta, String key,
+    String value) throws Throwable;
 
   /**
    * Writes the file or other output footer(s).
    *
-   * @param parms a <code>Dictionary</code> of command line parameters.
-   * @param meta a <code>Dictionary</code> of parsed non-resource data
+   * @param parms a <code>Map</code> of command line parameters.
+   * @param meta a <code>Map</code> of parsed non-resource data
    * (e.g., package).
    */
-  public void endBundle(Dictionary parms, Dictionary meta) throws Throwable;
+  public void endBundle(Map parms, Map meta) throws Throwable;
 
 }

Modified: incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/XRTSGenerator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/XRTSGenerator.java?view=diff&rev=518760&r1=518759&r2=518760
==============================================================================
--- incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/XRTSGenerator.java (original)
+++ incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/XRTSGenerator.java Thu Mar 15 14:37:42 2007
@@ -18,13 +18,7 @@
  */
 package org.apache.myfaces.trinidadbuild.plugin.xrts;
 
-import java.io.File;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.StringTokenizer;
-import java.util.Vector;
+import java.util.Map;
 
 import javax.xml.parsers.SAXParser;
 
@@ -52,32 +46,14 @@
    * @param parser see class description.
    * @param is the XML-based RTS source file.
    * @param rtsw an <code>RTSWriter</code> implementation.
-   * @param parms a <code>Dictionary</code> of command line parameters.
+   * @param parms a <code>Map</code> of command line parameters.
    *
    */
   public static void generate(SAXParser parser, InputSource is, RTSWriter rtsw,
-    Dictionary parms) throws Throwable
+    Map parms) throws Throwable
   {
     XRTSParser rtsp = new XRTSParser(rtsw, parms);
-
-    try
-    {
-      parser.parse(is, rtsp);
-    }
-    catch (IOException ioe)
-    {
-      System.err.println(ioe);
-      System.exit(1);
-    }
-    catch (SAXParseException spe)
-    {
-      System.exit(1);
-    }
-    catch (SAXException se)
-    {
-      System.err.println(se);
-      System.exit(1);
-    }
+    parser.parse(is, rtsp);
   }
 
   //

Modified: incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/XRTSParser.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/XRTSParser.java?view=diff&rev=518760&r1=518759&r2=518760
==============================================================================
--- incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/XRTSParser.java (original)
+++ incubator/adffaces/trunk/plugins/maven-xrts-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/xrts/XRTSParser.java Thu Mar 15 14:37:42 2007
@@ -18,11 +18,11 @@
  */
 package org.apache.myfaces.trinidadbuild.plugin.xrts;
 
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Stack;
-import java.util.Vector;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.List;
 
 import org.xml.sax.AttributeList;
 import org.xml.sax.HandlerBase;
@@ -32,27 +32,7 @@
 import org.xml.sax.SAXParseException;
 
 /**
- *
- * Data stored in the XML-based RTS format is parsed by <code>XRTSParser</code>.
- * The data in the resource elements is parsed into a Vector of Tuples.  The
- * data for other elements that do not have &lt;resource&gt; as their element
- * name (e.g., &lt;authors&gt;) are parsed into a <code>Hashtable</code> of
- * <code>Tuple</code>s. <p>
- *
- * The key attribute of the resource element is set to the key of the Tuple.
- * Any other attributes
- * for the resource element are set in the attribute Hashtable for the Tuple.
- * The translatable value of the resource element is the text between the start
- * of the element and the end of the element.  If the value is simply a String,
- * then it is set in the value of the Tuple.  If the value is a String array,
- * the value of the Tuple is set to a Vector of tuples that are built through
- * subsequent parsing.  If the value is a Dictionary, then the value of the
- * tuple is set to a Dictionary of Tuples that are built through subsequent
- * parsing. <p>
- *
- * @version $Name:  $ ($Revision: 1.1 $) $Date: 2001/04/09 23:23:22 $
- * @author Craig R. Cummings
- */
+ * */
 final class XRTSParser extends HandlerBase
 {
 
@@ -64,10 +44,10 @@
   {
   }
 
-  public XRTSParser(RTSWriter bw, Dictionary parms)
+  public XRTSParser(RTSWriter bw, Map parms)
   {
     _bundleWriter = bw;
-    _parms = (Hashtable)parms;
+    _parms = parms;
   }
 
   /**
@@ -89,10 +69,6 @@
    */
   public void startDocument() throws SAXException
   {
-//    System.out.println("StartDocument");
-    _xmlTagStack = new Stack();
-    if (_metaHt == null)
-      _metaHt = new Hashtable();
     _metaHt.put("fileType", "xrts");
     _startDoc = true;
 
@@ -123,72 +99,45 @@
    */
   public void startElement(String name, AttributeList atts) throws SAXException
   {
-//    System.out.println("StartElement:"+name);
-    Hashtable _attsHt = new Hashtable();
     _nestingLevel++;
 
-    if (name.equals("values"))
-      _inValues = true;
-    else if (name.equals("set"))
-      _inSet = true;
-
     // startBundle doesn't go in the startDocument method because it
     // requires metadata to be passed and in particular, requires
     // at least the package for any implementation of startBundle to work
-    else if (name.equals("resource") && _startDoc)
-      try
+    if ((_nestingLevel == 2) && name.equals("resource"))
+    {
+      if (_startDoc)
       {
-        _bundleWriter.startBundle(_parms, _metaHt);
-        _startDoc = false;
+        try
+        {
+          _bundleWriter.startBundle(_parms, _metaHt);
+          _startDoc = false;
+        }
+        catch (Throwable th)
+        {
+          throw new SAXException("startBundle Exception: " + th.getMessage());
+        }
       }
-      catch (Throwable th)
+
+      _currentResourceKey = atts.getValue("key");
+      if (_uniqKeys.contains(_currentResourceKey))
       {
-        throw new SAXException("startBundle Exception: " + th.getMessage());
+        System.err.println("Duplicate id \"" + _currentResourceKey + "\"");
       }
 
-    if (name.equals("resources"))
+      _uniqKeys.add(_currentResourceKey);
+      
+
+      _currentResourceValue = new StringBuilder();
+    }
+    else if ((_nestingLevel == 1) && name.equals("resources"))
     {
-      if (_metaHt == null)
-        _metaHt = new Hashtable();
       _metaHt.put("package", atts.getValue("package"));
       if (atts.getValue("version") != null)
         _metaHt.put("version", atts.getValue("version"));
       if (atts.getValue("baseversion") != null)
         _metaHt.put("baseVersion", atts.getValue("baseversion"));
     }
-
-    if (atts.getLength() > 0)
-      for (int i=0;i < atts.getLength(); i++)
-        _attsHt.put(atts.getName(i), atts.getValue(i));
-
-    if (name.equals("value") && _inSet)
-    {
-      System.err.println("String array structure (\'values/value\') not " +
-        "allowed within Dictionary (\'set\') XML-based RTS structure.  Please" +
-        "correct the XML-based RTS or DTD file and rebuild." +
-        " Line:" + _locator.getLineNumber());
-      System.exit(1);
-    }
-    else if (name.equals("set") && _inValues)
-    {
-      System.err.println("Dictionary structure (\'set\') not allowed within " +
-        "String array (\'values/value\') XML-based RTS structure.  Please" +
-        "correct the XML-based RTS or DTD file and rebuild." +
-        " Line:" + _locator.getLineNumber());
-      System.exit(1);
-    }
-    else
-    {
-      Tuple t = new Tuple();
-      t.key = name;
-      if (_attsHt.size() > 0)
-        t.attributes = _attsHt;
-      else
-        t.attributes = null;
-      t.nesting = _nestingLevel;
-      _xmlTagStack.push(t);
-    //  _printStack(_xmlTagStack);
-    }
   }
 
   /**
@@ -197,262 +146,20 @@
    */
   public void endElement(String name) throws SAXException
   {
-//    System.out.println("EndElement:"+name);
-
-    String key = name;
-    _nestingLevel--;
-
-    // Vector of Tuples for "values" String array
-    if (name.equals("values"))
-    {
-      Vector values = new Vector();
-      Vector dicts = new Vector();
-
-      Tuple t = (Tuple)_xmlTagStack.pop();
-      while (!t.key.equals("values"))
-      {
-        if (t.value != null)
-        {
-          if (t.key.equals("value"))
-          {
-            if (t.nesting <= 4)
-            {
-              values.addElement(t.value);
-              dicts.addElement(t.attributes);
-            }
-            else
-            {
-              System.err.println("Nesting within values not permitted." +
-                " Exiting.");
-              System.exit(1);
-            }
-          }
-          else
-          {
-            System.err.println("Non value element \'" + t.key +
-              "\' found. Discarding.");
-          }
-        }
-        else
-        {
-          System.err.println("Null value found. Discarding.");
-        }
-        t = (Tuple)_xmlTagStack.pop();
-      }
-      // last element in the vector will always be the 'values' Tuple (with any
-      // associated attributes e.g., DNT=)
-
-      //      v.addElement(t.value);
-      // need to save attributes Dictionary for 'values'
-
-      // pop off the resource or metadata Tuple, set its value to the Vector,
-      // and push it back on the stack
-
-      t = (Tuple)_xmlTagStack.pop();
-      // add the attributes for 'values' element itself
-      dicts.addElement(t.attributes);
-
-      if (t.key.equals("resource"))
-      {
-        key = (String)t.attributes.get("key");
-
-        String[] strArr = new String[values.size()];
-        int j = values.size()-1;
-        for (int i = 0; i < values.size(); i++)
-        {
-          strArr[j] = (String)values.elementAt(i);
-          j--;
-        }
-
-        Hashtable[] attsArr = new Hashtable[dicts.size()];
-        j = dicts.size()-1;
-        for (int i = 0; i < dicts.size(); i++)
-        {
-          attsArr[j] = (Hashtable)dicts.elementAt(i);
-          j--;
-        }
-
-        if (_uniqKeys == null)
-          _uniqKeys = new Hashtable();
-        if (_uniqKeys.get(key) == null)
-        {
-          _uniqKeys.put(key, "OK");
-        }
-        else
-        {
-          System.err.println("Duplicate key found for " + key);
-          System.exit(1);
-        }
-
-        try
-        {
-          _bundleWriter.writeStringArray(_parms, _metaHt, key, strArr, attsArr);
-        }
-        catch (Throwable th)
-        {
-          throw new SAXException("writeStringArray Exception: " +
-            th.getMessage());
-        }
-      }
-      else
-      {
-        key = t.key;
-        //consider handling as meta data if enough demand
-      }
-      // debugging
-//      _printStack(_xmlTagStack);
-    }
-
-    // Hashtable of Tuples for "set" String array
-    else if (name.equals("set"))
-    {
-      Vector setVals = new Vector();
-      Hashtable setAttrHt = new Hashtable();
-      Tuple t = (Tuple)_xmlTagStack.pop();
-      while (!t.key.equals("set"))
-      {
-        // a bit of redundancy here with Hashtable key = t.key and the Tuple
-        // itself containing t.key again.  They could be converted to a pair
-        // here with the loss of some performance.  Alternatively, the pair
-        // could originate in the start element event through some detection,
-        // but that code does not appear to be that trivial an effort.  Note
-        // this duplication also occurs in the meta data handling.
-        setVals.addElement(t);
-        if (t.attributes != null)
-          setAttrHt.put(t.key, t.attributes);
-        t = (Tuple)_xmlTagStack.pop();
-      }
-      // pop off the resource or metadata Tuple, set its value to the Vector,
-      // and push it back on the stack
-      t = (Tuple)_xmlTagStack.pop();
-      // add the attributes for the 'set' element itself
-      setAttrHt.put(t.key, t.attributes);
-      if (t.key.equals("resource"))
-      {
-        key = (String)t.attributes.get("key");
-
-        OrderedDictionary setHt = new OrderedDictionary();
-        for (int i = setVals.size() - 1; i >= 0; i--)
-        {
-          Tuple tVals = (Tuple)setVals.elementAt(i);
-          if (tVals.nesting <= 4)
-          {
-            try
-            {
-              setHt.put(tVals.key, tVals.value);
-            }
-            catch (NullPointerException npe)
-            {
-              System.err.println("Value for subkey \'" + tVals.key +
-                "\' is null. Discarding.");
-            }
-          }
-          else
-          {
-            System.err.println("Nesting within set elements not permitted." +
-              " Exiting.");
-            System.exit(1);
-          }
-        }
-
-        if (_uniqKeys == null)
-          _uniqKeys = new Hashtable();
-        if (_uniqKeys.get(key) == null)
-        {
-          _uniqKeys.put(key, "OK");
-        }
-        else
-        {
-          System.err.println("Duplicate key found for " + key);
-          System.exit(1);
-        }
-
-        try
-        {
-          _bundleWriter.writeDictionary(_parms, _metaHt, key, setHt, setAttrHt);
-        }
-        catch (Throwable th)
-        {
-          throw new SAXException("writeDictionary Exception: " +
-            th.getMessage());
-        }
-      }
-      else
-      {
-        key = t.key;
-        //consider handling as meta data if enough demand
-      }
-
-
-      // debugging
-//      _printStack(_xmlTagStack);
-    }
-    else if (name.equals("author"))
+    if ((_nestingLevel == 2) && name.equals("resource"))
     {
-      if (_authors == null)
-        _authors = new Vector();
-      Tuple t = (Tuple)_xmlTagStack.pop();
-      if (t.value != null)
-      {
-        _authors.addElement(t.value);
-        _metaHt.put("authors", _authors);
-      }
-      else
-      {
-        System.err.println("Null author value.  Discarding.");
-      }
-    }
-    else if (name.equals("resource"))
-    {
-//      _printStack(_xmlTagStack);
-//      System.out.println(name + ":" + _inValues + ":" + _inSet);
-      if (_inValues)
+      String value = _currentResourceValue.toString().trim();
+      try
       {
-        _inValues = false;
+        _bundleWriter.writeString(_parms, _metaHt, _currentResourceKey, value);
       }
-      else if (_inSet)
+      catch (Throwable t)
       {
-        _inSet = false;
-      }
-
-      else
-      {
-        Tuple t = (Tuple)_xmlTagStack.pop();
-        try
-        {
-          Hashtable ht = t.attributes;
-          key = (String)ht.get("key");
-
-          if (_uniqKeys == null)
-            _uniqKeys = new Hashtable();
-          if (_uniqKeys.get(key) == null)
-          {
-            _uniqKeys.put(key, "OK");
-          }
-          else
-          {
-            System.err.println("Duplicate key found for " + key);
-            System.exit(1);
-          }
-
-          if (t.value != null)
-          _bundleWriter.writeString(_parms, _metaHt, key,
-            (String)t.value, t.attributes);
-          else
-            System.err.println("Value for key \'" + key + "\' is null." +
-              " Discarding.");
-        }
-        catch (Throwable th)
-        {
-          throw new SAXException("writeString Exception: " + th.getMessage());
-        }
+        throw new SAXException(t.getMessage());
       }
     }
 
-//    else
-//    {
-//      consider handling as meta data if enough demand
-//    }
+    _nestingLevel--;
   }
 
   /**
@@ -477,133 +184,24 @@
    */
   public void characters(char[] cbuf, int start, int len) throws SAXException
   {
-//    System.out.println("Characters:" + len);
-
-    // Keep track of when resource elements start so we can be sure to
-    // collect and concatenate any initial whitespace for the value.  These are
-    // the pitfalls of a validating parser and I was unable to find a way to
-    // toggle separation of initial whitespace off.  Perhaps this could
-    // eventually be an enhancement request to the Oracle XML parser team.
-
-    // If it is text in a resource tag, concatenate it as it must be part of the
-    // value string.  The concatenation is required with a validating parser as
-    // the parser considers any leading spaces to be a string of characters
-    // separate of the string consisting of non-space and any following space
-    // characters
-    Tuple t = (Tuple)_xmlTagStack.pop();
-    String newStr = new String(cbuf,start,len);
-    if (t.value instanceof String)
+    if (_nestingLevel == 2)
     {
-      String tStr = (String)t.value;
-      if (tStr != null && !tStr.equals(""))
-        t.value = tStr.concat(newStr);
+      _currentResourceValue.append(cbuf, start, len);
     }
-    else
-    {
-      t.value = newStr;
-    }
-
-    _xmlTagStack.push(t);
-
-  }
-
-  /**
-   * Receive notification of a parser warning.
-   *
-   * @param spe the warning information encoded as an exception.
-   */
-  public void warning(SAXParseException spe) throws SAXException
-  {
-    System.err.println(spe + " Line:" + spe.getLineNumber());
-  }
-
-  // validity
-  /**
-   * Receive notification of a recoverable parser error.
-   *
-   * @param spe the error information encoded as an exception.
-   */
-  public void error(SAXParseException spe) throws SAXException
-  {
-    System.err.println(spe + " Line:" + spe.getLineNumber());
-  }
-
-  // well-formedness
-  /**
-   * Receive notification of a fatal XML-based RTS parsing error.
-   *
-   * @param spe the fatal error information encoded as an exception.
-   */
-  public void fatalError(SAXParseException spe) throws SAXException
-  {
-    System.err.println(spe + " Line:" + spe.getLineNumber());
   }
 
-  private final class Tuple
-  {
-
-    private String key;
-    /**
-     * The value is an <code>Object</code> that is either a <code>String</code>,
-     * an array of <code>String</code>s (stored as a <code>Vector</code>), or a
-     * <code>Dictionary</code> of key/value pairs where the values in the
-     * <code>Dictionary</code> are <code>String</code>s.
-     */
-    private Object value;
-    private Hashtable attributes;
-    private int nesting;
-
-    /**
-     * Create and empty <code>Tuple</code> object.
-     */
-    private Tuple()
-    {
-    }
-
-    /**
-     * Create a <code>Tuple</code> object with key, value, attributes, and type.
-     *
-     * @param key name of key
-     * @param value value <code>Object</code>
-     * @param attributes typically a <code>Hashtable</code> of attributes
-     * @param type see the field section for possible values
-     */
-    private Tuple(String key, Object value, Hashtable attributes, int nesting)
-    {
-      this.key = key;
-      this.value = value;
-      this.attributes = attributes;
-      this.nesting = nesting;
-    }
-  }
-
-  // For debugging purposes only
-  private void _printStack(Stack s)
-  {
-    Enumeration e = s.elements();
-    while (e.hasMoreElements())
-    {
-      Tuple t = (Tuple)e.nextElement();
-      System.out.println(t.key);
-      System.out.println("->" + t.value);
-      System.out.println("->" + t.attributes);
-    }
-    System.out.println();
-  }
 
   // Store the locator
   private Locator _locator;
 
-  private Stack _xmlTagStack;
-  private Hashtable _metaHt;
-  private Hashtable _uniqKeys;
-  private Vector _authors;
+  private String _currentResourceKey;
+  private StringBuilder _currentResourceValue;
+  private Map<String, Object> _metaHt = new HashMap<String, Object>();
+  private Set<String> _uniqKeys = new HashSet<String>();
 
   private RTSWriter _bundleWriter;
-  private Hashtable _parms;
+  private Map _parms;
 
   private int _nestingLevel = 0;
-  private boolean _inValues = false;
-  private boolean _inSet = false;
   private boolean _startDoc = false;
 }