incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From devin...@apache.org
Subject svn commit: r1172437 [2/2] - in /incubator/odf/trunk/validator/src: odfvalidator/ org/ org/odftoolkit/ org/odftoolkit/odfvalidator/
Date Mon, 19 Sep 2011 05:32:58 GMT
Added: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFPackageValidator.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFPackageValidator.java?rev=1172437&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFPackageValidator.java (added)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFPackageValidator.java Mon Sep 19 05:32:56 2011
@@ -0,0 +1,557 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008 Sun Microsystems, Inc. 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.Vector;
+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
+ */
+public abstract class ODFPackageValidator implements MetaInformationListener {
+
+    static final int CHECK_CONFORMANCE = 0; // all versions
+    static final int VALIDATE = 1;          // ODF 1.0 and 1.1 only
+    static final int VALIDATE_STRICT = 2;   // ODF 1.0 and 1.1 only
+    static final int CHECK_EXTENDED_CONFORMANCE = 3; // ODF 1.2 only
+
+    static final String ODF_VERSION_10 = "1.0";
+    static final String ODF_VERSION_11 = "1.1";
+    static final String ODF_VERSION_12 = "1.2";
+
+    static final String DOCUMENT_SETTINGS = "document-settings";
+    static final String DOCUMENT_STYLES = "document-styles";
+    static final String DOCUMENT_CONTENT = "document-content";
+
+    private int m_nLogLevel;
+    private int m_nMode = CHECK_CONFORMANCE;
+    private SAXParseExceptionFilter m_aFilter = null;
+    private ODFValidatorProvider m_aValidatorProvider = null;
+    
+    private String m_aMediaType = "";
+    private String m_aGenerator = "";
+    private String m_aConfigVersion = "";
+    private Vector<ManifestEntry> m_aSubDocs;
+
+    private SAXParserFactory m_aSAXParserFactory = null;
+
+
+    ODFPackageValidator( int nLogLevel, int nMode, String aVersion, String aMediaType,
+                             SAXParseExceptionFilter aFilter,ODFValidatorProvider aValidatorProvider) {
+        m_nLogLevel = nLogLevel;
+        m_nMode = nMode;
+        m_aFilter = aFilter;
+        m_aValidatorProvider = aValidatorProvider;
+        m_aMediaType = aMediaType;
+        m_aConfigVersion = aVersion;
+    }
+    
+       
+
+    abstract String getLoggerName();
+    
+    abstract OdfPackage getPackage( Logger aLogger );
+    
+    abstract boolean isRootPackage();
+    
+    abstract String getStreamName( String aEntry );
+    
+    public boolean validate(PrintStream aOut) throws ODFValidatorException
+    {
+        Logger aLogger = new Logger( getLoggerName(), "", aOut, m_nLogLevel);
+
+        boolean bHasErrors = false;
+
+        OdfPackage aPkg = getPackage( aLogger );
+        if( aPkg == null )
+            return true;
+
+        boolean bRoot = isRootPackage();
+        if( bRoot ) 
+            validateMimetype( aOut );
+        
+        try
+        {
+            String aDocVersion = getVersion( aLogger );
+            if( aDocVersion != null )
+                aLogger.logInfo( "ODF Version: " + aDocVersion, false );
+            String aVersion = m_aConfigVersion == null ? aDocVersion : m_aConfigVersion;
+            
+            bHasErrors |= validateMeta(aOut, getStreamName( OdfDocument.OdfXMLFile.META.getFileName()), aVersion, true );
+            if( bRoot )
+                bHasErrors |= validateManifest(aOut, aVersion  );
+            aLogger.logInfo( "Media Type: " + m_aMediaType , false);
+            bHasErrors |= validateEntry(aOut, getStreamName(OdfDocument.OdfXMLFile.SETTINGS.getFileName()), DOCUMENT_SETTINGS, aVersion);
+            bHasErrors |= validateEntry(aOut, getStreamName( OdfDocument.OdfXMLFile.STYLES.getFileName()), DOCUMENT_STYLES, aVersion );
+            if( m_aMediaType.equals(ODFMediaTypes.FORMULA_MEDIA_TYPE))
+                bHasErrors |= validateMathML(aOut, getStreamName( OdfDocument.OdfXMLFile.CONTENT.getFileName()), aVersion );
+            else
+                bHasErrors |= validateEntry(aOut, getStreamName( OdfDocument.OdfXMLFile.CONTENT.getFileName()), DOCUMENT_CONTENT, aVersion );
+            
+            if( bRoot )
+            {
+                if(m_aSubDocs != null )
+                {
+                    Iterator<ManifestEntry> aIter = m_aSubDocs.iterator();
+                    while( aIter.hasNext() )
+                    {
+                        ManifestEntry aEntry = aIter.next();
+                        ODFPackageValidator aPackageValidator = 
+                            new ODFSubPackageValidator( aPkg, getLoggerName(), aEntry.m_aFullPath, aEntry.m_aMediaType,
+                                                  m_nLogLevel, m_nMode, m_aConfigVersion, m_aFilter, m_aGenerator, m_aValidatorProvider );
+                        bHasErrors |= aPackageValidator.validate(aOut);
+                    }
+                }
+
+                if( aVersion.equals(ODF_VERSION_12))
+                {
+                    bHasErrors |= validateDSig( aOut, OdfPackageExt.STREAMNAME_DOCUMENT_SIGNATURES, aVersion );
+                    bHasErrors |= validateDSig( aOut, OdfPackageExt.STREAMNAME_MACRO_SIGNATURES, aVersion );
+                }
+            }
+        }
+        catch( ZipException e )
+        {
+            aLogger.logFatalError( e.getMessage() );
+        }
+        catch( IOException e )
+        {
+            aLogger.logFatalError( e.getMessage() );
+        }
+        
+        if( bRoot )
+        {
+            if( bHasErrors || aLogger.hasError() )
+            {
+                aLogger.logInfo( "validation errors found" , true );
+                if( m_nLogLevel < Logger.INFO )
+                    aLogger.logInfo( "Generator: " + m_aGenerator , true );
+            }
+            else
+                aLogger.logInfo(  "no errors" , false);  
+        }
+            
+        return bHasErrors || aLogger.hasError();
+    }
+    
+    protected boolean validateEntry(PrintStream aOut, String aEntryName, String aLocalElementName, String aVersion ) throws IOException, ZipException, IllegalStateException, ODFValidatorException
+    {
+        Logger aLogger = new Logger(getLoggerName(),aEntryName,aOut, m_nLogLevel);
+        XMLFilter aFilter = new ContentFilter(aLogger, aLocalElementName );
+        if( (m_nMode == CHECK_CONFORMANCE && (aVersion.equals(ODF_VERSION_10) || aVersion.equals(ODF_VERSION_11))) ||
+            m_nMode == CHECK_EXTENDED_CONFORMANCE )
+        {
+            XMLFilter aAlienFilter = new AlienFilter(aLogger,aVersion);
+            aAlienFilter.setParent(aFilter);
+            aFilter = aAlienFilter;
+        }
+        Validator aValidator = m_nMode == VALIDATE_STRICT ? m_aValidatorProvider.getStrictValidator(aOut, aVersion)
+                                                          : m_aValidatorProvider.getValidator(aOut,aVersion);
+        return validateEntry(aOut, aFilter, aValidator, aLogger, aEntryName );
+    }
+
+    private boolean validateMeta(PrintStream aOut, String aEntryName, String aVersion, boolean bIsRoot) throws IOException, ZipException, IllegalStateException, ODFValidatorException
+    {
+        Logger aLogger = new Logger(getLoggerName(),aEntryName,aOut, m_nLogLevel);
+        XMLFilter aFilter = new MetaFilter(aLogger, this );
+        if( (m_nMode == CHECK_CONFORMANCE && (aVersion.equals(ODF_VERSION_10) || aVersion.equals(ODF_VERSION_11))) ||
+            m_nMode == CHECK_EXTENDED_CONFORMANCE )
+        {
+            XMLFilter aAlienFilter = new AlienFilter(aLogger,aVersion);
+            aAlienFilter.setParent(aFilter);
+            aFilter = aAlienFilter;
+        }
+
+        Validator aValidator = m_nMode == VALIDATE_STRICT ? m_aValidatorProvider.getStrictValidator(aOut,aVersion)
+                                                          : m_aValidatorProvider.getValidator(aOut,aVersion);
+        return validateEntry(aOut, aFilter, aValidator, aLogger, aEntryName );
+    }
+
+    private boolean validateMathML(PrintStream aOut, String aEntryName, String aVersion ) throws IOException, ZipException, IllegalStateException, ODFValidatorException
+    {
+        Logger aLogger = new Logger(getLoggerName(),aEntryName,aOut, m_nLogLevel);
+        String aMathMLDTDSystemId = m_aValidatorProvider.getMathMLDTDSystemId(aVersion);
+        if( aMathMLDTDSystemId != null )
+        {
+            // validate using DTD
+            return parseEntry(aOut, new MathML101Filter(aMathMLDTDSystemId, aLogger), aLogger, aEntryName, true);
+        }
+        else
+        {
+            Validator aMathMLValidator = m_aValidatorProvider.getMathMLValidator(aOut,null);
+            if( aMathMLValidator == null )
+            {
+                aLogger.logInfo( "MathML schema is not available. Validation has been skipped.", false);
+                return false;
+            }
+            return validateEntry( aOut, new MathML20Filter(aLogger), aMathMLValidator, aLogger, aEntryName );
+        }
+    }
+    
+    private boolean validateManifest(PrintStream aOut, String aVersion ) throws IOException, ZipException, IllegalStateException, ODFValidatorException
+    {
+        boolean bRet;
+        Logger aLogger = new Logger(getLoggerName(),OdfPackage.OdfFile.MANIFEST.getPath(),aOut, m_nLogLevel);
+        ManifestFilter aFilter = new ManifestFilter(aLogger);
+        Validator aManifestValidator = m_aValidatorProvider.getManifestValidator(aOut,aVersion);
+        if( aManifestValidator != null )
+        {
+            bRet = validateEntry(aOut, aFilter, 
+                         aManifestValidator, aLogger, OdfPackage.OdfFile.MANIFEST.getPath() );
+        }
+        else
+        {
+            aLogger.logInfo( "Validation of " + OdfPackage.OdfFile.MANIFEST.getPath() + " skipped.", false);
+            bRet = parseEntry(aOut, aFilter, aLogger, OdfPackage.OdfFile.MANIFEST.getPath() , false);
+        }
+        
+        m_aSubDocs = aFilter.getSubDocuments();
+        m_aMediaType = aFilter.getMediaType();
+        return bRet;
+    }
+
+    protected boolean validateDSig(PrintStream aOut, String aEntryName, String aVersion ) throws IOException, ZipException, IllegalStateException, ODFValidatorException
+    {
+        Validator aValidator=m_aValidatorProvider.getDSigValidator(aOut,aVersion);
+        Logger aLogger = new Logger(getLoggerName(),aEntryName,aOut, m_nLogLevel);
+        if ( aValidator == null ) {
+            aLogger.logWarning("Signature not validated because there is no Signature Validator configured for the selected Configuration");
+            return false;
+        }
+
+        return validateEntry(aOut, new DSigFilter(aLogger), aValidator, aLogger, aEntryName );
+    }
+
+    private boolean validateEntry(PrintStream aOut, XMLFilter aFilter, 
+                           javax.xml.validation.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);
+        }
+        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(aOut, aInStream, aFilter, aValidator, aLogger ) : false;
+    }
+    
+    private boolean validate(PrintStream aOut, 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.logInfo( aLogger.hasError() ? "validation errors found" : "no errors" , false);            
+        return aLogger.hasError();
+    }
+
+    private boolean parseEntry(PrintStream aOut, 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);
+        }
+        catch( Exception e )
+        {
+            throw new ODFValidatorException( e );
+        }
+
+        return aInStream != null ? parse(aOut, aInStream, aFilter, bValidating, aLogger ) : false;
+    }
+
+    private boolean parse(PrintStream aOut, InputStream aInStream, XMLFilter aFilter, boolean bValidating, Logger aLogger ) throws ODFValidatorException
+    {
+        SAXParser aParser = getSAXParser(bValidating);
+        aLogger.setOutputStream(aOut);
+        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.logInfo( aLogger.hasError() ? "validation errors found" : "no errors" , false);            
+        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 boolean validateMimetype( PrintStream aOut )
+    {
+        Logger aLogger = new Logger(getLoggerName(),"MIMETYPE",aOut, m_nLogLevel);
+        
+        String aMimetype=getPackage(aLogger).getMediaType();
+        if( (aMimetype == null) || aMimetype.length() == 0 ) {
+            aLogger.logFatalError("file is not a zip file, or has no mimetype.");
+            return true;
+        }
+            
+        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);
+                return true;
+        }
+      
+        /* TODO: not supported by ODFDOM
+        if ( aDocFile .isMimeTypeValid() ) {
+            aLogger.logInfo("no errors",false);
+        } else {
+            aLogger.logError("file is not the first file in the ODF package or is compressed.");
+            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;
+    }
+
+    /**
+     * set the generator
+     */ 
+    public void setGenerator(String aGenerator) 
+    {
+        m_aGenerator = aGenerator;
+        if( m_aFilter != null )
+            m_aFilter.setGenerator(m_aGenerator);
+    }
+
+    /**
+     * get the generator
+     */
+    public String getGenerator() {
+        return m_aGenerator;
+    }
+
+    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()));
+            if( aInStream == null )
+                aInStream = aPkg.getInputStream(getStreamName(OdfDocument.OdfXMLFile.SETTINGS.getFileName()));
+            if( aInStream == null )
+                aInStream = aPkg.getInputStream(getStreamName(OdfDocument.OdfXMLFile.CONTENT.getFileName()));
+        }
+        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;
+    }
+
+}
\ No newline at end of file

Added: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFRootPackageValidator.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFRootPackageValidator.java?rev=1172437&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFRootPackageValidator.java (added)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFRootPackageValidator.java Mon Sep 19 05:32:56 2011
@@ -0,0 +1,65 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008 Sun Microsystems, Inc. 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 org.odftoolkit.odfdom.pkg.OdfPackage;
+
+public abstract class ODFRootPackageValidator extends ODFPackageValidator {
+
+    private OdfPackage m_aPkg = null;
+
+    ODFRootPackageValidator(int nLogLevel, int nMode, String aVersion, SAXParseExceptionFilter aFilter, ODFValidatorProvider aValidatorProvider) {
+        super(nLogLevel, nMode, aVersion, null, aFilter, aValidatorProvider);
+    }
+
+    abstract OdfPackage getPackage() throws Exception;
+    
+    OdfPackage getPackage(Logger aLogger) {
+        if (m_aPkg == null) {
+            try {
+                m_aPkg = getPackage();
+            } 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;
+    }
+
+    boolean isRootPackage() {
+        return true;
+    }
+
+    String getStreamName( String aEntry )
+    {
+        return aEntry;
+    }
+
+}

Added: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFStreamValidator.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFStreamValidator.java?rev=1172437&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFStreamValidator.java (added)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFStreamValidator.java Mon Sep 19 05:32:56 2011
@@ -0,0 +1,61 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008 Sun Microsystems, Inc. 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;
+
+/**
+ * Validator for Streams
+ */
+public class ODFStreamValidator extends ODFRootPackageValidator {
+
+    private InputStream m_aInputStream = null;
+    private String m_aBaseURI = null;
+
+    ODFStreamValidator(InputStream aInputStream,
+                              String aBaseURI,
+                              int nLogLevel, 
+                              int nMode,
+                              String aVersion,
+                              SAXParseExceptionFilter aFilter,
+                              ODFValidatorProvider aValidatorProvider ) 
+        
+        throws ODFValidatorException {
+        super(nLogLevel, nMode, aVersion, aFilter, aValidatorProvider );
+        
+        m_aInputStream=aInputStream;
+        m_aBaseURI=aBaseURI;
+    }
+
+    OdfPackage getPackage() throws Exception
+    {
+        return OdfPackage.loadPackage( m_aInputStream );
+    }
+    
+    String getLoggerName() {
+        return m_aBaseURI;
+    }
+
+};

Added: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFSubPackageValidator.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFSubPackageValidator.java?rev=1172437&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFSubPackageValidator.java (added)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFSubPackageValidator.java Mon Sep 19 05:32:56 2011
@@ -0,0 +1,66 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008 Sun Microsystems, Inc. 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.pkg.OdfPackage;
+
+public class ODFSubPackageValidator extends ODFPackageValidator {
+
+    private OdfPackage m_aPkg = null;
+    private String m_aBaseURI = null;
+    private String m_aSubEntryName = null;
+
+    ODFSubPackageValidator( OdfPackage aPkg, String aBaseURI, String aSubEntryName, String aMediaType,
+                             int nLogLevel, int nMode, String aVersion,
+                             SAXParseExceptionFilter aFilter, String aParentGenerator,
+                             ODFValidatorProvider aValidatorProvider ) throws ODFValidatorException
+    {
+        super( nLogLevel, nMode, aVersion, aMediaType, aFilter, aValidatorProvider );
+        m_aPkg = aPkg;
+        m_aBaseURI = aBaseURI + "/" + aSubEntryName;
+        m_aSubEntryName = aSubEntryName;
+        if( aFilter != null )
+            aFilter.startPackage(aParentGenerator);  // take build id from main document as default (embedded objects can nevern be newer)
+    }
+
+    @Override
+    String getLoggerName() {
+        return m_aBaseURI;
+    }
+
+    boolean isRootPackage()
+    {
+        return false;
+    }
+    
+    OdfPackage getPackage( Logger aLogger ) 
+    {
+        return m_aPkg;
+    }
+
+    String getStreamName( String aEntry )
+    {
+        return m_aSubEntryName + aEntry;
+    }
+    
+};

Added: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFValidator.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFValidator.java?rev=1172437&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFValidator.java (added)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFValidator.java Mon Sep 19 05:32:56 2011
@@ -0,0 +1,386 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008 Sun Microsystems, Inc. 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 javax.xml.XMLConstants;
+
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Validator;
+
+public class ODFValidator implements ODFValidatorProvider {
+
+    // Prefix used to distinguish internal resources from external ones
+    
+    // Loglevel
+    private int m_nLogLevel;
+
+    // Validator provider
+    private SchemaFactory m_aRNGSchemaFactory = null;
+    private SchemaFactory m_aXSDSchemaFactory = null;
+
+    // User provided Configuration
+    protected Configuration m_aConfig = null;
+    
+    // User provided ODF version
+    protected String m_aVersion = null;
+    
+    // User provided preference for using Math DTD
+    protected boolean m_bUseMathDTD = false;
+
+    // Validatore and configuration cache
+    private HashMap<String,Validator> m_aValidatorMap = null;
+    private HashMap<String,Configuration> m_aConfigurationMap = null;
+
+    // Generator from last validateFile or validateStream call
+    private String m_aGenerator = "";
+
+    /** Creates a new instance of Validator */
+    public ODFValidator( Configuration aConfig,
+                         int nLogLevel,
+                         String aVersion,
+                         boolean bUseMathDTD ) throws ODFValidatorException {
+        
+        m_nLogLevel = nLogLevel;
+        m_aConfig = aConfig;
+        m_aVersion = aVersion;
+        m_bUseMathDTD = bUseMathDTD;
+    }    
+    
+    public boolean validate(PrintStream aOut, Configuration aConfig, int nMode ) throws ODFValidatorException
+    {
+        List<String> aFileNames = aConfig.getListPropety(Configuration.PATH);
+        String aExcludeRegExp = aConfig.getProperty(Configuration.EXCLUDE);
+        String aRecursive = aConfig.getProperty(Configuration.RECURSIVE);
+        boolean bRecursive = aRecursive != null ? Boolean.valueOf(aRecursive) : false;
+        String aFilterFileName = aConfig.getProperty(Configuration.FILTER);
+
+        return validate(aOut, aFileNames, aExcludeRegExp, nMode, bRecursive, aFilterFileName );
+    }
+
+
+    public boolean validate(PrintStream aOut, List<String> aFileNames, String aExcludeRegExp, 
+                            int nMode, boolean bRecursive,                            
+                            String aFilterFileName ) throws ODFValidatorException
+    {
+        boolean bRet = false;
+
+        SAXParseExceptionFilter aFilter = null;
+        if( aFilterFileName != null && aFilterFileName.length() != 0 )
+            aFilter = new ValidationOOoTaskIdErrorFilter( new File(aFilterFileName), aOut );
+
+        FileFilter aFileFilter = new ODFFileFilter( aExcludeRegExp, bRecursive );
+        
+        Iterator<String> aIter = aFileNames.iterator();
+        while( aIter.hasNext() )
+        {
+            File aFile = new File( aIter.next() );
+            bRet |= aFile.isDirectory() ? validateDir(aOut, aFile, aFileFilter, nMode, aFilter )
+                : validateFile(aOut, aFile, nMode, aFilter );
+        }
+        
+        return bRet;
+    }
+    
+    public boolean validate(PrintStream aOut, InputStream aInputStream, String aBaseURI,
+                            int nMode,
+                            SAXParseExceptionFilter aFilter ) throws ODFValidatorException
+    {
+        return validateStream( aOut, aInputStream, aBaseURI, nMode, aFilter );
+    }
+    
+
+    private boolean validateDir(PrintStream aOut, final File aDir, FileFilter aFileFilter, int nMode, SAXParseExceptionFilter aFilter ) throws ODFValidatorException 
+    {
+        boolean bRet = true;
+        File[] aFiles = aDir.listFiles( aFileFilter );
+
+        if( aFiles != null )
+        {
+            for( int i=0; i<aFiles.length; ++i)
+            {
+                File aFile = aFiles[i];
+                if( aFile.isDirectory() )
+                {
+                    bRet |= validateDir(aOut, aFile, aFileFilter, nMode, aFilter );
+                }
+                else
+                {
+                    bRet |= validateFile(aOut, aFile, nMode, aFilter );
+                }
+            }
+        }
+        return bRet;
+    }
+
+    /**
+     * validate the input File
+     *
+     * <p>After validation the getGenerator method can be called to get the generator of the validated file</p>
+     */
+    public boolean validateFile(PrintStream aOut, File aDocFile, int nMode, SAXParseExceptionFilter aFilter ) throws ODFValidatorException
+    {
+        ODFFileValidator aFileValidator = 
+            new ODFFileValidator( aDocFile, m_nLogLevel, nMode, m_aVersion, aFilter, this );
+        
+        boolean result=aFileValidator.validate(aOut);
+
+        m_aGenerator=aFileValidator.getGenerator();
+        return result;
+    }
+
+    /**
+     * validate the input Stream
+     *
+     * <p>After validation the getGenerator method can be called to get the generator of the validated file</p>
+     */
+    public boolean validateStream(PrintStream aOut, InputStream aInputStream, String aBaseURI,
+                                  int nMode,
+                                  SAXParseExceptionFilter aFilter ) throws ODFValidatorException
+    {
+        ODFStreamValidator aStreamValidator = 
+            new ODFStreamValidator( aInputStream, aBaseURI, m_nLogLevel, nMode, m_aVersion, aFilter, this );
+
+        boolean result=aStreamValidator.validate(aOut);
+        m_aGenerator=aStreamValidator.getGenerator();
+
+        return result;
+    }
+
+    public Validator getManifestValidator(PrintStream aOut, String aVersion) throws ODFValidatorException
+    {
+        return getValidatorForSchema( aOut, getSchemaFileName(Configuration.MANIFEST_SCHEMA,aVersion));
+    }
+    
+    public Validator getValidator(PrintStream aOut, String aVersion) throws ODFValidatorException
+    {
+        return getValidatorForSchema( aOut, getSchemaFileName(Configuration.SCHEMA,aVersion));
+    }
+    
+    public Validator getStrictValidator(PrintStream aOut, String aVersion) throws ODFValidatorException
+    {
+        return getValidatorForSchema( aOut, getSchemaFileName(Configuration.STRICT_SCHEMA,aVersion));
+    }
+    
+    public Validator getMathMLValidator(PrintStream aOut, String aVersion) throws ODFValidatorException
+    {
+        return getValidatorForSchema( aOut, getSchemaFileName(Configuration.MATHML2_SCHEMA,aVersion));
+    }
+    
+    public String getMathMLDTDSystemId( String aVersion ) throws ODFValidatorException
+    {
+        String aDTD = null;
+        if( m_bUseMathDTD )
+        {
+            Configuration aConfig = 
+                m_aConfig != null ? m_aConfig : getConfiguration( aVersion );
+
+            aDTD = aConfig.getProperty(Configuration.MATHML_SCHEMA);
+            if( m_aConfig == null && aDTD != null && aDTD.length() > 0  )
+                aDTD = InternalResources.createInternalResourceIdentifier(aDTD);
+        }
+
+        return aDTD;
+    }
+    
+    public Validator getDSigValidator(PrintStream aOut, String aVersion) throws ODFValidatorException
+    {
+        return getValidatorForSchema( aOut, getSchemaFileName(Configuration.DSIG_SCHEMA,aVersion));
+    }
+
+    public void resetValidatorProvider()
+    {
+        m_aRNGSchemaFactory = null;
+        m_aXSDSchemaFactory = null;
+        m_aValidatorMap = null;
+    }
+
+    private String getSchemaFileName( String aConfigName, String aVersion) throws ODFValidatorException
+    {
+        Configuration aConfig = 
+            m_aConfig != null ? m_aConfig : getConfiguration( aVersion );
+
+        String aFileName = aConfig.getProperty(aConfigName);
+        if( m_aConfig == null && aFileName != null && aFileName.length() > 0  )
+            aFileName = InternalResources.createInternalResourceIdentifier(aFileName);
+        
+        return aFileName;
+    }
+
+    private Configuration getConfiguration( String aVersion ) throws ODFValidatorException
+    {
+        if( m_aConfigurationMap == null )
+            m_aConfigurationMap = new HashMap<String,Configuration>();
+        
+        Configuration aConfig = m_aConfigurationMap.get(aVersion);
+        if( aConfig == null)
+        {
+            String aConfigName = null;
+            if( aVersion == null || aVersion.equals("1.2") )
+                aConfigName = "/config/v12.properties";
+            else if( aVersion.equals("1.1") )
+                aConfigName = "/config/v11.properties";
+            else if( aVersion.equals("1.0") )
+                aConfigName = "/config/v10.properties";
+            else
+                throw new ODFValidatorException( "unsupported ODF version: ".concat(aVersion) );
+            
+            InputStream aInStream = getClass().getResourceAsStream(aConfigName);
+            if( aInStream == null )
+                throw new ODFValidatorException( "Internal configuration file is missing: ".concat(aConfigName));
+
+            aConfig = new Configuration();
+            try
+            {
+                aConfig.loadFromXML( aInStream );
+                aInStream.close();
+            }
+            catch( IOException e )
+            {
+                throw new ODFValidatorException( e );
+            }
+            
+            m_aConfigurationMap.put( aVersion, aConfig );
+        }
+
+        return aConfig;
+    }
+    
+    private Validator getValidatorForSchema( PrintStream aOut, String aSchemaFileName ) throws ODFValidatorException
+    {
+        if( m_aValidatorMap == null )
+            m_aValidatorMap = new HashMap<String,Validator>();
+        
+        Validator aValidator = m_aValidatorMap.get(aSchemaFileName);
+        if( aValidator == null )
+        {
+            aValidator = createValidator( aOut, aSchemaFileName );
+            m_aValidatorMap.put( aSchemaFileName, aValidator);
+        }
+        
+        return aValidator;
+    }
+    
+    private Validator createValidator(PrintStream aOut, String aSchemaFileName ) throws ODFValidatorException 
+    {
+        Logger aLogger = new Logger(aSchemaFileName, "", aOut, m_nLogLevel);
+        
+        if( aSchemaFileName == null || aSchemaFileName.length() == 0 )
+            return null;
+        
+        String aSchemaLanguage = 
+                aSchemaFileName.endsWith("xsd") ? XMLConstants.W3C_XML_SCHEMA_NS_URI
+                                                : XMLConstants.RELAXNG_NS_URI;
+        SchemaFactory aSchemaFactory = getSchemaFactory( aSchemaLanguage );
+        SchemaErrorHandler aErrorHandler = new SchemaErrorHandler( aLogger, null );
+        aSchemaFactory.setErrorHandler( aErrorHandler );
+        aSchemaFactory.setResourceResolver(new SchemaResourceResolver(aLogger,aSchemaFileName));
+        Schema aSchema = null;
+
+        StreamSource aSource = null;
+        if( InternalResources.isInternalResourceIdentifer(aSchemaFileName) )
+        {
+            String aPath = InternalResources.getResourcePath(aSchemaFileName);
+            InputStream aInStream = getClass().getResourceAsStream(aPath);
+            if( aInStream == null )
+                throw new ODFValidatorException( "Internal schema file is missing: ".concat(aPath));
+
+            aSource = new StreamSource(aInStream,aSchemaFileName);
+        }
+        else
+        {
+            File aFile=new File(aSchemaFileName);
+            if ( ! aFile.exists() ) {
+                aLogger.logFatalError( aSchemaFileName+": file does not exist" );
+                return null;
+            }
+            aSource = new StreamSource(aFile);
+        }
+
+        boolean bError = false; // Workaround: MSV seems not to call error handler
+        try
+        {
+            aSchema = aSchemaFactory.newSchema( aSource );
+        }
+        catch( org.xml.sax.SAXParseException e )
+        {
+            aLogger.logFatalError( e );
+        }
+        catch( org.xml.sax.SAXException e )
+        {
+            aLogger.logFatalError( e.getMessage() );
+        }
+        
+        if( aLogger.hasError() )
+        {
+            throw new ODFValidatorException( aSchemaFileName, "", "Schema has validation errors.");
+        }
+
+        aLogger.logInfo( "parsed." , false);
+        return aSchema.newValidator();
+    }
+
+    private SchemaFactory getSchemaFactory( String aSchemaLanguage ) throws ODFValidatorException
+    {
+        boolean bRNG = aSchemaLanguage.equals(XMLConstants.RELAXNG_NS_URI);
+        SchemaFactory aSchemaFactory = bRNG ? m_aRNGSchemaFactory
+                                            : m_aXSDSchemaFactory;
+        if( aSchemaFactory == null )
+        {
+
+            try
+            {
+                aSchemaFactory = SchemaFactory.newInstance( aSchemaLanguage );
+            }
+            catch( IllegalArgumentException e ) 
+            {
+                throw new ODFValidatorException( (bRNG ? "Relax-NG" : "W3C XML Schema") + " support is not installed: " + e.getMessage() );
+            }
+            if( bRNG )
+                m_aRNGSchemaFactory = aSchemaFactory;
+            else
+                m_aXSDSchemaFactory = aSchemaFactory;
+        }
+        
+        return aSchemaFactory;
+    }
+
+    /**
+     * get Generator from last validateFile or validateStream call
+     */
+    public String getGenerator() {
+        return m_aGenerator;
+    }
+
+  
+}

Added: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFValidatorException.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFValidatorException.java?rev=1172437&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFValidatorException.java (added)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFValidatorException.java Mon Sep 19 05:32:56 2011
@@ -0,0 +1,70 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008 Sun Microsystems, Inc. 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 ODFValidatorException extends Exception {
+    
+    private String m_aFile;
+    private String m_aEntry;
+    
+    /** Creates a new instance of ODFValidatorException */
+    ODFValidatorException( Exception e) {
+        super( e );
+    }
+    
+    ODFValidatorException( String aMsg ) {
+        super( aMsg );
+    }
+
+    ODFValidatorException( String aFile, String aEntry, String aMsg ) {
+        super( aMsg );
+        m_aFile = aFile;
+        m_aEntry = aEntry;
+    }
+ 
+    ODFValidatorException( String aFile, String aEntry, Exception e ) {
+        super( e );
+        m_aFile = aFile;
+        m_aEntry = aEntry;
+    }
+
+    @Override
+    public String getMessage() {
+        String retValue = "";
+        
+        if( m_aFile != null && m_aFile.length() > 0 )
+        {
+            retValue += m_aFile;
+            retValue += ":";
+        }
+        if( m_aEntry != null && m_aEntry.length() > 0 )
+        {
+            retValue += m_aEntry;
+            retValue += ":";
+        }
+        retValue += super.getMessage();
+        return retValue;
+    }
+    
+    
+}

Added: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFValidatorProvider.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFValidatorProvider.java?rev=1172437&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFValidatorProvider.java (added)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFValidatorProvider.java Mon Sep 19 05:32:56 2011
@@ -0,0 +1,42 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008 Sun Microsystems, Inc. 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 javax.xml.validation.Validator;
+import java.io.PrintStream;
+
+public interface ODFValidatorProvider {
+    Validator getValidator(PrintStream aOut, String aVersion ) throws ODFValidatorException;
+
+    Validator getStrictValidator(PrintStream aOut, String aVersion) throws ODFValidatorException;
+    
+    Validator getManifestValidator(PrintStream aOut, String aVersion) throws ODFValidatorException;
+
+    Validator getDSigValidator(PrintStream aOut, String aVersion) throws ODFValidatorException;
+
+    Validator getMathMLValidator(PrintStream aOut, String aVersion) throws ODFValidatorException;
+
+    String getMathMLDTDSystemId( String aVersion ) throws ODFValidatorException;
+        
+    void resetValidatorProvider();
+}

Added: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/OdfPackageExt.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/OdfPackageExt.java?rev=1172437&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/OdfPackageExt.java (added)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/OdfPackageExt.java Mon Sep 19 05:32:56 2011
@@ -0,0 +1,30 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008 Sun Microsystems, Inc. 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 OdfPackageExt {
+
+    public static final String STREAMNAME_DOCUMENT_SIGNATURES = "META-INF/documentsignatures.xml";    
+    public static final String STREAMNAME_MACRO_SIGNATURES = "META-INF/macrosignatures.xml";    
+
+}

Added: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SAXParseExceptionFilter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SAXParseExceptionFilter.java?rev=1172437&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SAXParseExceptionFilter.java (added)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SAXParseExceptionFilter.java Mon Sep 19 05:32:56 2011
@@ -0,0 +1,36 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008 Sun Microsystems, Inc. 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.SAXParseException;
+
+public interface SAXParseExceptionFilter {
+    
+    SAXParseException filterException( SAXParseException e );
+    
+    void startPackage( String aParentGenerator );
+    
+    void setGenerator( String aGenerator );
+    
+    void startSubFile();
+}

Added: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SAXVersionException.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SAXVersionException.java?rev=1172437&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SAXVersionException.java (added)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SAXVersionException.java Mon Sep 19 05:32:56 2011
@@ -0,0 +1,41 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008 Sun Microsystems, Inc. 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.SAXException;
+
+class SAXVersionException extends SAXException{
+
+    private String m_aVersion = null;
+    
+    SAXVersionException( String aVersion )
+    {
+        super();
+        m_aVersion = aVersion;
+    }
+    
+    String getVersion()
+    {
+        return m_aVersion;
+    }
+}

Added: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SchemaErrorHandler.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SchemaErrorHandler.java?rev=1172437&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SchemaErrorHandler.java (added)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SchemaErrorHandler.java Mon Sep 19 05:32:56 2011
@@ -0,0 +1,78 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008 Sun Microsystems, Inc. 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.SAXException;
+import org.xml.sax.SAXParseException;
+
+class SchemaErrorHandler implements org.xml.sax.ErrorHandler {
+    
+    private Logger m_aLogger;
+    private SAXParseExceptionFilter m_aFilter;
+
+    /** Creates a new instance of SchemaErrorHandler */
+    SchemaErrorHandler(Logger aLogger, SAXParseExceptionFilter aFilter ) {
+        m_aLogger = aLogger;
+        m_aFilter = aFilter;
+    }
+    
+    public void warning(SAXParseException e) throws SAXException {
+        if( !filter(e) )
+            m_aLogger.logWarning(  e );
+    }
+
+    public void fatalError(SAXParseException e) throws SAXException {
+        fatalErrorNoException( e );
+    }
+
+    public void error(SAXParseException e) throws SAXException {
+        if( !filter(e) )
+            m_aLogger.logError( e );
+    }
+
+    public void fatalErrorNoException(SAXParseException e) {
+        if( !filter(e) )
+            m_aLogger.logFatalError(  e );
+    }
+    
+    private boolean filter( SAXParseException e )
+    {
+        boolean bFiltered = false;
+        if( m_aFilter != null )
+        {
+            SAXParseException aNewExc = m_aFilter.filterException( e );
+            if( aNewExc == null  )
+            {
+                bFiltered = true;
+            }
+            else if( aNewExc != e )
+            {
+                m_aLogger.logWarning( aNewExc );
+                bFiltered = true;
+            }
+        }
+        
+        return bFiltered;
+    }
+}

Added: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SchemaFilter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SchemaFilter.java?rev=1172437&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SchemaFilter.java (added)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SchemaFilter.java Mon Sep 19 05:32:56 2011
@@ -0,0 +1,45 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008 Sun Microsystems, Inc. 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.XMLFilterImpl;
+
+class SchemaFilter extends XMLFilterImpl {
+    
+    /** Creates a new instance of SchemaFilter */
+    SchemaFilter() {
+    }
+
+    @Override
+    public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
+
+        if( qName.equals("param"))
+        {
+            System.out.println( atts.getValue(uri,"pattern"));
+        }
+        super.startElement(uri, localName, qName, atts);
+    }
+    
+}

Added: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SchemaResourceResolver.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SchemaResourceResolver.java?rev=1172437&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SchemaResourceResolver.java (added)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/SchemaResourceResolver.java Mon Sep 19 05:32:56 2011
@@ -0,0 +1,194 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008 Sun Microsystems, Inc. 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 java.io.Reader;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.bootstrap.DOMImplementationRegistry;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSResourceResolver;
+
+    class SchemaResourceResolver implements LSResourceResolver 
+    {
+        private String m_aBaseURI = null;
+        private Logger m_aLogger = null;
+        private DOMImplementationLS m_aDOMImplLS = null;
+        private boolean m_bGetDOMImplLSFailed = false;
+        
+        class LSInputImpl implements LSInput
+        {
+            private InputStream m_aInputStream = null;
+            private String m_aSystemId = null;
+
+            public Reader getCharacterStream() {
+                return null;
+            }
+
+            public void setCharacterStream(Reader aCharacterStream) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            public InputStream getByteStream() {
+                return m_aInputStream;
+            }
+
+            public void setByteStream(InputStream aByteStream) {
+                m_aInputStream = aByteStream;
+            }
+
+            public String getStringData() {
+                return null;
+            }
+
+            public void setStringData(String stringData) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            public String getSystemId() {
+                return m_aSystemId;
+            }
+
+            public void setSystemId(String aSystemId) {
+                m_aSystemId = aSystemId;
+            }
+
+            public String getPublicId() {
+                return null;
+            }
+
+            public void setPublicId(String publicId) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            public String getBaseURI() {
+                return null;
+            }
+
+            public void setBaseURI(String baseURI) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            public String getEncoding() {
+                return null;
+            }
+
+            public void setEncoding(String encoding) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            public boolean getCertifiedText() {
+                return false;
+            }
+
+            public void setCertifiedText(boolean certifiedText) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+        }
+        
+        public SchemaResourceResolver( Logger aLogger, String aBaseURI )
+        {
+            m_aBaseURI = aBaseURI;
+            m_aLogger = aLogger;
+        }
+    
+        public LSInput resolveResource(String aType, String aNamespaceURI, String aPublicId, String aSystemId, String aBaseURI) 
+        {
+            LSInput aInput = null;
+            
+            if( aBaseURI == null )
+                aBaseURI = m_aBaseURI; 
+
+            if( aSystemId != null && aBaseURI != null && 
+                InternalResources.isInternalResourceIdentifer(aBaseURI) )
+            {
+                String aURI = aBaseURI.substring(0, aBaseURI.lastIndexOf('/')+1).concat(aSystemId);
+                String aPath = InternalResources.getResourcePath(aURI);
+                InputStream aInStream = getClass().getResourceAsStream(aPath);
+                if( aInStream != null )
+                {
+                    aInput = createLSInput();
+                    aInput.setSystemId(aURI);
+                    aInput.setByteStream(aInStream);
+ 
+                    String aMsg = "resolving '" + aURI + "'";
+                    m_aLogger.logInfo( aMsg , false);
+                }
+                else
+                {
+                    m_aLogger.logFatalError("Missing internal schema file: ".concat(aPath));
+                }
+            }
+        
+           return aInput;
+        }
+        
+        private LSInput createLSInput()
+        {
+            LSInput aLSInput = null;
+            
+            if( m_aDOMImplLS == null && !m_bGetDOMImplLSFailed )
+            {
+                DOMImplementationRegistry aDOMReg = null;
+
+                try
+                {        
+                    aDOMReg = DOMImplementationRegistry.newInstance();
+                }
+                catch( ClassNotFoundException e )
+                {
+                    m_aLogger.logFatalError(e.getMessage());
+                }
+                catch( InstantiationException e )
+                {
+                    m_aLogger.logFatalError(e.getMessage());
+                }
+                catch( IllegalAccessException e )
+                {
+                    m_aLogger.logFatalError(e.getMessage());
+                }
+                DOMImplementation aDOMImpl = aDOMReg.getDOMImplementation( "LS 3.0");
+                if( aDOMImpl != null )
+                {
+                    m_aDOMImplLS = (DOMImplementationLS)aDOMImpl;
+                }
+                else
+                {
+                    m_bGetDOMImplLSFailed = true;
+                    m_aLogger.logInfo("Could not find DOM LS 3.0 Implementation, using own implementation", false);
+                }
+            }
+            if( m_aDOMImplLS != null )
+            {
+                aLSInput = m_aDOMImplLS.createLSInput();
+            }
+            else
+            {
+                aLSInput = new LSInputImpl();
+            }
+            
+            return aLSInput;
+        }
+    }

Added: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ValidationMessageCollectorErrorFilter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ValidationMessageCollectorErrorFilter.java?rev=1172437&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ValidationMessageCollectorErrorFilter.java (added)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ValidationMessageCollectorErrorFilter.java Mon Sep 19 05:32:56 2011
@@ -0,0 +1,74 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008 Sun Microsystems, Inc. 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.HashSet;
+import org.xml.sax.SAXParseException;
+
+/**
+ *
+ */
+public class ValidationMessageCollectorErrorFilter implements SAXParseExceptionFilter {
+
+    private String m_aGenerator;
+    private HashSet<String> m_aMsgsReported;
+
+    
+    /** Creates a new instance of ValidationErrorFilter */
+    public ValidationMessageCollectorErrorFilter() throws ODFValidatorException {
+        m_aMsgsReported = new HashSet<String>();
+    }
+    
+    public SAXParseException filterException( SAXParseException aExc )
+    {
+        String aMsg = aExc.getMessage();
+        if( !m_aMsgsReported.contains(aMsg))
+        {
+             m_aMsgsReported.add( aMsg );
+        }
+        
+        return aExc;
+    }
+
+    public void startPackage( String aGenerator )
+    {
+    }
+
+    public void setGenerator( String aGenerator )
+    {
+        m_aGenerator = aGenerator;
+    }
+    
+    public void startSubFile() {
+    }    
+    
+    public String getGenerator()
+    {
+        return m_aGenerator;
+    }
+
+    public HashSet<String> getMessages()
+    {
+        return m_aMsgsReported;
+    }
+}

Added: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ValidationOOoTaskIdErrorFilter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ValidationOOoTaskIdErrorFilter.java?rev=1172437&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ValidationOOoTaskIdErrorFilter.java (added)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ValidationOOoTaskIdErrorFilter.java Mon Sep 19 05:32:56 2011
@@ -0,0 +1,210 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008 Sun Microsystems, Inc. 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.PrintStream;
+import java.util.HashMap;
+import java.util.HashSet;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ *
+ */
+public class ValidationOOoTaskIdErrorFilter implements SAXParseExceptionFilter {
+
+    
+    private static final String FILTER_ENTRY = "filter-entry";
+    private static final String TASK_ID = "task-id";
+    private static final String RESOLVED_IN = "resolved-in";
+    
+    int m_nBuildId = 0;
+    
+    class FilterEntry
+    {
+        String m_aTaskId;
+        int m_nBuildId;
+        
+        FilterEntry( String aTaskId, int nBuildId )
+        {
+            m_aTaskId = aTaskId;
+            m_nBuildId = nBuildId;
+        }
+    }
+            
+
+    private HashMap<String,FilterEntry> m_aFilterEntries;
+    private HashSet<String> m_aTaskIdsReported;
+
+    class Handler extends DefaultHandler
+    {
+        class Entry
+        {
+            String m_aMessage = "";
+            String m_aTask = "";
+            int m_nBuildId = 0;
+
+            Entry( String aTask )
+            {
+                m_aTask = aTask;
+            }
+        }
+
+        HashMap<String,FilterEntry> m_aFilterEntries;
+        Entry m_aEntry = null;
+
+        Handler( HashMap<String,FilterEntry> aFilterEntries )
+        {
+            m_aFilterEntries = aFilterEntries;
+        }
+
+        public void characters(char[] aCh, int nStart, int nLength) throws SAXException {
+            if( m_aEntry != null )
+                m_aEntry.m_aMessage += new String(aCh, nStart, nLength);
+        }
+
+        public void startElement(String aUri, String aLocalName, String aQName, Attributes aAttributes) throws SAXException {
+            if( aQName.equals(FILTER_ENTRY) )
+            {
+               String aTaskId = aAttributes.getValue(TASK_ID);
+                if( aTaskId != null )
+                {
+                    m_aEntry = new Entry( aTaskId );
+                    String aBuildId = aAttributes.getValue(RESOLVED_IN);
+                    if( aBuildId != null && aBuildId.length() > 0)
+                        m_aEntry.m_nBuildId = Integer.valueOf(aBuildId);
+                }
+               
+            }
+        }
+
+        public void endElement(String aUri, String aLocalName, String aQName) throws SAXException {
+            if( aQName.equals(FILTER_ENTRY) )
+            {
+                if( m_aEntry != null )
+                {
+                    m_aFilterEntries.put( m_aEntry.m_aMessage, new FilterEntry(m_aEntry.m_aTask,m_aEntry.m_nBuildId) );
+                }
+            }
+        }
+
+    }
+    
+    /** Creates a new instance of ValidationErrorFilter */
+    public ValidationOOoTaskIdErrorFilter( File aFilterFile, PrintStream aOut ) throws ODFValidatorException {
+        m_aFilterEntries = new HashMap<String,FilterEntry>();
+        m_aTaskIdsReported = new HashSet<String>();
+        SAXParser aParser = null;
+        Logger aLogger = new Logger( aFilterFile.getAbsolutePath(), "", aOut, Logger.ERROR );
+        try
+        {
+            SAXParserFactory aParserFactory = SAXParserFactory.newInstance();
+            aParserFactory.setNamespaceAware(false);
+            aParser = aParserFactory.newSAXParser();
+
+            aParser.parse(aFilterFile, new Handler( m_aFilterEntries));
+        }
+        catch( javax.xml.parsers.ParserConfigurationException e )
+        {
+            throw new ODFValidatorException( e );
+        }
+        catch( org.xml.sax.SAXParseException e )
+        {
+            aLogger.logError( e );
+            throw new ODFValidatorException( e );
+        }
+        catch( org.xml.sax.SAXException e )
+        {
+            aLogger.logError( e.getMessage() );
+            throw new ODFValidatorException( e );
+        }
+        catch( java.io.IOException e )
+        {
+            throw new ODFValidatorException( e );
+        }
+
+
+    }
+    
+    public SAXParseException filterException( SAXParseException aExc )
+    {
+        if( m_nBuildId > 0 )
+        {
+            FilterEntry aEntry = m_aFilterEntries.get(aExc.getMessage());
+            if( aEntry != null && 
+                (aEntry.m_nBuildId == 0 || m_nBuildId <= aEntry.m_nBuildId) )
+            {
+                String aTaskId = aEntry.m_aTaskId;
+                if( !m_aTaskIdsReported.contains(aTaskId ))
+                {
+                    m_aTaskIdsReported.add( aTaskId );
+                    return new SAXParseException( "Issue " + aTaskId + " found.", aExc.getPublicId(), aExc.getSystemId(), aExc.getLineNumber(), aExc.getColumnNumber(), aExc );
+                }
+                else
+                    return null;
+            }
+        }
+        
+        return aExc;
+    }
+
+    public void startPackage( String aGenerator )
+    {
+        m_nBuildId = aGenerator.length() > 0 ? getBuildId( aGenerator) : 0;
+    }
+    
+    
+    public void startSubFile() {
+        m_aTaskIdsReported = new HashSet<String>();
+        // the build id is kept
+    }
+    
+    public void setGenerator( String aGenerator )
+    {
+        m_nBuildId = aGenerator.length() > 0 ? getBuildId( aGenerator) : 0;
+    }
+
+    public static int getBuildId( String aGenerator )
+    {
+        int nBuildId = 0;
+        int nPos = aGenerator.indexOf("OpenOffice.org_project/");
+        if( nPos>0 )
+        {
+            nPos = aGenerator.indexOf("Build-",nPos);
+            if( nPos > 0 )
+            {
+                int nStart = nPos+6;
+                nPos = aGenerator.indexOf("$",nStart);
+                nBuildId = Integer.valueOf(nPos > 0 ? aGenerator.substring(nStart,nPos) : aGenerator.substring(nStart));
+            }
+        }
+        
+        return nBuildId;
+    }
+    
+}

Added: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/VersionHandler.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/VersionHandler.java?rev=1172437&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/VersionHandler.java (added)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/VersionHandler.java Mon Sep 19 05:32:56 2011
@@ -0,0 +1,53 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008 Sun Microsystems, Inc. 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.DefaultHandler;
+
+public class VersionHandler extends DefaultHandler {
+
+    private static final String OFFICE_NAMESPACE_URI = "urn:oasis:names:tc:opendocument:xmlns:office:1.0";
+    private static final String DOCUMENT_META = "document-meta";
+    private static final String DOCUMENT_CONTENT = "document-content";
+    private static final String DOCUMENT_SETTINGS = "document-settings";
+    private static final String DOCUMENT_STYLES = "document-styles";
+    private static final String VERSION = "version";
+
+    @Override
+    public void startElement(String aUri, String aLocalName, String aQName, Attributes aAttributes) throws SAXException {
+        super.startElement(aUri, aLocalName, aQName, aAttributes);
+        
+        if( aUri.equals(OFFICE_NAMESPACE_URI) &&
+            (aLocalName.equalsIgnoreCase(DOCUMENT_META) ||
+             aLocalName.equalsIgnoreCase(DOCUMENT_CONTENT) || 
+             aLocalName.equalsIgnoreCase(DOCUMENT_SETTINGS) ||
+             aLocalName.equalsIgnoreCase(DOCUMENT_STYLES)) )
+        {
+            String aVersion = aAttributes.getValue(OFFICE_NAMESPACE_URI,VERSION);
+            throw new SAXVersionException(aVersion);
+        }
+    }
+
+}



Mime
View raw message