incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From devin...@apache.org
Subject svn commit: r1172466 [2/16] - in /incubator/odf/trunk/validator: ./ misc/ nbproject/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/odftoolkit/ src/main/java/org/odftoolkit/odfvalidator/ src/main/resources/ src/main/resources/META-INF/ s...
Date Mon, 19 Sep 2011 05:43:28 GMT
Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/Main.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/Main.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/Main.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/Main.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,289 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+/**
+ * This application validates an OpenDocument file. To run this application from the command line without Ant, try:
+ * java -jar "[path/]ODFValidator.jar".
+ * @author michael
+ */
+public class Main {
+
+    private static final String VERSION="1.1.4";
+    
+    /** Creates a new instance of Main */
+    public Main() {
+    }
+    
+    /**
+     * @param aArgs the command line arguments
+     */
+    public static void main(String[] aArgs) {
+        
+        String aConfigFileName = null;
+        String aFilterFileName = null;
+        String aSchemaFileName = null;
+        String aOutputFileName = null;
+        String aExcludeRegExp = null;
+        boolean bPrintGenerator = false;
+        boolean bUseMathDTD = false;
+        boolean bPrintHelp = false;
+        boolean bPrintVersion = false;
+        boolean bRecursive = false;
+        Logger.LogLevel nLogLevel = Logger.LogLevel.ERROR;
+        OdfValidatorMode eMode = OdfValidatorMode.VALIDATE;
+        List<String> aFileNames = new Vector<String>();
+        OdfVersion aVersion = null;
+
+        boolean bCommandLineValid = true;
+        List<String> aArgList = Arrays.asList(aArgs);
+        Iterator<String> aArgIter = aArgList.iterator();
+        while( aArgIter.hasNext() && bCommandLineValid )
+        {
+            String aArg = aArgIter.next();
+            if( aArg.equals("-c") )
+            {
+                eMode = OdfValidatorMode.CONFORMANCE;
+            }
+            else if( aArg.equals("-d") )
+            {
+                bUseMathDTD = true;
+            }
+            else if( aArg.equals("-e") )
+            {
+                eMode = OdfValidatorMode.EXTENDED_CONFORMANCE;
+            }
+            else if( aArg.equals("-f") )
+            {
+                if( aArgIter.hasNext() )
+                    aFilterFileName = aArgIter.next();
+                else
+                    bCommandLineValid = false;
+            }
+            else if( aArg.equals("-g") )
+            {
+                bPrintGenerator = true;
+            }
+            else if( aArg.equals("-h") )
+            {
+                bPrintHelp = true;
+            }
+            else if( aArg.equals("-o") )
+            {
+                if( aArgIter.hasNext() )
+                    aOutputFileName = aArgIter.next();
+                else
+                    bCommandLineValid = false;
+            }
+            else if( aArg.equals("-r") )
+            {
+                bRecursive = true;
+            }
+            else if( aArg.equals("-s") )
+            {
+                eMode = OdfValidatorMode.VALIDATE_STRICT;
+            }
+            else if( aArg.equals("-v") )
+            {
+                nLogLevel = Logger.LogLevel.INFO;
+            }
+            else if( aArg.equals("-w") )
+            {
+                nLogLevel = Logger.LogLevel.WARNING;
+            }
+            else if( aArg.equals("-x") )
+            {
+                if( aArgIter.hasNext() )
+                    aExcludeRegExp = aArgIter.next();
+                else
+                    bCommandLineValid = false;
+            }
+            else if( aArg.equals("-C") )
+            {
+                if( aArgIter.hasNext() )
+                    aConfigFileName = aArgIter.next();
+                else
+                    bCommandLineValid = false;
+            }
+            else if( aArg.equals("-S") )
+            {
+                if( aArgIter.hasNext() )
+                    aSchemaFileName = aArgIter.next();
+                else
+                    bCommandLineValid = false;
+            }
+            else if( aArg.equals("-V") )
+            {
+                bPrintVersion = true;
+            }
+            else if( aArg.equals("-1.0") || aArg.equals("-1.1") || aArg.equals("-1.2") )
+            {
+                aVersion = OdfVersion.valueOf( aArg.substring(1), false );
+            }
+            else if( aArg.startsWith("-") )
+            {
+                System.out.print(aArg);
+                System.out.println(": unknown option, use '-' for help");
+                return;
+            }
+            else if( aArg.length()>0 )
+            {
+                aFileNames.add( aArg );
+            }
+        }
+
+        // check usage
+        if( bPrintHelp || bPrintVersion )
+        {
+            bCommandLineValid = true;
+        }
+        else if( bPrintGenerator )
+        {
+            bCommandLineValid = aFileNames.size() > 0;
+        }
+        else if( aConfigFileName != null )
+        {
+            bCommandLineValid = aConfigFileName.length() > 0;
+        }
+        else
+        {
+            bCommandLineValid = aFileNames.size() > 0;
+        }
+
+        // print help
+        if( !bCommandLineValid || bPrintHelp )
+        {
+            printUsage();
+            return;
+        }
+        if( bPrintVersion )
+        {
+            System.out.print("odfvalidator v");
+            System.out.println( VERSION );
+            return;
+        }
+        
+        try
+        {
+            // Print generator (does not require config file)
+            if( bPrintGenerator ) 
+            {
+                MetaInformation aMetaInformation = new MetaInformation( System.out );
+                Iterator<String> aIter = aFileNames.iterator();
+                while( aIter.hasNext() )
+                    aMetaInformation.getInformation(aIter.next());
+                return;
+            }
+            
+            // Read configuration
+            Configuration aConfig = null;
+            if( aConfigFileName != null )
+            {
+                File aConfigFile = new File( aConfigFileName );
+                try
+                {
+                    aConfig = new Configuration( aConfigFile );
+                }
+                catch( FileNotFoundException e )
+                {
+                    if( aConfigFileName != null )
+                    {
+                        System.out.println( aConfigFile.getAbsolutePath() + ": file not found.");
+                        return;
+                    }
+                }
+                catch( IOException e )
+                {
+                    System.out.println("error reading " + aConfigFile.getAbsolutePath() + ": " + e.getLocalizedMessage() );
+                    return;
+                }
+            }
+            
+            if( aSchemaFileName != null )
+            {
+                aConfig = new Configuration();
+                aConfig.setProperty( Configuration.STRICT_SCHEMA, aSchemaFileName );
+            }
+
+            PrintStream aOut = aOutputFileName != null ? new PrintStream( aOutputFileName ) : System.out;
+            ODFValidator aValidator = new ODFValidator( aConfig, nLogLevel, aVersion, bUseMathDTD );
+
+            if( aConfigFileName != null )
+            {
+                aValidator.validate(aOut, aConfig, eMode );
+            }
+            else
+            {
+                aValidator.validate(aOut, aFileNames, aExcludeRegExp, eMode, bRecursive, aFilterFileName );
+            }
+        }
+        catch( ODFValidatorException e )
+        {
+            System.out.println( e.getMessage() );
+            System.out.println( "Validation aborted." );
+        }
+        catch( FileNotFoundException e )
+        {
+            System.out.println( e.getMessage() );
+            System.out.println( "Validation aborted." );
+        }
+    }
+    
+    private static void printUsage()
+    {
+        System.out.println( "usage: odfvalidator -g <odffiles>");
+        System.out.println( "       odfvalidator [-r] [-c|-e|-s] [-d] [-v|-w] [-f <filterfile>] [-x <regexp>] [-o outputfile] [-1.0|-1.1|-1.2] <odffiles>");
+        System.out.println( "       odfvalidator [-r] [-c|-e|-s] [-d] [-v|-w] [-f <filterfile>] [-x <regexp>] [-o outputfile] -S <schemafile> <odffiles>");
+        System.out.println( "       odfvalidator [-c|-s] [-v|-w] [-d] [-o outputfile] -C <configfile>");
+        System.out.println( "       odfvalidator -h");
+        System.out.println( "       odfvalidator -V");
+        System.out.println();
+        System.out.println( "-C: Validate using configuration file <configfile>" );
+        System.out.println( "-S: Use schema <schemafile> for validation" );
+        System.out.println( "-V: Print version" );
+        System.out.println( "-c: Check conformance (default for ODF 1.2 documents)" );
+        System.out.println( "-e: Check extended conformance (ODF 1.2 documents only)" );
+        System.out.println( "-d: Use MathML DTD rather than MathML2 schema for validation" );
+        System.out.println( "-f: Use filterfile <filterfile>" );
+        System.out.println( "-g: Show <odffiles> generators and exit" );
+        System.out.println( "-h: Print this help and exit" );
+        System.out.println( "-o: Store validation errors in <outputfile>" );
+        System.out.println( "-r: Process directory recursively" );
+        System.out.println( "-s: Validate against strict schema (ODF 1.2 documents only)" );
+        System.out.println( "-v: Verbose output, including generator and warnings" );
+        System.out.println( "-w: Print warnings" );
+        System.out.println( "-x: Exclude paths that match <regexp>" );
+        System.out.println();
+        System.out.println( "If no option is provided, <odffiles> are validated using <schemafile>" );
+    }
+
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ManifestEntry.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ManifestEntry.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ManifestEntry.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ManifestEntry.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,68 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+public class ManifestEntry
+{
+    private String m_aFullPath;
+    private String m_aMediaType;
+    
+    ManifestEntry(String aFullPath, String aMediaType)
+    {
+        m_aFullPath = aFullPath;
+        m_aMediaType = aMediaType;
+    }
+
+    String getFullPath()
+    {
+        return m_aFullPath;
+    }
+
+    String getMediaType()
+    {
+        return m_aMediaType;
+    }
+
+    boolean isOpenDocumentMediaType()
+    {
+        return m_aMediaType!=null && isOpenDocumentMediaType(m_aMediaType);
+    }
+
+    static boolean isOpenDocumentMediaType( String aMediaType )
+    {
+        if( aMediaType.length() >14 && aMediaType.substring(12,14).equals("x-") )
+        {
+            String aNewMediaType = aMediaType.substring(0,12) + aMediaType.substring(14);
+            aMediaType = aNewMediaType;
+        }
+
+        return aMediaType.equals(ODFMediaTypes.TEXT_MEDIA_TYPE) ||
+                aMediaType.equals(ODFMediaTypes.GRAPHICS_MEDIA_TYPE) ||
+                aMediaType.equals(ODFMediaTypes.SPREADSHEET_MEDIA_TYPE) ||
+                aMediaType.equals(ODFMediaTypes.PRESENTATION_MEDIA_TYPE) ||
+                aMediaType.equals(ODFMediaTypes.FORMULA_MEDIA_TYPE) ||
+                aMediaType.equals(ODFMediaTypes.CHART_MEDIA_TYPE);
+    }
+
+
+}
\ No newline at end of file

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ManifestEntryListener.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ManifestEntryListener.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ManifestEntryListener.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ManifestEntryListener.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,29 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+interface ManifestEntryListener {
+    
+    void foundManifestEntry( ManifestEntry aManifestEntry );
+    
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ManifestFilter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ManifestFilter.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ManifestFilter.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ManifestFilter.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,108 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import java.io.IOException;
+import java.io.StringReader;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+
+class ManifestFilter extends NamespaceFilter {
+    
+    private static final String OOO_MANIFEST_PUBLIC_ID = "-//OpenOffice.org//DTD Manifest 1.0//EN";
+    private static final String OOO_MANIFEST_NAMESPACE_URI = "http://openoffice.org/2001/manifest";
+    private static final String MANIFEST_NAMESPACE_URI = "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0";
+    
+    private static final String FILE_ENTRY = "file-entry";
+    private static final String FULL_PATH = "full-path";
+    private static final String MEDIA_TYPE = "media-type";
+    
+    private Logger m_aLogger;
+
+    private ManifestListener m_aManifestListener = null;
+    private ManifestEntryListener m_aManifestEntryListener = null;
+    
+    /** Creates a new instance of KnownIssueFilter */
+    ManifestFilter(Logger aLogger, ManifestListener aManifestListener,
+            ManifestEntryListener aManifestEntryListener)
+    {
+        m_aLogger = aLogger;
+        m_aManifestListener = aManifestListener;
+        m_aManifestEntryListener = aManifestEntryListener;
+    }
+
+    @Override
+    public InputSource resolveEntity(String aPublicId, String aSystemId) throws SAXException, IOException {
+        // Ignore the external OOo Manifest DTD which was errornously included
+        // in early OpenDocument files.
+        
+        if( aPublicId.equals(OOO_MANIFEST_PUBLIC_ID) )
+        {
+            String aMsg = "Ignoring doctype definition '" + OOO_MANIFEST_PUBLIC_ID + "' (has been stored by old OOo versions)";
+            m_aLogger.logInfo( aMsg , false);
+            return new InputSource(new StringReader(""));
+        }
+        else
+            return super.resolveEntity( aPublicId, aSystemId );
+    }
+
+    String adaptNamespaceUri( String aUri, String aPrefix)
+    {
+        String aNewUri = null;
+        if( aUri.equals(OOO_MANIFEST_NAMESPACE_URI) )
+            aNewUri = MANIFEST_NAMESPACE_URI;
+        
+        return aNewUri;
+    }
+
+    void namespaceUriAdapted( String aUri, String aNewUri )
+    {
+        String aMsg = "Adapting OpenOffice.org namspace'" + aUri + "' (has been stored by old OOo versions)";
+        m_aLogger.logInfo( aMsg , false);
+    }
+
+    @Override
+    public void startElement(String aUri, String aLocalName, String aQName, Attributes aAtts) throws SAXException {
+        super.startElement(aUri, aLocalName, aQName, aAtts);
+        if( (aUri.equals(MANIFEST_NAMESPACE_URI) || aUri.equals(OOO_MANIFEST_NAMESPACE_URI)) && aLocalName.equals(FILE_ENTRY))
+        {
+            String aFullPath = aAtts.getValue(aUri,FULL_PATH);
+            String aMediaType = aAtts.getValue(aUri,MEDIA_TYPE);
+            if( aFullPath != null )
+            {
+                if( aFullPath.equals("/") )
+                {
+                    if( m_aManifestListener != null )
+                        m_aManifestListener.setMediaType( aMediaType );
+                }
+                else
+                {
+                    if( m_aManifestEntryListener != null )
+                        m_aManifestEntryListener.foundManifestEntry( new ManifestEntry(aFullPath,aMediaType) );
+                }
+            }
+        }
+    }
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ManifestListener.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ManifestListener.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ManifestListener.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ManifestListener.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,29 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+interface ManifestListener {
+    
+    void setMediaType( String aMediaType );
+    
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MathML101Filter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MathML101Filter.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MathML101Filter.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MathML101Filter.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,98 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import java.io.IOException;
+import java.io.InputStream;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.XMLFilterImpl;
+
+/**
+ *
+ */
+class MathML101Filter extends XMLFilterImpl {
+//class MathML101Filter implements EntityResolver {
+    
+    private String m_aMathMLDTD;
+    private static final String MATHML_NAMESPACE_URI = "http://www.w3.org/1998/Math/MathML";
+    private static final String MATHML_PUBLIC_ID = "-//W3C//DTD MathML 1.01//EN";
+    private static final String OOO_MATHML_PUBLIC_ID = "-//OpenOffice.org//DTD Modified W3C MathML 1.01//EN";
+
+    private Logger m_aLogger;
+    
+    /** Creates a new instance of MathML101Filter */
+    MathML101Filter( String aMathMLDTD,  Logger aLogger )  {
+        m_aMathMLDTD = aMathMLDTD;
+        m_aLogger = aLogger;
+    }
+
+
+    public void startElement(String aUri, String aLocalName, String aQName, Attributes aAtts) throws SAXException {
+        super.startElement(aUri, aLocalName, aQName, aAtts);
+    }
+
+    public void endElement(String aUri, String aLocalName, String aQName) throws SAXException {
+        super.endElement(aUri, aLocalName, aQName);
+    }
+
+    public InputSource resolveEntity(String aPublicId, String aSystemId) throws SAXException, IOException {
+        InputSource aRet = null;
+        String aEntity = null;
+        
+        if( aPublicId != null &&
+            (aPublicId.equals(MATHML_PUBLIC_ID) ||
+            aPublicId.equals(OOO_MATHML_PUBLIC_ID)) )
+        {
+            aEntity = m_aMathMLDTD;
+            if( InternalResources.isInternalResourceIdentifer(aEntity) )
+            {
+                String aPath = InternalResources.getResourcePath(aEntity);
+                InputStream aInStream = getClass().getResourceAsStream(aPath);
+                if( aInStream == null )
+                {
+                    m_aLogger.logFatalError("Missing internal schema file: ".concat(aPath));
+                }
+                else
+                {
+                    aRet = new InputSource( aInStream );
+                    aRet.setPublicId(aPublicId);
+                    aRet.setSystemId(aEntity);
+                }
+            }
+        }
+        else
+        {
+            aEntity = aSystemId;
+        }
+
+        String aMsg = "Reading doctype definition '" + aEntity + "'";
+        m_aLogger.logInfo( aMsg , false);
+
+        if( aRet == null )
+            aRet = new InputSource( aEntity  );
+        return aRet;
+    }
+    
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MathML20Filter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MathML20Filter.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MathML20Filter.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MathML20Filter.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,52 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import java.io.IOException;
+import java.io.StringReader;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.XMLFilterImpl;
+
+/**
+ *
+ */
+class MathML20Filter extends XMLFilterImpl {
+    
+    private Logger m_aLogger;
+    
+    /** Creates a new instance of MathMLFilter */
+    MathML20Filter( Logger aLogger) {
+        m_aLogger = aLogger;
+    }
+
+    @Override
+    public InputSource resolveEntity(String aPublicId, String aSystemId) throws SAXException, IOException {
+        // Ignore the external OOo MathML DTD
+        
+        String aMsg = "Ignoring doctype definition '" + aPublicId + "'";
+            m_aLogger.logInfo( aMsg , false);
+        return new InputSource(new StringReader(""));
+    }
+    
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MetaFilter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MetaFilter.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MetaFilter.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MetaFilter.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,90 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import org.odftoolkit.odfdom.dom.OdfDocumentNamespace;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.XMLFilterImpl;
+
+class MetaFilter extends XMLFilterImpl {
+
+    private boolean m_bInGenerator = false;
+    private String m_aGenerator = "";
+    private boolean m_bRoot = true;
+    
+    private static final String META_NAMESPACE_URI = OdfDocumentNamespace.META.getUri();
+    private static final String OFFICE_NAMESPACE_URI = OdfDocumentNamespace.OFFICE.getUri();
+    private static final String GENERATOR = "generator";
+    private static final String DOCUMENT_META = "document-meta";
+
+    private Logger m_aLogger;
+    private MetaInformationListener m_aMetaListener;
+    
+    
+    /** Creates a new instance of MetaFilter */
+    MetaFilter( Logger aLogger, MetaInformationListener aMetaListener ) {
+        m_aLogger = aLogger;
+        m_aMetaListener = aMetaListener;
+    }
+    
+    @Override
+    public void characters(char[] aChars, int nStart, int nLength) throws SAXException {
+        super.characters(aChars, nStart, nLength);
+        
+        if( m_bInGenerator )
+        {
+            m_aGenerator += new String( aChars, nStart, nLength );
+        }
+    }
+
+    @Override
+    public void endElement(String aUri, String aLocalName, String aQName) throws SAXException {
+        super.endElement(aUri, aLocalName, aQName);
+        
+        if( aUri.equals(META_NAMESPACE_URI) && aLocalName.equals(GENERATOR) )
+        {
+            m_aGenerator = m_aGenerator.trim();
+            m_aLogger.logInfo( "Generator: " + m_aGenerator , false);
+            m_bInGenerator = false;
+            if( m_aMetaListener!=null ) {
+                m_aMetaListener.setGenerator( m_aGenerator );
+            }
+        }
+    }
+
+    @Override
+    public void startElement(String aUri, String aLocalName, String aQName, Attributes aAttributes) throws SAXException {
+        super.startElement(aUri, aLocalName, aQName, aAttributes);
+
+        if( m_bRoot )
+        {
+            if( !(aUri.equals(OFFICE_NAMESPACE_URI) && aLocalName.equals(DOCUMENT_META)) )
+                m_aLogger.logError("Invalid root element: " + aQName );
+            m_bRoot = false;
+        }
+                
+        if( aUri.equals(META_NAMESPACE_URI) && aLocalName.equals(GENERATOR) )
+            m_bInGenerator = true;
+    }
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MetaInformation.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MetaInformation.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MetaInformation.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MetaInformation.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,100 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import org.odftoolkit.odfdom.pkg.OdfPackage;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLFilter;
+
+
+public class MetaInformation {
+
+    private PrintStream m_aOut;
+    
+    /** Creates a new instance of Validator */
+    public MetaInformation( PrintStream aOut ) {
+        
+        m_aOut = aOut;
+    }
+
+    public void getInformation( String aDocFileName ) throws ODFValidatorException
+    {
+        try
+        {
+            OdfPackage aDocFile = OdfPackage.loadPackage( aDocFileName );
+            
+            getGenerator( aDocFile );
+        }
+        catch( Exception e )
+        {
+            throw new ODFValidatorException( aDocFileName, "", e );
+        }  
+    }
+    
+    public void getGenerator( OdfPackage aDocFile ) throws ODFValidatorException
+    {
+        try
+        {
+            InputStream aInStream = aDocFile.getInputStream(OdfPackage.OdfFile.MANIFEST.getPath(), true);
+            Logger aLogger = new Logger(aDocFile.getBaseURI(),OdfPackage.OdfFile.MANIFEST.getPath(),m_aOut, Logger.LogLevel.INFO);
+        
+            getInformation( aInStream, aLogger );
+        }
+        catch( Exception e )
+        {
+            throw new ODFValidatorException( aDocFile.getBaseURI(), "", e );
+        }  
+    }
+
+
+    
+    private void getInformation( InputStream aInStream, Logger aLogger ) throws IOException, ODFValidatorException
+    {
+        SAXParser aParser = null;
+        try
+        {
+            SAXParserFactory aParserFactory = SAXParserFactory.newInstance();
+            aParserFactory.setNamespaceAware(true);
+            aParser = aParserFactory.newSAXParser();
+
+            XMLFilter aFilter =  new MetaFilter(aLogger,null);
+            aFilter.setParent( aParser.getXMLReader() ) ;
+
+            aFilter.parse(new InputSource(aInStream));
+        }
+        catch( javax.xml.parsers.ParserConfigurationException e )
+        {
+            throw new ODFValidatorException( e );
+        }
+        catch( org.xml.sax.SAXException e )
+        {
+            throw new ODFValidatorException( e );
+        }
+    }
+
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MetaInformationListener.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MetaInformationListener.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MetaInformationListener.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/MetaInformationListener.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,29 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+interface MetaInformationListener {
+    
+    void setGenerator( String aGenerator );
+    
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/NamespaceFilter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/NamespaceFilter.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/NamespaceFilter.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/NamespaceFilter.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,94 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+import org.xml.sax.helpers.XMLFilterImpl;
+
+abstract class NamespaceFilter extends XMLFilterImpl {
+    
+    private boolean m_bFilterNamespaceUri = false;
+
+    /** Creates a new instance of NamespaceFilter */
+    NamespaceFilter() {
+    }
+
+    abstract String adaptNamespaceUri(String aUri, String aPrefix);
+    abstract void namespaceUriAdapted(String aUri, String aNewUri);
+
+
+    public void endElement(String aUri, String aLocalName, String aQName) throws SAXException {
+        if (m_bFilterNamespaceUri)
+        {    
+            String aNewUri = adaptNamespaceUri( aUri , aQName );
+            
+            if( aNewUri != null )
+                aUri = aNewUri;
+        }
+        
+        super.endElement(aUri, aLocalName, aQName);
+    }
+
+
+    public void startElement(String aUri, String aLocalName, String aQName, Attributes aAtts) throws SAXException {
+        if (m_bFilterNamespaceUri)
+        {    
+            String aNewUri = adaptNamespaceUri( aUri , aQName);
+            
+            if( aNewUri != null )
+                aUri = aNewUri;
+
+            Attributes aOldAtts = aAtts;
+            AttributesImpl aNewAtts = null;
+            for (int i = 0; i < aOldAtts.getLength(); ++i)
+            {
+                aNewUri = adaptNamespaceUri( aOldAtts.getURI(i) , aQName);
+                if (aNewUri != null)
+                {
+                    if (aNewAtts == null)
+                    {
+                        aNewAtts = new AttributesImpl(aOldAtts);
+                        aAtts = aNewAtts;
+                    }
+                    aNewAtts.setURI(i,aNewUri);
+                }
+            }
+        }
+        super.startElement(aUri, aLocalName, aQName, aAtts);
+    }
+
+
+
+    public void startPrefixMapping(String aPrefix, String aUri) throws SAXException {
+        String aNewUri = adaptNamespaceUri( aUri, aPrefix);
+        if (aNewUri != null)
+        {
+            m_bFilterNamespaceUri = true;
+            namespaceUriAdapted( aUri, aNewUri );
+        }
+        super.startPrefixMapping(aPrefix, aUri);
+    }
+    
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFFileFilter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFFileFilter.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFFileFilter.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFFileFilter.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,87 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.regex.Pattern;
+
+        
+public class ODFFileFilter implements FileFilter
+{
+    private boolean m_bRecursive;
+    private Pattern m_aExcludePattern = null;
+    
+    public ODFFileFilter( boolean bRecursive )
+    {
+        m_bRecursive = bRecursive;
+    }
+
+    public ODFFileFilter( String aExcludeRegExp, boolean bRecursive )
+    {
+        m_bRecursive = bRecursive;
+        if( aExcludeRegExp != null )
+            m_aExcludePattern = Pattern.compile(aExcludeRegExp);
+    }
+    
+    
+    public boolean accept(File aFile) {
+        return !exclude( aFile ) && (aFile.isDirectory() ? m_bRecursive : hasODFExtension( aFile ));
+    }
+    
+    private boolean exclude(File aFile)
+    {
+        boolean bExclude = false;
+        if( m_aExcludePattern != null )
+            bExclude = m_aExcludePattern.matcher(aFile.getAbsolutePath()).matches();
+        return bExclude;
+    }
+    
+    private boolean hasODFExtension(File aFile)
+    {
+        String aName = aFile.getName();
+        int nIndex = aName.lastIndexOf('.');
+        if (nIndex != -1 && aName.length() > nIndex+1)
+        {
+            String aExt = aName.substring(nIndex+1);
+            if( aExt.length() == 3 )
+            {
+                return aExt.equalsIgnoreCase("odt") ||
+                       aExt.equalsIgnoreCase("ods") ||
+                       aExt.equalsIgnoreCase("odg") ||
+                       aExt.equalsIgnoreCase("odp") ||
+                       aExt.equalsIgnoreCase("odf") ||
+                       aExt.equalsIgnoreCase("odc") ||
+                       aExt.equalsIgnoreCase("odb") ||
+                       aExt.equalsIgnoreCase("ott") ||
+                       aExt.equalsIgnoreCase("ots") ||
+                       aExt.equalsIgnoreCase("otg") ||
+                       aExt.equalsIgnoreCase("otp") ||
+                       aExt.equalsIgnoreCase("otf") ||
+                       aExt.equalsIgnoreCase("otc");
+            }
+        }
+        
+        return false;
+    }
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFFileValidator.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFFileValidator.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFFileValidator.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFFileValidator.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,63 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import java.io.File;
+import org.odftoolkit.odfdom.pkg.OdfPackage;
+import org.xml.sax.ErrorHandler;
+
+
+/**
+ * Validator for Files
+ */
+public class ODFFileValidator extends ODFRootPackageValidator {
+    
+    private File m_aFile = null;
+
+        /** Creates a new instance of ODFFileValidator */
+    public ODFFileValidator( File aFile, Logger.LogLevel nLogLevel,
+                             OdfValidatorMode eMode, OdfVersion aVersion,
+                             SAXParseExceptionFilter aFilter,
+                             ODFValidatorProvider aValidatorProvider ) throws ODFValidatorException
+    {
+        super( nLogLevel, eMode, aVersion, aFilter, aValidatorProvider );
+        m_aFile = aFile;
+    }
+
+    protected String getLoggerName()
+    {
+        return m_aFile.getAbsolutePath();
+    }
+
+    @Override
+    protected String getDocumentPath()
+    {
+        return ""; // this is the root document
+    }
+
+    protected OdfPackage getPackage(ErrorHandler handler) throws Exception
+    {
+        return OdfPackage.loadPackage(m_aFile, handler);
+    }
+
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFMediaTypes.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFMediaTypes.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFMediaTypes.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFMediaTypes.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,50 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+/**
+ * abstract Base class for OpenDocument filetype classes
+ */
+public abstract class ODFMediaTypes {
+
+    public static final String TEXT_MEDIA_TYPE = "application/vnd.oasis.opendocument.text";
+    public static final String TEXT_TEMPLATE_MEDIA_TYPE = "application/vnd.oasis.opendocument.text-template";
+    public static final String GRAPHICS_MEDIA_TYPE = "application/vnd.oasis.opendocument.graphics";
+    public static final String GRAPHICS_TEMPLATE_MEDIA_TYPE = "application/vnd.oasis.opendocument.graphics-template";
+    public static final String PRESENTATION_MEDIA_TYPE = "application/vnd.oasis.opendocument.presentation";
+    public static final String PRESENTATION_TEMPLATE_MEDIA_TYPE = "application/vnd.oasis.opendocument.presentation-template";
+    public static final String SPREADSHEET_MEDIA_TYPE = "application/vnd.oasis.opendocument.spreadsheet";
+    public static final String SPREADSHEET_TEMPLATE_MEDIA_TYPE = "application/vnd.oasis.opendocument.spreadsheet-template";
+    public static final String CHART_MEDIA_TYPE = "application/vnd.oasis.opendocument.chart";
+    public static final String CHART_TEMPLATE_MEDIA_TYPE = "application/vnd.oasis.opendocument.chart-template";
+    public static final String IMAGE_MEDIA_TYPE = "application/vnd.oasis.opendocument.image";
+    public static final String IMAGE_TEMPLATE_MEDIA_TYPE = "application/vnd.oasis.opendocument.image-template";
+    public static final String FORMULA_MEDIA_TYPE = "application/vnd.oasis.opendocument.formula";
+    public static final String FORMULA_TEMPLATE_MEDIA_TYPE = "application/vnd.oasis.opendocument.formula-template";
+    public static final String TEXT_MASTER_MEDIA_TYPE = "application/vnd.oasis.opendocument.text-master";
+    public static final String TEXT_WEB_MEDIA_TYPE = "application/vnd.oasis.opendocument.text-web";
+
+   
+}
+
+

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFPackageErrorHandler.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFPackageErrorHandler.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFPackageErrorHandler.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFPackageErrorHandler.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,146 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ *
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.odftoolkit.odfdom.pkg.OdfValidationException;
+import org.odftoolkit.odfdom.pkg.ValidationConstraint;
+import org.odftoolkit.odfdom.pkg.OdfPackageConstraint;
+import org.odftoolkit.odfdom.dom.OdfSchemaConstraint;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+class ODFPackageErrorHandler implements ErrorHandler {
+
+    List<SAXParseException> m_aExceptionList = new ArrayList<SAXParseException>();
+
+    ODFPackageErrorHandler()
+    {
+    }
+
+    public void warning(SAXParseException exception) throws SAXException {
+        m_aExceptionList.add(exception);
+    }
+
+    public void error(SAXParseException exception) throws SAXException {
+        m_aExceptionList.add(exception);
+    }
+
+    public void fatalError(SAXParseException exception) throws SAXException {
+        m_aExceptionList.add(exception);
+        throw exception;
+    }
+
+    /// deferred because aVersion is not available when odfdom checks mimetype
+    /// @returns true iff there was an error and package is not valid
+    boolean processErrors( Logger aPkgLogger, Logger aManifestLogger,
+                           Logger aMimetypeLogger,OdfVersion aVersion)
+    {
+        boolean bRet = false;
+        for (SAXParseException e : m_aExceptionList)
+        {
+            if (e instanceof OdfValidationException)
+            {
+                ValidationConstraint aConstraint =
+                    ((OdfValidationException) e).getConstraint();
+                if (aConstraint instanceof OdfPackageConstraint)
+                {
+                    switch (((OdfPackageConstraint) aConstraint))
+                    {
+                        case MANIFEST_DOES_NOT_LIST_FILE:
+                            switch (aVersion)
+                            {
+                                case V1_0:
+                                case V1_1:
+                                    aManifestLogger.logWarning(e.getMessage());
+                                    break;
+                                default:
+                                    aManifestLogger.logError(e.getMessage());
+                                    bRet = true;
+                                    break;
+                            }
+                            break;
+                        case MIMETYPE_NOT_FIRST_IN_PACKAGE:
+                        case MIMETYPE_NOT_IN_PACKAGE:
+                            switch (aVersion)
+                            {
+                                case V1_0:
+                                case V1_1:
+                                    aMimetypeLogger.logWarning(e.getMessage());
+                                    break;
+                                default:
+                                    aMimetypeLogger.logError(e.getMessage());
+                                    bRet = true;
+                                    break;
+                            }
+                            break;
+                        case MANIFEST_NOT_IN_PACKAGE:
+                        case MANIFEST_LISTS_NONEXISTENT_FILE:
+                            aManifestLogger.logError(e.getMessage());
+                            bRet = true;
+                            break;
+                        case MIMETYPE_IS_COMPRESSED:
+                        case MIMETYPE_HAS_EXTRA_FIELD:
+                        case MIMETYPE_DIFFERS_FROM_PACKAGE:
+                            aMimetypeLogger.logError(e.getMessage());
+                            bRet = true;
+                            break;
+                        case MANIFEST_LISTS_DIRECTORY:
+                        case MANIFEST_DOES_NOT_LIST_DIRECTORY:
+                            aManifestLogger.logWarning(e.getMessage());
+                            break;
+                        default:
+                            aPkgLogger.logError(e); // unknown aConstraint: assume error
+                            bRet = true;
+                            break;
+                    }
+                } 
+                else if (aConstraint instanceof OdfSchemaConstraint)
+                {
+                    switch (((OdfSchemaConstraint) aConstraint))
+                    {
+                        case DOCUMENT_WITHOUT_ODF_MIMETYPE:
+                        case DOCUMENT_WITHOUT_CONTENT_NOR_STYLES_XML:
+                            aPkgLogger.logError(e.getMessage());
+                            bRet = true;
+                            break;
+                        default:
+                            aPkgLogger.logError(e); // unknown aConstraint: assume error
+                            bRet = true;
+                            break;
+                    }
+                }
+            }
+            else
+            {
+                aPkgLogger.logError(e); // unknown aConstraint: assume error
+                bRet = true;
+            }
+        }
+
+        m_aExceptionList.clear();
+        return bRet;
+    }
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFPackageValidator.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFPackageValidator.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFPackageValidator.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFPackageValidator.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,435 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+package org.odftoolkit.odfvalidator;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.zip.ZipException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.validation.Validator;
+import org.odftoolkit.odfdom.doc.OdfDocument;
+import org.odftoolkit.odfdom.pkg.OdfPackage;
+import org.odftoolkit.odfdom.pkg.manifest.EncryptionData;
+import org.odftoolkit.odfdom.pkg.manifest.OdfFileEntry;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLFilter;
+import org.xml.sax.XMLReader;
+
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * Validator for Files
+ */
+abstract class ODFPackageValidator {
+
+	static final String DOCUMENT_SETTINGS = "document-settings";
+	static final String DOCUMENT_STYLES = "document-styles";
+	static final String DOCUMENT_CONTENT = "document-content";
+	protected Logger.LogLevel m_nLogLevel;
+	protected OdfValidatorMode m_eMode = OdfValidatorMode.CONFORMANCE;
+	protected SAXParseExceptionFilter m_aFilter = null;
+	protected ODFValidatorProvider m_aValidatorProvider = null;
+	protected ODFValidationResult m_aResult = null;
+	protected OdfVersion m_aConfigVersion = null;
+	private SAXParserFactory m_aSAXParserFactory = null;
+	protected OdfVersion mOdfPackageVersion = null;
+
+	protected ODFPackageValidator(Logger.LogLevel nLogLevel, OdfValidatorMode eMode, OdfVersion aVersion,
+			SAXParseExceptionFilter aFilter, ODFValidatorProvider aValidatorProvider) {
+		m_nLogLevel = nLogLevel;
+		m_eMode = eMode;
+		m_aFilter = aFilter;
+		m_aValidatorProvider = aValidatorProvider;
+		m_aConfigVersion = aVersion;
+		m_aResult = new ODFValidationResult(aVersion, eMode);
+	}
+
+	protected abstract String getLoggerName();
+
+	protected abstract String getDocumentPath();
+
+	protected abstract OdfPackage getPackage(Logger aLogger);
+
+	protected abstract String getStreamName(String aEntry);
+
+	protected boolean validate(PrintStream aOut) throws ODFValidatorException {
+		Logger aLogger =
+				new Logger(getLoggerName(), getDocumentPath(), aOut, m_nLogLevel);
+		return _validate(aLogger);
+	}
+
+	protected boolean validate(Logger aParentLogger) throws ODFValidatorException {
+		Logger aLogger =
+				new Logger(getDocumentPath(), aParentLogger);
+		return _validate(aLogger);
+	}
+
+	
+	OdfVersion getOdfPackageVersion(){
+		return mOdfPackageVersion;
+	}
+	
+	private boolean _validate(Logger aLogger) throws ODFValidatorException {
+		boolean bHasErrors = false;
+
+		OdfPackage aPkg = getPackage(aLogger);
+		if (aPkg == null) {
+			return true;
+		}
+
+		try {
+			String aDocVersion = getVersion(aLogger);
+			if (aDocVersion != null) {
+				aLogger.logInfo("ODF version of root document: " + aDocVersion, false);
+				mOdfPackageVersion = OdfVersion.valueOf(aDocVersion, true);
+			}
+			OdfVersion aVersion = m_aConfigVersion == null ? OdfVersion.valueOf(aDocVersion, true) : m_aConfigVersion;
+
+			bHasErrors |= validatePre(aLogger, aVersion);
+			aLogger.logInfo("Media Type: " + m_aResult.getMediaType(), false);
+
+			bHasErrors |= validateMeta(aLogger, getStreamName(OdfDocument.OdfXMLFile.META.getFileName()), aVersion, true);
+			bHasErrors |= validateEntry(aLogger, getStreamName(OdfDocument.OdfXMLFile.SETTINGS.getFileName()), DOCUMENT_SETTINGS, aVersion);
+			bHasErrors |= validateEntry(aLogger, getStreamName(OdfDocument.OdfXMLFile.STYLES.getFileName()), DOCUMENT_STYLES, aVersion);
+			if (m_aResult.getMediaType().equals(ODFMediaTypes.FORMULA_MEDIA_TYPE)) {
+				bHasErrors |= validateMathML(aLogger, getStreamName(OdfDocument.OdfXMLFile.CONTENT.getFileName()), aVersion);
+			} else {
+				bHasErrors |= validateEntry(aLogger, getStreamName(OdfDocument.OdfXMLFile.CONTENT.getFileName()), DOCUMENT_CONTENT, aVersion);
+			}
+			bHasErrors |= validatePost(aLogger, aVersion);
+		} catch (ZipException e) {
+			aLogger.logFatalError(e.getMessage());
+		} catch (IOException e) {
+			aLogger.logFatalError(e.getMessage());
+		}
+
+		logSummary(bHasErrors, aLogger);
+
+		return bHasErrors || aLogger.hasError();
+	}
+
+	protected boolean validatePre(Logger aLogger, OdfVersion aVersion) throws ODFValidatorException, IOException {
+		return false;
+	}
+
+	protected boolean validatePost(Logger aLogger, OdfVersion aVersion) throws ODFValidatorException, IOException {
+		return false;
+	}
+
+	protected void logSummary(boolean bHasErrors, Logger aLogger) {
+	}
+
+	protected boolean validateEntry(Logger aParentLogger, String aEntryName, String aLocalElementName, OdfVersion aVersion) throws IOException, ZipException, IllegalStateException, ODFValidatorException {
+		Logger aLogger = new Logger(aEntryName, aParentLogger);
+		XMLFilter aFilter = new ContentFilter(aLogger, aLocalElementName);
+		if ((m_eMode == OdfValidatorMode.CONFORMANCE && aVersion.compareTo(OdfVersion.V1_1) <= 0)
+				|| m_eMode == OdfValidatorMode.EXTENDED_CONFORMANCE) {
+			XMLFilter aAlienFilter = new ForeignContentFilter(aLogger, aVersion, m_aResult);
+			aAlienFilter.setParent(aFilter);
+			aFilter = aAlienFilter;
+		}
+		Validator aValidator = null;
+		if (m_eMode == OdfValidatorMode.VALIDATE_STRICT) {
+			aValidator = m_aValidatorProvider.getStrictValidator(aParentLogger.getOutputStream(), aVersion);
+		} else {
+			aValidator = m_aValidatorProvider.getValidator(aParentLogger.getOutputStream(), aVersion);
+		}
+//		Validator aValidator = m_eMode == OdfValidatorMode.VALIDATE_STRICT ? m_aValidatorProvider.getStrictValidator(aParentLogger.getOutputStream(), aVersion)
+//				: m_aValidatorProvider.getValidator(aParentLogger.getOutputStream(), aVersion);
+		return validateEntry(aFilter, aValidator, aLogger, aEntryName);
+	}
+
+	private boolean validateMeta(Logger aParentLogger, String aEntryName, OdfVersion aVersion, boolean bIsRoot) throws IOException, ZipException, IllegalStateException, ODFValidatorException {
+		Logger aLogger = new Logger(aEntryName, aParentLogger);
+		XMLFilter aFilter = new MetaFilter(aLogger, m_aResult);
+		if ((m_eMode == OdfValidatorMode.CONFORMANCE && aVersion.compareTo(OdfVersion.V1_1) <= 0)
+				|| m_eMode == OdfValidatorMode.EXTENDED_CONFORMANCE) {
+			XMLFilter aAlienFilter = new ForeignContentFilter(aLogger, aVersion, m_aResult);
+			aAlienFilter.setParent(aFilter);
+			aFilter = aAlienFilter;
+		}
+
+		Validator aValidator = null;
+		if (m_eMode == OdfValidatorMode.VALIDATE_STRICT) {
+			aValidator = m_aValidatorProvider.getStrictValidator(aParentLogger.getOutputStream(), aVersion);
+		} else {
+			aValidator = m_aValidatorProvider.getValidator(aParentLogger.getOutputStream(), aVersion);
+		}
+		return validateEntry(aFilter, aValidator, aLogger, aEntryName);
+	}
+
+	private boolean validateMathML(Logger aParentLogger, String aEntryName, OdfVersion aVersion) throws IOException, ZipException, IllegalStateException, ODFValidatorException {
+		Logger aLogger = new Logger(aEntryName, aParentLogger);
+		String aMathMLDTDSystemId = m_aValidatorProvider.getMathMLDTDSystemId(aVersion);
+		if (aMathMLDTDSystemId != null) {
+			// validate using DTD
+			return parseEntry(new MathML101Filter(aMathMLDTDSystemId, aLogger), aLogger, aEntryName, true);
+		} else {
+			Validator aMathMLValidator = m_aValidatorProvider.getMathMLValidator(aParentLogger.getOutputStream(), null);
+			if (aMathMLValidator == null) {
+				aLogger.logInfo("MathML schema is not available. Validation has been skipped.", false);
+				return false;
+			}
+			return validateEntry(new MathML20Filter(aLogger), aMathMLValidator, aLogger, aEntryName);
+		}
+	}
+
+	protected boolean validateDSig(Logger aParentLogger, String aEntryName, OdfVersion aVersion) throws IOException, ZipException, IllegalStateException, ODFValidatorException {
+		Validator aValidator = m_aValidatorProvider.getDSigValidator(aParentLogger.getOutputStream(), aVersion);
+		Logger aLogger = new Logger(aEntryName, aParentLogger);
+		if (aValidator == null) {
+			aLogger.logWarning("Signature not validated because there is no Signature Validator configured for the selected Configuration");
+			return false;
+		}
+
+		return validateEntry(new DSigFilter(aLogger), aValidator, aLogger, aEntryName);
+	}
+
+	protected boolean validateEntry(XMLFilter aFilter,
+			Validator aValidator, Logger aLogger,
+			String aEntryName) throws IOException, ZipException, IllegalStateException, ODFValidatorException {
+		OdfPackage aPkg = getPackage(aLogger);
+
+		if (!aEntryName.equals(OdfPackage.OdfFile.MANIFEST.getPath()) && isEncrypted(aEntryName, aLogger)) {
+			return false;
+		}
+
+		InputStream aInStream = null;
+		try {
+			aInStream = aPkg.getInputStream(aEntryName, true);
+		} catch (Exception e) {
+			throw new ODFValidatorException(e);
+		}
+
+
+		if (aValidator == null) {
+
+			aLogger.logWarning("no Validator configured in selected Configuration for this file type");
+			return false;
+		}
+
+
+
+		return aInStream != null ? validate(aInStream, aFilter, aValidator, aLogger) : false;
+	}
+
+	private boolean validate(InputStream aInStream,
+			XMLFilter aFilter,
+			javax.xml.validation.Validator aValidator,
+			Logger aLogger) throws ODFValidatorException {
+		SAXParser aParser = getSAXParser(false);
+		SchemaErrorHandler aErrorHandler = new SchemaErrorHandler(aLogger, m_aFilter);
+
+		try {
+			XMLReader aReader;
+			if (aFilter != null) {
+				XMLReader aParent = aFilter.getParent();
+				if (aParent != null) {
+					((XMLFilter) aParent).setParent(aParser.getXMLReader());
+				} else {
+					aFilter.setParent(aParser.getXMLReader());
+				}
+				aReader = aFilter;
+			} else {
+				aReader = aParser.getXMLReader();
+			}
+
+			if (m_aFilter != null) {
+				m_aFilter.startSubFile();
+			}
+			aValidator.setErrorHandler(aErrorHandler);
+			try {
+				aValidator.validate(new SAXSource(aReader,
+						new InputSource(aInStream)));
+			} catch (RuntimeException e) {
+				aLogger.logFatalError(e.getMessage());
+				m_aValidatorProvider.resetValidatorProvider();
+			}
+		} catch (org.xml.sax.SAXParseException e) {
+			aErrorHandler.fatalErrorNoException(e);
+		} catch (org.xml.sax.SAXException e) {
+			aLogger.logFatalError(e.getMessage());
+		} catch (IOException e) {
+			aLogger.logFatalError(e.getMessage());
+		}
+
+		aLogger.logSummaryInfo();
+		if (m_aResult.hasForeignElements()) {
+			Set<String> aForeignElementURISet = m_aResult.getForeignElements().keySet();
+			StringBuilder aBuffer = new StringBuilder();
+			Iterator<String> aIter = aForeignElementURISet.iterator();
+			boolean bFirst = true;
+			while (aIter.hasNext()) {
+				String aURI = aIter.next();
+				aBuffer.setLength(0);
+				aBuffer.append(m_aResult.getForeignElements().get(aURI));
+				aBuffer.append(" extension elements from the following namespace were found: ");
+				aBuffer.append(aURI);
+				aLogger.logInfo(aBuffer.toString(), false);
+			}
+		}
+		if (m_aResult.hasForeignAttributes()) {
+			Set<String> aForeignAttributeURISet = m_aResult.getForeignAttributes().keySet();
+			Iterator<String> aIter = aForeignAttributeURISet.iterator();
+			StringBuilder aBuffer = new StringBuilder();
+			while (aIter.hasNext()) {
+				String aURI = aIter.next();
+				aBuffer.setLength(0);
+				aBuffer.append(m_aResult.getForeignAttributes().get(aURI));
+				aBuffer.append(" extension attributes from the following namespace were found: ");
+				aBuffer.append(aURI);
+				aLogger.logInfo(aBuffer.toString(), false);
+			}
+		}
+		return aLogger.hasError();
+	}
+
+	protected boolean parseEntry(XMLFilter aFilter,
+			Logger aLogger,
+			String aEntryName, boolean bValidating) throws IOException, ZipException, IllegalStateException, ODFValidatorException {
+		OdfPackage aPkg = getPackage(aLogger);
+
+		if (isEncrypted(aEntryName, aLogger)) {
+			return false;
+		}
+
+		InputStream aInStream = null;
+		try {
+			aInStream = getPackage(aLogger).getInputStream(aEntryName, true);
+		} catch (Exception e) {
+			throw new ODFValidatorException(e);
+		}
+
+		return aInStream != null ? parse(aInStream, aFilter, bValidating, aLogger) : false;
+	}
+
+	private boolean parse(InputStream aInStream, XMLFilter aFilter, boolean bValidating, Logger aLogger) throws ODFValidatorException {
+		SAXParser aParser = getSAXParser(bValidating);
+		SchemaErrorHandler aErrorHandler = new SchemaErrorHandler(aLogger, m_aFilter);
+
+		try {
+			XMLReader aReader;
+			if (aFilter != null) {
+				aFilter.setParent(aParser.getXMLReader());
+				aReader = aFilter;
+			} else {
+				aReader = aParser.getXMLReader();
+			}
+			if (m_aFilter != null) {
+				m_aFilter.startSubFile();
+			}
+			aReader.setErrorHandler(aErrorHandler);
+			aReader.parse(new InputSource(aInStream));
+		} catch (org.xml.sax.SAXParseException e) {
+			aErrorHandler.fatalErrorNoException(e);
+		} catch (org.xml.sax.SAXException e) {
+			aLogger.logFatalError(e.getMessage());
+		} catch (IOException e) {
+			aLogger.logFatalError(e.getMessage());
+		}
+
+		if (bValidating) {
+			aLogger.logSummaryInfo();
+		}
+		return aLogger.hasError();
+	}
+
+	private boolean isEncrypted(String aEntryName, Logger aLogger) {
+		OdfFileEntry aFileEntry = getPackage(aLogger).getFileEntry(aEntryName);
+		if (aFileEntry != null) {
+			EncryptionData aEncData = aFileEntry.getEncryptionData();
+			if (aEncData != null) {
+				aLogger.logFatalError("stream content is encrypted. Validataion of encrypted content is not supported.");
+				return true;
+			}
+		}
+		return false;
+	}
+
+	private SAXParser getSAXParser(boolean bValidating) throws ODFValidatorException {
+		SAXParser aParser = null;
+		if (m_aSAXParserFactory == null) {
+			m_aSAXParserFactory = SAXParserFactory.newInstance();
+			m_aSAXParserFactory.setNamespaceAware(true);
+		}
+
+		try {
+			m_aSAXParserFactory.setValidating(bValidating);
+			aParser = m_aSAXParserFactory.newSAXParser();
+		} catch (javax.xml.parsers.ParserConfigurationException e) {
+			throw new ODFValidatorException(e);
+		} catch (org.xml.sax.SAXException e) {
+			throw new ODFValidatorException(e);
+		}
+
+		return aParser;
+	}
+
+	/**
+	 * get the generator
+	 */
+	public String getGenerator() {
+		return m_aResult.getGenerator();
+	}
+
+	private String getVersion(Logger aLogger) throws ODFValidatorException {
+		String aVersion = null;
+
+		InputStream aInStream = null;
+		try {
+			OdfPackage aPkg = getPackage(aLogger);
+			aInStream = aPkg.getInputStream(getStreamName(OdfDocument.OdfXMLFile.META.getFileName()), true);
+			if (aInStream == null) {
+				aInStream = aPkg.getInputStream(getStreamName(OdfDocument.OdfXMLFile.SETTINGS.getFileName()), true);
+			}
+			if (aInStream == null) {
+				aInStream = aPkg.getInputStream(getStreamName(OdfDocument.OdfXMLFile.CONTENT.getFileName()), true);
+			}
+			if (aInStream == null) {
+				return null;
+			}
+		} catch (Exception e) {
+			aLogger.logFatalError(e.getMessage());
+		}
+
+		SAXParser aParser = getSAXParser(false);
+
+		DefaultHandler aHandler = new VersionHandler();
+
+		try {
+			aParser.parse(aInStream, aHandler);
+		} catch (SAXVersionException e) {
+			aVersion = e.getVersion();
+		} catch (org.xml.sax.SAXException e) {
+			aLogger.logFatalError(e.getMessage());
+		} catch (IOException e) {
+			aLogger.logFatalError(e.getMessage());
+		}
+
+		return aVersion;
+	}
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFRootPackageValidator.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFRootPackageValidator.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFRootPackageValidator.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFRootPackageValidator.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,192 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.zip.ZipException;
+import javax.xml.validation.Validator;
+import org.odftoolkit.odfdom.pkg.OdfPackage;
+import org.odftoolkit.odfdom.doc.OdfDocument;
+import org.xml.sax.ErrorHandler;
+
+abstract class ODFRootPackageValidator extends ODFPackageValidator implements ManifestEntryListener {
+
+    private OdfPackage m_aPkg = null;
+    private ArrayList<ManifestEntry> m_aSubDocs = null;
+    private ODFPackageErrorHandler m_ErrorHandler = null;
+
+    protected ODFRootPackageValidator(Logger.LogLevel nLogLevel, OdfValidatorMode eMode, OdfVersion aVersion, SAXParseExceptionFilter aFilter, ODFValidatorProvider aValidatorProvider) {
+        super(nLogLevel, eMode, aVersion, aFilter, aValidatorProvider);
+    }
+
+    protected abstract OdfPackage getPackage(ErrorHandler handler) throws Exception;
+
+    protected OdfPackage getPackage(Logger aLogger) {
+        if (m_aPkg == null) {
+            try {
+                m_ErrorHandler = new ODFPackageErrorHandler();
+                m_aPkg = getPackage(m_ErrorHandler);
+                // for additional mimetype checking, load root document
+                try {
+                    OdfDocument.loadDocument(m_aPkg, "");
+                } catch (Exception e) {
+                    // ignore -- the interesting stuff is passed to handler
+                }
+            } catch (IOException e) {
+                if (e.getMessage().startsWith("only DEFLATED entries can have EXT descriptor")) {
+                    aLogger.logFatalError("The document is encrypted. Validation of encrypted documents is not supported.");
+                } else {
+                    aLogger.logFatalError(e.getMessage());
+                }
+            } catch (Exception e) {
+                aLogger.logFatalError(e.getMessage());
+            }
+        }
+
+        return m_aPkg;
+    }
+
+    protected String getStreamName( String aEntry )
+    {
+        return aEntry;
+    }
+
+    @Override
+    protected boolean validatePre(Logger aLogger, OdfVersion aVersion ) throws ODFValidatorException, IOException
+    {
+        Logger aManifestLogger = new Logger(OdfPackage.OdfFile.MANIFEST.getPath(),aLogger);
+        Logger aMimetypeLogger = new Logger("mimetype",aLogger);
+
+        // UGLY: do something that causes ODFDOM to parse the manifest, which
+        // may cause m_ErrorHandler to be called
+        m_aPkg.getFilePaths();
+        // hack: just create logger again, too lazy to create a Pair class
+        // and return it from validateMimetype...
+        boolean bErrorsFound = m_ErrorHandler.processErrors( aLogger, aManifestLogger,
+                                              aMimetypeLogger, aVersion);
+
+        bErrorsFound |= validateMimetype(aMimetypeLogger, aVersion);
+        bErrorsFound |= validateManifest(aManifestLogger, aVersion  );
+        aMimetypeLogger.logSummaryInfo();
+
+        return bErrorsFound;
+    }
+
+    @Override
+    protected boolean validatePost(Logger aLogger,OdfVersion aVersion ) throws ODFValidatorException, IOException
+    {
+        boolean bHasErrors = false;
+        if(m_aSubDocs != null )
+        {
+            Iterator<ManifestEntry> aIter = m_aSubDocs.iterator();
+            while( aIter.hasNext() )
+            {
+                ManifestEntry aEntry = aIter.next();
+                ODFPackageValidator aPackageValidator =
+                    new ODFSubPackageValidator( getPackage(aLogger), getLoggerName(), aEntry.getFullPath(), aEntry.getMediaType(),
+                                                  m_nLogLevel, m_eMode, m_aConfigVersion, m_aFilter, m_aResult.getGenerator(), m_aValidatorProvider );
+                bHasErrors |= aPackageValidator.validate(aLogger);
+            }
+        }
+
+        if( aVersion.compareTo(OdfVersion.V1_2) >= 0 )
+        {
+            bHasErrors |= validateDSig( aLogger, OdfPackageExt.STREAMNAME_DOCUMENT_SIGNATURES, aVersion );
+            bHasErrors |= validateDSig( aLogger, OdfPackageExt.STREAMNAME_MACRO_SIGNATURES, aVersion );
+        }
+
+        return bHasErrors;
+    }
+
+    @Override
+    protected void logSummary( boolean bHasErrors, Logger aLogger )
+    {
+        aLogger.logSummaryInfo();
+        if( (bHasErrors || aLogger.hasError()) && m_nLogLevel.compareTo(Logger.LogLevel.INFO) < 0  )
+            aLogger.logInfo( "Generator: " + m_aResult.getGenerator() , true );
+    }
+
+
+    public void foundManifestEntry( ManifestEntry aManifestEntry )
+    {
+        if( aManifestEntry.isOpenDocumentMediaType() )
+        {
+            if( m_aSubDocs == null )
+                m_aSubDocs = new ArrayList<ManifestEntry>();
+            m_aSubDocs.add( aManifestEntry );
+        }
+    }
+
+    private boolean validateMimetype(Logger aLogger, OdfVersion aVersion)
+    {
+        boolean bHasErrors = false;
+
+        String aMimetype=getPackage(aLogger).getMediaTypeString();
+        if( (aMimetype == null) || aMimetype.length() == 0 ) {
+            aLogger.logFatalError("file is not a zip file, or has no mimetype.");
+            bHasErrors = true;
+        } else if(
+            ! (aMimetype.equals(ODFMediaTypes.TEXT_MEDIA_TYPE)
+            || aMimetype.equals(ODFMediaTypes.TEXT_TEMPLATE_MEDIA_TYPE)
+            || aMimetype.equals(ODFMediaTypes.GRAPHICS_MEDIA_TYPE)
+            || aMimetype.equals(ODFMediaTypes.GRAPHICS_TEMPLATE_MEDIA_TYPE)
+            || aMimetype.equals(ODFMediaTypes.PRESENTATION_MEDIA_TYPE)
+            || aMimetype.equals(ODFMediaTypes.SPREADSHEET_MEDIA_TYPE)
+            || aMimetype.equals(ODFMediaTypes.SPREADSHEET_TEMPLATE_MEDIA_TYPE)
+            || aMimetype.equals(ODFMediaTypes.CHART_MEDIA_TYPE)
+            || aMimetype.equals(ODFMediaTypes.CHART_TEMPLATE_MEDIA_TYPE)
+            || aMimetype.equals(ODFMediaTypes.IMAGE_MEDIA_TYPE)
+            || aMimetype.equals(ODFMediaTypes.IMAGE_TEMPLATE_MEDIA_TYPE)
+            || aMimetype.equals(ODFMediaTypes.FORMULA_MEDIA_TYPE)
+            || aMimetype.equals(ODFMediaTypes.FORMULA_TEMPLATE_MEDIA_TYPE)
+            || aMimetype.equals(ODFMediaTypes.TEXT_MASTER_MEDIA_TYPE)
+            || aMimetype.equals(ODFMediaTypes.TEXT_WEB_MEDIA_TYPE) ) )
+        {
+                aLogger.logInfo("mimetype is not an ODFMediaTypes mimetype.",false);
+                bHasErrors = true;
+        }
+
+        return bHasErrors;
+    }
+
+    private boolean validateManifest(Logger aLogger, OdfVersion aVersion ) throws IOException, ZipException, IllegalStateException, ODFValidatorException
+    {
+        boolean bRet;
+        ManifestFilter aFilter = new ManifestFilter(aLogger, m_aResult, this);
+        Validator aManifestValidator = m_aValidatorProvider.getManifestValidator(aLogger.getOutputStream(),aVersion);
+        if( aManifestValidator != null )
+        {
+            bRet = validateEntry(aFilter,
+                         aManifestValidator, aLogger, OdfPackage.OdfFile.MANIFEST.getPath() );
+        }
+        else
+        {
+            aLogger.logInfo( "Validation of " + OdfPackage.OdfFile.MANIFEST.getPath() + " skipped.", false);
+            bRet = parseEntry(aFilter, aLogger, OdfPackage.OdfFile.MANIFEST.getPath() , false);
+        }
+        return bRet;
+    }
+
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFStreamValidator.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFStreamValidator.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFStreamValidator.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFStreamValidator.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,68 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import java.io.InputStream;
+import org.odftoolkit.odfdom.pkg.OdfPackage;
+import org.xml.sax.ErrorHandler;
+
+
+/**
+ * Validator for Streams
+ */
+public class ODFStreamValidator extends ODFRootPackageValidator {
+
+    private InputStream m_aInputStream = null;
+    private String m_aBaseURI = null;
+
+    ODFStreamValidator(InputStream aInputStream,
+                              String aBaseURI,
+                              Logger.LogLevel nLogLevel,
+                              OdfValidatorMode eMode,
+                              OdfVersion aVersion,
+                              SAXParseExceptionFilter aFilter,
+                              ODFValidatorProvider aValidatorProvider ) 
+        
+        throws ODFValidatorException {
+        super(nLogLevel, eMode, aVersion, aFilter, aValidatorProvider );
+        
+        m_aInputStream=aInputStream;
+        m_aBaseURI=aBaseURI;
+    }
+
+    protected OdfPackage getPackage(ErrorHandler handler) throws Exception
+    {
+        return OdfPackage.loadPackage(m_aInputStream, m_aBaseURI, handler);
+    }
+    
+    protected String getLoggerName() {
+        return m_aBaseURI;
+    }
+
+    protected @Override
+    String getDocumentPath()
+    {
+        return ""; // this is the root document
+    }
+
+};



Mime
View raw message