You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2013/10/30 18:50:43 UTC
svn commit: r1537203 - in
/cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation:
Stax2ValidationUtils.java W3CMultiSchemaFactory.java
Author: dkulp
Date: Wed Oct 30 17:50:43 2013
New Revision: 1537203
URL: http://svn.apache.org/r1537203
Log:
Merged revisions 1537200 via git cherry-pick from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1537200 | dkulp | 2013-10-30 13:47:18 -0400 (Wed, 30 Oct 2013) | 2 lines
[CXF-5367] Work around some issues with MSV with included schemas
........
Modified:
cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java
cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/W3CMultiSchemaFactory.java
Modified: cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java?rev=1537203&r1=1537202&r2=1537203&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java (original)
+++ cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/Stax2ValidationUtils.java Wed Oct 30 17:50:43 2013
@@ -127,7 +127,6 @@ class Stax2ValidationUtils {
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(uri)) {
continue;
}
- LOG.info(uri);
Element serialized = schemaInfo.getElement();
String schemaSystemId = sch.getSourceURI();
Modified: cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/W3CMultiSchemaFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/W3CMultiSchemaFactory.java?rev=1537203&r1=1537202&r2=1537203&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/W3CMultiSchemaFactory.java (original)
+++ cxf/branches/2.7.x-fixes/common/wstx-msv-validation/src/main/java/org/apache/cxf/wstx_msv_validation/W3CMultiSchemaFactory.java Wed Oct 30 17:50:43 2013
@@ -24,17 +24,26 @@
package org.apache.cxf.wstx_msv_validation;
import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.stream.XMLStreamException;
+import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
import com.ctc.wstx.msv.BaseSchemaFactory;
import com.ctc.wstx.msv.W3CSchema;
+import com.sun.msv.grammar.ExpressionPool;
import com.sun.msv.grammar.xmlschema.XMLSchemaGrammar;
+import com.sun.msv.grammar.xmlschema.XMLSchemaSchema;
+import com.sun.msv.reader.GrammarReaderController;
+import com.sun.msv.reader.State;
import com.sun.msv.reader.xmlschema.MultiSchemaReader;
+import com.sun.msv.reader.xmlschema.SchemaState;
import com.sun.msv.reader.xmlschema.XMLSchemaReader;
import org.codehaus.stax2.validation.XMLValidationSchema;
@@ -46,18 +55,69 @@ public class W3CMultiSchemaFactory exten
private MultiSchemaReader multiSchemaReader;
private SAXParserFactory parserFactory;
- private XMLSchemaReader xmlSchemaReader;
+ private RecursiveAllowedXMLSchemaReader xmlSchemaReader;
public W3CMultiSchemaFactory() {
super(XMLValidationSchema.SCHEMA_ID_W3C_SCHEMA);
}
+ static class RecursiveAllowedXMLSchemaReader extends XMLSchemaReader {
+ Set<String> sysIds = new TreeSet<String>();
+ public RecursiveAllowedXMLSchemaReader(GrammarReaderController controller,
+ SAXParserFactory parserFactory) {
+ super(controller, parserFactory, new StateFactory() {
+ public State schemaHead(String expectedNamespace) {
+ return new SchemaState(expectedNamespace) {
+ private XMLSchemaSchema old;
+ protected void endSelf() {
+ super.endSelf();
+ RecursiveAllowedXMLSchemaReader r = (RecursiveAllowedXMLSchemaReader)reader;
+ r.currentSchema = old;
+ }
+ protected void onTargetNamespaceResolved(String targetNs, boolean ignoreContents) {
+
+ RecursiveAllowedXMLSchemaReader r = (RecursiveAllowedXMLSchemaReader)reader;
+ // sets new XMLSchemaGrammar object.
+ old = r.currentSchema;
+ r.currentSchema = r.getOrCreateSchema(targetNs);
+ if (ignoreContents) {
+ return;
+ }
+ if (!r.isSchemaDefined(r.currentSchema)) {
+ r.markSchemaAsDefined(r.currentSchema);
+ }
+ }
+ };
+ }
+ }, new ExpressionPool());
+ }
+
+ public final XMLSchemaGrammar getResultNoError() {
+ return grammar;
+ }
+
+ public void setLocator(Locator locator) {
+ if (locator == null && getLocator() != null && getLocator().getSystemId() != null) {
+ sysIds.add(getLocator().getSystemId());
+ }
+ super.setLocator(locator);
+ }
+ public void switchSource(Source source, State newState) {
+ String url = source.getSystemId();
+ if (url != null && sysIds.contains(url)) {
+ return;
+ }
+ super.switchSource(source, newState);
+ }
+
+ }
+
public XMLValidationSchema loadSchemas(String baseURI,
Map<String, EmbeddedSchema> sources) throws XMLStreamException {
parserFactory = getSaxFactory();
ResolvingGrammarReaderController ctrl = new ResolvingGrammarReaderController(baseURI, sources);
- xmlSchemaReader = new XMLSchemaReader(ctrl, parserFactory);
+ xmlSchemaReader = new RecursiveAllowedXMLSchemaReader(ctrl, parserFactory);
multiSchemaReader = new MultiSchemaReader(xmlSchemaReader);
for (EmbeddedSchema source : sources.values()) {
DOMSource domSource = new DOMSource(source.getSchemaElement());
@@ -67,6 +127,9 @@ public class W3CMultiSchemaFactory exten
XMLSchemaGrammar grammar = multiSchemaReader.getResult();
if (grammar == null) {
+ grammar = xmlSchemaReader.getResultNoError();
+ }
+ if (grammar == null) {
throw new XMLStreamException("Failed to load schemas");
}
return new W3CSchema(grammar);