incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From devin...@apache.org
Subject svn commit: r1172458 - in /incubator/odf/trunk/validator: ./ src/org/odftoolkit/odfvalidator/ test-resources/ test/org/odftoolkit/odfvalidator/ xslt/
Date Mon, 19 Sep 2011 05:39:05 GMT
Author: devinhan
Date: Mon Sep 19 05:39:04 2011
New Revision: 1172458

URL: http://svn.apache.org/viewvc?rev=1172458&view=rev
Log:
changeset:   27:73c00a2f018a
user:        Michael Brauer <mib@openoffice.org>
date:        Wed Dec 15 11:16:29 2010 +0100
- package validation cleanup
- repaired and improved tests
- added counters for errors and warnings
- ODF schemas now can be used without modifications

Added:
    incubator/odf/trunk/validator/test-resources/testValid1.odt   (with props)
    incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/OdfValidatorTestBase.java
    incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/ValidTest.java
Removed:
    incubator/odf/trunk/validator/xslt/fix_rng_for_msv.xsl
Modified:
    incubator/odf/trunk/validator/build.xml
    incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/Logger.java
    incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFPackageErrorHandler.java
    incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFPackageValidator.java
    incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFRootPackageValidator.java
    incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/InvalidPackageTest.java

Modified: incubator/odf/trunk/validator/build.xml
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/build.xml?rev=1172458&r1=1172457&r2=1172458&view=diff
==============================================================================
--- incubator/odf/trunk/validator/build.xml (original)
+++ incubator/odf/trunk/validator/build.xml Mon Sep 19 05:39:04 2011
@@ -104,31 +104,23 @@
 
        
     <target name="-copy-v10-schema" depends="init">
-        <xslt style="xslt/fix_rng_for_msv.xsl" 
-                    in="${opendocument.v10.schema.dir}/${opendocument.v10.schema}" 
-                    out="${build.classes.dir}/schema/odf10/${opendocument.v10.schema}"/>
 
         <copy todir="${build.classes.dir}/schema/odf10">
             <fileset dir="${opendocument.v10.schema.dir}"
-                includes="${opendocument.v10.schema.strict},${opendocument.v10.schema.manifest}"/>
+                includes="${opendocument.v10.schema},${opendocument.v10.schema.strict},${opendocument.v10.schema.manifest}"/>
         </copy>
     </target>
 
     <target name="-copy-v11-schema" depends="init">
-        <xslt style="xslt/fix_rng_for_msv.xsl" 
-                    in="${opendocument.v11.schema.dir}/${opendocument.v11.schema}" 
-                    out="${build.classes.dir}/schema/odf11/${opendocument.v11.schema}"/>
 
         <copy todir="${build.classes.dir}/schema/odf11">
             <fileset dir="${opendocument.v11.schema.dir}"
-                includes="${opendocument.v11.schema.strict},${opendocument.v11.schema.manifest}"/>
+                includes="${opendocument.v11.schema},${opendocument.v11.schema.strict},${opendocument.v11.schema.manifest}"/>
         </copy>
     </target>
 
     <target name="-copy-v12-schema" depends="init">
-        <xslt style="xslt/fix_rng_for_msv.xsl" 
-                    in="${opendocument.v12.part1.schema.dir}/${opendocument.v12.schema}"
-                    out="${build.classes.dir}/schema/odf12/${opendocument.v12.schema}"/>
 
         <copy todir="${build.classes.dir}/schema/odf12">
-            <fileset dir="${opendocument.v12.part3.schema.dir}" includes="${opendocument.v12.schema.manifest},${opendocument.v12.schema.dsig}"/>
+            <fileset dir="${opendocument.v12.part3.schema.dir}" 
+                includes="${opendocument.v12.schema},${opendocument.v12.schema.manifest},${opendocument.v12.schema.dsig}"/>
         </copy>
     </target>
 

Modified: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/Logger.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/Logger.java?rev=1172458&r1=1172457&r2=1172458&view=diff
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/Logger.java (original)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/Logger.java Mon Sep 19 05:39:04
2011
@@ -38,21 +38,41 @@ public class Logger {
     private String m_aFileName;
     private String m_aEntryName;
     private PrintStream m_aOut;
-    private boolean m_bError;
+    private int m_nErrors;
+    private int m_nWarnings;
     private LogLevel m_nLevel;
+    private Logger m_aParentLogger;
     
     private static final String INFO_PREFIX = "Info:";
     private static final String WARNING_PREFIX = "Warning:";
     private static final String ERROR_PREFIX = "Error:";
     private static final String FATAL_PREFIX = "Fatal:";
     
-    /** Creates a new instance of SchemaErrorHandler */
+    /** Creates a new instance of Logger */
     Logger( String aFileName, String aEntryName, PrintStream aOut , LogLevel nLevel) {
         m_aFileName = aFileName;
         m_aEntryName = aEntryName;
         m_aOut = aOut;
         m_nLevel = nLevel;
-        m_bError = false;
+        m_nErrors = 0;
+        m_nWarnings = 0;
+        m_aParentLogger = null;
+    }
+
+    /** Creates a new instance of Logger */
+    Logger(  String aEntryName, Logger aParentLogger ) {
+        m_aFileName = aParentLogger.m_aFileName;
+        m_aEntryName = aEntryName;
+        m_aOut = aParentLogger.m_aOut;
+        m_nLevel = aParentLogger.m_nLevel;
+        m_nErrors = 0;
+        m_nWarnings = 0;
+        m_aParentLogger = aParentLogger;
+    }
+
+    public PrintStream getOutputStream()
+    {
+        return m_aOut;
     }
 
     public void setOutputStream(PrintStream aOut) {
@@ -61,23 +81,39 @@ public class Logger {
 
     boolean hasError()
     {
-        return m_bError;
+        return m_nErrors>0;
+    }
+
+    boolean hasWarning()
+    {
+        return m_nWarnings>0;
+    }
+
+    int getErrorCount()
+    {
+        return m_nErrors;
+    }
+
+    int getWarningCount()
+    {
+        return m_nWarnings;
     }
 
     void logWarning(String aMsg) {
         if( m_nLevel.compareTo(LogLevel.WARNING) >= 0 )
             logMessage( WARNING_PREFIX, aMsg );
+        incWarnings();
     }
 
     void logFatalError(String aMsg) {
         logMessage( FATAL_PREFIX, aMsg );
-        m_bError = true;
+        incErrors();
     }
 
     void logError(String aMsg) {
         if( m_nLevel.compareTo(LogLevel.ERROR) >= 0 )
             logMessage( ERROR_PREFIX, aMsg );
-        m_bError = true;
+        incErrors();
     }
 
     void logInfo(String aMsg, boolean bForceOutput) {
@@ -88,17 +124,23 @@ public class Logger {
     void logWarning(SAXParseException e) {
         if( m_nLevel.compareTo(LogLevel.WARNING) >= 0 )
             logMessage( WARNING_PREFIX, e );
+        incWarnings();
     }
 
     void logFatalError(SAXParseException e) {
         logMessage( FATAL_PREFIX, e );
-        m_bError = true;
+        incErrors();
     }
 
     void logError(SAXParseException e) {
         if( m_nLevel.compareTo(LogLevel.ERROR) >= 0 )
             logMessage( ERROR_PREFIX, e );
-        m_bError = true;
+        incErrors();
+    }
+
+    void logSummaryInfo()
+    {
+        logInfo( (hasError() ? getErrorCount() : "no") + " errors, " + (hasWarning() ? getWarningCount()
: "no") + " warnings", false );
     }
         
     private void printFileEntryPrefix()
@@ -130,4 +172,19 @@ public class Logger {
         m_aOut.print( aPrefix );
         m_aOut.println( aMsg);
     }
+
+    private void incErrors()
+    {
+        ++m_nErrors;
+        if( m_aParentLogger != null )
+            m_aParentLogger.incErrors();
+    }
+
+    private void incWarnings()
+    {
+        ++m_nWarnings;
+        if( m_aParentLogger != null )
+            m_aParentLogger.incWarnings();
+    }
+
 }

Modified: incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFPackageErrorHandler.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFPackageErrorHandler.java?rev=1172458&r1=1172457&r2=1172458&view=diff
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFPackageErrorHandler.java
(original)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFPackageErrorHandler.java
Mon Sep 19 05:39:04 2011
@@ -34,87 +34,113 @@ import org.xml.sax.SAXParseException;
 
 class ODFPackageErrorHandler implements ErrorHandler {
 
-    List<SAXParseException> m_Saved = new ArrayList<SAXParseException>();
+    List<SAXParseException> m_aExceptionList = new ArrayList<SAXParseException>();
+
+    ODFPackageErrorHandler()
+    {
+    }
 
     public void warning(SAXParseException exception) throws SAXException {
-        m_Saved.add(exception);
+        m_aExceptionList.add(exception);
     }
 
     public void error(SAXParseException exception) throws SAXException {
-        m_Saved.add(exception);
+        m_aExceptionList.add(exception);
     }
 
     public void fatalError(SAXParseException exception) throws SAXException {
+        m_aExceptionList.add(exception);
         throw exception;
     }
 
-    /// deferred because version is not available when odfdom checks mimetype
+    /// deferred because aVersion is not available when odfdom checks mimetype
     /// @returns true iff there was an error and package is not valid
-    boolean validate(Logger manifestLogger, Logger mimeTypeLogger,
-                     OdfVersion version)
+    boolean processErrors( Logger aPkgLogger, Logger aManifestLogger,
+                           Logger aMimetypeLogger,OdfVersion aVersion)
     {
         boolean bRet = false;
-        LOOP:
-        for (SAXParseException e : m_Saved) {
-            if (e instanceof OdfValidationException) {
-                ValidationConstraint constraint =
+        for (SAXParseException e : m_aExceptionList)
+        {
+            if (e instanceof OdfValidationException)
+            {
+                ValidationConstraint aConstraint =
                     ((OdfValidationException) e).getConstraint();
-                if (constraint instanceof OdfPackageConstraint) {
-                    switch (((OdfPackageConstraint) constraint)) {
+                if (aConstraint instanceof OdfPackageConstraint)
+                {
+                    switch (((OdfPackageConstraint) aConstraint))
+                    {
                         case MANIFEST_DOES_NOT_LIST_FILE:
-                            switch (version) {
+                            switch (aVersion)
+                            {
                                 case V1_0:
                                 case V1_1:
-                                    manifestLogger.logWarning(e.getMessage());
-                                break;
+                                    aManifestLogger.logWarning(e.getMessage());
+                                    break;
                                 default:
-                                    manifestLogger.logError(e.getMessage());
+                                    aManifestLogger.logError(e.getMessage());
                                     bRet = true;
-                                break;
+                                    break;
                             }
-                            continue LOOP;
+                            break;
                         case MIMETYPE_NOT_FIRST_IN_PACKAGE:
                         case MIMETYPE_NOT_IN_PACKAGE:
-                            switch (version) {
+                            switch (aVersion)
+                            {
                                 case V1_0:
                                 case V1_1:
-                                    mimeTypeLogger.logWarning(e.getMessage());
-                                break;
+                                    aMimetypeLogger.logWarning(e.getMessage());
+                                    break;
                                 default:
-                                    mimeTypeLogger.logError(e.getMessage());
+                                    aMimetypeLogger.logError(e.getMessage());
                                     bRet = true;
-                                break;
+                                    break;
                             }
-                            continue LOOP;
+                            break;
                         case MANIFEST_NOT_IN_PACKAGE:
                         case MANIFEST_LISTS_NONEXISTENT_FILE:
-                            manifestLogger.logError(e.getMessage());
+                            aManifestLogger.logError(e.getMessage());
                             bRet = true;
-                            continue LOOP;
+                            break;
                         case MIMETYPE_IS_COMPRESSED:
                         case MIMETYPE_HAS_EXTRA_FIELD:
                         case MIMETYPE_DIFFERS_FROM_PACKAGE:
-                            mimeTypeLogger.logError(e.getMessage());
+                            aMimetypeLogger.logError(e.getMessage());
                             bRet = true;
-                            continue LOOP;
+                            break;
                         case MANIFEST_LISTS_DIRECTORY:
                         case MANIFEST_DOES_NOT_LIST_DIRECTORY:
-                            manifestLogger.logWarning(e.getMessage());
-                            continue LOOP;
+                            aManifestLogger.logWarning(e.getMessage());
+                            break;
+                        default:
+                            aPkgLogger.logError(e); // unknown aConstraint: assume error
+                            bRet = true;
+                            break;
                     }
-                } else if (constraint instanceof OdfSchemaConstraint) {
-                    switch (((OdfSchemaConstraint) constraint)) {
+                } 
+                else if (aConstraint instanceof OdfSchemaConstraint)
+                {
+                    switch (((OdfSchemaConstraint) aConstraint))
+                    {
                         case DOCUMENT_WITHOUT_ODF_MIMETYPE:
                         case DOCUMENT_WITHOUT_CONTENT_NOR_STYLES_XML:
-                            manifestLogger.logError(e.getMessage());
+                            aPkgLogger.logError(e.getMessage());
                             bRet = true;
-                            continue LOOP;
+                            break;
+                        default:
+                            aPkgLogger.logError(e); // unknown aConstraint: assume error
+                            bRet = true;
+                            break;
                     }
                 }
             }
-            manifestLogger.logError(e); // unknown constraint: assume error
+            else
+            {
+                aPkgLogger.logError(e); // unknown aConstraint: assume error
+                bRet = true;
+            }
         }
-        m_Saved.clear();
+
+        m_aExceptionList.clear();
         return bRet;
     }
 }

Modified: 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=1172458&r1=1172457&r2=1172458&view=diff
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFPackageValidator.java
(original)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFPackageValidator.java
Mon Sep 19 05:39:04 2011
@@ -81,11 +81,24 @@ public abstract class ODFPackageValidato
 
     abstract String getStreamName( String aEntry );
 
+
     public boolean validate(PrintStream aOut) throws ODFValidatorException
     {
         Logger aLogger =
             new Logger( getLoggerName(), getDocumentPath(), aOut, m_nLogLevel);
+        return _validate( aLogger );
+    }
+
+    public boolean validate(Logger aParentLogger) throws ODFValidatorException
+    {
+        Logger aLogger =
+            new Logger( getDocumentPath(), aParentLogger);
+        return _validate( aLogger );
+    }
 
+
+    private boolean _validate(Logger aLogger) throws ODFValidatorException
+    {
         boolean bHasErrors = false;
 
         OdfPackage aPkg = getPackage( aLogger );
@@ -99,17 +112,17 @@ public abstract class ODFPackageValidato
                 aLogger.logInfo( "ODF Version: " + aDocVersion, false );
             OdfVersion aVersion = m_aConfigVersion == null ? OdfVersion.valueOf(aDocVersion,true)
: m_aConfigVersion;
 
-            bHasErrors |= validatePre(aOut, aVersion);
+            bHasErrors |= validatePre(aLogger, aVersion);
             aLogger.logInfo( "Media Type: " + m_aResult.getMediaType(), false);
 
-            bHasErrors |= validateMeta(aOut, getStreamName( OdfDocument.OdfXMLFile.META.getFileName()),
aVersion, true );
-            bHasErrors |= validateEntry(aOut, getStreamName(OdfDocument.OdfXMLFile.SETTINGS.getFileName()),
DOCUMENT_SETTINGS, aVersion);
-            bHasErrors |= validateEntry(aOut, getStreamName( OdfDocument.OdfXMLFile.STYLES.getFileName()),
DOCUMENT_STYLES, aVersion );
+            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(aOut, getStreamName( OdfDocument.OdfXMLFile.CONTENT.getFileName()),
aVersion );
+                bHasErrors |= validateMathML(aLogger, getStreamName( OdfDocument.OdfXMLFile.CONTENT.getFileName()),
aVersion );
             else
-                bHasErrors |= validateEntry(aOut, getStreamName( OdfDocument.OdfXMLFile.CONTENT.getFileName()),
DOCUMENT_CONTENT, aVersion );
-            bHasErrors |= validatePost(aOut, aLogger, aVersion);
+                bHasErrors |= validateEntry(aLogger, getStreamName( OdfDocument.OdfXMLFile.CONTENT.getFileName()),
DOCUMENT_CONTENT, aVersion );
+            bHasErrors |= validatePost(aLogger, aVersion);
         }
         catch( ZipException e )
         {
@@ -125,12 +138,12 @@ public abstract class ODFPackageValidato
         return bHasErrors || aLogger.hasError();
     }
 
-    protected boolean validatePre(PrintStream aOut, OdfVersion aVersion ) throws ODFValidatorException,
IOException
+    protected boolean validatePre(Logger aLogger, OdfVersion aVersion ) throws ODFValidatorException,
IOException
     {
         return false;
     }
 
-    protected boolean validatePost(PrintStream aOut, Logger aLogger, OdfVersion aVersion
) throws ODFValidatorException, IOException
+    protected boolean validatePost(Logger aLogger, OdfVersion aVersion ) throws ODFValidatorException,
IOException
     {
         return false;
     }
@@ -139,9 +152,9 @@ public abstract class ODFPackageValidato
     {
     }
 
-    protected boolean validateEntry(PrintStream aOut, String aEntryName, String aLocalElementName,
OdfVersion aVersion ) throws IOException, ZipException, IllegalStateException, ODFValidatorException
+    protected boolean validateEntry(Logger aParentLogger, String aEntryName, String aLocalElementName,
OdfVersion aVersion ) throws IOException, ZipException, IllegalStateException, ODFValidatorException
     {
-        Logger aLogger = new Logger(getLoggerName(),aEntryName,aOut, m_nLogLevel);
+        Logger aLogger = new Logger(aEntryName,aParentLogger);
         XMLFilter aFilter = new ContentFilter(aLogger, aLocalElementName );
         if( (m_eMode == OdfValidatorMode.CHECK_CONFORMANCE && aVersion.compareTo(OdfVersion.V1_1)
<= 0) ||
             m_eMode == OdfValidatorMode.CHECK_EXTENDED_CONFORMANCE )
@@ -150,14 +163,14 @@ public abstract class ODFPackageValidato
             aAlienFilter.setParent(aFilter);
             aFilter = aAlienFilter;
         }
-        Validator aValidator = m_eMode == OdfValidatorMode.VALIDATE_STRICT ? m_aValidatorProvider.getStrictValidator(aOut,
aVersion)
-                                                          : m_aValidatorProvider.getValidator(aOut,aVersion);
-        return validateEntry(aOut, aFilter, aValidator, aLogger, aEntryName );
+        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(PrintStream aOut, String aEntryName, OdfVersion aVersion,
boolean bIsRoot) throws IOException, ZipException, IllegalStateException, ODFValidatorException
+    private boolean validateMeta(Logger aParentLogger, String aEntryName, OdfVersion aVersion,
boolean bIsRoot) throws IOException, ZipException, IllegalStateException, ODFValidatorException
     {
-        Logger aLogger = new Logger(getLoggerName(),aEntryName,aOut, m_nLogLevel);
+        Logger aLogger = new Logger(aEntryName,aParentLogger);
         XMLFilter aFilter = new MetaFilter(aLogger, m_aResult );
         if( (m_eMode == OdfValidatorMode.CHECK_CONFORMANCE && aVersion.compareTo(OdfVersion.V1_1)
<= 0) ||
             m_eMode == OdfValidatorMode.CHECK_EXTENDED_CONFORMANCE )
@@ -167,46 +180,46 @@ public abstract class ODFPackageValidato
             aFilter = aAlienFilter;
         }
 
-        Validator aValidator = m_eMode == OdfValidatorMode.VALIDATE_STRICT ? m_aValidatorProvider.getStrictValidator(aOut,aVersion)
-                                                          : m_aValidatorProvider.getValidator(aOut,aVersion);
-        return validateEntry(aOut, aFilter, aValidator, aLogger, aEntryName );
+        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 validateMathML(PrintStream aOut, String aEntryName, OdfVersion aVersion
) throws IOException, ZipException, IllegalStateException, ODFValidatorException
+    private boolean validateMathML(Logger aParentLogger, String aEntryName, OdfVersion aVersion
) throws IOException, ZipException, IllegalStateException, ODFValidatorException
     {
-        Logger aLogger = new Logger(getLoggerName(),aEntryName,aOut, m_nLogLevel);
+        Logger aLogger = new Logger(aEntryName,aParentLogger);
         String aMathMLDTDSystemId = m_aValidatorProvider.getMathMLDTDSystemId(aVersion);
         if( aMathMLDTDSystemId != null )
         {
             // validate using DTD
-            return parseEntry(aOut, new MathML101Filter(aMathMLDTDSystemId, aLogger), aLogger,
aEntryName, true);
+            return parseEntry(new MathML101Filter(aMathMLDTDSystemId, aLogger), aLogger,
aEntryName, true);
         }
         else
         {
-            Validator aMathMLValidator = m_aValidatorProvider.getMathMLValidator(aOut,null);
+            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( aOut, new MathML20Filter(aLogger), aMathMLValidator, aLogger,
aEntryName );
+            return validateEntry( new MathML20Filter(aLogger), aMathMLValidator, aLogger,
aEntryName );
         }
     }
     
 
-    protected boolean validateDSig(PrintStream aOut, String aEntryName, OdfVersion aVersion
) throws IOException, ZipException, IllegalStateException, ODFValidatorException
+    protected boolean validateDSig(Logger aParentLogger, String aEntryName, OdfVersion aVersion
) throws IOException, ZipException, IllegalStateException, ODFValidatorException
     {
-        Validator aValidator=m_aValidatorProvider.getDSigValidator(aOut,aVersion);
-        Logger aLogger = new Logger(getLoggerName(),aEntryName,aOut, m_nLogLevel);
+        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(aOut, new DSigFilter(aLogger), aValidator, aLogger, aEntryName
);
+        return validateEntry(new DSigFilter(aLogger), aValidator, aLogger, aEntryName );
     }
 
-    protected boolean validateEntry(PrintStream aOut, XMLFilter aFilter,
+    protected boolean validateEntry(XMLFilter aFilter,
                            Validator aValidator, Logger aLogger,
                            String aEntryName ) throws IOException, ZipException, IllegalStateException,
ODFValidatorException
     {
@@ -234,10 +247,10 @@ public abstract class ODFPackageValidato
 
 
 
-        return aInStream != null ? validate(aOut, aInStream, aFilter, aValidator, aLogger
) : false;
+        return aInStream != null ? validate(aInStream, aFilter, aValidator, aLogger ) : false;
     }
     
-    private boolean validate(PrintStream aOut, InputStream aInStream,
+    private boolean validate(InputStream aInStream,
                       XMLFilter aFilter,
                       javax.xml.validation.Validator aValidator,
                       Logger aLogger ) throws ODFValidatorException
@@ -291,7 +304,7 @@ public abstract class ODFPackageValidato
             aLogger.logFatalError(e.getMessage());
         }
         
-        aLogger.logInfo( aLogger.hasError() ? "validation errors found" : "no errors" , false);
+        aLogger.logSummaryInfo();
         if( m_aResult.hasForeignElements())
         {
             Set<String> aForeignElementURISet = m_aResult.getForeignElements().keySet();
@@ -326,7 +339,7 @@ public abstract class ODFPackageValidato
         return aLogger.hasError();
     }
 
-    protected boolean parseEntry(PrintStream aOut, XMLFilter aFilter,
+    protected boolean parseEntry(XMLFilter aFilter,
                            Logger aLogger,
                            String aEntryName , boolean bValidating) throws IOException, ZipException,
IllegalStateException, ODFValidatorException
     {
@@ -345,13 +358,12 @@ public abstract class ODFPackageValidato
             throw new ODFValidatorException( e );
         }
 
-        return aInStream != null ? parse(aOut, aInStream, aFilter, bValidating, aLogger )
: false;
+        return aInStream != null ? parse(aInStream, aFilter, bValidating, aLogger ) : false;
     }
 
-    private boolean parse(PrintStream aOut, InputStream aInStream, XMLFilter aFilter, boolean
bValidating, Logger aLogger ) throws ODFValidatorException
+    private boolean parse(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
@@ -387,7 +399,7 @@ public abstract class ODFPackageValidato
         }
         
         if( bValidating )
-            aLogger.logInfo( aLogger.hasError() ? "validation errors found" : "no errors"
, false);            
+            aLogger.logSummaryInfo();
         return aLogger.hasError();
     }
 

Modified: 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=1172458&r1=1172457&r2=1172458&view=diff
==============================================================================
--- incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFRootPackageValidator.java
(original)
+++ incubator/odf/trunk/validator/src/org/odftoolkit/odfvalidator/ODFRootPackageValidator.java
Mon Sep 19 05:39:04 2011
@@ -75,16 +75,28 @@ public abstract class ODFRootPackageVali
     }
 
     @Override
-    protected boolean validatePre(PrintStream aOut, OdfVersion aVersion ) throws ODFValidatorException,
IOException
+    protected boolean validatePre(Logger aLogger, OdfVersion aVersion ) throws ODFValidatorException,
IOException
     {
-        boolean bErrorsFound = validateMimetype(aOut, aVersion);
-        bErrorsFound |= validateManifest(aOut, aVersion  );
+        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(PrintStream aOut,Logger aLogger,OdfVersion aVersion )
throws ODFValidatorException, IOException
+    protected boolean validatePost(Logger aLogger,OdfVersion aVersion ) throws ODFValidatorException,
IOException
     {
         boolean bHasErrors = false;
         if(m_aSubDocs != null )
@@ -96,14 +108,14 @@ public abstract class ODFRootPackageVali
                 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(aOut);
+                bHasErrors |= aPackageValidator.validate(aLogger);
             }
         }
 
         if( aVersion.compareTo(OdfVersion.V1_2) >= 0 )
         {
-            bHasErrors |= validateDSig( aOut, OdfPackageExt.STREAMNAME_DOCUMENT_SIGNATURES,
aVersion );
-            bHasErrors |= validateDSig( aOut, OdfPackageExt.STREAMNAME_MACRO_SIGNATURES,
aVersion );
+            bHasErrors |= validateDSig( aLogger, OdfPackageExt.STREAMNAME_DOCUMENT_SIGNATURES,
aVersion );
+            bHasErrors |= validateDSig( aLogger, OdfPackageExt.STREAMNAME_MACRO_SIGNATURES,
aVersion );
         }
 
         return bHasErrors;
@@ -112,14 +124,9 @@ public abstract class ODFRootPackageVali
     @Override
     protected void logSummary( boolean bHasErrors, Logger aLogger )
     {
-        if( bHasErrors || aLogger.hasError() )
-        {
-            aLogger.logInfo( "validation errors found" , true );
-            if( m_nLogLevel.compareTo(Logger.LogLevel.INFO) < 0 )
-                aLogger.logInfo( "Generator: " + m_aResult.getGenerator() , true );
-        }
-        else
-            aLogger.logInfo(  "no errors" , false);
+        aLogger.logSummaryInfo();
+        if( (bHasErrors || aLogger.hasError()) && m_nLogLevel.compareTo(Logger.LogLevel.INFO)
< 0  )
+            aLogger.logInfo( "Generator: " + m_aResult.getGenerator() , true );
     }
 
 
@@ -133,9 +140,8 @@ public abstract class ODFRootPackageVali
         }
     }
 
-    private boolean validateMimetype(PrintStream aOut, OdfVersion aVersion)
+    private boolean validateMimetype(Logger aLogger, OdfVersion aVersion)
     {
-        Logger aLogger = new Logger(getLoggerName(),"MIMETYPE",aOut, m_nLogLevel);
         boolean bHasErrors = false;
 
         String aMimetype=getPackage(aLogger).getMediaTypeString();
@@ -166,30 +172,21 @@ public abstract class ODFRootPackageVali
         return bHasErrors;
     }
 
-    private boolean validateManifest(PrintStream aOut, OdfVersion aVersion ) throws IOException,
ZipException, IllegalStateException, ODFValidatorException
+    private boolean validateManifest(Logger aLogger, OdfVersion 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, m_aResult, this);
-        Validator aManifestValidator = m_aValidatorProvider.getManifestValidator(aOut,aVersion);
+        Validator aManifestValidator = m_aValidatorProvider.getManifestValidator(aLogger.getOutputStream(),aVersion);
         if( aManifestValidator != null )
         {
-            bRet = validateEntry(aOut, aFilter,
+            bRet = validateEntry(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);
+            bRet = parseEntry(aFilter, aLogger, OdfPackage.OdfFile.MANIFEST.getPath() , false);
         }
-        // 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...
-        Logger aMimetypeLogger =
-            new Logger(getLoggerName(),"MIMETYPE",aOut, m_nLogLevel);
-        bRet |= m_ErrorHandler.validate(aLogger, aMimetypeLogger, aVersion);
         return bRet;
     }
 

Added: incubator/odf/trunk/validator/test-resources/testValid1.odt
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/test-resources/testValid1.odt?rev=1172458&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/odf/trunk/validator/test-resources/testValid1.odt
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/InvalidPackageTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/InvalidPackageTest.java?rev=1172458&r1=1172457&r2=1172458&view=diff
==============================================================================
--- incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/InvalidPackageTest.java
(original)
+++ incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/InvalidPackageTest.java
Mon Sep 19 05:39:04 2011
@@ -22,26 +22,12 @@
 
 package org.odftoolkit.odfvalidator;
 
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.PrintStream;
 import junit.framework.Assert;
 import org.junit.Test;
 
 /** Test some invalid packages.
  */
-public class InvalidPackageTest {
-    private String doValidation(String file, OdfVersion version) throws Exception
-    {
-        ODFValidator validator = new ODFValidator(null, Logger.LogLevel.INFO, version, true);
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        PrintStream pout = new PrintStream(out);
-        InputStream is = getClass().getClassLoader().getResourceAsStream(file);
-//            validator.validateFile(pout, f, OdfValidatorMode.VALIDATE, null);
-        validator.validateStream(pout, is, file, OdfValidatorMode.VALIDATE, null);
-//            System.err.println(out.toString());
-        return out.toString();
-    }
+public class InvalidPackageTest extends OdfValidatorTestBase {
 
     @Test
     public void validatePackage1() {
@@ -53,11 +39,11 @@ public class InvalidPackageTest {
             t.printStackTrace();
             Assert.fail(t.toString());
         }
-        Assert.assertTrue(output.contains("testInvalidPkg1.odt/MIMETYPE:Error:The file 'mimetype'
is not the first file in the ODF package"));
-        Assert.assertTrue(output.contains("testInvalidPkg1.odt/MIMETYPE:Error:The file 'mimetype'
shall not be compressed"));
-        Assert.assertTrue(output.contains("testInvalidPkg1.odt/MIMETYPE:Error:There shall
be no extra field for the 'mimetype' file"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:Error:The file 'mimetype'
is not the first file in the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:Error:The file 'mimetype'
shall not be compressed"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:Error:There shall
be no extra field for the 'mimetype' file"));
         Assert.assertTrue(output.contains("testInvalidPkg1.odt/META-INF/manifest.xml:Error:The
file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
-        Assert.assertTrue(output.contains("testInvalidPkg1.odt:Info:validation errors found"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt:Info:7 errors, 10 warnings"));
     }
 
     @Test
@@ -70,11 +56,11 @@ public class InvalidPackageTest {
             t.printStackTrace();
             Assert.fail(t.toString());
         }
-        Assert.assertTrue(output.contains("testInvalidPkg1.odt/MIMETYPE:Warning:The file
'mimetype' is not the first file in the ODF package"));
-        Assert.assertTrue(output.contains("testInvalidPkg1.odt/MIMETYPE:Error:The file 'mimetype'
shall not be compressed"));
-        Assert.assertTrue(output.contains("testInvalidPkg1.odt/MIMETYPE:Error:There shall
be no extra field for the 'mimetype' file"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:Warning:The file
'mimetype' is not the first file in the ODF package"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:Error:The file 'mimetype'
shall not be compressed"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt/mimetype:Error:There shall
be no extra field for the 'mimetype' file"));
         Assert.assertTrue(output.contains("testInvalidPkg1.odt/META-INF/manifest.xml:Error:The
file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
-        Assert.assertTrue(output.contains("testInvalidPkg1.odt:Info:validation errors found"));
+        Assert.assertTrue(output.contains("testInvalidPkg1.odt:Info:9 errors, 11 warnings"));
     }
 
     @Test
@@ -87,10 +73,10 @@ public class InvalidPackageTest {
             t.printStackTrace();
             Assert.fail(t.toString());
         }
-        Assert.assertTrue(output.contains("testInvalidPkg2.odt/MIMETYPE:Error:The ODF package
'testInvalidPkg2.odt' contains no 'mimetype' file"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt/mimetype:Error:The ODF package
'testInvalidPkg2.odt' contains no 'mimetype' file"));
         Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:Error:The
file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
         Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:Error:The
file 'not_in_manifest' shall be listed in the 'META-INF/manifest.xml' file as it exists in
the ODF package"));
-        Assert.assertTrue(output.contains("testInvalidPkg2.odt:Info:validation errors found"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt:Info:5 errors, 10 warnings"));
     }
 
     @Test
@@ -103,10 +89,10 @@ public class InvalidPackageTest {
             t.printStackTrace();
             Assert.fail(t.toString());
         }
-        Assert.assertTrue(output.contains("testInvalidPkg2.odt/MIMETYPE:Warning:The ODF package
'testInvalidPkg2.odt' contains no 'mimetype' file"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt/mimetype:Warning:The ODF package
'testInvalidPkg2.odt' contains no 'mimetype' file"));
         Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:Error:The
file 'Configurations2/accelerator/current.xml' shall not be listed in the 'META-INF/manifest.xml'
file as it does not exist in the ODF package"));
         Assert.assertTrue(output.contains("testInvalidPkg2.odt/META-INF/manifest.xml:Warning:The
file 'not_in_manifest' shall be listed in the 'META-INF/manifest.xml' file as it exists in
the ODF package"));
-        Assert.assertTrue(output.contains("testInvalidPkg2.odt:Info:validation errors found"));
+        Assert.assertTrue(output.contains("testInvalidPkg2.odt:Info:6 errors, 12 warnings"));
     }
 
     @Test
@@ -120,7 +106,7 @@ public class InvalidPackageTest {
             Assert.fail(t.toString());
         }
         Assert.assertTrue(output.contains("Error:The ODF package 'testInvalidPkg3.odt' shall
contain the 'META-INF/manifest.xml' file"));
-        Assert.assertTrue(output.contains("testInvalidPkg3.odt:Info:validation errors found"));
+        Assert.assertTrue(output.contains("testInvalidPkg3.odt:Info:3 errors, no warnings"));
     }
 
 }

Added: incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/OdfValidatorTestBase.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/OdfValidatorTestBase.java?rev=1172458&view=auto
==============================================================================
--- incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/OdfValidatorTestBase.java
(added)
+++ incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/OdfValidatorTestBase.java
Mon Sep 19 05:39:04 2011
@@ -0,0 +1,48 @@
+/************************************************************************
+ *
+ * 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.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.PrintStream;
+import org.junit.Ignore;
+
+@Ignore
+public class OdfValidatorTestBase {
+
+    public OdfValidatorTestBase() {
+    }
+
+    String doValidation(String aFileName, OdfVersion aVersion) throws Exception {
+        ODFValidator aValidator = new ODFValidator(null, Logger.LogLevel.INFO, aVersion,
true);
+        ByteArrayOutputStream aOut = new ByteArrayOutputStream();
+        PrintStream aPOut = new PrintStream(aOut);
+        InputStream aIn = getClass().getClassLoader().getResourceAsStream(aFileName);
+//            aValidator.validateFile(aPOut, f, OdfValidatorMode.VALIDATE, null);
+        aValidator.validateStream(aPOut, aIn, aFileName, OdfValidatorMode.VALIDATE, null);
+        System.out.println(aOut.toString());
+        return aOut.toString();
+    }
+
+
+}

Added: incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/ValidTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/ValidTest.java?rev=1172458&view=auto
==============================================================================
--- incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/ValidTest.java (added)
+++ incubator/odf/trunk/validator/test/org/odftoolkit/odfvalidator/ValidTest.java Mon Sep
19 05:39:04 2011
@@ -0,0 +1,45 @@
+/************************************************************************
+ *
+ * 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 junit.framework.Assert;
+import org.junit.Test;
+
+/** Test some invalid packages.
+ */
+public class ValidTest extends OdfValidatorTestBase {
+
+    @Test
+    public void validate1() {
+        String output = "";
+        try {
+            String name = "testValid1.odt";
+            output = doValidation(name, null);
+        } catch (Throwable t) {
+            t.printStackTrace();
+            Assert.fail(t.toString());
+        }
+        Assert.assertTrue(output.contains("testValid1.odt:Info:no errors, no warnings"));
+    }
+
+}



Mime
View raw message