|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.xml.schema.cookies; import java.io.*; import java.net.*; import org.xml.sax.*; import org.netbeans.spi.xml.cookies.*; import org.netbeans.api.xml.parsers.SAXEntityParser; import org.netbeans.api.xml.services.UserCatalog; import org.openide.xml.XMLUtil; import org.xml.sax.EntityResolver; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; /** * CheckXMLCookie and ValidateXMLCookie implementation for XML Schemas. * * @author Petr Kuzel */ public final class ValidateSchemaSupport extends ValidateXMLSupport { /** Creates a new instance of CheckSchemaSupport */ public ValidateSchemaSupport(InputSource inputSource) { super( inputSource); } /** * In validating mode create XMLReader able to parse XML Schemas. */ protected XMLReader createParser(boolean validate) { final String XERCES_FEATURE_PREFIX = "http://apache.org/xml/features/"; // NOI18N XMLReader parser = super.createParser(validate); if (parser == null) return null; // for validaton use wrapping parser if (validate) { // we urgently need XML Schema aware parser try { if (parser.getFeature(XERCES_FEATURE_PREFIX + "validation/schema") == false) { // NOI18N //??? try get Xerces explicitly, no such library except ou outdate X2b4 exists return null; } else { // check all schema oddities with Xerces parser parser.setFeature(XERCES_FEATURE_PREFIX + "validation/schema-full-checking", true); // NOI18N return new SchemaChecker(parser); } } catch (SAXException ex) { return null; } } else { return parser; } } /** * Redefine wrapping policy. */ private static class SchemaChecker extends SAXEntityParser { private static String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema"; // schema target ns private String ns = null; public SchemaChecker(XMLReader parser) { super( parser); } /** * Create fake document referencing XML Schema document. * Besides it must guarantee that the first entity resolution * query caused by parsing of wrapped document is * resolved at a context where XML Schema InputSource * is expected. It is SAXEntityParser logic. */ protected InputSource wrapInputSource(InputSource inputSource) { String targetNamespace = getTargetNamespace(); String url = inputSource.getSystemId(); StringBuffer buffer = new StringBuffer(); String namespace = "http://www.w3.org/2001/XMLSchema-instance"; // NOI18N buffer.append(" |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.