Added: incubator/odf/trunk/validator/src/odfvalidator/Main.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/odfvalidator/Main.java?rev=1172430&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/odfvalidator/Main.java (added)
+++ incubator/odf/trunk/validator/src/odfvalidator/Main.java Mon Sep 19 05:30:38 2011
@@ -0,0 +1,284 @@
+/************************************************************************
+ *
+ * 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 odfvalidator;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+/**
+ * This application validates an OpenDocument file. To run this application from the command line without Ant, try:
+ * java -jar "[path/]ODFValidator.jar".
+ * @author michael
+ */
+public class Main {
+
+ private static final String VERSION="1.1.1";
+
+ /** Creates a new instance of Main */
+ public Main() {
+ }
+
+ /**
+ * @param aArgs the command line arguments
+ */
+ public static void main(String[] aArgs) {
+
+ String aConfigFileName = null;
+ String aFilterFileName = null;
+ String aSchemaFileName = null;
+ String aOutputFileName = null;
+ String aExcludeRegExp = null;
+ boolean bPrintGenerator = false;
+ boolean bUseMathDTD = false;
+ boolean bPrintHelp = false;
+ boolean bPrintVersion = false;
+ boolean bRecursive = false;
+ int nLogLevel = Logger.ERROR;
+ int nMode = ODFPackageValidator.VALIDATE;
+ List<String> aFileNames = new Vector<String>();
+ String aVersion = null;
+
+ boolean bCommandLineValid = true;
+ List<String> aArgList = Arrays.asList(aArgs);
+ Iterator<String> aArgIter = aArgList.iterator();
+ while( aArgIter.hasNext() && bCommandLineValid )
+ {
+ String aArg = aArgIter.next();
+ if( aArg.equals("-c") )
+ {
+ nMode = ODFPackageValidator.CHECK_CONFORMANCE;
+ }
+ else if( aArg.equals("-d") )
+ {
+ bUseMathDTD = true;
+ }
+ else if( aArg.equals("-f") )
+ {
+ if( aArgIter.hasNext() )
+ aFilterFileName = aArgIter.next();
+ else
+ bCommandLineValid = false;
+ }
+ else if( aArg.equals("-g") )
+ {
+ bPrintGenerator = true;
+ }
+ else if( aArg.equals("-h") )
+ {
+ bPrintHelp = true;
+ }
+ else if( aArg.equals("-o") )
+ {
+ if( aArgIter.hasNext() )
+ aOutputFileName = aArgIter.next();
+ else
+ bCommandLineValid = false;
+ }
+ else if( aArg.equals("-r") )
+ {
+ bRecursive = true;
+ }
+ else if( aArg.equals("-s") )
+ {
+ nMode = ODFPackageValidator.VALIDATE_STRICT;
+ }
+ else if( aArg.equals("-v") )
+ {
+ nLogLevel = Logger.INFO;
+ }
+ else if( aArg.equals("-w") )
+ {
+ nLogLevel = Logger.WARNING;
+ }
+ else if( aArg.equals("-x") )
+ {
+ if( aArgIter.hasNext() )
+ aExcludeRegExp = aArgIter.next();
+ else
+ bCommandLineValid = false;
+ }
+ else if( aArg.equals("-C") )
+ {
+ if( aArgIter.hasNext() )
+ aConfigFileName = aArgIter.next();
+ else
+ bCommandLineValid = false;
+ }
+ else if( aArg.equals("-S") )
+ {
+ if( aArgIter.hasNext() )
+ aSchemaFileName = aArgIter.next();
+ else
+ bCommandLineValid = false;
+ }
+ else if( aArg.equals("-V") )
+ {
+ bPrintVersion = true;
+ }
+ else if( aArg.equals("-1.0") || aArg.equals("-1.1") || aArg.equals("-1.2") )
+ {
+ aVersion = aArg.substring(1);
+ }
+ else if( aArg.startsWith("-") )
+ {
+ System.out.print(aArg);
+ System.out.println(": unknown option, use '-' for help");
+ return;
+ }
+ else
+ {
+ aFileNames.add( aArg );
+ }
+ }
+
+ // check usage
+ if( bPrintHelp || bPrintVersion )
+ {
+ bCommandLineValid = true;
+ }
+ else if( bPrintGenerator )
+ {
+ bCommandLineValid = aFileNames.size() > 0;
+ }
+ else if( aConfigFileName != null )
+ {
+ bCommandLineValid = aConfigFileName.length() > 0;
+ }
+ else
+ {
+ bCommandLineValid = aFileNames.size() > 0;
+ }
+
+ // print help
+ if( !bCommandLineValid || bPrintHelp )
+ {
+ printUsage();
+ return;
+ }
+ if( bPrintVersion )
+ {
+ System.out.print("odfvalidator v");
+ System.out.println( VERSION );
+ return;
+ }
+
+ try
+ {
+ // Print generator (does not require config file)
+ if( bPrintGenerator )
+ {
+ MetaInformation aMetaInformation = new MetaInformation( System.out );
+ Iterator<String> aIter = aFileNames.iterator();
+ while( aIter.hasNext() )
+ aMetaInformation.getInformation(aIter.next());
+ return;
+ }
+
+ // Read configuration
+ Configuration aConfig = null;
+ if( aConfigFileName != null )
+ {
+ File aConfigFile = new File( aConfigFileName );
+ try
+ {
+ aConfig = new Configuration( aConfigFile );
+ }
+ catch( FileNotFoundException e )
+ {
+ if( aConfigFileName != null )
+ {
+ System.out.println( aConfigFile.getAbsolutePath() + ": file not found.");
+ return;
+ }
+ }
+ catch( IOException e )
+ {
+ System.out.println("error reading " + aConfigFile.getAbsolutePath() + ": " + e.getLocalizedMessage() );
+ return;
+ }
+ }
+
+ if( aSchemaFileName != null )
+ {
+ aConfig = new Configuration();
+ aConfig.setProperty( Configuration.STRICT_SCHEMA, aSchemaFileName );
+ }
+
+ PrintStream aOut = aOutputFileName != null ? new PrintStream( aOutputFileName ) : System.out;
+ ODFValidator aValidator = new ODFValidator( aConfig, nLogLevel, aVersion, bUseMathDTD );
+
+ if( aConfigFileName != null )
+ {
+ aValidator.validate(aOut, aConfig, nMode );
+ }
+ else
+ {
+ aValidator.validate(aOut, aFileNames, aExcludeRegExp, nMode, bRecursive, aFilterFileName );
+ }
+ }
+ catch( ODFValidatorException e )
+ {
+ System.out.println( e.getMessage() );
+ System.out.println( "Validation aborted." );
+ }
+ catch( FileNotFoundException e )
+ {
+ System.out.println( e.getMessage() );
+ System.out.println( "Validation aborted." );
+ }
+ }
+
+ private static void printUsage()
+ {
+ System.out.println( "usage: odfvalidator -g <odffiles>");
+ System.out.println( " odfvalidator [-r] [-c|-s] [-d] [-v|-w] [-f <filterfile>] [-x <regexp>] [-o outputfile] [-1.0|-1.1|-1.2] <odffiles>");
+ System.out.println( " odfvalidator [-r] [-c|-s] [-d] [-v|-w] [-f <filterfile>] [-x <regexp>] [-o outputfile] -S <schemafile> <odffiles>");
+ System.out.println( " odfvalidator [-c|-s] [-v|-w] [-d] [-o outputfile] -C <configfile>");
+ System.out.println( " odfvalidator -h");
+ System.out.println( " odfvalidator -V");
+ System.out.println();
+ System.out.println( "-C: Validate using configuration file <configfile>" );
+ System.out.println( "-S: Use schema <schemafile> for validation" );
+ System.out.println( "-V: Print version" );
+ System.out.println( "-c: Check conformance" );
+ System.out.println( "-d: Use MathML DTD rather than MathML2 schema for validation" );
+ System.out.println( "-f: Use filterfile <filterfile>" );
+ System.out.println( "-g: Show <odffiles> generators and exit" );
+ System.out.println( "-h: Print this help and exit" );
+ System.out.println( "-o: Store validation errors in <outputfile>" );
+ System.out.println( "-r: Process directory recursivly" );
+ System.out.println( "-s: Validate against strict schema" );
+ System.out.println( "-v: Verbose output, including generator and warnings" );
+ System.out.println( "-w: Print warnings" );
+ System.out.println( "-x: Exclude paths that match <regexp>" );
+ System.out.println();
+ System.out.println( "If no option is provided, <odffiles> are validated using <schemafile>" );
+ }
+
+}
Added: incubator/odf/trunk/validator/src/odfvalidator/ManifestEntry.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/odfvalidator/ManifestEntry.java?rev=1172430&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/odfvalidator/ManifestEntry.java (added)
+++ incubator/odf/trunk/validator/src/odfvalidator/ManifestEntry.java Mon Sep 19 05:30:38 2011
@@ -0,0 +1,35 @@
+/************************************************************************
+ *
+ * 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 odfvalidator;
+
+class ManifestEntry
+{
+ String m_aFullPath;
+ String m_aMediaType;
+
+ ManifestEntry(String aFullPath, String aMediaType)
+ {
+ m_aFullPath = aFullPath;
+ m_aMediaType = aMediaType;
+ }
+}
\ No newline at end of file
Added: incubator/odf/trunk/validator/src/odfvalidator/ManifestFilter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/odfvalidator/ManifestFilter.java?rev=1172430&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/odfvalidator/ManifestFilter.java (added)
+++ incubator/odf/trunk/validator/src/odfvalidator/ManifestFilter.java Mon Sep 19 05:30:38 2011
@@ -0,0 +1,128 @@
+/************************************************************************
+ *
+ * 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 odfvalidator;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Vector;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+
+class ManifestFilter extends NamespaceFilter {
+
+ private static final String OOO_MANIFEST_PUBLIC_ID = "-//OpenOffice.org//DTD Manifest 1.0//EN";
+ private static final String OOO_MANIFEST_NAMESPACE_URI = "http://openoffice.org/2001/manifest";
+ private static final String MANIFEST_NAMESPACE_URI = "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0";
+
+ private static final String FILE_ENTRY = "file-entry";
+ private static final String FULL_PATH = "full-path";
+ private static final String MEDIA_TYPE = "media-type";
+
+ private Logger m_aLogger;
+
+ private String m_aMediaType = "";
+ private Vector<ManifestEntry> m_aSubDocs = new Vector<ManifestEntry>();
+
+ /** Creates a new instance of KnownIssueFilter */
+ ManifestFilter( Logger aLogger ) {
+ m_aLogger = aLogger;
+ }
+
+ @Override
+ public InputSource resolveEntity(String aPublicId, String aSystemId) throws SAXException, IOException {
+ // Ignore the external OOo Manifest DTD which was errornously included
+ // in early OpenDocument files.
+
+ if( aPublicId.equals(OOO_MANIFEST_PUBLIC_ID) )
+ {
+ String aMsg = "Ignoring doctype definition '" + OOO_MANIFEST_PUBLIC_ID + "' (has been stored by old OOo versions)";
+ m_aLogger.logInfo( aMsg , false);
+ return new InputSource(new StringReader(""));
+ }
+ else
+ return super.resolveEntity( aPublicId, aSystemId );
+ }
+
+ String adaptNamespaceUri( String aUri, String aPrefix)
+ {
+ String aNewUri = null;
+ if( aUri.equals(OOO_MANIFEST_NAMESPACE_URI) )
+ aNewUri = MANIFEST_NAMESPACE_URI;
+
+ return aNewUri;
+ }
+
+ void namespaceUriAdapted( String aUri, String aNewUri )
+ {
+ String aMsg = "Adapting OpenOffice.org namspace'" + aUri + "' (has been stored by old OOo versions)";
+ m_aLogger.logInfo( aMsg , false);
+ }
+
+ @Override
+ public void startElement(String aUri, String aLocalName, String aQName, Attributes aAtts) throws SAXException {
+ super.startElement(aUri, aLocalName, aQName, aAtts);
+ if( (aUri.equals(MANIFEST_NAMESPACE_URI) || aUri.equals(OOO_MANIFEST_NAMESPACE_URI)) && aLocalName.equals(FILE_ENTRY))
+ {
+ String aMediaType = aAtts.getValue(aUri,MEDIA_TYPE);
+ if( aMediaType != null && isOpenDocumentMediaType(aMediaType))
+ {
+ String aFullPath = aAtts.getValue(aUri,FULL_PATH);
+ if( aFullPath != null )
+ {
+ if( aFullPath.equals("/") )
+ m_aMediaType = aMediaType;
+ else
+ m_aSubDocs.add( new ManifestEntry(aFullPath,aMediaType));
+ }
+ }
+ }
+ }
+
+ private boolean isOpenDocumentMediaType( String aMediaType )
+ {
+ if( aMediaType.length() >14 && aMediaType.substring(12,14).equals("x-") )
+ {
+ String aNewMediaType = aMediaType.substring(0,12) + aMediaType.substring(14);
+ aMediaType = aNewMediaType;
+ }
+
+ return aMediaType.equals(ODFMediaTypes.TEXT_MEDIA_TYPE) ||
+ aMediaType.equals(ODFMediaTypes.GRAPHICS_MEDIA_TYPE) ||
+ aMediaType.equals(ODFMediaTypes.SPREADSHEET_MEDIA_TYPE) ||
+ aMediaType.equals(ODFMediaTypes.PRESENTATION_MEDIA_TYPE) ||
+ aMediaType.equals(ODFMediaTypes.FORMULA_MEDIA_TYPE) ||
+ aMediaType.equals(ODFMediaTypes.CHART_MEDIA_TYPE);
+ }
+
+ String getMediaType()
+ {
+ return m_aMediaType;
+ }
+
+ Vector<ManifestEntry> getSubDocuments()
+ {
+ return m_aSubDocs;
+ }
+}
Added: incubator/odf/trunk/validator/src/odfvalidator/MathML101Filter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/odfvalidator/MathML101Filter.java?rev=1172430&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/odfvalidator/MathML101Filter.java (added)
+++ incubator/odf/trunk/validator/src/odfvalidator/MathML101Filter.java Mon Sep 19 05:30:38 2011
@@ -0,0 +1,98 @@
+/************************************************************************
+ *
+ * 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 odfvalidator;
+
+import java.io.IOException;
+import java.io.InputStream;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.XMLFilterImpl;
+
+/**
+ *
+ */
+class MathML101Filter extends XMLFilterImpl {
+//class MathML101Filter implements EntityResolver {
+
+ private String m_aMathMLDTD;
+ private static final String MATHML_NAMESPACE_URI = "http://www.w3.org/1998/Math/MathML";
+ private static final String MATHML_PUBLIC_ID = "-//W3C//DTD MathML 1.01//EN";
+ private static final String OOO_MATHML_PUBLIC_ID = "-//OpenOffice.org//DTD Modified W3C MathML 1.01//EN";
+
+ private Logger m_aLogger;
+
+ /** Creates a new instance of MathML101Filter */
+ MathML101Filter( String aMathMLDTD, Logger aLogger ) {
+ m_aMathMLDTD = aMathMLDTD;
+ m_aLogger = aLogger;
+ }
+
+
+ public void startElement(String aUri, String aLocalName, String aQName, Attributes aAtts) throws SAXException {
+ super.startElement(aUri, aLocalName, aQName, aAtts);
+ }
+
+ public void endElement(String aUri, String aLocalName, String aQName) throws SAXException {
+ super.endElement(aUri, aLocalName, aQName);
+ }
+
+ public InputSource resolveEntity(String aPublicId, String aSystemId) throws SAXException, IOException {
+ InputSource aRet = null;
+ String aEntity = null;
+
+ if( aPublicId != null &&
+ (aPublicId.equals(MATHML_PUBLIC_ID) ||
+ aPublicId.equals(OOO_MATHML_PUBLIC_ID)) )
+ {
+ aEntity = m_aMathMLDTD;
+ if( InternalResources.isInternalResourceIdentifer(aEntity) )
+ {
+ String aPath = InternalResources.getResourcePath(aEntity);
+ InputStream aInStream = getClass().getResourceAsStream(aPath);
+ if( aInStream == null )
+ {
+ m_aLogger.logFatalError("Missing internal schema file: ".concat(aPath));
+ }
+ else
+ {
+ aRet = new InputSource( aInStream );
+ aRet.setPublicId(aPublicId);
+ aRet.setSystemId(aEntity);
+ }
+ }
+ }
+ else
+ {
+ aEntity = aSystemId;
+ }
+
+ String aMsg = "Reading doctype definition '" + aEntity + "'";
+ m_aLogger.logInfo( aMsg , false);
+
+ if( aRet == null )
+ aRet = new InputSource( aEntity );
+ return aRet;
+ }
+
+}
Added: incubator/odf/trunk/validator/src/odfvalidator/MathML20Filter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/odfvalidator/MathML20Filter.java?rev=1172430&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/odfvalidator/MathML20Filter.java (added)
+++ incubator/odf/trunk/validator/src/odfvalidator/MathML20Filter.java Mon Sep 19 05:30:38 2011
@@ -0,0 +1,51 @@
+/************************************************************************
+ *
+ * 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 odfvalidator;
+
+import java.io.IOException;
+import java.io.StringReader;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.XMLFilterImpl;
+
+/**
+ *
+ */
+class MathML20Filter extends XMLFilterImpl {
+
+ private Logger m_aLogger;
+
+ /** Creates a new instance of MathMLFilter */
+ MathML20Filter( Logger aLogger) {
+ m_aLogger = aLogger;
+ }
+
+ public InputSource resolveEntity(String aPublicId, String aSystemId) throws SAXException, IOException {
+ // Ignore the external OOo MathML DTD
+
+ String aMsg = "Ignoring doctype definition '" + aPublicId + "'";
+ m_aLogger.logInfo( aMsg , false);
+ return new InputSource(new StringReader(""));
+ }
+
+}
Added: incubator/odf/trunk/validator/src/odfvalidator/MetaFilter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/odfvalidator/MetaFilter.java?rev=1172430&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/odfvalidator/MetaFilter.java (added)
+++ incubator/odf/trunk/validator/src/odfvalidator/MetaFilter.java Mon Sep 19 05:30:38 2011
@@ -0,0 +1,77 @@
+/************************************************************************
+ *
+ * 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 odfvalidator;
+
+import org.openoffice.odf.dom.OdfNamespace;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.XMLFilterImpl;
+
+class MetaFilter extends XMLFilterImpl {
+
+ private boolean m_bInGenerator = false;
+ private String m_aGenerator = "";
+
+ private static final String META_NAMESPACE_URI = OdfNamespace.META.toString();
+ private static final String GENERATOR = "generator";
+
+ private Logger m_aLogger;
+ private MetaInformationListener m_aMetaListener;
+
+
+ /** Creates a new instance of MetaFilter */
+ MetaFilter( Logger aLogger, MetaInformationListener aMetaListener ) {
+ m_aLogger = aLogger;
+ m_aMetaListener = aMetaListener;
+ }
+
+ public void characters(char[] aChars, int nStart, int nLength) throws SAXException {
+ super.characters(aChars, nStart, nLength);
+
+ if( m_bInGenerator )
+ {
+ m_aGenerator += new String( aChars, nStart, nLength );
+ }
+ }
+
+ public void endElement(String aUri, String aLocalName, String aQName) throws SAXException {
+ super.endElement(aUri, aLocalName, aQName);
+
+ if( aUri.equals(META_NAMESPACE_URI) && aLocalName.equals(GENERATOR) )
+ {
+ m_aGenerator = m_aGenerator.trim();
+ m_aLogger.logInfo( "Generator: " + m_aGenerator , false);
+ m_bInGenerator = false;
+ if( m_aMetaListener!=null ) {
+ m_aMetaListener.setGenerator( m_aGenerator );
+ }
+ }
+ }
+
+ public void startElement(String aUri, String aLocalName, String aQName, Attributes aAttributes) throws SAXException {
+ super.startElement(aUri, aLocalName, aQName, aAttributes);
+
+ if( aUri.equals(META_NAMESPACE_URI) && aLocalName.equals(GENERATOR) )
+ m_bInGenerator = true;
+ }
+}
Added: incubator/odf/trunk/validator/src/odfvalidator/MetaInformation.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/odfvalidator/MetaInformation.java?rev=1172430&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/odfvalidator/MetaInformation.java (added)
+++ incubator/odf/trunk/validator/src/odfvalidator/MetaInformation.java Mon Sep 19 05:30:38 2011
@@ -0,0 +1,100 @@
+/************************************************************************
+ *
+ * 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 odfvalidator;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLFilter;
+
+import org.openoffice.odf.pkg.OdfPackage;
+
+public class MetaInformation {
+
+ private PrintStream m_aOut;
+
+ /** Creates a new instance of Validator */
+ public MetaInformation( PrintStream aOut ) {
+
+ m_aOut = aOut;
+ }
+
+ public void getInformation( String aDocFileName ) throws ODFValidatorException
+ {
+ try
+ {
+ OdfPackage aDocFile = OdfPackage.loadPackage( aDocFileName );
+
+ getGenerator( aDocFile );
+ }
+ catch( Exception e )
+ {
+ throw new ODFValidatorException( aDocFileName, "", e );
+ }
+ }
+
+ public void getGenerator( OdfPackage aDocFile ) throws ODFValidatorException
+ {
+ try
+ {
+ InputStream aInStream = aDocFile.getInputStream(OdfPackage.OdfFile.MANIFEST.getPath());
+ Logger aLogger = new Logger(aDocFile.getBaseURI(),OdfPackage.OdfFile.MANIFEST.getPath(),m_aOut, Logger.INFO);
+
+ getInformation( aInStream, aLogger );
+ }
+ catch( Exception e )
+ {
+ throw new ODFValidatorException( aDocFile.getBaseURI(), "", e );
+ }
+ }
+
+
+
+ private void getInformation( InputStream aInStream, Logger aLogger ) throws IOException, ODFValidatorException
+ {
+ SAXParser aParser = null;
+ try
+ {
+ SAXParserFactory aParserFactory = SAXParserFactory.newInstance();
+ aParserFactory.setNamespaceAware(true);
+ aParser = aParserFactory.newSAXParser();
+
+ XMLFilter aFilter = new MetaFilter(aLogger,null);
+ aFilter.setParent( aParser.getXMLReader() ) ;
+
+ aFilter.parse(new InputSource(aInStream));
+ }
+ catch( javax.xml.parsers.ParserConfigurationException e )
+ {
+ throw new ODFValidatorException( e );
+ }
+ catch( org.xml.sax.SAXException e )
+ {
+ throw new ODFValidatorException( e );
+ }
+ }
+
+}
Added: incubator/odf/trunk/validator/src/odfvalidator/MetaInformationListener.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/odfvalidator/MetaInformationListener.java?rev=1172430&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/odfvalidator/MetaInformationListener.java (added)
+++ incubator/odf/trunk/validator/src/odfvalidator/MetaInformationListener.java Mon Sep 19 05:30:38 2011
@@ -0,0 +1,29 @@
+/************************************************************************
+ *
+ * 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 odfvalidator;
+
+interface MetaInformationListener {
+
+ void setGenerator( String aGenerator );
+
+}
Added: incubator/odf/trunk/validator/src/odfvalidator/NamespaceFilter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/odfvalidator/NamespaceFilter.java?rev=1172430&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/odfvalidator/NamespaceFilter.java (added)
+++ incubator/odf/trunk/validator/src/odfvalidator/NamespaceFilter.java Mon Sep 19 05:30:38 2011
@@ -0,0 +1,94 @@
+/************************************************************************
+ *
+ * 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 odfvalidator;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+import org.xml.sax.helpers.XMLFilterImpl;
+
+abstract class NamespaceFilter extends XMLFilterImpl {
+
+ private boolean m_bFilterNamespaceUri = false;
+
+ /** Creates a new instance of NamespaceFilter */
+ NamespaceFilter() {
+ }
+
+ abstract String adaptNamespaceUri(String aUri, String aPrefix);
+ abstract void namespaceUriAdapted(String aUri, String aNewUri);
+
+
+ public void endElement(String aUri, String aLocalName, String aQName) throws SAXException {
+ if (m_bFilterNamespaceUri)
+ {
+ String aNewUri = adaptNamespaceUri( aUri , aQName );
+
+ if( aNewUri != null )
+ aUri = aNewUri;
+ }
+
+ super.endElement(aUri, aLocalName, aQName);
+ }
+
+
+ public void startElement(String aUri, String aLocalName, String aQName, Attributes aAtts) throws SAXException {
+ if (m_bFilterNamespaceUri)
+ {
+ String aNewUri = adaptNamespaceUri( aUri , aQName);
+
+ if( aNewUri != null )
+ aUri = aNewUri;
+
+ Attributes aOldAtts = aAtts;
+ AttributesImpl aNewAtts = null;
+ for (int i = 0; i < aOldAtts.getLength(); ++i)
+ {
+ aNewUri = adaptNamespaceUri( aOldAtts.getURI(i) , aQName);
+ if (aNewUri != null)
+ {
+ if (aNewAtts == null)
+ {
+ aNewAtts = new AttributesImpl(aOldAtts);
+ aAtts = aNewAtts;
+ }
+ aNewAtts.setURI(i,aNewUri);
+ }
+ }
+ }
+ super.startElement(aUri, aLocalName, aQName, aAtts);
+ }
+
+
+
+ public void startPrefixMapping(String aPrefix, String aUri) throws SAXException {
+ String aNewUri = adaptNamespaceUri( aUri, aPrefix);
+ if (aNewUri != null)
+ {
+ m_bFilterNamespaceUri = true;
+ namespaceUriAdapted( aUri, aNewUri );
+ }
+ super.startPrefixMapping(aPrefix, aUri);
+ }
+
+}
Added: incubator/odf/trunk/validator/src/odfvalidator/ODFFileFilter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/odfvalidator/ODFFileFilter.java?rev=1172430&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/odfvalidator/ODFFileFilter.java (added)
+++ incubator/odf/trunk/validator/src/odfvalidator/ODFFileFilter.java Mon Sep 19 05:30:38 2011
@@ -0,0 +1,87 @@
+/************************************************************************
+ *
+ * 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 odfvalidator;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.regex.Pattern;
+
+
+public class ODFFileFilter implements FileFilter
+{
+ private boolean m_bRecursive;
+ private Pattern m_aExcludePattern = null;
+
+ public ODFFileFilter( boolean bRecursive )
+ {
+ m_bRecursive = bRecursive;
+ }
+
+ public ODFFileFilter( String aExcludeRegExp, boolean bRecursive )
+ {
+ m_bRecursive = bRecursive;
+ if( aExcludeRegExp != null )
+ m_aExcludePattern = Pattern.compile(aExcludeRegExp);
+ }
+
+
+ public boolean accept(File aFile) {
+ return !exclude( aFile ) && (aFile.isDirectory() ? m_bRecursive : hasODFExtension( aFile ));
+ }
+
+ private boolean exclude(File aFile)
+ {
+ boolean bExclude = false;
+ if( m_aExcludePattern != null )
+ bExclude = m_aExcludePattern.matcher(aFile.getAbsolutePath()).matches();
+ return bExclude;
+ }
+
+ private boolean hasODFExtension(File aFile)
+ {
+ String aName = aFile.getName();
+ int nIndex = aName.lastIndexOf('.');
+ if (nIndex != -1 && aName.length() > nIndex+1)
+ {
+ String aExt = aName.substring(nIndex+1);
+ if( aExt.length() == 3 )
+ {
+ return aExt.equalsIgnoreCase("odt") ||
+ aExt.equalsIgnoreCase("ods") ||
+ aExt.equalsIgnoreCase("odg") ||
+ aExt.equalsIgnoreCase("odp") ||
+ aExt.equalsIgnoreCase("odf") ||
+ aExt.equalsIgnoreCase("odc") ||
+ aExt.equalsIgnoreCase("odb") ||
+ aExt.equalsIgnoreCase("ott") ||
+ aExt.equalsIgnoreCase("ots") ||
+ aExt.equalsIgnoreCase("otg") ||
+ aExt.equalsIgnoreCase("otp") ||
+ aExt.equalsIgnoreCase("otf") ||
+ aExt.equalsIgnoreCase("otc");
+ }
+ }
+
+ return false;
+ }
+}
Added: incubator/odf/trunk/validator/src/odfvalidator/ODFFileValidator.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/odfvalidator/ODFFileValidator.java?rev=1172430&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/odfvalidator/ODFFileValidator.java (added)
+++ incubator/odf/trunk/validator/src/odfvalidator/ODFFileValidator.java Mon Sep 19 05:30:38 2011
@@ -0,0 +1,56 @@
+/************************************************************************
+ *
+ * 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 odfvalidator;
+
+import java.io.File;
+
+import org.openoffice.odf.pkg.OdfPackage;
+
+/**
+ * Validator for Files
+ */
+public class ODFFileValidator extends ODFRootPackageValidator {
+
+ private File m_aFile = null;
+
+ /** Creates a new instance of ODFFileValidator */
+ public ODFFileValidator( File aFile, int nLogLevel,
+ int nMode,
+ SAXParseExceptionFilter aFilter,
+ ODFValidatorProvider aValidatorProvider ) throws ODFValidatorException
+ {
+ super( nLogLevel, nMode, aFilter, aValidatorProvider );
+ m_aFile = aFile;
+ }
+
+ protected String getLoggerName()
+ {
+ return m_aFile.getAbsolutePath();
+ }
+
+ protected OdfPackage getPackage() throws Exception
+ {
+ return OdfPackage.loadPackage( m_aFile );
+ }
+
+}
Added: incubator/odf/trunk/validator/src/odfvalidator/ODFMediaTypes.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/odfvalidator/ODFMediaTypes.java?rev=1172430&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/odfvalidator/ODFMediaTypes.java (added)
+++ incubator/odf/trunk/validator/src/odfvalidator/ODFMediaTypes.java Mon Sep 19 05:30:38 2011
@@ -0,0 +1,50 @@
+/************************************************************************
+ *
+ * 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 odfvalidator;
+
+/**
+ * abstract Base class for OpenDocument filetype classes
+ */
+public abstract class ODFMediaTypes {
+
+ public static final String TEXT_MEDIA_TYPE = "application/vnd.oasis.opendocument.text";
+ public static final String TEXT_TEMPLATE_MEDIA_TYPE = "application/vnd.oasis.opendocument.text-template";
+ public static final String GRAPHICS_MEDIA_TYPE = "application/vnd.oasis.opendocument.graphics";
+ public static final String GRAPHICS_TEMPLATE_MEDIA_TYPE = "application/vnd.oasis.opendocument.graphics-template";
+ public static final String PRESENTATION_MEDIA_TYPE = "application/vnd.oasis.opendocument.presentation";
+ public static final String PRESENTATION_TEMPLATE_MEDIA_TYPE = "application/vnd.oasis.opendocument.presentation-template";
+ public static final String SPREADSHEET_MEDIA_TYPE = "application/vnd.oasis.opendocument.spreadsheet";
+ public static final String SPREADSHEET_TEMPLATE_MEDIA_TYPE = "application/vnd.oasis.opendocument.spreadsheet-template";
+ public static final String CHART_MEDIA_TYPE = "application/vnd.oasis.opendocument.chart";
+ public static final String CHART_TEMPLATE_MEDIA_TYPE = "application/vnd.oasis.opendocument.chart-template";
+ public static final String IMAGE_MEDIA_TYPE = "application/vnd.oasis.opendocument.image";
+ public static final String IMAGE_TEMPLATE_MEDIA_TYPE = "application/vnd.oasis.opendocument.image-template";
+ public static final String FORMULA_MEDIA_TYPE = "application/vnd.oasis.opendocument.formula";
+ public static final String FORMULA_TEMPLATE_MEDIA_TYPE = "application/vnd.oasis.opendocument.formula-template";
+ public static final String TEXT_MASTER_MEDIA_TYPE = "application/vnd.oasis.opendocument.text-master";
+ public static final String TEXT_WEB_MEDIA_TYPE = "application/vnd.oasis.opendocument.text-web";
+
+
+}
+
+
Added: incubator/odf/trunk/validator/src/odfvalidator/ODFPackageValidator.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/odfvalidator/ODFPackageValidator.java?rev=1172430&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/odfvalidator/ODFPackageValidator.java (added)
+++ incubator/odf/trunk/validator/src/odfvalidator/ODFPackageValidator.java Mon Sep 19 05:30:38 2011
@@ -0,0 +1,543 @@
+/************************************************************************
+ *
+ * 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 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.openoffice.odf.doc.OdfDocument;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLFilter;
+import org.xml.sax.XMLReader;
+
+import org.openoffice.odf.pkg.OdfPackage;
+import org.openoffice.odf.pkg.manifest.EncryptionData;
+import org.openoffice.odf.pkg.manifest.OdfFileEntry;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * Validator for Files
+ */
+public abstract class ODFPackageValidator implements MetaInformationListener {
+
+ static final int CHECK_CONFORMANCE = 0;
+ static final int VALIDATE = 1;
+ static final int VALIDATE_STRICT = 2;
+
+ 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_aVersion = "";
+ private Vector<ManifestEntry> m_aSubDocs;
+
+ private SAXParserFactory m_aSAXParserFactory = null;
+
+
+ ODFPackageValidator( int nLogLevel, int nMode, String aMediaType,
+ SAXParseExceptionFilter aFilter,ODFValidatorProvider aValidatorProvider) {
+ m_nLogLevel = nLogLevel;
+ m_nMode = nMode;
+ m_aFilter = aFilter;
+ m_aValidatorProvider = aValidatorProvider;
+ m_aMediaType = aMediaType;
+ }
+
+
+
+ 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
+ {
+ m_aVersion = getVersion( aLogger );
+ if( m_aVersion != null )
+ aLogger.logInfo( "ODF Version: " + m_aVersion, false );
+
+ bHasErrors |= validateMeta(aOut, getStreamName( OdfDocument.OdfXMLFile.META.getFileName()), true );
+ if( bRoot )
+ bHasErrors |= validateManifest(aOut );
+ aLogger.logInfo( "Media Type: " + m_aMediaType , false);
+ bHasErrors |= validateEntry(aOut, getStreamName(OdfDocument.OdfXMLFile.SETTINGS.getFileName() ));
+ bHasErrors |= validateEntry(aOut, getStreamName( OdfDocument.OdfXMLFile.STYLES.getFileName() ));
+ if( m_aMediaType.equals(ODFMediaTypes.FORMULA_MEDIA_TYPE))
+ bHasErrors |= validateMathML(aOut, getStreamName( OdfDocument.OdfXMLFile.CONTENT.getFileName() ) );
+ else
+ bHasErrors |= validateEntry(aOut, getStreamName( OdfDocument.OdfXMLFile.CONTENT.getFileName() ) );
+
+ 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_aFilter, m_aGenerator, m_aValidatorProvider );
+ bHasErrors |= aPackageValidator.validate(aOut);
+ }
+ }
+
+ bHasErrors |= validateDSig( aOut, OdfPackageExt.STREAMNAME_DOCUMENT_SIGNATURES );
+ bHasErrors |= validateDSig( aOut, OdfPackageExt.STREAMNAME_MACRO_SIGNATURES );
+ }
+
+ }
+ 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 ) throws IOException, ZipException, IllegalStateException, ODFValidatorException
+ {
+ Logger aLogger = new Logger(getLoggerName(),aEntryName,aOut, m_nLogLevel);
+ XMLFilter aFilter = new ContentFilter(aLogger);
+ if( m_nMode == CHECK_CONFORMANCE )
+ {
+ XMLFilter aAlienFilter = new AlienFilter(aLogger);
+ aAlienFilter.setParent(aFilter);
+ aFilter = aAlienFilter;
+ }
+ Validator aValidator = m_nMode == VALIDATE_STRICT ? m_aValidatorProvider.getStrictValidator(aOut,m_aVersion)
+ : m_aValidatorProvider.getValidator(aOut,m_aVersion);
+ return validateEntry(aOut, aFilter, aValidator, aLogger, aEntryName );
+ }
+
+ private boolean validateMeta(PrintStream aOut, String aEntryName , 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 )
+ {
+ XMLFilter aAlienFilter = new AlienFilter(aLogger);
+ aAlienFilter.setParent(aFilter);
+ aFilter = aAlienFilter;
+ }
+
+ Validator aValidator = m_nMode == VALIDATE_STRICT ? m_aValidatorProvider.getStrictValidator(aOut,m_aVersion)
+ : m_aValidatorProvider.getValidator(aOut,m_aVersion);
+ return validateEntry(aOut, aFilter, aValidator, aLogger, aEntryName );
+ }
+
+ private boolean validateMathML(PrintStream aOut, String aEntryName ) throws IOException, ZipException, IllegalStateException, ODFValidatorException
+ {
+ Logger aLogger = new Logger(getLoggerName(),aEntryName,aOut, m_nLogLevel);
+ String aMathMLDTDSystemId = m_aValidatorProvider.getMathMLDTDSystemId(m_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 ) 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,m_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 ) throws IOException, ZipException, IllegalStateException, ODFValidatorException
+ {
+ Validator aValidator=m_aValidatorProvider.getDSigValidator(aOut,m_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/odfvalidator/ODFRootPackageValidator.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/odfvalidator/ODFRootPackageValidator.java?rev=1172430&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/odfvalidator/ODFRootPackageValidator.java (added)
+++ incubator/odf/trunk/validator/src/odfvalidator/ODFRootPackageValidator.java Mon Sep 19 05:30:38 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 odfvalidator;
+
+import java.io.IOException;
+import org.openoffice.odf.pkg.OdfPackage;
+
+public abstract class ODFRootPackageValidator extends ODFPackageValidator {
+
+ private OdfPackage m_aPkg = null;
+
+ ODFRootPackageValidator(int nLogLevel, int nMode, SAXParseExceptionFilter aFilter, ODFValidatorProvider aValidatorProvider) {
+ super(nLogLevel, nMode, 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/odfvalidator/ODFStreamValidator.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/odfvalidator/ODFStreamValidator.java?rev=1172430&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/odfvalidator/ODFStreamValidator.java (added)
+++ incubator/odf/trunk/validator/src/odfvalidator/ODFStreamValidator.java Mon Sep 19 05:30:38 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 odfvalidator;
+
+import java.io.InputStream;
+
+import org.openoffice.odf.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,
+ SAXParseExceptionFilter aFilter,
+ ODFValidatorProvider aValidatorProvider )
+
+ throws ODFValidatorException {
+ super(nLogLevel, nMode, 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/odfvalidator/ODFSubPackageValidator.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/odfvalidator/ODFSubPackageValidator.java?rev=1172430&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/odfvalidator/ODFSubPackageValidator.java (added)
+++ incubator/odf/trunk/validator/src/odfvalidator/ODFSubPackageValidator.java Mon Sep 19 05:30:38 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 odfvalidator;
+
+import org.openoffice.odf.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,
+ SAXParseExceptionFilter aFilter, String aParentGenerator,
+ ODFValidatorProvider aValidatorProvider ) throws ODFValidatorException
+ {
+ super( nLogLevel, nMode, 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;
+ }
+
+};
|