incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From devin...@apache.org
Subject svn commit: r1172466 [3/16] - in /incubator/odf/trunk/validator: ./ misc/ nbproject/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/odftoolkit/ src/main/java/org/odftoolkit/odfvalidator/ src/main/resources/ src/main/resources/META-INF/ s...
Date Mon, 19 Sep 2011 05:43:28 GMT
Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFSubPackageValidator.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFSubPackageValidator.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFSubPackageValidator.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFSubPackageValidator.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,69 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import org.odftoolkit.odfdom.pkg.OdfPackage;
+
+
+class ODFSubPackageValidator extends ODFPackageValidator {
+
+    private OdfPackage m_aPkg = null;
+    // this is the URI of the root package, not this subpackage!
+    private String m_aBaseURI = null;
+    private String m_aSubEntryName = null;
+
+    ODFSubPackageValidator( OdfPackage aPkg, String aBaseURI, String aSubEntryName, String aMediaType,
+                             Logger.LogLevel nLogLevel, OdfValidatorMode eMode, OdfVersion aVersion,
+                             SAXParseExceptionFilter aFilter, String aParentGenerator,
+                             ODFValidatorProvider aValidatorProvider ) throws ODFValidatorException
+    {
+        super( nLogLevel, eMode, aVersion, aFilter, aValidatorProvider);
+        m_aPkg = aPkg;
+        m_aBaseURI = aBaseURI;
+        m_aSubEntryName = aSubEntryName;
+        m_aResult.setMediaType(aMediaType);
+        if( aFilter != null )
+            aFilter.startPackage(aParentGenerator);  // take build id from main document as default (embedded objects can nevern be newer)
+    }
+
+    @Override
+    protected String getLoggerName() {
+        return m_aBaseURI;
+    }
+
+    @Override
+    protected String getDocumentPath() {
+        return m_aSubEntryName;
+    }
+
+    protected OdfPackage getPackage( Logger aLogger ) 
+    {
+        return m_aPkg;
+    }
+
+    protected String getStreamName( String aEntry )
+    {
+        return m_aSubEntryName + aEntry;
+    }
+    
+};

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFValidationResult.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFValidationResult.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFValidationResult.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFValidationResult.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,135 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ *
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.xml.sax.Attributes;
+
+public class ODFValidationResult implements ManifestListener, MetaInformationListener, ForeignContentListener
+{
+    public enum Status
+    {
+        /**
+         * The document is non conforming to a particular conformance level.
+         */
+        NON_CONFORMING,
+        /**
+         * The document is conforming to a particular conformance level.
+         */
+        CONFORMING,
+        /**
+         * It is unknown whether the document conforms to a particular level.
+         */
+        UNKNOWN,
+        /**
+         * The conformance level is not applicable to the specified file.
+         */
+        NOT_APPLICABLE
+    }
+
+    private String m_aGenerator = null;
+    private String m_aMediaType = "";
+
+    private HashMap<String,Long> m_aForeignElementMap = null;
+    private HashMap<String,Long> m_aForeignAttributeMap = null;
+
+    private Status m_aStrictValid = Status.UNKNOWN;
+    private Status m_aValid = Status.UNKNOWN;
+    private Status m_aConforming = Status.UNKNOWN;
+    private Status m_aExtendedConforming = Status.UNKNOWN;
+
+    private OdfVersion m_aVersion = null;
+    private OdfValidatorMode m_eMode = null;
+
+    ODFValidationResult( OdfVersion aVersion, OdfValidatorMode eMode )
+    {
+        m_aVersion = aVersion;
+        m_eMode = eMode;
+    }
+
+
+    public void setGenerator(String aGenerator)
+    {
+        m_aGenerator = aGenerator;
+    }
+
+    public void setMediaType(String aMediaType)
+    {
+        m_aMediaType = aMediaType;
+    }
+
+    public void foreignElementDetected(String aUri, String aLocalName, String aQName, Attributes aAtts)
+    {
+        if( m_aForeignElementMap == null )
+            m_aForeignElementMap = new HashMap<String,Long>();
+
+        Long aCount = m_aForeignElementMap.get(aUri);
+        if( aCount == null )
+            aCount = Long.valueOf(0);
+        m_aForeignElementMap.put(aUri, aCount+1);
+    }
+
+    public void foreignAttributeDetected(String aUri, String aLocalName, String aQName, String aValue)
+    {
+        if( m_aForeignAttributeMap == null )
+            m_aForeignAttributeMap = new HashMap<String,Long>();
+
+        Long aCount = m_aForeignAttributeMap.get(aUri);
+        if( aCount == null )
+            aCount = Long.valueOf(0);
+        m_aForeignAttributeMap.put(aUri, aCount+1);
+    }
+
+
+    public String getGenerator()
+    {
+        return m_aGenerator;
+    }
+
+    public String getMediaType()
+    {
+        return m_aMediaType;
+    }
+
+    public boolean hasForeignElements()
+    {
+        return m_aForeignElementMap != null;
+    }
+
+    public Map<String,Long> getForeignElements()
+    {
+        return m_aForeignElementMap;
+    }
+
+    public boolean hasForeignAttributes()
+    {
+        return m_aForeignAttributeMap != null;
+    }
+
+    public Map<String,Long> getForeignAttributes()
+    {
+        return m_aForeignAttributeMap;
+    }
+
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFValidator.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFValidator.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFValidator.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFValidator.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,372 @@
+/************************************************************************
+ *
+ * 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 javax.xml.XMLConstants;
+
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Validator;
+
+public class ODFValidator implements ODFValidatorProvider {
+
+	// Prefix used to distinguish internal resources from external ones
+	// Loglevel
+	private Logger.LogLevel m_nLogLevel;
+	// Validator provider
+	private SchemaFactory m_aRNGSchemaFactory = null;
+	private SchemaFactory m_aXSDSchemaFactory = null;
+	// User provided Configuration
+	protected Configuration m_aConfig = null;
+	// User provided ODF version
+	protected OdfVersion m_aVersion = null;
+	protected OdfVersion mOdfPackageVersion = null;
+	// User provided preference for using Math DTD
+	protected boolean m_bUseMathDTD = false;
+	// Validatore and configuration cache
+	private HashMap<String, Schema> m_aSchemaMap = null;
+	private HashMap<OdfVersion, Configuration> m_aConfigurationMap = null;
+	// Generator from last validateFile or validateStream call
+	private String m_aGenerator = "";
+
+	/** Creates a new instance of Validator */
+	public ODFValidator(Configuration aConfig,
+			Logger.LogLevel nLogLevel,
+			OdfVersion aVersion,
+			boolean bUseMathDTD) throws ODFValidatorException {
+
+		m_nLogLevel = nLogLevel;
+		m_aConfig = aConfig;
+		m_aVersion = aVersion;
+		m_bUseMathDTD = bUseMathDTD;
+		Logger.enableHTML(false);
+	}
+
+	/** Creates a new instance of Validator */
+	public ODFValidator(Configuration aConfig,
+			Logger.LogLevel nLogLevel,
+			boolean logAsHTML,
+			OdfVersion aVersion,
+			boolean bUseMathDTD) throws ODFValidatorException {
+
+		m_nLogLevel = nLogLevel;
+		m_aConfig = aConfig;
+		m_aVersion = aVersion;
+		m_bUseMathDTD = bUseMathDTD;
+		Logger.enableHTML(logAsHTML);
+
+	}
+
+	/** Returns either the ODF version request to validate or the ODF version of the root document as fall-back */
+	public String getOdfVersion() {
+		String version = null;
+		if (m_aVersion != null) {
+			version = m_aVersion.toString();
+		} else {
+			version = mOdfPackageVersion.toString();
+		}
+		return version;
+	}
+
+	public boolean validate(PrintStream aOut, Configuration aConfig, OdfValidatorMode eMode) throws ODFValidatorException {
+		List<String> aFileNames = aConfig.getListPropety(Configuration.PATH);
+		String aExcludeRegExp = aConfig.getProperty(Configuration.EXCLUDE);
+		String aRecursive = aConfig.getProperty(Configuration.RECURSIVE);
+		boolean bRecursive = aRecursive != null ? Boolean.valueOf(aRecursive) : false;
+		String aFilterFileName = aConfig.getProperty(Configuration.FILTER);
+
+		return validate(aOut, aFileNames, aExcludeRegExp, eMode, bRecursive, aFilterFileName);
+	}
+
+	public boolean validate(PrintStream aOut, List<String> aFileNames, String aExcludeRegExp,
+			OdfValidatorMode eMode, boolean bRecursive,
+			String aFilterFileName) throws ODFValidatorException {
+		boolean bRet = false;
+
+		SAXParseExceptionFilter aFilter = null;
+		if (aFilterFileName != null && aFilterFileName.length() != 0) {
+			aFilter = new ValidationOOoTaskIdErrorFilter(new File(aFilterFileName), aOut);
+		}
+
+		FileFilter aFileFilter = new ODFFileFilter(aExcludeRegExp, bRecursive);
+
+		Iterator<String> aIter = aFileNames.iterator();
+		while (aIter.hasNext()) {
+			File aFile = new File(aIter.next());
+			bRet |= aFile.isDirectory() ? validateDir(aOut, aFile, aFileFilter, eMode, aFilter)
+					: validateFile(aOut, aFile, eMode, aFilter);
+		}
+
+		return bRet;
+	}
+
+	public boolean validate(PrintStream aOut, InputStream aInputStream, String aBaseURI,
+			OdfValidatorMode eMode,
+			SAXParseExceptionFilter aFilter) throws ODFValidatorException {
+		return validateStream(aOut, aInputStream, aBaseURI, eMode, aFilter);
+	}
+
+	private boolean validateDir(PrintStream aOut, final File aDir, FileFilter aFileFilter, OdfValidatorMode eMode, SAXParseExceptionFilter aFilter) throws ODFValidatorException {
+		boolean bRet = true;
+		File[] aFiles = aDir.listFiles(aFileFilter);
+
+		if (aFiles != null) {
+			for (int i = 0; i < aFiles.length; ++i) {
+				File aFile = aFiles[i];
+				if (aFile.isDirectory()) {
+					bRet |= validateDir(aOut, aFile, aFileFilter, eMode, aFilter);
+				} else {
+					bRet |= validateFile(aOut, aFile, eMode, aFilter);
+				}
+			}
+		}
+		return bRet;
+	}
+
+	/**
+	 * validate the input File
+	 *
+	 * <p>After validation the getGenerator method can be called to get the generator of the validated file</p>
+	 */
+	public boolean validateFile(PrintStream aOut, File aDocFile, OdfValidatorMode eMode, SAXParseExceptionFilter aFilter) throws ODFValidatorException {
+		ODFFileValidator aFileValidator =
+				new ODFFileValidator(aDocFile, m_nLogLevel, eMode, m_aVersion, aFilter, this);
+
+		boolean result = aFileValidator.validate(aOut);
+		mOdfPackageVersion = aFileValidator.mOdfPackageVersion;
+		m_aGenerator = aFileValidator.getGenerator();
+		return result;
+	}
+
+	/**
+	 * validate the input Stream
+	 *
+	 * <p>After validation the getGenerator method can be called to get the generator of the validated file</p>
+	 */
+	public boolean validateStream(PrintStream aOut, InputStream aInputStream, String aBaseURI,
+			OdfValidatorMode eMode,
+			SAXParseExceptionFilter aFilter) throws ODFValidatorException {
+		ODFStreamValidator aStreamValidator =
+				new ODFStreamValidator(aInputStream, aBaseURI, m_nLogLevel, eMode, m_aVersion, aFilter, this);
+		boolean result = aStreamValidator.validate(aOut);
+		m_aGenerator = aStreamValidator.getGenerator();
+		mOdfPackageVersion = aStreamValidator.mOdfPackageVersion;
+		return result;
+	}
+
+	public Validator getManifestValidator(PrintStream aOut, OdfVersion aVersion) throws ODFValidatorException {
+		return getValidatorForSchema(aOut, getSchemaFileName(Configuration.MANIFEST_SCHEMA, aVersion));
+	}
+
+	public Validator getValidator(PrintStream aOut, OdfVersion aVersion) throws ODFValidatorException {
+		return getValidatorForSchema(aOut, getSchemaFileName(Configuration.SCHEMA, aVersion));
+	}
+
+	public Validator getStrictValidator(PrintStream aOut, OdfVersion aVersion) throws ODFValidatorException {
+		return getValidatorForSchema(aOut, getSchemaFileName(Configuration.STRICT_SCHEMA, aVersion));
+	}
+
+	public Validator getMathMLValidator(PrintStream aOut, OdfVersion aVersion) throws ODFValidatorException {
+		return getValidatorForSchema(aOut, getSchemaFileName(Configuration.MATHML2_SCHEMA, aVersion));
+	}
+
+	public String getMathMLDTDSystemId(OdfVersion aVersion) throws ODFValidatorException {
+		String aDTD = null;
+		if (m_bUseMathDTD) {
+			Configuration aConfig =
+					m_aConfig != null ? m_aConfig : getConfiguration(aVersion);
+
+			aDTD = aConfig.getProperty(Configuration.MATHML_SCHEMA);
+			if (m_aConfig == null && aDTD != null && aDTD.length() > 0) {
+				aDTD = InternalResources.createInternalResourceIdentifier(aDTD);
+			}
+		}
+
+		return aDTD;
+	}
+
+	public Validator getDSigValidator(PrintStream aOut, OdfVersion aVersion) throws ODFValidatorException {
+		return getValidatorForSchema(aOut, getSchemaFileName(Configuration.DSIG_SCHEMA, aVersion));
+	}
+
+	public void resetValidatorProvider() {
+		m_aRNGSchemaFactory = null;
+		m_aXSDSchemaFactory = null;
+		m_aSchemaMap = null;
+	}
+
+	private String getSchemaFileName(String aConfigName, OdfVersion aVersion) throws ODFValidatorException {
+		Configuration aConfig =
+				m_aConfig != null ? m_aConfig : getConfiguration(aVersion);
+
+		String aFileName = aConfig.getProperty(aConfigName);
+		if (m_aConfig == null && aFileName != null && aFileName.length() > 0) {
+			aFileName = InternalResources.createInternalResourceIdentifier(aFileName);
+		}
+
+		return aFileName;
+	}
+
+	private Configuration getConfiguration(OdfVersion aVersion) throws ODFValidatorException {
+		if (m_aConfigurationMap == null) {
+			m_aConfigurationMap = new HashMap<OdfVersion, Configuration>();
+		}
+
+		Configuration aConfig = m_aConfigurationMap.get(aVersion);
+		if (aConfig == null) {
+			String aConfigName = null;
+			if (aVersion == null || aVersion == OdfVersion.V1_2) {
+				aConfigName = "/schema/odf1_2.properties";
+			} else if (aVersion == OdfVersion.V1_1) {
+				aConfigName = "/schema/odf1_1.properties";
+			} else if (aVersion == OdfVersion.V1_0) {
+				aConfigName = "/schema/odf1_0.properties";
+			} else {
+				throw new ODFValidatorException("unsupported ODF version: ".concat(aVersion.toString()));
+			}
+
+			InputStream aInStream = getClass().getResourceAsStream(aConfigName);
+			if (aInStream == null) {
+				throw new ODFValidatorException("Internal configuration file is missing: ".concat(aConfigName));
+			}
+
+			aConfig = new Configuration();
+			try {
+				aConfig.loadFromXML(aInStream);
+				aInStream.close();
+			} catch (IOException e) {
+				throw new ODFValidatorException(e);
+			}
+
+			m_aConfigurationMap.put(aVersion, aConfig);
+		}
+
+		return aConfig;
+	}
+
+	private Validator getValidatorForSchema(PrintStream aOut, String aSchemaFileName) throws ODFValidatorException {
+		if (m_aSchemaMap == null) {
+			m_aSchemaMap = new HashMap<String, Schema>();
+		}
+
+		Schema aSchema = m_aSchemaMap.get(aSchemaFileName);
+		if (aSchema == null) {
+			aSchema = createSchema(aOut, aSchemaFileName);
+			m_aSchemaMap.put(aSchemaFileName, aSchema);
+		}
+
+		return aSchema.newValidator();
+	}
+
+	private Schema createSchema(PrintStream aOut, String aSchemaFileName) throws ODFValidatorException {
+		Logger aLogger = new Logger(aSchemaFileName, "", aOut, m_nLogLevel);
+
+		if (aSchemaFileName == null || aSchemaFileName.length() == 0) {
+			return null;
+		}
+
+		String aSchemaLanguage =
+				aSchemaFileName.endsWith("xsd") ? XMLConstants.W3C_XML_SCHEMA_NS_URI
+				: XMLConstants.RELAXNG_NS_URI;
+
+
+		SchemaFactory aSchemaFactory = getSchemaFactory(aSchemaLanguage);
+		SchemaErrorHandler aErrorHandler = new SchemaErrorHandler(aLogger, null);
+		aSchemaFactory.setErrorHandler(aErrorHandler);
+		aSchemaFactory.setResourceResolver(new SchemaResourceResolver(aLogger, aSchemaFileName));
+		Schema aSchema = null;
+
+		StreamSource aSource = null;
+		if (InternalResources.isInternalResourceIdentifer(aSchemaFileName)) {
+			String aPath = InternalResources.getResourcePath(aSchemaFileName);
+			InputStream aInStream = getClass().getResourceAsStream(aPath);
+			if (aInStream == null) {
+				throw new ODFValidatorException("Internal schema file is missing: ".concat(aPath));
+			}
+
+			aSource = new StreamSource(aInStream, aSchemaFileName);
+		} else {
+			File aFile = new File(aSchemaFileName);
+			if (!aFile.exists()) {
+				aLogger.logFatalError(aSchemaFileName + ": file does not exist");
+				return null;
+			}
+			aSource = new StreamSource(aFile);
+		}
+
+		// Workaround: MSV seems not to call error handler
+		try {
+			aSchema = aSchemaFactory.newSchema(aSource);
+		} catch (org.xml.sax.SAXParseException e) {
+			aLogger.logFatalError(e);
+		} catch (org.xml.sax.SAXException e) {
+			aLogger.logFatalError(e.getMessage());
+		}
+
+		if (aLogger.hasError()) {
+			throw new ODFValidatorException(aSchemaFileName, "", "Schema has validation errors.");
+		}
+
+		aLogger.logInfo("parsed.", false);
+		return aSchema;
+	}
+
+	private SchemaFactory getSchemaFactory(String aSchemaLanguage) throws ODFValidatorException {
+		boolean isRNG = aSchemaLanguage.equals(XMLConstants.RELAXNG_NS_URI);
+		SchemaFactory aSchemaFactory = isRNG ? m_aRNGSchemaFactory
+				: m_aXSDSchemaFactory;
+		if (aSchemaFactory == null) {
+			try {
+				if (isRNG) {
+					System.setProperty("javax.xml.validation.SchemaFactory:" + aSchemaLanguage, "org.iso_relax.verifier.jaxp.validation.RELAXNGSchemaFactoryImpl");
+					SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.RELAXNG_NS_URI);
+					m_aRNGSchemaFactory = SchemaFactory.newInstance(aSchemaLanguage);
+					aSchemaFactory = m_aRNGSchemaFactory;
+				} else {
+					System.setProperty("javax.xml.validation.SchemaFactory:" + aSchemaLanguage, "org.apache.xerces.jaxp.validation.XMLSchemaFactory");
+					m_aXSDSchemaFactory = SchemaFactory.newInstance(aSchemaLanguage);
+					aSchemaFactory = m_aXSDSchemaFactory;
+				}
+			} catch (IllegalArgumentException e) {
+				throw new ODFValidatorException(aSchemaLanguage + " support is not installed: " + e.getMessage());
+			}
+		}
+		return aSchemaFactory;
+	}
+
+	/**
+	 * get Generator from last validateFile or validateStream call
+	 */
+	public String getGenerator() {
+		return m_aGenerator;
+	}
+}

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

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFValidatorProvider.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFValidatorProvider.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFValidatorProvider.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFValidatorProvider.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,42 @@
+/************************************************************************
+ *
+ * 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 javax.xml.validation.Validator;
+import java.io.PrintStream;
+
+public interface ODFValidatorProvider {
+    Validator getValidator(PrintStream aOut, OdfVersion aVersion ) throws ODFValidatorException;
+
+    Validator getStrictValidator(PrintStream aOut, OdfVersion aVersion) throws ODFValidatorException;
+    
+    Validator getManifestValidator(PrintStream aOut, OdfVersion aVersion) throws ODFValidatorException;
+
+    Validator getDSigValidator(PrintStream aOut, OdfVersion aVersion) throws ODFValidatorException;
+
+    Validator getMathMLValidator(PrintStream aOut, OdfVersion aVersion) throws ODFValidatorException;
+
+    String getMathMLDTDSystemId( OdfVersion aVersion ) throws ODFValidatorException;
+        
+    void resetValidatorProvider();
+}

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

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

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

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

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

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/SchemaErrorHandler.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/SchemaErrorHandler.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/SchemaErrorHandler.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/SchemaErrorHandler.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,78 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+class SchemaErrorHandler implements org.xml.sax.ErrorHandler {
+    
+    private Logger m_aLogger;
+    private SAXParseExceptionFilter m_aFilter;
+
+    /** Creates a new instance of SchemaErrorHandler */
+    SchemaErrorHandler(Logger aLogger, SAXParseExceptionFilter aFilter ) {
+        m_aLogger = aLogger;
+        m_aFilter = aFilter;
+    }
+    
+    public void warning(SAXParseException e) throws SAXException {
+        if( !filter(e) )
+            m_aLogger.logWarning(  e );
+    }
+
+    public void fatalError(SAXParseException e) throws SAXException {
+        fatalErrorNoException( e );
+    }
+
+    public void error(SAXParseException e) throws SAXException {
+        if( !filter(e) )
+            m_aLogger.logError( e );
+    }
+
+    public void fatalErrorNoException(SAXParseException e) {
+        if( !filter(e) )
+            m_aLogger.logFatalError(  e );
+    }
+    
+    private boolean filter( SAXParseException e )
+    {
+        boolean bFiltered = false;
+        if( m_aFilter != null )
+        {
+            SAXParseException aNewExc = m_aFilter.filterException( e );
+            if( aNewExc == null  )
+            {
+                bFiltered = true;
+            }
+            else if( aNewExc != e )
+            {
+                m_aLogger.logWarning( aNewExc );
+                bFiltered = true;
+            }
+        }
+        
+        return bFiltered;
+    }
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/SchemaFilter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/SchemaFilter.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/SchemaFilter.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/SchemaFilter.java Mon Sep 19 05:43:23 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 org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.XMLFilterImpl;
+
+class SchemaFilter extends XMLFilterImpl {
+    
+    /** Creates a new instance of SchemaFilter */
+    SchemaFilter() {
+    }
+
+    @Override
+    public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
+
+        if( qName.equals("param"))
+        {
+            System.out.println( atts.getValue(uri,"pattern"));
+        }
+        super.startElement(uri, localName, qName, atts);
+    }
+    
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/SchemaResourceResolver.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/SchemaResourceResolver.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/SchemaResourceResolver.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/SchemaResourceResolver.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,194 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import java.io.InputStream;
+import java.io.Reader;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.bootstrap.DOMImplementationRegistry;
+import org.w3c.dom.ls.DOMImplementationLS;
+import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSResourceResolver;
+
+    class SchemaResourceResolver implements LSResourceResolver 
+    {
+        private String m_aBaseURI = null;
+        private Logger m_aLogger = null;
+        private DOMImplementationLS m_aDOMImplLS = null;
+        private boolean m_bGetDOMImplLSFailed = false;
+        
+        class LSInputImpl implements LSInput
+        {
+            private InputStream m_aInputStream = null;
+            private String m_aSystemId = null;
+
+            public Reader getCharacterStream() {
+                return null;
+            }
+
+            public void setCharacterStream(Reader aCharacterStream) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            public InputStream getByteStream() {
+                return m_aInputStream;
+            }
+
+            public void setByteStream(InputStream aByteStream) {
+                m_aInputStream = aByteStream;
+            }
+
+            public String getStringData() {
+                return null;
+            }
+
+            public void setStringData(String stringData) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            public String getSystemId() {
+                return m_aSystemId;
+            }
+
+            public void setSystemId(String aSystemId) {
+                m_aSystemId = aSystemId;
+            }
+
+            public String getPublicId() {
+                return null;
+            }
+
+            public void setPublicId(String publicId) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            public String getBaseURI() {
+                return null;
+            }
+
+            public void setBaseURI(String baseURI) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            public String getEncoding() {
+                return null;
+            }
+
+            public void setEncoding(String encoding) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+            public boolean getCertifiedText() {
+                return false;
+            }
+
+            public void setCertifiedText(boolean certifiedText) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+
+        }
+        
+        public SchemaResourceResolver( Logger aLogger, String aBaseURI )
+        {
+            m_aBaseURI = aBaseURI;
+            m_aLogger = aLogger;
+        }
+    
+        public LSInput resolveResource(String aType, String aNamespaceURI, String aPublicId, String aSystemId, String aBaseURI) 
+        {
+            LSInput aInput = null;
+            
+            if( aBaseURI == null )
+                aBaseURI = m_aBaseURI; 
+
+            if( aSystemId != null && aBaseURI != null && 
+                InternalResources.isInternalResourceIdentifer(aBaseURI) )
+            {
+                String aURI = aBaseURI.substring(0, aBaseURI.lastIndexOf('/')+1).concat(aSystemId);
+                String aPath = InternalResources.getResourcePath(aURI);
+                InputStream aInStream = getClass().getResourceAsStream(aPath);
+                if( aInStream != null )
+                {
+                    aInput = createLSInput();
+                    aInput.setSystemId(aURI);
+                    aInput.setByteStream(aInStream);
+ 
+                    String aMsg = "resolving '" + aURI + "'";
+                    m_aLogger.logInfo( aMsg , false);
+                }
+                else
+                {
+                    m_aLogger.logFatalError("Missing internal schema file: ".concat(aPath));
+                }
+            }
+        
+           return aInput;
+        }
+        
+        private LSInput createLSInput()
+        {
+            LSInput aLSInput = null;
+            
+            if( m_aDOMImplLS == null && !m_bGetDOMImplLSFailed )
+            {
+                DOMImplementationRegistry aDOMReg = null;
+
+                try
+                {        
+                    aDOMReg = DOMImplementationRegistry.newInstance();
+                }
+                catch( ClassNotFoundException e )
+                {
+                    m_aLogger.logFatalError(e.getMessage());
+                }
+                catch( InstantiationException e )
+                {
+                    m_aLogger.logFatalError(e.getMessage());
+                }
+                catch( IllegalAccessException e )
+                {
+                    m_aLogger.logFatalError(e.getMessage());
+                }
+                DOMImplementation aDOMImpl = aDOMReg.getDOMImplementation( "LS 3.0");
+                if( aDOMImpl != null )
+                {
+                    m_aDOMImplLS = (DOMImplementationLS)aDOMImpl;
+                }
+                else
+                {
+                    m_bGetDOMImplLSFailed = true;
+                    m_aLogger.logInfo("Could not find DOM LS 3.0 Implementation, using own implementation", false);
+                }
+            }
+            if( m_aDOMImplLS != null )
+            {
+                aLSInput = m_aDOMImplLS.createLSInput();
+            }
+            else
+            {
+                aLSInput = new LSInputImpl();
+            }
+            
+            return aLSInput;
+        }
+    }

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ValidationMessageCollectorErrorFilter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ValidationMessageCollectorErrorFilter.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ValidationMessageCollectorErrorFilter.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ValidationMessageCollectorErrorFilter.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,74 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import java.util.HashSet;
+import org.xml.sax.SAXParseException;
+
+/**
+ *
+ */
+public class ValidationMessageCollectorErrorFilter implements SAXParseExceptionFilter {
+
+    private String m_aGenerator;
+    private HashSet<String> m_aMsgsReported;
+
+    
+    /** Creates a new instance of ValidationErrorFilter */
+    public ValidationMessageCollectorErrorFilter() throws ODFValidatorException {
+        m_aMsgsReported = new HashSet<String>();
+    }
+    
+    public SAXParseException filterException( SAXParseException aExc )
+    {
+        String aMsg = aExc.getMessage();
+        if( !m_aMsgsReported.contains(aMsg))
+        {
+             m_aMsgsReported.add( aMsg );
+        }
+        
+        return aExc;
+    }
+
+    public void startPackage( String aGenerator )
+    {
+    }
+
+    public void setGenerator( String aGenerator )
+    {
+        m_aGenerator = aGenerator;
+    }
+    
+    public void startSubFile() {
+    }    
+    
+    public String getGenerator()
+    {
+        return m_aGenerator;
+    }
+
+    public HashSet<String> getMessages()
+    {
+        return m_aMsgsReported;
+    }
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ValidationOOoTaskIdErrorFilter.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ValidationOOoTaskIdErrorFilter.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ValidationOOoTaskIdErrorFilter.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ValidationOOoTaskIdErrorFilter.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,213 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import java.io.File;
+import java.io.PrintStream;
+import java.util.HashMap;
+import java.util.HashSet;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ *
+ */
+public class ValidationOOoTaskIdErrorFilter implements SAXParseExceptionFilter {
+
+    
+    private static final String FILTER_ENTRY = "filter-entry";
+    private static final String TASK_ID = "task-id";
+    private static final String RESOLVED_IN = "resolved-in";
+    
+    int m_nBuildId = 0;
+    
+    class FilterEntry
+    {
+        String m_aTaskId;
+        int m_nBuildId;
+        
+        FilterEntry( String aTaskId, int nBuildId )
+        {
+            m_aTaskId = aTaskId;
+            m_nBuildId = nBuildId;
+        }
+    }
+            
+
+    private HashMap<String,FilterEntry> m_aFilterEntries;
+    private HashSet<String> m_aTaskIdsReported;
+
+    class Handler extends DefaultHandler
+    {
+        class Entry
+        {
+            String m_aMessage = "";
+            String m_aTask = "";
+            int m_nBuildId = 0;
+
+            Entry( String aTask )
+            {
+                m_aTask = aTask;
+            }
+        }
+
+        HashMap<String,FilterEntry> m_aFilterEntries;
+        Entry m_aEntry = null;
+
+        Handler( HashMap<String,FilterEntry> aFilterEntries )
+        {
+            m_aFilterEntries = aFilterEntries;
+        }
+
+        @Override
+        public void characters(char[] aCh, int nStart, int nLength) throws SAXException {
+            if( m_aEntry != null )
+                m_aEntry.m_aMessage += new String(aCh, nStart, nLength);
+        }
+
+        @Override
+        public void startElement(String aUri, String aLocalName, String aQName, Attributes aAttributes) throws SAXException {
+            if( aQName.equals(FILTER_ENTRY) )
+            {
+               String aTaskId = aAttributes.getValue(TASK_ID);
+                if( aTaskId != null )
+                {
+                    m_aEntry = new Entry( aTaskId );
+                    String aBuildId = aAttributes.getValue(RESOLVED_IN);
+                    if( aBuildId != null && aBuildId.length() > 0)
+                        m_aEntry.m_nBuildId = Integer.valueOf(aBuildId);
+                }
+               
+            }
+        }
+
+        @Override
+        public void endElement(String aUri, String aLocalName, String aQName) throws SAXException {
+            if( aQName.equals(FILTER_ENTRY) )
+            {
+                if( m_aEntry != null )
+                {
+                    m_aFilterEntries.put( m_aEntry.m_aMessage, new FilterEntry(m_aEntry.m_aTask,m_aEntry.m_nBuildId) );
+                }
+            }
+        }
+
+    }
+    
+    /** Creates a new instance of ValidationErrorFilter */
+    public ValidationOOoTaskIdErrorFilter( File aFilterFile, PrintStream aOut ) throws ODFValidatorException {
+        m_aFilterEntries = new HashMap<String,FilterEntry>();
+        m_aTaskIdsReported = new HashSet<String>();
+        SAXParser aParser = null;
+        Logger aLogger = new Logger( aFilterFile.getAbsolutePath(), "", aOut, Logger.LogLevel.ERROR );
+        try
+        {
+            SAXParserFactory aParserFactory = SAXParserFactory.newInstance();
+            aParserFactory.setNamespaceAware(false);
+            aParser = aParserFactory.newSAXParser();
+
+            aParser.parse(aFilterFile, new Handler( m_aFilterEntries));
+        }
+        catch( javax.xml.parsers.ParserConfigurationException e )
+        {
+            throw new ODFValidatorException( e );
+        }
+        catch( org.xml.sax.SAXParseException e )
+        {
+            aLogger.logError( e );
+            throw new ODFValidatorException( e );
+        }
+        catch( org.xml.sax.SAXException e )
+        {
+            aLogger.logError( e.getMessage() );
+            throw new ODFValidatorException( e );
+        }
+        catch( java.io.IOException e )
+        {
+            throw new ODFValidatorException( e );
+        }
+
+
+    }
+    
+    public SAXParseException filterException( SAXParseException aExc )
+    {
+        if( m_nBuildId > 0 )
+        {
+            FilterEntry aEntry = m_aFilterEntries.get(aExc.getMessage());
+            if( aEntry != null && 
+                (aEntry.m_nBuildId == 0 || m_nBuildId <= aEntry.m_nBuildId) )
+            {
+                String aTaskId = aEntry.m_aTaskId;
+                if( !m_aTaskIdsReported.contains(aTaskId ))
+                {
+                    m_aTaskIdsReported.add( aTaskId );
+                    return new SAXParseException( "Issue " + aTaskId + " found.", aExc.getPublicId(), aExc.getSystemId(), aExc.getLineNumber(), aExc.getColumnNumber(), aExc );
+                }
+                else
+                    return null;
+            }
+        }
+        
+        return aExc;
+    }
+
+    public void startPackage( String aGenerator )
+    {
+        m_nBuildId = aGenerator.length() > 0 ? getBuildId( aGenerator) : 0;
+    }
+    
+    
+    public void startSubFile() {
+        m_aTaskIdsReported = new HashSet<String>();
+        // the build id is kept
+    }
+    
+    public void setGenerator( String aGenerator )
+    {
+        m_nBuildId = aGenerator.length() > 0 ? getBuildId( aGenerator) : 0;
+    }
+
+    public static int getBuildId( String aGenerator )
+    {
+        int nBuildId = 0;
+        int nPos = aGenerator.indexOf("OpenOffice.org_project/");
+        if( nPos>0 )
+        {
+            nPos = aGenerator.indexOf("Build-",nPos);
+            if( nPos > 0 )
+            {
+                int nStart = nPos+6;
+                nPos = aGenerator.indexOf("$",nStart);
+                nBuildId = Integer.valueOf(nPos > 0 ? aGenerator.substring(nStart,nPos) : aGenerator.substring(nStart));
+            }
+        }
+        
+        return nBuildId;
+    }
+    
+}

Added: incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/VersionHandler.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/VersionHandler.java?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/VersionHandler.java (added)
+++ incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/VersionHandler.java Mon Sep 19 05:43:23 2011
@@ -0,0 +1,53 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ * 
+ * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
+ * 
+ * Use is subject to license terms.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
+ * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+
+package org.odftoolkit.odfvalidator;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class VersionHandler extends DefaultHandler {
+
+    private static final String OFFICE_NAMESPACE_URI = "urn:oasis:names:tc:opendocument:xmlns:office:1.0";
+    private static final String DOCUMENT_META = "document-meta";
+    private static final String DOCUMENT_CONTENT = "document-content";
+    private static final String DOCUMENT_SETTINGS = "document-settings";
+    private static final String DOCUMENT_STYLES = "document-styles";
+    private static final String VERSION = "version";
+
+    @Override
+    public void startElement(String aUri, String aLocalName, String aQName, Attributes aAttributes) throws SAXException {
+        super.startElement(aUri, aLocalName, aQName, aAttributes);
+        
+        if( aUri.equals(OFFICE_NAMESPACE_URI) &&
+            (aLocalName.equalsIgnoreCase(DOCUMENT_META) ||
+             aLocalName.equalsIgnoreCase(DOCUMENT_CONTENT) || 
+             aLocalName.equalsIgnoreCase(DOCUMENT_SETTINGS) ||
+             aLocalName.equalsIgnoreCase(DOCUMENT_STYLES)) )
+        {
+            String aVersion = aAttributes.getValue(OFFICE_NAMESPACE_URI,VERSION);
+            throw new SAXVersionException(aVersion);
+        }
+    }
+
+}

Added: incubator/odf/trunk/validator/src/main/resources/META-INF/services/org.iso_relax.verifier.VerifierFactoryLoader
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/validator/src/main/resources/META-INF/services/org.iso_relax.verifier.VerifierFactoryLoader?rev=1172466&view=auto
==============================================================================
--- incubator/odf/trunk/validator/src/main/resources/META-INF/services/org.iso_relax.verifier.VerifierFactoryLoader (added)
+++ incubator/odf/trunk/validator/src/main/resources/META-INF/services/org.iso_relax.verifier.VerifierFactoryLoader Mon Sep 19 05:43:23 2011
@@ -0,0 +1 @@
+com.sun.msv.verifier.jarv.FactoryLoaderImpl
\ No newline at end of file



Mime
View raw message