openoffice-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1602077 [1/2] - in /openoffice/trunk/main/ooxml/source/framework: JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/ SchemaParser/src/org/apache/openoffice/ooxml/schema/ SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/ S...
Date Thu, 12 Jun 2014 07:15:25 GMT
Author: af
Date: Thu Jun 12 07:15:24 2014
New Revision: 1602077

URL: http://svn.apache.org/r1602077
Log:
125035: Added support for attributes.

Added:
    openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AttributeDescriptor.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/CreatorBase.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/iterator/AttributeNodeIterator.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/optimize/CopyVisitor.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/parser/FormDefault.java
Removed:
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/ValidatingCreatorVisitor.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/optimize/ProcessTypeVisitor.java
Modified:
    openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AcceptingStateTable.java
    openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AttributeManager.java
    openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AttributeProvider.java
    openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/NameMap.java
    openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/NamespaceMap.java
    openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/OOXMLParser.java
    openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/ParseTableReader.java
    openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/SkipStateTable.java
    openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/StateMachine.java
    openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/TransitionTable.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/SchemaReader.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/Test.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/DFACreator.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/FiniteAutomaton.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/FiniteAutomatonContainer.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/HopcroftMinimizer.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/NonValidatingCreator.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/ValidatingCreator.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/generator/ParserTablesGenerator.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/iterator/AttributeIterator.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/attribute/Attribute.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/attribute/AttributeBase.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/attribute/AttributeReference.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/optimize/RequestVisitor.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/optimize/SchemaOptimizer.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/model/schema/SchemaBase.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/parser/SchemaParser.java
    openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/parser/XmlNamespace.java

Modified: openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AcceptingStateTable.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AcceptingStateTable.java?rev=1602077&r1=1602076&r2=1602077&view=diff
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AcceptingStateTable.java (original)
+++ openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AcceptingStateTable.java Thu Jun 12 07:15:24 2014
@@ -23,7 +23,6 @@ public class AcceptingStateTable
 
             maAcceptingStates.add(nStateId);
         }
-        Log.Std.printf("read %d accepting states\n",  maAcceptingStates.size());
     }
 
     
@@ -37,5 +36,13 @@ public class AcceptingStateTable
     
     
     
+    public int GetAcceptingStateCount ()
+    {
+        return maAcceptingStates.size();
+    }
+    
+    
+    
+    
     private final Set<Integer> maAcceptingStates;
 }

Added: openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AttributeDescriptor.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AttributeDescriptor.java?rev=1602077&view=auto
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AttributeDescriptor.java (added)
+++ openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AttributeDescriptor.java Thu Jun 12 07:15:24 2014
@@ -0,0 +1,112 @@
+package org.apache.openoffice.ooxml.parser;
+
+/** Store information about a single attribute (per state) that was read
+ *  from the parse table.
+ * 
+ *  Note that an attribute that is defined for more than one state has one
+ *  AttributeDescriptor object per state.
+ *
+ */
+public class AttributeDescriptor
+{
+    public AttributeDescriptor (
+        final int nPrefixId,
+        final int nAttributeId,
+        final boolean bCanBeUnqualified,
+        final boolean bIsOptional,
+        final String sDefaultValue,
+        final String sAttributeName,
+        final String sAttributeType)
+    {
+        mnNamespaceId = nPrefixId;
+        mnAttributeId = nAttributeId;
+        mbCanBeUnqualified = bCanBeUnqualified;
+        mbIsOptional = bIsOptional;
+        msDefaultValue = sDefaultValue;
+        msAttributeName = sAttributeName;
+        msAttributeType = sAttributeType;
+    }
+    
+    
+    
+    
+    public String GetType()
+    {
+        if (msAttributeType != null)
+            return msAttributeType;
+        else
+            return "<undefined>";
+    }
+
+    
+    
+    
+    public int GetNamespaceId ()
+    {
+        return mnNamespaceId;
+    }
+    
+    
+    
+    
+    public int GetNameId ()
+    {
+        return mnAttributeId;
+    }
+    
+    
+    
+    
+    public boolean CanBeUnqualified ()
+    {
+        return mbCanBeUnqualified;
+    }
+
+    
+    
+    
+    public boolean IsOptional ()
+    {
+        return mbIsOptional;
+    }
+    
+    
+    
+    
+    public String GetDefaultValue ()
+    {
+        return msDefaultValue;
+    }
+    
+    
+    
+    
+    public String GetName ()
+    {
+        return msAttributeName;
+    }
+    
+    
+    
+    
+    @Override
+    public String toString ()
+    {
+        return String.format(
+            "attribute %s(%d) of type %s",
+            msAttributeName,
+            mnAttributeId,
+            msAttributeType);
+    }
+
+    
+    
+    
+    private final int mnNamespaceId;
+    private final int mnAttributeId;
+    private final boolean mbCanBeUnqualified;
+    private final boolean mbIsOptional;
+    private final String msDefaultValue;
+    private final String msAttributeName;
+    private final String msAttributeType;
+}

Modified: openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AttributeManager.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AttributeManager.java?rev=1602077&r1=1602076&r2=1602077&view=diff
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AttributeManager.java (original)
+++ openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AttributeManager.java Thu Jun 12 07:15:24 2014
@@ -22,57 +22,193 @@
 package org.apache.openoffice.ooxml.parser;
 
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
-import java.util.Map.Entry;
+import java.util.Set;
 import java.util.Vector;
 
+
+/** Match a set of attributes from the document with the attribute
+ *  specifications of a state.
+ *
+ */
 public class AttributeManager
 {
-    public AttributeManager (final Vector<String[]> aData)
+    /** Create a new AttributeManager for the attribute specifications that
+     *  are given in the parse table. 
+     */
+    public AttributeManager (
+        final Vector<String[]> aData,
+        final NamespaceMap aNamespaceMap,
+        final NameMap aNameMap)
     {
-        maStateIdToAttributesMap = new HashMap<>();        
+        maStateIdToAttributesMap = new HashMap<>();
+        maNamespaceMap = aNamespaceMap;
+        maNameMap = aNameMap;
+
+        for (final String[] aLine : aData)
+        {
+            final int nStateId = Integer.parseInt(aLine[1]);
+            final int nPrefixId = Integer.parseInt(aLine[2]);
+            final boolean bCanBeUnqualified = aLine[3].startsWith("u");
+            final int nAttributeId = Integer.parseInt(aLine[4]);
+            final String sAttributeType = aLine[5];
+            final boolean bIsOptional = aLine[6].startsWith("o");
+            final String sDefault = UnquoteString(aLine[7]);
+            final String sAttributeName = aLine[8];
+            
+            Map<Integer,AttributeDescriptor> aAttributesPerState = maStateIdToAttributesMap.get(nStateId);
+            if (aAttributesPerState == null)
+            {
+                aAttributesPerState = new HashMap<>();
+                maStateIdToAttributesMap.put(nStateId, aAttributesPerState);
+            }
+            
+            final AttributeDescriptor aAttributeDescriptor = new AttributeDescriptor(
+                nPrefixId,
+                nAttributeId,
+                bCanBeUnqualified,
+                bIsOptional,
+                sDefault,
+                sAttributeName,
+                sAttributeType);
+            
+            aAttributesPerState.put(
+                (nPrefixId<<16)|nAttributeId,
+                aAttributeDescriptor);
+            if (bCanBeUnqualified)
+                aAttributesPerState.put(
+                    nAttributeId,
+                    aAttributeDescriptor);
+        }
     }
     
     
     
     
+    /** For the state with id nStateId, match the attributes from the document
+     *  with the attribute specifications of that state. 
+     */
     public void ParseAttributes (
         final int nStateId,
-        final AttributeProvider aAttributeProvider)
+        final AttributeProvider aDocumentAttributes)
     {
-        final Map<String,String> aAttributeDefinitions = maStateIdToAttributesMap.get(nStateId);
-        if (aAttributeDefinitions == null)
+        final Map<Integer,AttributeDescriptor> aAttributesPerState = maStateIdToAttributesMap.get(nStateId);
+        if (aAttributesPerState == null)
         {
-           // if (aAttributeProvider.HasAttributes())
-                //throw new RuntimeException();
+            if (aDocumentAttributes.HasAttributes())
+            {
+                Log.Std.printf("state has not attributes defined but document provides %d attributes\n",
+                    aDocumentAttributes.GetAttributeCount());
+                for (final String[] aEntry : aDocumentAttributes)
+                {
+                    Log.Dbg.printf("    %s -> %s\n", aEntry[0], aEntry[1]);
+                }
+                throw new RuntimeException();
+            }
         }
         else
         {
-            for (final Entry<String,String> aEntry : aAttributeProvider)
+            final Set<AttributeDescriptor> aUsedAttributes = new HashSet<>();
+            
+            // Process all attributes from the document.
+            for (final String[] aEntry : aDocumentAttributes)
             {
-                ParseAttributeValue(
-                    aEntry.getKey(),
-                    aEntry.getValue(),
-                    aAttributeDefinitions.get(aEntry.getKey()));
+                final AttributeDescriptor aAttributeDescriptor = ProcessAttribute(
+                    aEntry[0],
+                    aEntry[1],
+                    aEntry[2],
+                    aAttributesPerState);
+                aUsedAttributes.add(aAttributeDescriptor);
+                if (Log.Dbg != null)
+                {
+                    if (aAttributeDescriptor == null)
+                        Log.Dbg.printf("attribute %s%s is not known\n",
+                            aEntry[0]==null ? "" : ":"+aEntry[0],
+                            aEntry[1]);
+                    else
+                        Log.Dbg.printf("attribute %s:%s(%d:%d) has type and value %s\n",
+                            maNamespaceMap.GetDescriptorForId(aAttributeDescriptor.GetNamespaceId()).Prefix,
+                            maNameMap.GetNameForId(aAttributeDescriptor.GetNameId()),
+                            aAttributeDescriptor.GetNamespaceId(),
+                            aAttributeDescriptor.GetNameId(),
+                            aAttributeDescriptor.GetType(),
+                            aEntry[2]);
+                }
+            }
+            
+            // Check if all required attributes where given.
+            for (final AttributeDescriptor aAttribute : aAttributesPerState.values())
+            {
+                if ( ! aAttribute.IsOptional())
+                {
+                    if ( ! aUsedAttributes.contains(aAttribute))
+                        throw new RuntimeException("attribute '"+aAttribute.GetName()+"' is not present but also not optional");
+                }
             }
         }
     }
+
+    
+    
+    
+    private AttributeDescriptor ProcessAttribute (
+        final String sNamespace,
+        final String sAttributeName,
+        final String sAttributeValue,
+        final Map<Integer,AttributeDescriptor> aAttributesPerState)
+    {
+        final AttributeDescriptor aAttributeDescriptor;
+        if (sNamespace == null)
+        {
+            // Attribute name has no namespace.
+            final int nAttributeNameId = maNameMap.GetIdForName(sAttributeName);
+            aAttributeDescriptor = aAttributesPerState.get(nAttributeNameId);
+        }
+        else
+        {
+            // Attribute name has explicit namespace.
+            final NamespaceMap.NamespaceDescriptor aDescriptor = maNamespaceMap.GetDescriptorForURI(sNamespace);
+            final int nAttributeNameId = maNameMap.GetIdForName(sAttributeName);
+            aAttributeDescriptor = aAttributesPerState.get((aDescriptor.Id<<16) | nAttributeNameId);
+        }
+        return aAttributeDescriptor;
+    }
+
+
+
+
+    /** Remove the quotes around the given string.
+     *  If it has the special value null (without quotes) then the null reference
+     *  is returned.
+     */
+    private String UnquoteString (final String sValue)
+    {
+        if (sValue.equals("null"))
+            return null;
+        else
+        {
+            assert(sValue.startsWith("\""));
+            assert(sValue.endsWith("\""));
+            return sValue.substring(1, sValue.length()-1);
+        }
+    }
+
     
     
     
-    private void ParseAttributeValue (
-        final String sName,
-        final String sValue,
-        final String sSimpleTypeName)
+    public int GetAttributeCount ()
     {
-        Log.Dbg.printf("attribute %s has type %s and value %s\n", 
-            sName,
-            sSimpleTypeName,
-            sValue);
+        int nCount = 0;
+        for (final Map<Integer,AttributeDescriptor> aMap : maStateIdToAttributesMap.values())
+            nCount += aMap.size();
+        return nCount;
     }
     
     
     
     
-    private final Map<String,Map<String,String>> maStateIdToAttributesMap;
+    private final Map<Integer,Map<Integer,AttributeDescriptor>> maStateIdToAttributesMap;
+    private final NamespaceMap maNamespaceMap;
+    private final NameMap maNameMap;
 }

Modified: openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AttributeProvider.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AttributeProvider.java?rev=1602077&r1=1602076&r2=1602077&view=diff
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AttributeProvider.java (original)
+++ openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/AttributeProvider.java Thu Jun 12 07:15:24 2014
@@ -22,12 +22,13 @@
 package org.apache.openoffice.ooxml.parser;
 
 import java.util.Iterator;
-import java.util.Map.Entry;
 
 import javax.xml.stream.XMLStreamReader;
 
+/** Give access to the attributes that are read from an OOXML stream.
+ */
 public class AttributeProvider
-    implements Iterable<Entry<String,String>>
+    implements Iterable<String[]>
 {
     public AttributeProvider(XMLStreamReader aReader)
     {
@@ -52,9 +53,9 @@ public class AttributeProvider
     
     
     @Override
-    public Iterator<Entry<String,String>> iterator ()
+    public Iterator<String[]> iterator ()
     {
-        return new Iterator<Entry<String,String>> ()
+        return new Iterator<String[]> ()
         {
             int nIndex = 0;
             final int nCount = maReader.getAttributeCount();
@@ -64,30 +65,16 @@ public class AttributeProvider
                 return nIndex < nCount;
             }
 
-            @Override public Entry<String, String> next()
+            @Override public String[] next()
             {
-                final Entry<String,String> aEntry = new Entry<String,String>()
-                {
-                    final String msKey = maReader.getAttributeLocalName(nIndex);
-                    final String msValue = maReader.getAttributeValue(nIndex);
-                    
-                    @Override public String getKey()
+                final String[] aResult = new String[]
                     {
-                        return msKey;
-                    }
-
-                    @Override public String getValue()
-                    {
-                        return msValue;
-                    }
-
-                    @Override public String setValue (final String sValue)
-                    {
-                        return null;
-                    }
-                };
+                        maReader.getAttributeNamespace(nIndex),
+                        maReader.getAttributeLocalName(nIndex),
+                        maReader.getAttributeValue(nIndex)
+                    };
                 ++nIndex;
-                return aEntry;
+                return aResult;
             }
 
             @Override public void remove()
@@ -97,5 +84,16 @@ public class AttributeProvider
         };
     }
     
+
+    
+    
+    public Integer GetAttributeCount ()
+    {
+        return maReader.getAttributeCount();
+    }
+
+    
+    
+    
     private final XMLStreamReader maReader;
 }

Modified: openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/NameMap.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/NameMap.java?rev=1602077&r1=1602076&r2=1602077&view=diff
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/NameMap.java (original)
+++ openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/NameMap.java Thu Jun 12 07:15:24 2014
@@ -42,24 +42,14 @@ public class NameMap
                 maIdToNameMap.setSize(nId+1);
             maIdToNameMap.set(nId, aLine[2]);
         }
-            
-        if (Log.Dbg != null)
-            Log.Dbg.printf("initialized name map with %d definitions\n", maNameToIdMap.size());
     }
 
 
 
 
     public int GetIdForName (
-        final String sPrefix,
-        final String sElementName)
+        final String sName)
     {
-        final String sName;
-        if (sPrefix == null)
-            sName = sElementName;
-        else
-            sName = sPrefix+"_"+sElementName;
-        
         if ( ! maNameToIdMap.containsKey(sName))
             throw new RuntimeException("token '"+sName+"' is not known");
         
@@ -79,6 +69,14 @@ public class NameMap
     
     
     
+    
+    public int GetNameCount ()
+    {
+        return maIdToNameMap.size();
+    }
+    
+    
+    
 
     private final Map<String,Integer> maNameToIdMap;
     private final Vector<String> maIdToNameMap;

Modified: openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/NamespaceMap.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/NamespaceMap.java?rev=1602077&r1=1602076&r2=1602077&view=diff
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/NamespaceMap.java (original)
+++ openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/NamespaceMap.java Thu Jun 12 07:15:24 2014
@@ -27,31 +27,65 @@ import java.util.Vector;
 
 public class NamespaceMap
 {
+    class NamespaceDescriptor
+    {
+        NamespaceDescriptor (final String sPrefix, final int nId)
+        {
+            Prefix = sPrefix;
+            Id = nId;
+        }
+        public final String Prefix;
+        public final int Id;
+    }
     NamespaceMap (final Vector<String[]> aData)
     {
-        maUriToPrefixMap = new HashMap<>();
+        maUriToDescriptorMap = new HashMap<>();
+        maIdToDescriptorMap = new HashMap<>();
         
         for (final String[] aLine : aData)
         {
-            maUriToPrefixMap.put(aLine[2], aLine[1]);
+            final int nId = Integer.parseInt(aLine[2]);
+            final NamespaceDescriptor aDescriptor = new NamespaceDescriptor(aLine[1], nId);
+            maUriToDescriptorMap.put(
+                aLine[3], 
+                aDescriptor);
+            maIdToDescriptorMap.put(
+                nId,
+                aDescriptor);
         }
-            
-        if (Log.Dbg != null)
-            Log.Dbg.printf("initialized namespace map with %d definitions\n", maUriToPrefixMap.size());
     }
     
     
     
     
-    public String GetPrefixForURI (final String sURI)
+    public NamespaceDescriptor GetDescriptorForURI (final String sURI)
     {
-        if ( ! maUriToPrefixMap.containsKey(sURI))
+        if (sURI == null)
+            throw new RuntimeException("namespace is null");
+        if ( ! maUriToDescriptorMap.containsKey(sURI))
             throw new RuntimeException("namespace '"+sURI+"' is not known");
-        return maUriToPrefixMap.get(sURI);
+        return maUriToDescriptorMap.get(sURI);
+    }
+
+    
+    
+    
+    public NamespaceDescriptor GetDescriptorForId (final int nId)
+    {
+        return maIdToDescriptorMap.get(nId);
     }
 
     
     
+
+    public int GetNamespaceCount ()
+    {
+        return maUriToDescriptorMap.size();
+    }
+    
+    
+    
     
-    private final Map<String,String> maUriToPrefixMap;
+    private final Map<String,NamespaceDescriptor> maUriToDescriptorMap;
+    private final Map<Integer,NamespaceDescriptor> maIdToDescriptorMap;
 }

Modified: openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/OOXMLParser.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/OOXMLParser.java?rev=1602077&r1=1602076&r2=1602077&view=diff
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/OOXMLParser.java (original)
+++ openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/OOXMLParser.java Thu Jun 12 07:15:24 2014
@@ -48,9 +48,21 @@ public class OOXMLParser
      */
     public static void main (final String ... aArgumentList)
     {
-        if (aArgumentList.length != 3)
-            throw new RuntimeException("usage: OOXMLParser <parser-tables-path> <XML-input-file> <log-file>");
+        if (aArgumentList.length<2 ||aArgumentList.length>3)
+            throw new RuntimeException("usage: OOXMLParser <parser-tables-path> <XML-input-file> <log-file>?");
         
+        if (aArgumentList.length == 3)
+        {
+            final File aLogFile = new File(aArgumentList[2]);
+            Log.Dbg = new Log(aLogFile);
+            System.out.printf("writing log data to %s\n", aLogFile.toString());
+        }
+        else
+        {
+            Log.Dbg = null;
+            System.out.printf("writing no log data\n");
+        }
+
         long nStartTime = System.currentTimeMillis();
         final StateMachine aMachine = new StateMachine(new File(aArgumentList[0]));
         final InputStream aIn = GetInputStream(aArgumentList[1]);
@@ -63,7 +75,7 @@ public class OOXMLParser
             if (aReader != null)
             {
                 nStartTime = System.currentTimeMillis();
-                final int  nElementCount = Parse(aReader, aMachine, new File(aArgumentList[2]));
+                final int  nElementCount = Parse(aReader, aMachine);
                 nEndTime = System.currentTimeMillis();
                 System.out.printf("parsed %d elements in %fs\n",
                     nElementCount,
@@ -77,6 +89,8 @@ public class OOXMLParser
     }
     
     
+    
+    
     private static InputStream GetInputStream (final String sInputName)
     {
         final InputStream aIn;
@@ -146,11 +160,8 @@ public class OOXMLParser
     
     private static int Parse (
         final XMLStreamReader aReader,
-        final StateMachine aMachine,
-        final File aLogFile)
+        final StateMachine aMachine)
     {
-        Log.Dbg = new Log(aLogFile);
-
         int nElementCount = 0;
         try
         {
@@ -164,7 +175,8 @@ public class OOXMLParser
                         ++nElementCount;
                         if (aMachine.IsInSkipState())
                         {
-                            Log.Dbg.printf("is skip state -> starting to skip\n");
+                            if (Log.Dbg != null)
+                                Log.Dbg.printf("is skip state -> starting to skip\n");
                             nElementCount += Skip(aReader);
                         }
                         else if ( ! aMachine.ProcessStartElement(
@@ -173,7 +185,8 @@ public class OOXMLParser
                             aReader.getLocation(),
                             aAttributeProvider))
                         {
-                            Log.Dbg.printf("starting to skip to recover from error\n");
+                            if (Log.Dbg != null)
+                                Log.Dbg.printf("starting to skip to recover from error\n");
                             nElementCount += Skip(aReader);
                         }
                         break;
@@ -187,7 +200,8 @@ public class OOXMLParser
                         
                     case XMLStreamReader.CHARACTERS:
                         final String sText = aReader.getText();
-                        Log.Dbg.printf("text [%s]\n", sText.replace("\n", "\\n"));
+                        if (Log.Dbg != null)
+                            Log.Dbg.printf("text [%s]\n", sText.replace("\n", "\\n"));
                         aMachine.ProcessCharacters(sText);
                         break;
                         
@@ -215,11 +229,14 @@ public class OOXMLParser
     
     private static int Skip (final XMLStreamReader aReader)
     {
-        Log.Dbg.printf("starting to skip on %s at L%dC%d\n",
-            aReader.getLocalName(),
-            aReader.getLocation().getLineNumber(),
-            aReader.getLocation().getColumnNumber());
-        Log.Dbg.IncreaseIndentation();
+        if (Log.Dbg != null)
+        {
+            Log.Dbg.printf("starting to skip on %s at L%dC%d\n",
+                aReader.getLocalName(),
+                aReader.getLocation().getLineNumber(),
+                aReader.getLocation().getColumnNumber());
+            Log.Dbg.IncreaseIndentation();
+        }
         
         // We are called when processing a start element.  This means that we are
         // already at relative depth 1.
@@ -235,16 +252,21 @@ public class OOXMLParser
                     case XMLStreamReader.START_ELEMENT:
                         ++nRelativeDepth;
                         ++nElementCount;
-                        Log.Dbg.printf("skipping start element %s\n", aReader.getLocalName());
-                        Log.Dbg.IncreaseIndentation();
+                        if (Log.Dbg != null)
+                        {
+                            Log.Dbg.printf("skipping start element %s\n", aReader.getLocalName());
+                            Log.Dbg.IncreaseIndentation();
+                        }
                         break;
                         
                     case XMLStreamReader.END_ELEMENT:
                         --nRelativeDepth;
-                        Log.Dbg.DecreaseIndentation();
+                        if (Log.Dbg != null)
+                            Log.Dbg.DecreaseIndentation();
                         if (nRelativeDepth <= 0)
                         {
-                            Log.Dbg.printf("leaving skip mode on %s\n", aReader.getLocalName());
+                            if (Log.Dbg != null)
+                                Log.Dbg.printf("leaving skip mode on %s\n", aReader.getLocalName());
                             return nElementCount;
                         }
                         break;
@@ -257,7 +279,9 @@ public class OOXMLParser
                         break;
 
                     default:
-                        Log.Dbg.printf("%s\n",  nCode);
+                        if (Log.Dbg != null)
+                            Log.Dbg.printf("%s\n",  nCode);
+                        break;
                 }
             }
         }
@@ -270,8 +294,10 @@ public class OOXMLParser
     
     
     
+    
     private static void SkipText (final String sText)
     {
-        Log.Dbg.printf("skipping text [%s]\n", sText.replace("\n", "\\n"));
+        if (Log.Dbg != null)
+            Log.Dbg.printf("skipping text [%s]\n", sText.replace("\n", "\\n"));
     }
 }

Modified: openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/ParseTableReader.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/ParseTableReader.java?rev=1602077&r1=1602076&r2=1602077&view=diff
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/ParseTableReader.java (original)
+++ openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/ParseTableReader.java Thu Jun 12 07:15:24 2014
@@ -30,6 +30,11 @@ public class ParseTableReader
                     break;
                 if (sLine.startsWith("#"))
                     continue;
+                
+                // Splitting just at whitespace may be too simple to keep quoted text
+                // (used e.g. for attribute default values) in one peace when
+                // it contains whitespace.  Should this case occur than this 
+                // implementation has to be improved.
                 final String aParts[] = sLine.split("\\s+");
                 
                 GetSection(aParts[0]).add(aParts);

Modified: openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/SkipStateTable.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/SkipStateTable.java?rev=1602077&r1=1602076&r2=1602077&view=diff
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/SkipStateTable.java (original)
+++ openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/SkipStateTable.java Thu Jun 12 07:15:24 2014
@@ -24,7 +24,6 @@ public class SkipStateTable
 
             maSkipStates.add(nStateId);
         }
-        Log.Std.printf("read %d skip states\n",  maSkipStates.size());
     }
 
     
@@ -38,5 +37,13 @@ public class SkipStateTable
     
     
     
+    public int GetSkipStateCount ()
+    {
+        return maSkipStates.size();
+    }
+    
+    
+    
+    
     private final Set<Integer> maSkipStates;
 }

Modified: openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/StateMachine.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/StateMachine.java?rev=1602077&r1=1602076&r2=1602077&view=diff
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/StateMachine.java (original)
+++ openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/StateMachine.java Thu Jun 12 07:15:24 2014
@@ -33,20 +33,37 @@ public class StateMachine
 {
     public StateMachine (final File aParseTableFile)
     {
+        if (Log.Dbg != null)
+            Log.Dbg.printf("reading parse tables from %s\n", aParseTableFile.toString());
+        
         final ParseTableReader aReader = new ParseTableReader(aParseTableFile);
         maNamespaceMap = new NamespaceMap(aReader.GetSection("namespace"));
-        maElementNameMap = new NameMap(aReader.GetSection("element-name"));
+        maNameMap = new NameMap(aReader.GetSection("name"));
         maStateNameMap = new NameMap(aReader.GetSection("state-name"));
         maTransitions = new TransitionTable(aReader.GetSection("transition"));
         maSkipStates = new SkipStateTable(aReader.GetSection("skip"));
         maAcceptingStates = new AcceptingStateTable(aReader.GetSection("accepting-state"));
-        maAttributeManager = new AttributeManager(aReader.GetSection("attribute"));
+        maAttributeManager = new AttributeManager(
+            aReader.GetSection("attribute"),
+            maNamespaceMap,
+            maNameMap);
         
+        System.out.printf("read %d namespace, %d names, %d states (%d skip, %d accept), %d transitions and %d attributes\n",
+                maNamespaceMap.GetNamespaceCount(),
+                maNameMap.GetNameCount(),
+                maStateNameMap.GetNameCount(),
+                maSkipStates.GetSkipStateCount(),
+                maAcceptingStates.GetAcceptingStateCount(),
+                maTransitions.GetTransitionCount(),
+                maAttributeManager.GetAttributeCount());
+
         mnStartStateId = Integer.parseInt(aReader.GetSection("start-state").firstElement()[1]);
         mnEndStateId = Integer.parseInt(aReader.GetSection("end-state").firstElement()[1]);
         mnCurrentStateId = mnStartStateId;
         maStateStack = new Stack<>();
-        Log.Dbg.printf("starting in state _start_ (%d)\n", mnCurrentStateId);
+        
+        if (Log.Dbg != null)
+            Log.Dbg.printf("starting in state _start_ (%d)\n", mnCurrentStateId);
     }
 
 
@@ -62,41 +79,49 @@ public class StateMachine
 
         try
         {
-            final String sPrefix = maNamespaceMap.GetPrefixForURI(sNamespaceURI);
-            final int nElementId = maElementNameMap.GetIdForName(sPrefix, sElementName);
-            Log.Dbg.printf("%s:%s(%d) L%dC%d\n",
-                sPrefix,
-                sElementName,
-                nElementId,
-                aLocation.getLineNumber(),
-                aLocation.getColumnNumber());
+            final NamespaceMap.NamespaceDescriptor aDescriptor = maNamespaceMap.GetDescriptorForURI(sNamespaceURI);
+            final int nElementNameId = maNameMap.GetIdForName(sElementName);
+            if (Log.Dbg != null)
+                Log.Dbg.printf("%s:%s(%d:%d) L%dC%d\n",
+                    aDescriptor.Prefix,
+                    sElementName,
+                    aDescriptor.Id,
+                    nElementNameId,
+                    aLocation.getLineNumber(),
+                    aLocation.getColumnNumber());
             
             final Transition aTransition = maTransitions.GetTransition(
                 mnCurrentStateId,
-                nElementId);
+                aDescriptor.Id,
+                nElementNameId);
             if (aTransition == null)
             {
                 final String sText = String.format(
-                    "can not find transition for state %s(%d) and element %s(%d) at L%dC%d\n",
+                    "can not find transition for state %s(%d) and element %s(%d:%d) at L%dC%d\n",
                     maStateNameMap.GetNameForId(mnCurrentStateId),
                     mnCurrentStateId,
-                    maElementNameMap.GetNameForId(nElementId),
-                    nElementId,
+                    aDescriptor.Id,
+                    maNameMap.GetNameForId(nElementNameId),
+                    nElementNameId,
                     aLocation.getLineNumber(),
                     aLocation.getColumnNumber());
                 Log.Err.printf(sText);
-                Log.Dbg.printf(sText);
+                if (Log.Dbg != null)
+                    Log.Dbg.printf(sText);
             }
             else
             {
-                Log.Dbg.printf(" %s(%d) -> %s(%d) via %s(%d)",
-                    maStateNameMap.GetNameForId(mnCurrentStateId),
-                    mnCurrentStateId,
-                    maStateNameMap.GetNameForId(aTransition.GetEndStateId()),
-                    aTransition.GetEndStateId(),
-                    maStateNameMap.GetNameForId(aTransition.GetActionId()),
-                    aTransition.GetActionId());
-                Log.Dbg.printf("\n");
+                if (Log.Dbg != null)
+                {
+                    Log.Dbg.printf(" %s(%d) -> %s(%d) via %s(%d)",
+                        maStateNameMap.GetNameForId(mnCurrentStateId),
+                        mnCurrentStateId,
+                        maStateNameMap.GetNameForId(aTransition.GetEndStateId()),
+                        aTransition.GetEndStateId(),
+                        maStateNameMap.GetNameForId(aTransition.GetActionId()),
+                        aTransition.GetActionId());
+                    Log.Dbg.printf("\n");
+                }
                 
                 final int nOldState = mnCurrentStateId;
                 SetCurrentState(aTransition.GetEndStateId());
@@ -108,7 +133,7 @@ public class StateMachine
         }
         catch (RuntimeException aException)
         {
-            System.err.printf("error at line %d and column %d\n",
+            Log.Err.printf("error at line %d and column %d\n",
                 aLocation.getLineNumber(),
                 aLocation.getColumnNumber());
             throw aException;
@@ -127,28 +152,32 @@ public class StateMachine
         if ( ! maAcceptingStates.Contains(mnCurrentStateId)
             && mnCurrentStateId!=-1)
         {
-            Log.Dbg.printf("current state %s(%d) is not an accepting state\n",
-                maStateNameMap.GetNameForId(mnCurrentStateId),
-                mnCurrentStateId);
+            if (Log.Dbg != null)
+                Log.Dbg.printf("current state %s(%d) is not an accepting state\n",
+                    maStateNameMap.GetNameForId(mnCurrentStateId),
+                    mnCurrentStateId);
             throw new RuntimeException("not expecting end element "+sElementName);
         }
 
-        final String sPrefix = maNamespaceMap.GetPrefixForURI(sNamespaceURI);
+        final NamespaceMap.NamespaceDescriptor aDescriptor = maNamespaceMap.GetDescriptorForURI(sNamespaceURI);
         
         final int nOldStateId = mnCurrentStateId;
         SetCurrentState(maStateStack.pop());
         
-        Log.Dbg.DecreaseIndentation();
-        Log.Dbg.printf("/%s:%s L%d%d\n",
-            sPrefix,
-            sElementName,
-            aLocation.getLineNumber(),
-            aLocation.getColumnNumber());
-        Log.Dbg.printf(" %s(%d) <- %s(%d)\n",
-            maStateNameMap.GetNameForId(nOldStateId),
-            nOldStateId,
-            maStateNameMap.GetNameForId(mnCurrentStateId),
-            mnCurrentStateId);
+        if (Log.Dbg != null)
+        {
+            Log.Dbg.DecreaseIndentation();
+            Log.Dbg.printf("/%s:%s L%d%d\n",
+                aDescriptor.Prefix,
+                sElementName,
+                aLocation.getLineNumber(),
+                aLocation.getColumnNumber());
+            Log.Dbg.printf(" %s(%d) <- %s(%d)\n",
+                maStateNameMap.GetNameForId(nOldStateId),
+                nOldStateId,
+                maStateNameMap.GetNameForId(mnCurrentStateId),
+                mnCurrentStateId);
+        }
     }
     
     
@@ -191,17 +220,20 @@ public class StateMachine
         final int nNewState)
     {
         maStateStack.push(mnCurrentStateId);
-        Log.Dbg.IncreaseIndentation();
+        if (Log.Dbg != null)
+            Log.Dbg.IncreaseIndentation();
         final int nActionId = aTransition.GetActionId(); 
         SetCurrentState(nActionId);
-        maAttributeManager.ParseAttributes(nActionId, aAttributes);
+        maAttributeManager.ParseAttributes(
+            nActionId,
+            aAttributes);
     }
     
     
     
     
     private final NamespaceMap maNamespaceMap;
-    private final NameMap maElementNameMap;
+    private final NameMap maNameMap;
     private final NameMap maStateNameMap;
     private final TransitionTable maTransitions;
     private final AttributeManager maAttributeManager;

Modified: openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/TransitionTable.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/TransitionTable.java?rev=1602077&r1=1602076&r2=1602077&view=diff
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/TransitionTable.java (original)
+++ openoffice/trunk/main/ooxml/source/framework/JavaOOXMLParser/src/org/apache/openoffice/ooxml/parser/TransitionTable.java Thu Jun 12 07:15:24 2014
@@ -30,21 +30,20 @@ public class TransitionTable
     public TransitionTable (final Vector<String[]> aData)
     {
         maTransitions = new HashMap<>();
-        int nTransitionCount = 0;
         
         for (final String[] aLine : aData)
         {
             // Create new transition.
             final int nStartStateId = Integer.parseInt(aLine[1]);
             final int nEndStateId = Integer.parseInt(aLine[2]);
-            final int nElementId = Integer.parseInt(aLine[3]);
-            final int nElementStateId = Integer.parseInt(aLine[4]);
+            final int nElementPrefixId = Integer.parseInt(aLine[3]);
+            final int nElementLocalId = Integer.parseInt(aLine[4]);
+            final int nElementStateId = Integer.parseInt(aLine[5]);
             final Transition aTransition = new Transition(
                 nStartStateId,
                 nEndStateId,
-                nElementId,
+                (nElementPrefixId<<16) | nElementLocalId,
                 nElementStateId);
-            ++nTransitionCount;
 
             Map<Integer,Transition> aPerElementTransitions = maTransitions.get(aTransition.GetStartStateId());
             if (aPerElementTransitions == null)
@@ -54,7 +53,6 @@ public class TransitionTable
             }
             aPerElementTransitions.put(aTransition.GetElementId(), aTransition);
         }
-        Log.Std.printf("read %d transitions\n",  nTransitionCount);
     }
 
 
@@ -62,17 +60,26 @@ public class TransitionTable
 
     public Transition GetTransition (
         final int nStateId,
-        final int nElementId)
+        final int nPrefixId,
+        final int nLocalId)
     {
         Map<Integer,Transition> aPerElementTransitions = maTransitions.get(nStateId);
         if (aPerElementTransitions == null)
             return null;
         else
-            return aPerElementTransitions.get(nElementId);
+            return aPerElementTransitions.get((nPrefixId<<16) | nLocalId);
     }
 
     
     
     
+    public int GetTransitionCount ()
+    {
+        return maTransitions.size();
+    }
+    
+    
+    
+    
     private final Map<Integer,Map<Integer,Transition>> maTransitions;
 }

Modified: openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/SchemaReader.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/SchemaReader.java?rev=1602077&r1=1602076&r2=1602077&view=diff
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/SchemaReader.java (original)
+++ openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/SchemaReader.java Thu Jun 12 07:15:24 2014
@@ -37,10 +37,10 @@ import javax.xml.stream.XMLStreamExcepti
 
 import org.apache.openoffice.ooxml.schema.automaton.FiniteAutomatonContainer;
 import org.apache.openoffice.ooxml.schema.automaton.NonValidatingCreator;
-import org.apache.openoffice.ooxml.schema.automaton.FiniteAutomaton;
 import org.apache.openoffice.ooxml.schema.automaton.ValidatingCreator;
 import org.apache.openoffice.ooxml.schema.generator.LogGenerator;
 import org.apache.openoffice.ooxml.schema.generator.ParserTablesGenerator;
+import org.apache.openoffice.ooxml.schema.model.attribute.Attribute;
 import org.apache.openoffice.ooxml.schema.model.schema.Schema;
 import org.apache.openoffice.ooxml.schema.model.schema.SchemaBase;
 import org.apache.openoffice.ooxml.schema.parser.SchemaParser;

Modified: openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/Test.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/Test.java?rev=1602077&r1=1602076&r2=1602077&view=diff
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/Test.java (original)
+++ openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/Test.java Thu Jun 12 07:15:24 2014
@@ -53,6 +53,7 @@ public class Test
         HopcroftMinimizer.MinimizeDFA (
             new StateContainer(),
             aStates,
+            null,
             System.out);
     }
 }

Added: openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/CreatorBase.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/CreatorBase.java?rev=1602077&view=auto
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/CreatorBase.java (added)
+++ openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/CreatorBase.java Thu Jun 12 07:15:24 2014
@@ -0,0 +1,124 @@
+package org.apache.openoffice.ooxml.schema.automaton;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
+import java.util.Vector;
+
+import org.apache.openoffice.ooxml.schema.iterator.AttributeIterator;
+import org.apache.openoffice.ooxml.schema.iterator.DereferencingNodeIterator;
+import org.apache.openoffice.ooxml.schema.model.attribute.Attribute;
+import org.apache.openoffice.ooxml.schema.model.base.INode;
+import org.apache.openoffice.ooxml.schema.model.schema.SchemaBase;
+
+/** Base class of the creator classes for DFAs and NFAs.
+ */
+public class CreatorBase
+{
+    CreatorBase (
+        final SchemaBase aSchemaBase,
+        final File aLogFile)
+    {
+        maSchemaBase = aSchemaBase;
+        maStateContainer = new StateContainer();
+
+        PrintStream aLog = null;
+        try
+        {
+            aLog = new PrintStream(new FileOutputStream(aLogFile));
+        }
+        catch (FileNotFoundException e)
+        {
+            e.printStackTrace();
+        }
+        maLog = aLog;
+        msLogIndentation = "";
+    }
+    
+    
+    
+    
+    protected Vector<Attribute> CollectAttributes (final INode aRoot)
+    {
+        final Vector<Attribute> aAttributes = new Vector<>();
+        for (final INode aNode : new DereferencingNodeIterator(aRoot, maSchemaBase, true))
+            for (final Attribute aAttribute : new AttributeIterator(aNode, maSchemaBase))
+                aAttributes.add(aAttribute);
+        return aAttributes;
+    }
+
+    
+    
+    
+    protected void AddSkipTransition (
+        final State aState,
+        final SkipData aSkipData)
+    {
+        aState.AddSkipData(aSkipData);
+        
+        if (maLog != null)
+        {
+            maLog.printf("%sskip state %s\n",
+                msLogIndentation,
+                aState.GetFullname());
+        }
+    }
+    
+    
+    
+    
+    protected void ProcessAttributes (final INode aNode)
+    {
+        for (final Attribute aAttribute : new AttributeIterator(aNode, maSchemaBase))
+        {
+            maLog.printf("%sattribute %s\n",
+                msLogIndentation,
+                aAttribute.GetName().GetDisplayName());
+            maAttributes.add(aAttribute);
+        }
+    }
+    
+        
+
+    
+    protected void AddComment (
+        final String sFormat,
+        final Object ... aArgumentList)
+    {
+        if (maLog != null)
+        {
+            maLog.print(msLogIndentation);
+            maLog.print("// ");
+            maLog.printf(sFormat, aArgumentList);
+            maLog.print("\n");
+        }
+    }
+    
+    
+    
+    
+    protected void StartBlock ()
+    {
+        if (maLog != null)
+            msLogIndentation += "    ";
+    }
+    
+    
+    
+    
+    protected void EndBlock ()
+    {
+        if (maLog != null)
+            msLogIndentation = msLogIndentation.substring(4);
+    }
+    
+    
+    
+    
+    protected final SchemaBase maSchemaBase;
+    protected final StateContainer maStateContainer;
+    protected final PrintStream maLog;
+    protected String msLogIndentation;
+    protected Vector<Attribute> maAttributes;
+}

Modified: openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/DFACreator.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/DFACreator.java?rev=1602077&r1=1602076&r2=1602077&view=diff
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/DFACreator.java (original)
+++ openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/DFACreator.java Thu Jun 12 07:15:24 2014
@@ -12,6 +12,7 @@ import java.util.TreeMap;
 import java.util.TreeSet;
 import java.util.Vector;
 
+import org.apache.openoffice.ooxml.schema.model.attribute.Attribute;
 import org.apache.openoffice.ooxml.schema.model.base.QualifiedName;
 
 /** Convert an NFA into a DFA via the powerset construction (also called subset
@@ -25,11 +26,14 @@ public class DFACreator
     public static FiniteAutomaton CreateDFAforNFA (
         final StateContainer aDFAStateContainer,
         final StateContext aNFAStateContext,
+        final Vector<Attribute> aAttributes,
         final QualifiedName aTypeName)
     {
         final DFACreator aCreator = new DFACreator(aDFAStateContainer, aNFAStateContext, aTypeName);
         aCreator.CreateDFAforNFA();
-        return new FiniteAutomaton(aCreator.maDFAStateContext);
+        return new FiniteAutomaton(
+            aCreator.maDFAStateContext,
+            aAttributes);
     }
 
     

Modified: openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/FiniteAutomaton.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/FiniteAutomaton.java?rev=1602077&r1=1602076&r2=1602077&view=diff
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/FiniteAutomaton.java (original)
+++ openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/FiniteAutomaton.java Thu Jun 12 07:15:24 2014
@@ -23,6 +23,7 @@ package org.apache.openoffice.ooxml.sche
 
 import java.util.Vector;
 
+import org.apache.openoffice.ooxml.schema.model.attribute.Attribute;
 import org.apache.openoffice.ooxml.schema.model.base.QualifiedName;
 
 
@@ -37,9 +38,13 @@ import org.apache.openoffice.ooxml.schem
 public class FiniteAutomaton
 {
     FiniteAutomaton (
-        final StateContext aContext)
+        final StateContext aContext,
+        final Vector<Attribute> aAttributes)
     {
         maStateContext = aContext;
+        maAttributes = aAttributes!=null
+            ? aAttributes
+            : new Vector<Attribute>();
     }
     
     
@@ -92,6 +97,7 @@ public class FiniteAutomaton
         return DFACreator.CreateDFAforNFA(
             aDFAContainer,
             maStateContext,
+            maAttributes,
             aTypeName);
     }
 
@@ -137,5 +143,14 @@ public class FiniteAutomaton
     
     
     
+    public Vector<Attribute> GetAttributes ()
+    {
+        return maAttributes;
+    }
+    
+    
+    
+    
     private final StateContext maStateContext;
+    private final Vector<Attribute> maAttributes; 
 }

Modified: openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/FiniteAutomatonContainer.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/FiniteAutomatonContainer.java?rev=1602077&r1=1602076&r2=1602077&view=diff
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/FiniteAutomatonContainer.java (original)
+++ openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/FiniteAutomatonContainer.java Thu Jun 12 07:15:24 2014
@@ -72,18 +72,6 @@ public class FiniteAutomatonContainer
 
 
 
-    public Iterable<Transition> GetTransitions ()
-    {
-        final Vector<Transition> aTransitions = new Vector<>();
-        for (final FiniteAutomaton aAutomaton : maComplexTypeNameToAutomatonMap.values())
-            for (final Transition aTransition : aAutomaton.GetTransitions())
-                aTransitions.add(aTransition);
-        return aTransitions;
-    }
-
-    
-    
-    
     public int GetTransitionCount ()
     {
         int nTransitionCount = 0;
@@ -135,6 +123,7 @@ public class FiniteAutomatonContainer
                 HopcroftMinimizer.MinimizeDFA(
                     aNewStateContainer,
                     aEntry.getValue().GetStateContext(),
+                    aEntry.getValue().GetAttributes(),
                     aLog));
         }
         return aDFAs;

Modified: openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/HopcroftMinimizer.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/HopcroftMinimizer.java?rev=1602077&r1=1602076&r2=1602077&view=diff
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/HopcroftMinimizer.java (original)
+++ openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/HopcroftMinimizer.java Thu Jun 12 07:15:24 2014
@@ -9,7 +9,9 @@ import java.util.Map.Entry;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
+import java.util.Vector;
 
+import org.apache.openoffice.ooxml.schema.model.attribute.Attribute;
 import org.apache.openoffice.ooxml.schema.model.base.QualifiedName;
 
 /** Minimize an DFA with respect to its number of states.
@@ -24,6 +26,7 @@ public class HopcroftMinimizer
     public static FiniteAutomaton MinimizeDFA (
         final StateContainer aNewStateContainer,
         final StateContext aOriginalStates,
+        final Vector<Attribute> aAttributes,
         final PrintStream aLog)
     {
         if (aLog != null)
@@ -95,7 +98,8 @@ public class HopcroftMinimizer
 
         // Create and return the new minimized automaton.
         return new FiniteAutomaton(
-            aMinimizedStates);
+            aMinimizedStates,
+            aAttributes);
     }
 
 

Modified: openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/NonValidatingCreator.java
URL: http://svn.apache.org/viewvc/openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/NonValidatingCreator.java?rev=1602077&r1=1602076&r2=1602077&view=diff
==============================================================================
--- openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/NonValidatingCreator.java (original)
+++ openoffice/trunk/main/ooxml/source/framework/SchemaParser/src/org/apache/openoffice/ooxml/schema/automaton/NonValidatingCreator.java Thu Jun 12 07:15:24 2014
@@ -22,9 +22,6 @@
 package org.apache.openoffice.ooxml.schema.automaton;
 
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.PrintStream;
 import java.util.Vector;
 
 import org.apache.openoffice.ooxml.schema.iterator.DereferencingNodeIterator;
@@ -42,24 +39,13 @@ import org.apache.openoffice.ooxml.schem
  *  Input files but are not validated to conform to the schemas.
  */
 public class NonValidatingCreator
+    extends CreatorBase
 {
     public NonValidatingCreator (
         final SchemaBase aSchemaBase,
         final File aLogFile)
     {
-        maSchemaBase = aSchemaBase;
-        maStateContainer = new StateContainer();
-        
-        PrintStream aLog = null;
-        try
-        {
-            aLog = new PrintStream(new FileOutputStream(aLogFile));
-        }
-        catch (FileNotFoundException e)
-        {
-            e.printStackTrace();
-        }
-        maLog = aLog;
+        super(aSchemaBase, aLogFile);
     }
     
     
@@ -89,23 +75,40 @@ public class NonValidatingCreator
     private FiniteAutomaton CreateForTopLevelElements (
         final Iterable<Schema> aTopLevelSchemas)
     {
+        AddComment("top level elements");
+        StartBlock();
         final String sTypeName = "<top-level>"; 
         final StateContext aStateContext = new StateContext(
             maStateContainer,
             sTypeName);
+        final State aStartState = aStateContext.GetStartState();
         final State aEndState = aStateContext.CreateEndState();
 
         // top level elements
         for (final Schema aSchema : aTopLevelSchemas)
+        {
+            AddComment("schema %s", aSchema.GetShortName());
+            StartBlock();
             for (final Element aElement : aSchema.TopLevelElements.GetSorted())
+            {
+                AddComment("Element: on '%s' go from %s to %s via %s",
+                    aElement.GetElementName().GetDisplayName(),
+                    aStartState.GetFullname(),
+                    aEndState.GetFullname(),
+                    aElement.GetTypeName().GetStateName());
+
                 aStateContext.GetStartState().AddTransition(
                     new Transition(
-                        aStateContext.GetStartState(),
+                        aStartState,
                         aEndState,
                         aElement.GetElementName(),
                         aElement.GetTypeName().GetStateName()));
+            }
+            EndBlock();
+        }
+        EndBlock();
         
-        return new FiniteAutomaton(aStateContext);
+        return new FiniteAutomaton(aStateContext, null);
     }
     
     
@@ -113,12 +116,24 @@ public class NonValidatingCreator
     
     private FiniteAutomaton CreateForComplexType (final ComplexType aComplexType)
     {
+        maLog.printf("\n");
+        AddComment ("Complex Type %s defined in %s.",
+            aComplexType.GetName().GetDisplayName(),
+            aComplexType.GetLocation());
+        StartBlock();
+        
         final StateContext aStateContext = new StateContext(
             maStateContainer,
             aComplexType.GetName().GetStateName());
 
         for (final Element aElement : CollectElements(aComplexType))
         {
+            AddComment("Element: on '%s' go from %s to %s via %s",
+                aElement.GetElementName().GetDisplayName(),
+                aStateContext.GetStartState().GetFullname(),
+                aStateContext.GetStartState().GetFullname(),
+                aElement.GetTypeName().GetStateName());
+
             aStateContext.GetStartState().AddTransition(
                 new Transition(
                     aStateContext.GetStartState(),
@@ -129,15 +144,23 @@ public class NonValidatingCreator
         
         for (final Any aAny : CollectAnys(aComplexType))
         {
-            aStateContext.GetStartState().AddSkipData(
+            AddSkipTransition(
+                aStateContext.GetStartState(),
                 new SkipData(
                     aAny.GetProcessContentsFlag(),
                     aAny.GetNamespaces()));
         }
 
+        // Collect all attributes.
+        maAttributes = new Vector<>();
+        for (final INode aNode : new DereferencingNodeIterator(aComplexType, maSchemaBase, true))
+            ProcessAttributes(aNode);
+
         aStateContext.GetStartState().SetIsAccepting();
         
-        return new FiniteAutomaton(aStateContext); 
+        EndBlock();
+        
+        return new FiniteAutomaton(aStateContext, maAttributes); 
     }
     
     
@@ -170,11 +193,4 @@ public class NonValidatingCreator
         }
         return aAnys;
     }
-
-    
-    
-    
-    private final SchemaBase maSchemaBase;
-    private final StateContainer maStateContainer;
-    private final PrintStream maLog;
 }



Mime
View raw message