pax_global_header00006660000000000000000000000064112505443660014520gustar00rootroot0000000000000052 comment=3f4f8bb9cbf499ba3f7f429e231b35241b6391a3 isorelax-20041111/000077500000000000000000000000001125054436600136015ustar00rootroot00000000000000isorelax-20041111/jp/000077500000000000000000000000001125054436600142125ustar00rootroot00000000000000isorelax-20041111/jp/gr/000077500000000000000000000000001125054436600146225ustar00rootroot00000000000000isorelax-20041111/jp/gr/xml/000077500000000000000000000000001125054436600154225ustar00rootroot00000000000000isorelax-20041111/jp/gr/xml/relax/000077500000000000000000000000001125054436600165355ustar00rootroot00000000000000isorelax-20041111/jp/gr/xml/relax/dom/000077500000000000000000000000001125054436600173145ustar00rootroot00000000000000isorelax-20041111/jp/gr/xml/relax/dom/DOMVisitorException.java000066400000000000000000000024751125054436600240450ustar00rootroot00000000000000package jp.gr.xml.relax.dom; import java.io.PrintStream; import java.io.PrintWriter; /** * DOMVisitorException * * @since Feb. 23, 2001 * @version Feb. 24, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public class DOMVisitorException extends RuntimeException { private Exception cause_ = null; public DOMVisitorException(String message) { super(message); } public DOMVisitorException(Exception e) { super(e.getMessage()); cause_ = e; } public DOMVisitorException(String message, Exception e) { super(message); cause_ = e; } public Exception getException() { if (cause_ != null) { return (cause_); } else { return (this); } } public Exception getCauseException() { return (cause_); } public void printStackTrace() { printStackTrace(new PrintWriter(System.err, true)); } public void printStackTrace(PrintStream out) { printStackTrace(new PrintWriter(out)); } public void printStackTrace(PrintWriter writer) { if (writer == null) { writer = new PrintWriter(System.err, true); } super.printStackTrace(writer); if (cause_ != null) { writer.println(); writer.println("StackTrace of Original Exception:"); cause_.printStackTrace(writer); } } } isorelax-20041111/jp/gr/xml/relax/dom/IDOMVisitor.java000066400000000000000000000043361125054436600222750ustar00rootroot00000000000000package jp.gr.xml.relax.dom; import org.w3c.dom.Attr; import org.w3c.dom.CDATASection; import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.DocumentFragment; import org.w3c.dom.DocumentType; import org.w3c.dom.Element; import org.w3c.dom.Entity; import org.w3c.dom.EntityReference; import org.w3c.dom.Node; import org.w3c.dom.Notation; import org.w3c.dom.ProcessingInstruction; import org.w3c.dom.Text; /** * IDOMVisitor * * @since Oct. 7, 2000 * @version Feb. 24, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public interface IDOMVisitor { boolean enter(Element element) throws DOMVisitorException; boolean enter(Attr attr) throws DOMVisitorException; boolean enter(Text text) throws DOMVisitorException; boolean enter(CDATASection cdata) throws DOMVisitorException; boolean enter(EntityReference entityRef) throws DOMVisitorException; boolean enter(Entity entity) throws DOMVisitorException; boolean enter(ProcessingInstruction pi) throws DOMVisitorException; boolean enter(Comment comment) throws DOMVisitorException; boolean enter(Document doc) throws DOMVisitorException; boolean enter(DocumentType doctype) throws DOMVisitorException; boolean enter(DocumentFragment docfrag) throws DOMVisitorException; boolean enter(Notation notation) throws DOMVisitorException; boolean enter(Node node) throws DOMVisitorException; void leave(Element element) throws DOMVisitorException; void leave(Attr attr) throws DOMVisitorException; void leave(Text text) throws DOMVisitorException; void leave(CDATASection cdata) throws DOMVisitorException; void leave(EntityReference entityRef) throws DOMVisitorException; void leave(Entity entity) throws DOMVisitorException; void leave(ProcessingInstruction pi) throws DOMVisitorException; void leave(Comment comment) throws DOMVisitorException; void leave(Document doc) throws DOMVisitorException; void leave(DocumentType doctype) throws DOMVisitorException; void leave(DocumentFragment docfrag) throws DOMVisitorException; void leave(Notation notation) throws DOMVisitorException; void leave(Node node) throws DOMVisitorException; } isorelax-20041111/jp/gr/xml/relax/dom/UDOM.java000066400000000000000000000013021125054436600207170ustar00rootroot00000000000000package jp.gr.xml.relax.dom; import org.w3c.dom.Document; import org.w3c.dom.Node; /** * UDOM * * @since Jan. 29, 2000 * @version Feb. 24, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public final class UDOM { // text generation public static String getXMLText(Document doc) { return (getXMLText(doc, "UTF-8")); } public static String getXMLText(Document doc, String encoding) { XMLMaker maker = new XMLMaker(); UDOMVisitor.traverse(doc, maker); return (maker.getText()); } public static String getXMLText(Node node) { XMLMaker maker = new XMLMaker(); UDOMVisitor.traverse(node, maker); return (maker.getText()); } } isorelax-20041111/jp/gr/xml/relax/dom/UDOMVisitor.java000066400000000000000000000064621125054436600223130ustar00rootroot00000000000000package jp.gr.xml.relax.dom; import org.w3c.dom.Attr; import org.w3c.dom.CDATASection; import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.DocumentFragment; import org.w3c.dom.DocumentType; import org.w3c.dom.Element; import org.w3c.dom.Entity; import org.w3c.dom.EntityReference; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.Notation; import org.w3c.dom.ProcessingInstruction; import org.w3c.dom.Text; /** * UDOMVisitor * * @since Oct. 7, 2000 * @version Feb. 24, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public final class UDOMVisitor { public static void traverse( Node node, IDOMVisitor visitor ) throws DOMVisitorException { boolean doContinue; switch (node.getNodeType()) { case Node.ELEMENT_NODE: doContinue = visitor.enter((Element)node); break; case Node.ATTRIBUTE_NODE: doContinue = visitor.enter((Attr)node); break; case Node.TEXT_NODE: doContinue = visitor.enter((Text)node); break; case Node.CDATA_SECTION_NODE: doContinue = visitor.enter((CDATASection)node); break; case Node.ENTITY_REFERENCE_NODE: doContinue = visitor.enter((EntityReference)node); break; case Node.ENTITY_NODE: doContinue = visitor.enter((Entity)node); break; case Node.PROCESSING_INSTRUCTION_NODE: doContinue = visitor.enter((ProcessingInstruction)node); break; case Node.COMMENT_NODE: doContinue = visitor.enter((Comment)node); break; case Node.DOCUMENT_NODE: doContinue = visitor.enter((Document)node); break; case Node.DOCUMENT_TYPE_NODE: doContinue = visitor.enter((DocumentType)node); break; case Node.DOCUMENT_FRAGMENT_NODE: doContinue = visitor.enter((DocumentFragment)node); break; case Node.NOTATION_NODE: doContinue = visitor.enter((Notation)node); break; default: doContinue = visitor.enter(node); break; } if (doContinue) { traverseChildren(node, visitor); switch (node.getNodeType()) { case Node.ELEMENT_NODE: visitor.leave((Element)node); break; case Node.ATTRIBUTE_NODE: visitor.leave((Attr)node); break; case Node.TEXT_NODE: visitor.leave((Text)node); break; case Node.CDATA_SECTION_NODE: visitor.leave((CDATASection)node); break; case Node.ENTITY_REFERENCE_NODE: visitor.leave((EntityReference)node); break; case Node.ENTITY_NODE: visitor.leave((Entity)node); break; case Node.PROCESSING_INSTRUCTION_NODE: visitor.leave((ProcessingInstruction)node); break; case Node.COMMENT_NODE: visitor.leave((Comment)node); break; case Node.DOCUMENT_NODE: visitor.leave((Document)node); break; case Node.DOCUMENT_TYPE_NODE: visitor.leave((DocumentType)node); break; case Node.DOCUMENT_FRAGMENT_NODE: visitor.leave((DocumentFragment)node); break; case Node.NOTATION_NODE: visitor.leave((Notation)node); break; default: visitor.leave(node); break; } } } public static void traverseChildren(Node node, IDOMVisitor visitor) { NodeList children = node.getChildNodes(); int size = children.getLength(); for (int i = 0;i < size;i++) { traverse(children.item(i), visitor); } } } isorelax-20041111/jp/gr/xml/relax/dom/XMLMaker.java000066400000000000000000000174171125054436600216110ustar00rootroot00000000000000package jp.gr.xml.relax.dom; import jp.gr.xml.relax.xml.UXML; import org.w3c.dom.Attr; import org.w3c.dom.CDATASection; import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.DocumentFragment; import org.w3c.dom.DocumentType; import org.w3c.dom.Element; import org.w3c.dom.Entity; import org.w3c.dom.EntityReference; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.Notation; import org.w3c.dom.ProcessingInstruction; import org.w3c.dom.Text; /** * XMLMaker * * @since Oct. 27, 2000 * @version Feb. 24, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public class XMLMaker implements IDOMVisitor { protected StringBuffer buffer_; protected String encoding_ = "UTF-8"; protected boolean dom2_ = false; protected boolean expandEntityReference_ = false; protected boolean emptyElementTag_ = false; public XMLMaker() { buffer_ = new StringBuffer(); } public void setEncoding(String encoding) { encoding_ = encoding; } public void setDOM2(boolean dom2) { dom2_ = dom2; } public void setExpandEntityReference(boolean expand) { expandEntityReference_ = expand; } public void setEmptyElementTag(boolean empty) { emptyElementTag_ = empty; } public String getText() { return (new String(buffer_)); } public boolean enter(Element element) { String tag = element.getTagName(); buffer_.append("<"); buffer_.append(tag); NamedNodeMap attrs = element.getAttributes(); int nAttrs = attrs.getLength(); for (int i = 0;i < nAttrs;i++) { Attr attr = (Attr)attrs.item(i); if (attr.getSpecified()) { buffer_.append(' '); enter(attr); leave(attr); } } buffer_.append(">"); return (true); } public void leave(Element element) { String tag = element.getTagName(); buffer_.append(""); } public boolean enter(Attr attr) { buffer_.append(attr.getName()); buffer_.append("=\""); buffer_.append(UXML.escapeAttrQuot(attr.getValue())); buffer_.append('\"'); return (true); } public void leave(Attr attr) { // do nothing } public boolean enter(Text text) { buffer_.append(UXML.escapeCharData(text.getData())); return (true); } public void leave(Text text) { // do nothing } public boolean enter(CDATASection cdata) { buffer_.append(""); return (true); } public void leave(CDATASection cdata) { // do nothing } public boolean enter(EntityReference entityRef) { buffer_.append("&"); buffer_.append(entityRef.getNodeName()); buffer_.append(";"); return (false); } public void leave(EntityReference entityRef) { // do nothing } public boolean enter(Entity entity) { String name = entity.getNodeName(); String pid = entity.getPublicId(); String sid = entity.getSystemId(); String notation = entity.getNotationName(); buffer_.append(""); } else { buffer_.append(" SYSTEM \""); buffer_.append(UXML.escapeSystemQuot(sid)); buffer_.append("\">"); } if (notation != null) { buffer_.append(" NDATA "); buffer_.append(notation); buffer_.append(">"); } } else { buffer_.append(" \""); XMLMaker entityMaker = new XMLMaker(); UDOMVisitor.traverseChildren(entity, entityMaker); buffer_.append(UXML.escapeEntityQuot(entityMaker.getText())); buffer_.append("\""); buffer_.append(">"); } return (false); } public void leave(Entity entity) { // do nothing } public boolean enter(ProcessingInstruction pi) { buffer_.append(""); return (true); } public void leave(ProcessingInstruction pi) { // do nothing } public boolean enter(Comment comment) { buffer_.append(""); return (true); } public void leave(Comment comment) { // do nothing } public boolean enter(Document doc) { buffer_.append("\n"); return (true); } public void leave(Document doc) { // do nothing } public boolean enter(DocumentType doctype) { if (dom2_) { String name = doctype.getName(); String publicId = doctype.getPublicId(); String systemId = doctype.getSystemId(); String internalSubset = doctype.getInternalSubset(); buffer_.append("\n"); return (true); } else { String name = doctype.getName(); NamedNodeMap entities = doctype.getEntities(); NamedNodeMap notations = doctype.getNotations(); buffer_.append(" 0 || notations != null && notations.getLength() > 0) { buffer_.append(" ["); int nEntities = entities.getLength(); for (int i = 0;i < nEntities;i++) { XMLMaker entityMaker = new XMLMaker(); UDOMVisitor.traverse(entities.item(i), entityMaker); buffer_.append(entityMaker.getText()); } int nNotations = notations.getLength(); for (int i = 0;i < nNotations;i++) { enter((Notation)notations.item(i)); leave((Notation)notations.item(i)); } buffer_.append("]"); } buffer_.append(">\n"); return (true); } } public void leave(DocumentType doctype) { // do nothing } public boolean enter(DocumentFragment docfrag) { // do nothing return (true); } public void leave(DocumentFragment docfrag) { // do nothing } public boolean enter(Notation notation) { String name = notation.getNodeName(); String pid = notation.getPublicId(); String sid = notation.getSystemId(); buffer_.append(""); return (true); } public void leave(Notation notation) { // do nothing } public boolean enter(Node node) { throw (new InternalError(node.toString())); } public void leave(Node node) { throw (new InternalError(node.toString())); } public boolean isParsedEntity(EntityReference entityRef) { String name = entityRef.getNodeName(); Document doc = entityRef.getOwnerDocument(); DocumentType doctype = doc.getDoctype(); if (doctype == null) { return (false); } NamedNodeMap entities = doctype.getEntities(); Entity entity = (Entity)entities.getNamedItem(name); if (entity == null) { return (false); } return (entity.getNotationName() == null); } } isorelax-20041111/jp/gr/xml/relax/dtd/000077500000000000000000000000001125054436600173105ustar00rootroot00000000000000isorelax-20041111/jp/gr/xml/relax/dtd/DTDVerifier.java_000066400000000000000000000114421125054436600224230ustar00rootroot00000000000000package jp.gr.xml.relax.dtd; import java.io.IOException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParser; import org.xml.sax.XMLReader; import org.xml.sax.ErrorHandler; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; import org.w3c.dom.Node; import org.iso_relax.verifier.Verifier; import org.iso_relax.verifier.VerifierHandler; import org.iso_relax.verifier.VerifierFilter; import org.iso_relax.verifier.VerifierConfigurationException; import org.iso_relax.verifier.VerifierException; /** * DTDVerifier * * @since Mar. 14, 2001 * @version May. 28, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public class DTDVerifier implements Verifier { public DTDVerifier(String uri) throws VerifierConfigurationException, SAXException, IOException { try { } catch (SchemaSyntaxErrorException e) { throw (new VerifierException(e)); } catch (ClassNotFoundException e) { throw (new VerifierException(e)); } catch (IllegalAccessException e) { throw (new VerifierException(e)); } catch (InstantiationException e) { throw (new VerifierException(e)); } catch (SAXException e) { throw (new VerifierException(e)); } } public DTDVerifier(InputSource source) throws VerifierConfigurationException, SAXException { try { } catch (SchemaSyntaxErrorException e) { throw (new VerifierException(e)); } catch (ClassNotFoundException e) { throw (new VerifierException(e)); } catch (IllegalAccessException e) { throw (new VerifierException(e)); } catch (InstantiationException e) { throw (new VerifierException(e)); } catch (SAXException e) { throw (new VerifierException(e)); } catch (IOException e) { throw (new VerifierException(e)); } } private void _init(Grammar grammar) throws VerifierConfigurationException { grammar_ = grammar; reader_ = _getXMLReader(); } private XMLReader _getXMLReader() throws VerifierConfigurationException { try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); // return (saxParser.getXMLReader()); return (new org.apache.xerces.parsers.SAXParser());// XXX } catch (ParserConfigurationException e) { throw (new VerifierConfigurationException(e)); } catch (SAXException e) { throw (new VerifierConfigurationException(e)); } } public boolean isFeature(String feature) throws SAXNotRecognizedException, SAXNotSupportedException { if (FEATURE_HANDLER.equals(feature) || FEATURE_FILTER.equals(feature)) { return (true); } else { throw (new SAXNotRecognizedException(feature)); } } public void setFeature(String feature, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { throw (new SAXNotRecognizedException(feature)); } public Object getProperty(String property) throws SAXNotRecognizedException, SAXNotSupportedException { throw (new SAXNotRecognizedException(property)); } public void setProperty(String property, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { throw (new SAXNotRecognizedException(property)); } public void setErrorHandler(ErrorHandler handler) { reader_.setErrorHandler(handler); } public void setEntityResolver(EntityResolver handler) { reader_.setEntityResolver(handler); } public boolean verify(String uri) throws SAXException, IOException { RELAXNormalHandler verifier = new RELAXNormalHandler(grammar_); reader_.setContentHandler(verifier); try { reader_.parse(uri); return (true); } catch (NotValidException e) { return (false); } catch (SAXException e) { throw (new SAXException(e)); } } public boolean verify(InputSource source) throws SAXException, IOException { RELAXNormalHandler verifier = new RELAXNormalHandler(grammar_); reader_.setContentHandler(verifier); try { reader_.parse(source); return (true); } catch (NotValidException e) { return (false); } catch (SAXException e) { throw (new SAXException(e)); } } public boolean verify(Node node) throws SAXException { DOMSAXProducer producer = new DOMSAXProducer(node); RELAXNormalHandler verifier = new RELAXNormalHandler(grammar_); try { producer.makeEvent(verifier); return (true); } catch (NotValidException e) { return (false); } catch (SAXException e) { throw (new VerifierException(e)); } } public VerifierHandler getVerifierHandler() { return (new DTDVerifierHandler()); } public VerifierFilter getVerifierFilter() { return (new DTDVerifierFilter()); } } isorelax-20041111/jp/gr/xml/relax/dtd/DTDVerifierFactory.java_000066400000000000000000000031561125054436600237560ustar00rootroot00000000000000package jp.gr.xml.relax.dtd; import java.io.IOException; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; import org.iso_relax.verifier.VerifierFactory; import org.iso_relax.verifier.Verifier; import org.iso_relax.verifier.VerifierConfigurationException; import org.iso_relax.verifier.VerifierException; /** * DTDVerifierFactory * * @since Mar. 14, 2001 * @version Mar. 14, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public class DTDVerifierFactory extends VerifierFactory { public boolean isFeature(String feature) throws SAXNotRecognizedException, SAXNotSupportedException { throw (new SAXNotRecognizedException(feature)); } public void setFeature(String feature, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { throw (new SAXNotRecognizedException(feature)); } public Object getProperty(String property) throws SAXNotRecognizedException, SAXNotSupportedException { throw (new SAXNotRecognizedException(property)); } public void setProperty(String property, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { throw (new SAXNotRecognizedException(property)); } public Verifier newVerifier( String uri ) throws VerifierConfigurationException, SAXException, IOException { return (new DTDVerifier(uri)); } public Verifier newVerifier( InputSource source ) throws VerifierConfigurationException, SAXException, IOException { return (new DTDVerifier(source)); } } isorelax-20041111/jp/gr/xml/relax/lib/000077500000000000000000000000001125054436600173035ustar00rootroot00000000000000isorelax-20041111/jp/gr/xml/relax/lib/datatypes.mod000066400000000000000000000070501125054436600220040ustar00rootroot00000000000000 isorelax-20041111/jp/gr/xml/relax/lib/datatypes.rxm000066400000000000000000000124741125054436600220410ustar00rootroot00000000000000 isorelax-20041111/jp/gr/xml/relax/lib/relax.dtd000066400000000000000000000011371125054436600211150ustar00rootroot00000000000000 %relaxCore; %relaxNamespace; isorelax-20041111/jp/gr/xml/relax/lib/relax.rxg000066400000000000000000000034431125054436600211440ustar00rootroot00000000000000 isorelax-20041111/jp/gr/xml/relax/lib/relaxCore.dtd000066400000000000000000000224261125054436600217320ustar00rootroot00000000000000 %datatype-definitions; isorelax-20041111/jp/gr/xml/relax/lib/relaxCore.rxm000066400000000000000000000307521125054436600217660ustar00rootroot00000000000000 ]>
isorelax-20041111/jp/gr/xml/relax/lib/relaxNamespace.dtd000066400000000000000000000046371125054436600227420ustar00rootroot00000000000000 isorelax-20041111/jp/gr/xml/relax/lib/relaxNamespace.rxm000066400000000000000000000055431125054436600227720ustar00rootroot00000000000000 isorelax-20041111/jp/gr/xml/relax/lib/relaxNg.rxm000066400000000000000000000075361125054436600214460ustar00rootroot00000000000000 isorelax-20041111/jp/gr/xml/relax/sax/000077500000000000000000000000001125054436600173305ustar00rootroot00000000000000isorelax-20041111/jp/gr/xml/relax/sax/DOMSAXProducer.java000066400000000000000000000054511125054436600226770ustar00rootroot00000000000000package jp.gr.xml.relax.sax; import jp.gr.xml.relax.dom.DOMVisitorException; import jp.gr.xml.relax.dom.UDOMVisitor; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.xml.sax.ContentHandler; import org.xml.sax.DTDHandler; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.ext.DeclHandler; import org.xml.sax.ext.LexicalHandler; /** * SAX event producer from DOM tree * * @since Feb. 18, 2001 * @version Feb. 24, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public class DOMSAXProducer { private boolean needDocumentEmulation_ = true; private Node root_; private String systemID_; private String publicID_; private DTDHandler dtd_; private ContentHandler content_; private DeclHandler decl_; private LexicalHandler lexical_; private ErrorHandler error_; public DOMSAXProducer(Node node) { root_ = node; } public void setDocumentEmulation(boolean emulate) { needDocumentEmulation_ = emulate; } public void setDTDHandler(DTDHandler dtd) { dtd_ = dtd; } public void setContentHandler(ContentHandler content) { content_ = content; } public void setLexicalHandler(LexicalHandler lexical) { lexical_ = lexical; } public void setDeclHandler(DeclHandler decl) { decl_ = decl; } public void setErrorHandler(ErrorHandler error) { error_ = error; } public void makeEvent() throws SAXException { try { DOMSAXProducerVisitor visitor = new DOMSAXProducerVisitor(); visitor.setSystemID(systemID_); visitor.setPublicID(publicID_); visitor.setDTDHandler(dtd_); visitor.setContentHandler(content_); visitor.setLexicalHandler(lexical_); visitor.setDeclHandler(decl_); visitor.setErrorHandler(error_); if (!(root_ instanceof Document) && needDocumentEmulation_) { visitor.emulateStartDocument(); UDOMVisitor.traverse(root_, visitor); visitor.emulateEndDocument(); } else { UDOMVisitor.traverse(root_, visitor); } } catch (DOMVisitorException e) { Exception cause = e.getCauseException(); if (cause == null) { throw (new SAXException(e.getMessage())); } else if (cause instanceof SAXException) { throw ((SAXException) cause); } else { throw (new SAXException(e.getMessage())); } } } public void makeEvent(ContentHandler handler) throws SAXException { setContentHandler(handler); makeEvent(); } } isorelax-20041111/jp/gr/xml/relax/sax/DOMSAXProducerVisitor.java000066400000000000000000000315211125054436600242540ustar00rootroot00000000000000package jp.gr.xml.relax.sax; import jp.gr.xml.relax.dom.DOMVisitorException; import jp.gr.xml.relax.dom.IDOMVisitor; import jp.gr.xml.relax.dom.UDOM; import org.w3c.dom.Attr; import org.w3c.dom.CDATASection; import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.DocumentFragment; import org.w3c.dom.DocumentType; import org.w3c.dom.Element; import org.w3c.dom.Entity; import org.w3c.dom.EntityReference; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.Notation; import org.w3c.dom.ProcessingInstruction; import org.w3c.dom.Text; import org.xml.sax.ContentHandler; import org.xml.sax.DTDHandler; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.ext.DeclHandler; import org.xml.sax.ext.LexicalHandler; import org.xml.sax.helpers.AttributesImpl; import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.LocatorImpl; import org.xml.sax.helpers.NamespaceSupport; /** * DOMVisitor of SAX event producer from DOM tree * * @since Feb. 18, 2001 * @version Feb. 24, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public class DOMSAXProducerVisitor implements IDOMVisitor { private String systemID_; private String publicID_; private DTDHandler dtd_; private ContentHandler content_; private DeclHandler decl_; private LexicalHandler lexical_; private ErrorHandler error_; private NamespaceSupport namespace_; private boolean throwException_; public DOMSAXProducerVisitor() { DefaultHandler handler = new DefaultHandler(); dtd_ = handler; content_ = handler; error_ = handler; lexical_ = new LexicalHandlerBase(); decl_ = new DeclHandlerBase(); namespace_ = new NamespaceSupport(); throwException_ = false; } public void setSystemID(String id) { systemID_ = id; } public void setPublicID(String id) { publicID_ = id; } public void setDTDHandler(DTDHandler dtd) { dtd_ = dtd; } public void setContentHandler(ContentHandler content) { content_ = content; } public void setLexicalHandler(LexicalHandler lexical) { lexical_ = lexical; } public void setDeclHandler(DeclHandler decl) { decl_ = decl; } public void setErrorHandler(ErrorHandler error) { error_ = error; } public void emulateStartDocument() { try { _handleLocator(); content_.startDocument(); } catch (SAXException e) { _errorReport(e); } } public void emulateEndDocument() { try { content_.endDocument(); } catch (SAXException e) { _errorReport(e); } } public void throwException(boolean useException) { throwException_ = useException; } public boolean enter(Element element) { try { namespace_.pushContext(); String namespaceURI = element.getNamespaceURI(); if (namespaceURI == null) { namespaceURI = ""; } String localName = element.getLocalName(); String qName = element.getTagName(); NamedNodeMap attrMap = element.getAttributes(); AttributesImpl attrs = new AttributesImpl(); int size = attrMap.getLength(); for (int i = 0; i < size; i++) { Attr attr = (Attr) attrMap.item(i); String attrNamespaceURI = attr.getNamespaceURI(); if (attrNamespaceURI == null) { attrNamespaceURI = ""; } String attrLocalName = attr.getLocalName(); String attrQName = attr.getName(); String attrValue = attr.getValue(); if (attrQName.startsWith("xmlns")) { String prefix; int index = attrQName.indexOf(':'); if (index == -1) { prefix = ""; } else { prefix = attrQName.substring(index + 1); } if (!namespace_.declarePrefix(prefix, attrValue)) { _errorReport("bad prefix = " + prefix); } else { content_.startPrefixMapping(prefix, attrValue); } } else { attrs.addAttribute( attrNamespaceURI, attrLocalName, attrQName, "CDATA", attrValue); } } content_.startElement(namespaceURI, localName, qName, attrs); } catch (SAXException e) { _errorReport(e); } return (true); } public boolean enter(Attr attr) { return (false); } public boolean enter(Text text) { try { String data = text.getData(); content_.characters(data.toCharArray(), 0, data.length()); } catch (SAXException e) { _errorReport(e); } return (false); } public boolean enter(CDATASection cdata) { try { lexical_.startCDATA(); String data = cdata.getData(); content_.characters(data.toCharArray(), 0, data.length()); lexical_.endCDATA(); } catch (SAXException e) { _errorReport(e); } return (false); } public boolean enter(EntityReference entityRef) { try { lexical_.startEntity(entityRef.getNodeName()); } catch (SAXException e) { _errorReport(e); } return (true); } public boolean enter(Entity entity) { return (false); } public boolean enter(ProcessingInstruction pi) { try { content_.processingInstruction(pi.getTarget(), pi.getData()); } catch (SAXException e) { _errorReport(e); } return (false); } public boolean enter(Comment comment) { try { String data = comment.getData(); lexical_.comment(data.toCharArray(), 0, data.length()); } catch (SAXException e) { _errorReport(e); } return (false); } public boolean enter(Document doc) { try { _handleLocator(); content_.startDocument(); _handleDoctype(doc.getDoctype()); } catch (SAXException e) { _errorReport(e); } return (true); } private void _handleLocator() { if (systemID_ == null && publicID_ == null) { return; } _locatorEvent(systemID_, publicID_); } private void _locatorEvent(String systemID, String publicID) { LocatorImpl locator = new LocatorImpl(); locator.setSystemId(systemID_); locator.setPublicId(publicID_); locator.setLineNumber(-1); locator.setColumnNumber(-1); content_.setDocumentLocator(locator); } private void _handleDoctype(DocumentType doctype) { try { if (doctype == null) { return; } String systemID = doctype.getSystemId(); String publicID = doctype.getPublicId(); String internalSubset = doctype.getInternalSubset(); if (systemID != null) { lexical_.startDTD(doctype.getName(), publicID, systemID); if (internalSubset == null) { lexical_.endDTD(); _handleEntities(doctype); } else { _handleEntities(doctype); lexical_.endDTD(); } } else { _handleEntities(doctype); } } catch (SAXException e) { _errorReport(e); } } private void _handleEntities(DocumentType doctype) { try { NamedNodeMap entities = doctype.getEntities(); int nEntities = entities.getLength(); for (int i = 0; i < nEntities; i++) { Entity entity = (Entity) entities.item(i); String publicID = entity.getPublicId(); String systemID = entity.getSystemId(); String notationName = entity.getNotationName(); if (publicID != null || systemID != null) { _handleExternalEntity( entity.getNodeName(), publicID, systemID, notationName); } else { _handleInternalEntity(entity); } } NamedNodeMap notations = doctype.getNotations(); int nNotations = notations.getLength(); for (int i = 0; i < nNotations; i++) { Notation notation = (Notation) notations.item(i); String publicID = notation.getPublicId(); String systemID = notation.getSystemId(); dtd_.notationDecl(notation.getNodeName(), publicID, systemID); } } catch (SAXException e) { _errorReport(e); } } private void _handleExternalEntity( String name, String publicID, String systemID, String notationName) { try { if (notationName == null) { decl_.externalEntityDecl(name, publicID, systemID); } else { dtd_.unparsedEntityDecl(name, publicID, systemID, notationName); } } catch (SAXException e) { _errorReport(e); } } private void _handleInternalEntity(Entity entity) { try { decl_.internalEntityDecl( entity.getNodeName(), UDOM.getXMLText(entity)); } catch (SAXException e) { _errorReport(e); } } public boolean enter(DocumentType doctype) { return (false); } public boolean enter(DocumentFragment docfrag) { return (true); } public boolean enter(Notation notation) { return (false); } public boolean enter(Node node) { return (false); } public void leave(Element element) { try { String namespaceURI = element.getNamespaceURI(); if (namespaceURI == null) { namespaceURI = ""; } String localName = element.getLocalName(); String qName = element.getTagName(); content_.endElement(namespaceURI, localName, qName); namespace_.popContext(); } catch (SAXException e) { _errorReport(e); } } public void leave(Attr attr) { } public void leave(Text text) { } public void leave(CDATASection cdata) { } public void leave(EntityReference entityRef) { try { lexical_.endEntity(entityRef.getNodeName()); } catch (SAXException e) { _errorReport(e); } } public void leave(Entity entity) { } public void leave(ProcessingInstruction pi) { } public void leave(Comment comment) { } public void leave(Document doc) { try { content_.endDocument(); } catch (SAXException e) { _errorReport(e); } } public void leave(DocumentType doctype) { } public void leave(DocumentFragment docfrag) { } public void leave(Notation notation) { } public void leave(Node node) { } private void _errorReport(String message) throws DOMVisitorException { _errorReport( new SAXParseException(message, publicID_, systemID_, -1, -1)); } private void _errorReport(SAXException e) throws DOMVisitorException { try { SAXParseException parseException; if (e instanceof SAXParseException) { parseException = (SAXParseException) e; } else { parseException = new SAXParseException( e.getMessage(), publicID_, systemID_, -1, -1, e); } error_.fatalError(parseException); if (throwException_) { throw (new DOMVisitorException(e)); } } catch (SAXException ee) { } } } isorelax-20041111/jp/gr/xml/relax/sax/DTDSkipper.java000066400000000000000000000011451125054436600221450ustar00rootroot00000000000000package jp.gr.xml.relax.sax; import java.io.StringReader; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; /** * DTDSkipper * * @since May. 28, 2001 * @version May. 28, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public class DTDSkipper implements EntityResolver { public InputSource resolveEntity(String publicId, String systemId) { if (!systemId.endsWith(".dtd")) { return (null); } StringReader reader = new StringReader(""); InputSource is = new InputSource(reader); return (is); } } isorelax-20041111/jp/gr/xml/relax/sax/DeclHandlerBase.java000066400000000000000000000015131125054436600231330ustar00rootroot00000000000000package jp.gr.xml.relax.sax; import org.xml.sax.SAXException; import org.xml.sax.ext.DeclHandler; /** * Base class of DeclHandler * * @since Feb. 18, 2001 * @version Feb. 24, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public class DeclHandlerBase implements DeclHandler { public void elementDecl(String name, String model) throws SAXException { } public void attributeDecl( String eName, String aName, String type, String valueDefault, String value) throws SAXException { } public void internalEntityDecl(String name, String value) throws SAXException { } public void externalEntityDecl( String name, String publicId, String systemId) throws SAXException { } } isorelax-20041111/jp/gr/xml/relax/sax/LexicalHandlerBase.java000066400000000000000000000014711125054436600236500ustar00rootroot00000000000000package jp.gr.xml.relax.sax; import org.xml.sax.SAXException; import org.xml.sax.ext.LexicalHandler; /** * Base class of LexicalHandler * * @since Feb. 18, 2001 * @version Feb. 24, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public class LexicalHandlerBase implements LexicalHandler { public void startDTD(String name, String publidId, String systemID) throws SAXException { } public void endDTD() throws SAXException { } public void startEntity(String name) throws SAXException { } public void endEntity(String name) throws SAXException { } public void startCDATA() throws SAXException { } public void endCDATA() throws SAXException { } public void comment(char ch[], int start, int length) { } } isorelax-20041111/jp/gr/xml/relax/sax/RELAXEntityResolver.java000066400000000000000000000022621125054436600237670ustar00rootroot00000000000000package jp.gr.xml.relax.sax; /** * RELAXEntityResolver * * @since Nov. 23, 2000 * @version May. 28, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public class RELAXEntityResolver extends SimpleEntityResolver { public RELAXEntityResolver() { String coreUri = getClass() .getResource("/jp/gr/xml/relax/lib/relaxCore.dtd") .toExternalForm(); String nsUri = getClass() .getResource("/jp/gr/xml/relax/lib/relaxNamespace.dtd") .toExternalForm(); String grammarUri = getClass() .getResource("/jp/gr/xml/relax/lib/relax.dtd") .toExternalForm(); addSystemId("http://www.xml.gr.jp/relax/core1/relaxCore.dtd", coreUri); addSystemId("relaxCore.dtd", coreUri); addSystemId("relaxNamespace.dtd", nsUri); addSystemId("relax.dtd", grammarUri); addPublicId("-//RELAX//DTD RELAX Core 1.0//JA", coreUri); addPublicId("-//RELAX//DTD RELAX Namespace 1.0//JA", nsUri); // XXX addPublicId("-//RELAX//DTD RELAX Grammar 1.0//JA", grammarUri); // XXX } } isorelax-20041111/jp/gr/xml/relax/sax/SimpleEntityResolver.java000066400000000000000000000067261125054436600243560ustar00rootroot00000000000000package jp.gr.xml.relax.sax; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; /** * SimpleEntityResolver * * @since Aug. 12, 2000 * @version May. 28, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public class SimpleEntityResolver implements EntityResolver { private Map publicIds_ = new HashMap(); private Map systemIds_ = new HashMap(); private List relativeSystemIds_ = new ArrayList(); public SimpleEntityResolver() { } public SimpleEntityResolver(String name, String uri) { _init(new String[][] { { name, uri } }, null); } public SimpleEntityResolver(String[][] systemIds) { _init(systemIds, null); } public SimpleEntityResolver(String[][] systemIds, String[][] publicIds) { _init(systemIds, publicIds); } private void _init(String[][] systemIds, String[][] publicIds) { if (systemIds != null) { for (int i = 0; i < systemIds.length; i++) { String systemId = systemIds[i][0]; addSystemId(systemId, systemIds[i][1]); } } if (publicIds != null) { for (int i = 0; i < publicIds.length; i++) { addPublicId(publicIds[i][0], publicIds[i][1]); } } } public void addSystemId(String systemId, String uri) { systemIds_.put(systemId, uri); relativeSystemIds_.add(systemId); } public void addPublicId(String publicId, String uri) { publicIds_.put(publicId, uri); } public InputSource resolveEntity(String publicId, String systemId) { if (systemId != null) { if (_isExist(systemId)) { return (new InputSource(systemId)); } } if (publicId != null) { String uri = (String) publicIds_.get(publicId); if (uri != null) { return (new InputSource(uri)); } else { return (null); } } if (systemId != null) { String uri = _getURIBySystemId(systemId); if (uri != null) { return (new InputSource(uri)); } else { return (new InputSource(systemId)); } } else { return (null); } } private boolean _isExist(String uri) { try { URL url = new URL(uri); if ("file".equals(url.getProtocol())) { InputStream in = url.openStream(); in.close(); return (true); } else { return (false); // XXX : http } } catch (IOException e) { return (false); } } private String _getURIBySystemId(String systemId) { String uri = (String) systemIds_.get(systemId); if (uri != null) { return (uri); } int size = relativeSystemIds_.size(); for (int i = 0; i < size; i++) { String relativeId = (String) relativeSystemIds_.get(i); if (systemId.endsWith(relativeId)) { return ((String) systemIds_.get(relativeId)); } } return (null); } } isorelax-20041111/jp/gr/xml/relax/xml/000077500000000000000000000000001125054436600173355ustar00rootroot00000000000000isorelax-20041111/jp/gr/xml/relax/xml/UXML.java000066400000000000000000000112541125054436600207700ustar00rootroot00000000000000package jp.gr.xml.relax.xml; /** * UXML * * @since Jan. 29, 2000 * @version Feb. 24, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public final class UXML { public static String escape(String string) { if (string.indexOf('<') == -1 && string.indexOf('>') == -1 && string.indexOf('&') == -1 && string.indexOf('"') == -1 && string.indexOf('\'') == -1) { return (string); } StringBuffer buffer = new StringBuffer(); int size = string.length(); for (int i = 0;i < size;i++) { char c = string.charAt(i); if (c == '<') { buffer.append("<"); } else if (c == '>') { buffer.append(">"); } else if (c == '&') { buffer.append("&"); } else if (c == '"') { buffer.append("""); } else if (c == '\'') { buffer.append("'"); } else { buffer.append(c); } } return (new String(buffer)); } public static String escapeEntityQuot(String string) { if (string.indexOf('%') == -1 && string.indexOf('&') == -1 && string.indexOf('"') == -1) { return (string); } StringBuffer buffer = new StringBuffer(); int size = string.length(); for (int i = 0;i < size;i++) { char c = string.charAt(i); if (c == '%') { buffer.append("&---;"); } else if (c == '&') { buffer.append("&"); } else if (c == '"') { buffer.append("""); } else { buffer.append(c); } } return (new String(buffer)); } public static String escapeEntityApos(String string) { if (string.indexOf('%') == -1 && string.indexOf('&') == -1 && string.indexOf('\'') == -1) { return (string); } StringBuffer buffer = new StringBuffer(); int size = string.length(); for (int i = 0;i < size;i++) { char c = string.charAt(i); if (c == '%') { buffer.append("%"); } else if (c == '&') { buffer.append("&"); } else if (c == '\'') { buffer.append("'"); } else { buffer.append(c); } } return (new String(buffer)); } public static String escapeAttrQuot(String string) { if (string.indexOf('<') == -1 && string.indexOf('&') == -1 && string.indexOf('"') == -1) { return (string); } StringBuffer buffer = new StringBuffer(); int size = string.length(); for (int i = 0;i < size;i++) { char c = string.charAt(i); if (c == '<') { buffer.append("<"); } else if (c == '&') { buffer.append("&"); } else if (c == '"') { buffer.append("""); } else { buffer.append(c); } } return (new String(buffer)); } public static String escapeAttrApos(String string) { if (string.indexOf('<') == -1 && string.indexOf('&') == -1 && string.indexOf('\'') == -1) { return (string); } StringBuffer buffer = new StringBuffer(); int size = string.length(); for (int i = 0;i < size;i++) { char c = string.charAt(i); if (c == '<') { buffer.append("<"); } else if (c == '&') { buffer.append("&"); } else if (c == '\'') { buffer.append("'"); } else { buffer.append(c); } } return (new String(buffer)); } public static String escapeSystemQuot(String string) { if (string.indexOf('"') == -1) { return (string); } StringBuffer buffer = new StringBuffer(); int size = string.length(); for (int i = 0;i < size;i++) { char c = string.charAt(i); if (c == '"') { buffer.append("""); } else { buffer.append(c); } } return (new String(buffer)); } public static String escapeSystemApos(String string) { if (string.indexOf('\'') == -1) { return (string); } StringBuffer buffer = new StringBuffer(); int size = string.length(); for (int i = 0;i < size;i++) { char c = string.charAt(i); if (c == '\'') { buffer.append("'"); } else { buffer.append(c); } } return (new String(buffer)); } public static String escapeCharData(String string) { if (string.indexOf('<') == -1 && string.indexOf('&') == -1 && string.indexOf("]]>") == -1) { return (string); } StringBuffer buffer = new StringBuffer(); int nBrackets = 0; int size = string.length(); for (int i = 0;i < size;i++) { char c = string.charAt(i); if (c == '<') { buffer.append("<"); } else if (c == '&') { buffer.append("&"); } else if (c == '>' && nBrackets >= 2) { buffer.append(">"); } else { buffer.append(c); } if (c == ']') { nBrackets++; } else { nBrackets = 0; } } return (new String(buffer)); } } isorelax-20041111/org/000077500000000000000000000000001125054436600143705ustar00rootroot00000000000000isorelax-20041111/org/iso_relax/000077500000000000000000000000001125054436600163555ustar00rootroot00000000000000isorelax-20041111/org/iso_relax/ant/000077500000000000000000000000001125054436600171375ustar00rootroot00000000000000isorelax-20041111/org/iso_relax/ant/ErrorHandlerImpl.java000066400000000000000000000025361125054436600232210ustar00rootroot00000000000000package org.iso_relax.ant; import java.io.PrintWriter; import java.io.StringWriter; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; /** * Error handler implementation that reports errors through * the logging mechanism of Ant task. * * @author Kohsuke Kawaguchi (kk@kohsuke.org) */ public class ErrorHandlerImpl implements ErrorHandler { private final Task task; boolean hadError = false; public ErrorHandlerImpl( Task t ) { this.task = t; } public void warning(SAXParseException e) throws SAXException { print( e, Project.MSG_WARN ); } public void error(SAXParseException e) throws SAXException { print( e, Project.MSG_ERR ); hadError = true; } public void fatalError(SAXParseException e) throws SAXException { print( e, Project.MSG_ERR ); hadError = true; } private void print( SAXParseException e, int msgLevel ) { task.log( e.getMessage(), msgLevel ); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); pw.close(); task.log( sw.toString(), Project.MSG_VERBOSE ); } } isorelax-20041111/org/iso_relax/ant/JARVTask.java000066400000000000000000000105231125054436600213700ustar00rootroot00000000000000package org.iso_relax.ant; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.FileSet; import org.iso_relax.verifier.Verifier; import org.iso_relax.verifier.VerifierConfigurationException; import org.iso_relax.verifier.VerifierFactory; import org.xml.sax.SAXException; /** * Ant Task that performs XML validation through JARV. * * @author Kohsuke Kawaguchi (kk@kohsuke.org) */ public class JARVTask extends Task { /** Schema file. */ private File schemaFile; /** Schema language. */ private String schemaLanguage; /** XML file that will be validated. */ private File xmlFile; /** FileSets to be validated. */ private List xmlFiles = new ArrayList(); /** * Handles the schema attribute. */ public void setSchema(String schemaFilename) { schemaFile = project.resolveFile(schemaFilename); } /** * Handles the schemaLanguage attribute. */ public void setSchemaLanguage(String schemaLanguage) { this.schemaLanguage = schemaLanguage; } /** * Handles the file attribute. */ public void setFile(File file) { this.xmlFile = file; } /** * Handles the nested file set. */ public void addFileset( FileSet fs ) { xmlFiles.add(fs); } public void execute() throws BuildException { try { if( schemaLanguage==null ) throw new BuildException( "schema language needs to be specified through the schemaLanguage attribute", location ); if( schemaFile==null ) throw new BuildException( "schema file needs to be specified through the schema attribute", location ); // load verifier factory VerifierFactory factory; try { factory = VerifierFactory.newInstance(schemaLanguage,this.getClass().getClassLoader()); } catch( VerifierConfigurationException e ) { throw new BuildException( "unable to load a validator for the schema language: "+schemaLanguage, e, location ); } // create a verifier by compiling a schema Verifier verifier; ErrorHandlerImpl errorHandler = new ErrorHandlerImpl(this); try { verifier = factory.newVerifier(schemaFile); verifier.setErrorHandler(errorHandler); } catch( VerifierConfigurationException e ) { throw new BuildException( "failed to compile the schema:"+ e.getMessage(), e, location ); } boolean noError = true; // do the validation if( xmlFile!=null ) { log( "validating "+xmlFile, Project.MSG_INFO ); noError |= verifier.verify( xmlFile ); } for( int i=0; iKohsuke KAWAGUCHI */ public interface AttributesDecl { /** * gets name of this rule. * every AttributesDecl has a unique name within the schema. */ String getName(); /** looks up the value of a feature * * this method works like getFeature method of SAX. * featureName is a fully-qualified URI. * * Implementators are encouraged to invent their own features, * by using their own URIs. */ boolean getFeature( String featureName ) throws SAXNotRecognizedException,SAXNotSupportedException; /** looks up the value of a property * * this method works like getProperty method of SAX. * propertyName is a fully-qualified URI. * * Implementators are encouraged to invent their own properties, * by using their own URIs. */ Object getProperty( String propertyName ) throws SAXNotRecognizedException,SAXNotSupportedException; } isorelax-20041111/org/iso_relax/dispatcher/AttributesVerifier.java000066400000000000000000000001451125054436600251700ustar00rootroot00000000000000package org.iso_relax.dispatcher; public interface AttributesVerifier { // work in progress } isorelax-20041111/org/iso_relax/dispatcher/Dispatcher.java000066400000000000000000000075441125054436600234460ustar00rootroot00000000000000/* * @(#)$Id: Dispatcher.java,v 1.6 2003/05/30 23:46:32 kkawa Exp $ * * Copyright 2001 MURATA Makoto, KAWAGUCHI Kohsuke * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.iso_relax.dispatcher; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; /** * splits incoming SAX events to "islands", and feed events to IslandVerifier. * * @author * MURATA Makoto (FAMILY Given), * Kohsuke KAWAGUCHI * * @version 1.1 */ public interface Dispatcher { /** * configure XMLReader to use this Dispatcher as a ContentHandler. */ void attachXMLReader( XMLReader reader ); /** * switches to the child IslandVerifier. * this method can only be called during startElement method. */ void switchVerifier( IslandVerifier newVerifier ) throws SAXException; /** * sets application-implemented ErrorHandler, which will receive all validation * errors. */ void setErrorHandler( ErrorHandler handler ); /** * gets ErrorHandler to which IslandVerifier reports validation errors. * * the caller may not assume that this method returns the same object * that was passed to setErrorHandler method. * * this method cannot return null. */ ErrorHandler getErrorHandler(); /** get ShcmeaProvider object which is attached to this Dispatcher. */ SchemaProvider getSchemaProvider(); public static class NotationDecl { public final String name; public final String publicId; public final String systemId; public NotationDecl( String name, String publicId, String systemId ) { this.name=name; this.publicId=publicId; this.systemId=systemId; } } /** counts notation declarations found in this XML instance. */ int countNotationDecls(); /** gets ith notation declaration found in this XML instance. * * IslandVerifiers can not receive DTDHandler events. * Those who need DTD information should call this method. */ NotationDecl getNotationDecl( int index ); public static class UnparsedEntityDecl { public final String name; public final String publicId; public final String systemId; public final String notation; public UnparsedEntityDecl( String name, String publicId, String systemId, String notation ) { this.name=name; this.publicId=publicId; this.systemId=systemId; this.notation=notation; } } /** counts unparsed entities found in this XML instance. */ int countUnparsedEntityDecls(); /** gets ith unparsed entity found in this XML instance. * * IslandVerifiers can not receive DTDHandler events. * Those who need DTD information should call this method. */ UnparsedEntityDecl getUnparsedEntityDecl( int index ); } isorelax-20041111/org/iso_relax/dispatcher/ElementDecl.java000066400000000000000000000051321125054436600235300ustar00rootroot00000000000000/* * @(#)$Id: ElementDecl.java,v 1.3 2001/11/01 00:11:45 kkawa Exp $ * * Copyright 2001 Kohsuke KAWAGUCHI * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.iso_relax.dispatcher; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; /** * represents a constraint for one XML element. * * One can obtain an IslandVerifier that validates this constraint by calling * createNewVerifier method of IslandSchema who exported this object. * * This interface also provides feature/property mechanism to encourage * communications between two different implementations. * * @author Kohsuke KAWAGUCHI */ public interface ElementDecl { /** * gets name of this rule. * every ElementDecl has a unique name within the schema. */ String getName(); /** looks up the value of a feature * * this method works like getFeature method of SAX. * featureName is a fully-qualified URI. * * Implementators are encouraged to invent their own features, * by using their own URIs. */ boolean getFeature( String featureName ) throws SAXNotRecognizedException,SAXNotSupportedException; /** looks up the value of a property * * this method works like getProperty method of SAX. * propertyName is a fully-qualified URI. * * Implementators are encouraged to invent their own properties, * by using their own URIs. */ Object getProperty( String propertyName ) throws SAXNotRecognizedException,SAXNotSupportedException; } isorelax-20041111/org/iso_relax/dispatcher/IslandSchema.java000066400000000000000000000070111125054436600237000ustar00rootroot00000000000000/* * @(#)$Id: IslandSchema.java,v 1.5 2003/05/30 23:46:32 kkawa Exp $ * * Copyright 2001 KAWAGUCHI Kohsuke * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.iso_relax.dispatcher; import java.util.Iterator; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; /** * represents a schema that validates one island. * * @author * Kohsuke KAWAGUCHI */ public interface IslandSchema { /** * creates a new IslandVerifier instance that is going to validate * one island. * * @param namespaceURI * namespace URI of the newly found element, which is going to be * validated by the newly created IslandVerifier. * @param elementDecls * set of ElementDecl objects that newly created verifier shall validate. */ IslandVerifier createNewVerifier( String namespaceURI, ElementDecl[] elementDecls ); /** * gets exported elementDecl object that has specified name. * * @return null * if no elementDecl is exported under the given name. */ ElementDecl getElementDeclByName( String name ); /** iterates all exported elementDecl objects. */ Iterator iterateElementDecls(); /** returns all exported elementDecl objects at once. */ ElementDecl[] getElementDecls(); /** * gets exported AttributesDecl object that has specified name. * * @return null * if no AttributesDecl is exported under the given name. */ AttributesDecl getAttributesDeclByName( String name ); /** iterates all exported attributesDecl objects. */ Iterator iterateAttributesDecls(); /** returns all exported attributesDecl objects at once. */ AttributesDecl[] getAttributesDecls(); /** * creates a new AttributesVerifier instance that is going to validate * attribute declarations. * * @param namespaceURI * namespace URI of the attributes, which is going to be * validated by the newly created verifier. * @param decls * set of AttributesDecl objects that newly created verifier shall validate. */ AttributesVerifier createNewAttributesVerifier( String namespaceURI, AttributesDecl[] decls ); /** * binds references to imported elementDecls by using given provider. * * this method is only called once before the first validation starts. * * @exception SAXException * any error has to be reported to ErrorHandler first. */ void bind( SchemaProvider provider, ErrorHandler errorHandler ) throws SAXException; } isorelax-20041111/org/iso_relax/dispatcher/IslandSchemaReader.java000066400000000000000000000032731125054436600250310ustar00rootroot00000000000000/* * @(#)$Id: IslandSchemaReader.java,v 1.4 2001/11/01 00:11:45 kkawa Exp $ * * Copyright 2001 KAWAGUCHI Kohsuke * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.iso_relax.dispatcher; /** * IslandSchemaReader is responsible for parsing IslandSchema. * * @author * Kohsuke KAWAGUCHI */ public interface IslandSchemaReader extends org.xml.sax.ContentHandler { /** * gets parsed schema. * this method is called after parsing is finished. * * @return * return null if parsing was failed * (for example by an error in the schema file). */ IslandSchema getSchema(); } isorelax-20041111/org/iso_relax/dispatcher/IslandVerifier.java000066400000000000000000000054261125054436600242630ustar00rootroot00000000000000/* * @(#)$Id: IslandVerifier.java,v 1.6 2003/05/30 23:46:32 kkawa Exp $ * * Copyright 2001 MURATA Makoto, KAWAGUCHI Kohsuke * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.iso_relax.dispatcher; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; /** * Interface for verifier that validates one island. * * @author * MURATA Makoto (FAMILY Given), * Kohsuke KAWAGUCHI * * @version 1.1 */ public interface IslandVerifier extends ContentHandler { /** * Dispatcher passes itself to IslandVerifier by calling this method * from Dispatcher.switchVerifier method. */ void setDispatcher( Dispatcher disp ); /** * substitute for endDocument event. * * This method is called after endElement method is called * for the top element in the island. * endDocument method is never called for IslandVerifier. * * @return * the callee must return all validated ElementDecls. * If every candidate fails, return an empty array. * * It is the callee's responsibility * to report an error. The callee may also recover from error. * * Never return null. */ public ElementDecl[] endIsland() throws SAXException; /** * this method is called after verification of the child island * is completed, instead of endElement method. * * @param uri * namespace URI of the child island. * @param assignedLabel * set of elementDecls that were successfully assigned * to this child island. * when every elementDecl was failed, then an empty array is passed. */ public void endChildIsland( String uri, ElementDecl assignedDecls[] ) throws SAXException; }isorelax-20041111/org/iso_relax/dispatcher/SchemaProvider.java000066400000000000000000000037731125054436600242730ustar00rootroot00000000000000/* * @(#)$Id: SchemaProvider.java,v 1.6 2003/05/30 23:46:32 kkawa Exp $ * * Copyright 2001 Kohsuke KAWAGUCHI * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.iso_relax.dispatcher; import java.util.Iterator; /** * provides necessary schema information for Dispatcher. * * This interface can be implemented by applications. * * @author Kohsuke KAWAGUCHI */ public interface SchemaProvider { /** * creates IslandVerifier that validates document element. */ IslandVerifier createTopLevelVerifier(); /** * gets IslandSchema whose primary namespace URI is the given value. * * @return null * if no such IslandSchema exists. */ IslandSchema getSchemaByNamespace( String uri ); /** * iterates all namespaces that are registered in this object. */ Iterator iterateNamespace(); /** * returns all IslandSchemata at once. */ IslandSchema[] getSchemata(); } isorelax-20041111/org/iso_relax/dispatcher/impl/000077500000000000000000000000001125054436600214445ustar00rootroot00000000000000isorelax-20041111/org/iso_relax/dispatcher/impl/AbstractSchemaProviderImpl.java000066400000000000000000000046541125054436600275410ustar00rootroot00000000000000/* * @(#)$Id: AbstractSchemaProviderImpl.java,v 1.5 2003/05/30 23:46:32 kkawa Exp $ * * Copyright 2001 Kohsuke KAWAGUCHI * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.iso_relax.dispatcher.impl; import java.util.Iterator; import java.util.Map; import org.iso_relax.dispatcher.IslandSchema; import org.iso_relax.dispatcher.SchemaProvider; /** * default implementation of SchemaProvider. * * Applications can use this class as the base class of their own SchemaProvider. * * @author Kohsuke KAWAGUCHI */ public abstract class AbstractSchemaProviderImpl implements SchemaProvider { /** a map from primary namespace to IslandSchema. */ protected final Map schemata = new java.util.HashMap(); /** adds a new IslandSchema. * * the caller should make sure that the given uri is not defined already. */ public void addSchema( String uri, IslandSchema s ) { if( schemata.containsKey(uri) ) throw new IllegalArgumentException(); schemata.put( uri, s ); } public IslandSchema getSchemaByNamespace( String uri ) { return (IslandSchema)schemata.get(uri); } public Iterator iterateNamespace() { return schemata.keySet().iterator(); } public IslandSchema[] getSchemata() { IslandSchema[] r = new IslandSchema[schemata.size()]; schemata.values().toArray(r); return r; } } isorelax-20041111/org/iso_relax/dispatcher/impl/DispatcherImpl.java000066400000000000000000000167331125054436600252310ustar00rootroot00000000000000/* * @(#)$Id: DispatcherImpl.java,v 1.5 2003/05/30 23:46:32 kkawa Exp $ * * Copyright 2001 Kohsuke KAWAGUCHI * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.iso_relax.dispatcher.impl; import java.util.Enumeration; import java.util.Vector; import org.iso_relax.dispatcher.ElementDecl; import org.iso_relax.dispatcher.IslandVerifier; import org.iso_relax.dispatcher.SchemaProvider; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.DTDHandler; import org.xml.sax.ErrorHandler; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.NamespaceSupport; /** * reference implementation of Dispatcher interface. * * @author * Kohsuke KAWAGUCHI */ public class DispatcherImpl implements org.iso_relax.dispatcher.Dispatcher { /** * depth of the nesting of elements from the start of the current IslandVerifier. * * this value has to start with 1 to prevent initial IslandVerifier * from being cut in. */ private int depth =1; protected Locator documentLocator =null; protected final NamespaceSupport nsMap = new NamespaceSupport(); protected ErrorHandler errorHandler; /** current validating processor which processes this island. */ private IslandVerifier currentHandler =null; /** Dispatcher will consult this object about schema information */ protected final SchemaProvider schema; public SchemaProvider getSchemaProvider() { return schema; } /** this object passes SAX events to IslandVerifier. */ protected Transponder transponder; public DispatcherImpl( SchemaProvider schema ) { this.schema = schema; this.transponder = new Transponder(); this.currentHandler = schema.createTopLevelVerifier(); this.currentHandler.setDispatcher(this); } protected static final class Context { public final IslandVerifier handler; public final int depth; public final Context previous; public Context( IslandVerifier handler, int depth, Context previous ) { this.handler = handler; this.depth = depth; this.previous = previous; } } protected Context contextStack = null; public void attachXMLReader( XMLReader reader ) { reader.setContentHandler(transponder); } public void switchVerifier( IslandVerifier newVerifier ) throws SAXException { // push context contextStack = new Context( currentHandler, depth, contextStack ); currentHandler = newVerifier; currentHandler.setDispatcher(this); currentHandler.setDocumentLocator(documentLocator); depth = 0; // inform new IslandHandler about all prefix mappings Enumeration e = nsMap.getDeclaredPrefixes(); while( e.hasMoreElements() ) { String prefix = (String)e.nextElement(); currentHandler.startPrefixMapping( prefix, nsMap.getURI(prefix) ); } } public void setErrorHandler( ErrorHandler handler ) { this.errorHandler = handler; } public ErrorHandler getErrorHandler() { return errorHandler; } protected final Vector unparsedEntityDecls = new Vector(); public int countUnparsedEntityDecls() { return unparsedEntityDecls.size(); } public UnparsedEntityDecl getUnparsedEntityDecl( int index ) { return (UnparsedEntityDecl)unparsedEntityDecls.get(index); } protected final Vector notationDecls = new Vector(); public int countNotationDecls() { return notationDecls.size(); } public NotationDecl getNotationDecl( int index ) { return (NotationDecl)notationDecls.get(index); } /** * relays SAX events to IslandVerifiers. * * This class is kept separate to make document of Dispatcher cleaner * (by removing SAX events from Dispatcher). */ private class Transponder implements ContentHandler, DTDHandler { public void unparsedEntityDecl( String name, String systemId, String publicId, String notation ) {// memorize unparsedEntityDecl unparsedEntityDecls.add( new UnparsedEntityDecl(name,systemId,publicId,notation) ); } public void notationDecl( String name, String systemId, String publicId ) {// memorize notationDecl notationDecls.add( new NotationDecl(name,systemId,publicId) ); } public void setDocumentLocator( Locator locator ) { documentLocator = locator; currentHandler.setDocumentLocator(locator); } public void startElement( String uri, String localName, String qName, Attributes attributes ) throws SAXException { currentHandler.startElement(uri,localName,qName,attributes); depth++; nsMap.pushContext(); } public void endElement (String uri, String localName, String qName) throws SAXException { nsMap.popContext(); currentHandler.endElement(uri,localName,qName); if( --depth == 0 ) {// cut in and restore the previos IslandVerifier. // call endPrefixMapping for all pre-declared prefixes. Enumeration e = nsMap.getDeclaredPrefixes(); while( e.hasMoreElements() ) currentHandler.endPrefixMapping( (String)e.nextElement() ); // gets labels which are actually verified. ElementDecl[] results = currentHandler.endIsland(); // pop context depth = contextStack.depth; currentHandler = contextStack.handler; contextStack = contextStack.previous; // report assigned label to the parent currentHandler.endChildIsland(uri,results); } } public void characters (char ch[], int start, int length) throws SAXException { currentHandler.characters(ch, start, length); } public void ignorableWhitespace (char ch[], int start, int length) throws SAXException { currentHandler.ignorableWhitespace(ch, start, length); } public void processingInstruction (String target, String data) throws SAXException { currentHandler.processingInstruction (target, data); } public void skippedEntity( String name ) throws SAXException { currentHandler.skippedEntity(name); } // those events should not be reported to island verifier. public void startDocument() {} public void endDocument() {} public void startPrefixMapping(String prefix,String uri) throws SAXException { nsMap.declarePrefix(prefix,uri); currentHandler.startPrefixMapping(prefix,uri); } public void endPrefixMapping(String prefix) throws SAXException { currentHandler.endPrefixMapping(prefix); } } } isorelax-20041111/org/iso_relax/dispatcher/impl/IgnoreVerifier.java000066400000000000000000000064661125054436600252420ustar00rootroot00000000000000/* * @(#)$Id: IgnoreVerifier.java,v 1.5 2003/05/30 23:46:32 kkawa Exp $ * * Copyright 2001 Kohsuke KAWAGUCHI * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.iso_relax.dispatcher.impl; import org.iso_relax.dispatcher.Dispatcher; import org.iso_relax.dispatcher.ElementDecl; import org.iso_relax.dispatcher.IslandSchema; import org.iso_relax.dispatcher.IslandVerifier; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; /** * ignores namespaces which have no associated grammar. * * @author * Kohsuke KAWAGUCHI */ public final class IgnoreVerifier extends DefaultHandler implements IslandVerifier { private final ElementDecl[] rules; /** * * @param assignedRules * this Verifier is supposed to validate these rules. * since this IslandVerifier actually does nothing, * all these rules will be reported as satisfied * upon completion. */ public IgnoreVerifier( String namespaceToIgnore, ElementDecl[] assignedRules ) { this.namespaceToIgnore = namespaceToIgnore; this.rules = assignedRules; } /** * elements in this namespace is validated by this IgnoreVerifier. */ private final String namespaceToIgnore; public ElementDecl[] endIsland() { return rules; } public void endChildIsland( String uri, ElementDecl[] assignedLabels ){} private Dispatcher dispatcher; public void setDispatcher( Dispatcher disp ) { this.dispatcher=disp; } public void startElement( String namespaceURI, String localName, String qName, Attributes attributes ) throws SAXException { if( namespaceToIgnore.equals(namespaceURI) ) return; // this element is "validated". // try to locate a grammar of this namespace IslandSchema is = dispatcher.getSchemaProvider().getSchemaByNamespace(namespaceURI); if( is==null ) {// no grammar is declared with this namespace URI. return; // continue ignoring. } // a schema is found: revert to normal mode and validate them. IslandVerifier iv = is.createNewVerifier( namespaceURI, is.getElementDecls() ); dispatcher.switchVerifier(iv); // simulate this startElement method. iv.startElement(namespaceURI,localName,qName,attributes); } } isorelax-20041111/org/iso_relax/dispatcher/impl/IgnoredSchema.java000066400000000000000000000075211125054436600250240ustar00rootroot00000000000000/* * @(#)$Id: IgnoredSchema.java,v 1.5 2003/05/30 23:46:32 kkawa Exp $ * * Copyright 2001 Kohsuke KAWAGUCHI * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.iso_relax.dispatcher.impl; import java.util.Iterator; import java.util.Vector; import org.iso_relax.dispatcher.AttributesDecl; import org.iso_relax.dispatcher.AttributesVerifier; import org.iso_relax.dispatcher.ElementDecl; import org.iso_relax.dispatcher.IslandSchema; import org.iso_relax.dispatcher.IslandVerifier; import org.iso_relax.dispatcher.SchemaProvider; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXNotRecognizedException; /** * IslandSchema implementation for "ignored" island. * * This schema exports whatever importer wants, and anything is valid in this schema. * * @author Kohsuke KAWAGUCHI */ public class IgnoredSchema implements IslandSchema { private static final ElementDecl[] theElemDecl = new ElementDecl[]{ new ElementDecl(){ public String getName() { return "$$any$$"; } public Object getProperty(String propertyName) throws SAXNotRecognizedException { throw new SAXNotRecognizedException(propertyName); } public boolean getFeature(String featureName) throws SAXNotRecognizedException { throw new SAXNotRecognizedException(featureName); } } }; private static final AttributesDecl[] theAttDecl = new AttributesDecl[]{ new AttributesDecl(){ public String getName() { return "$$any$$"; } public Object getProperty(String propertyName) throws SAXNotRecognizedException { throw new SAXNotRecognizedException(propertyName); } public boolean getFeature(String featureName) throws SAXNotRecognizedException { throw new SAXNotRecognizedException(featureName); } } }; public ElementDecl getElementDeclByName( String name ) { return theElemDecl[0]; } public ElementDecl[] getElementDecls() { return theElemDecl; } public Iterator iterateElementDecls() { Vector vec = new Vector(); vec.add(theElemDecl[0]); return vec.iterator(); } public IslandVerifier createNewVerifier( String namespaceURI, ElementDecl[] rules ) { return new IgnoreVerifier(namespaceURI,rules); } public AttributesDecl getAttributesDeclByName( String name ) { return theAttDecl[0]; } public AttributesDecl[] getAttributesDecls() { return theAttDecl; } public Iterator iterateAttributesDecls() { Vector vec = new Vector(); vec.add(theAttDecl[0]); return vec.iterator(); } public AttributesVerifier createNewAttributesVerifier( String namespaceURI, AttributesDecl[] decls ) { throw new Error("not implemented yet"); } public void bind( SchemaProvider provider, ErrorHandler handler ) {} } isorelax-20041111/org/iso_relax/jaxp/000077500000000000000000000000001125054436600173175ustar00rootroot00000000000000isorelax-20041111/org/iso_relax/jaxp/ValidatingDocumentBuilder.java000066400000000000000000000071721125054436600252610ustar00rootroot00000000000000package org.iso_relax.jaxp; import java.io.File; import java.io.IOException; import java.io.InputStream; import javax.xml.parsers.DocumentBuilder; import org.iso_relax.verifier.Verifier; import org.w3c.dom.DOMImplementation; import org.w3c.dom.Document; import org.xml.sax.EntityResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; /** * Wrapper DocumentBuilder with validation through JARV API. * * @author Daisuke OKAJIMA */ class ValidatingDocumentBuilder extends DocumentBuilder { protected DocumentBuilder _WrappedBuilder; protected Verifier _Verifier; /** * creates a new instance with an internal DocumentBuilder and Schema. * @param wrapped internal DOM parser * @param schema compiled schema. */ public ValidatingDocumentBuilder(DocumentBuilder wrapped, Verifier verifier) { _WrappedBuilder = wrapped; _Verifier = verifier; } /** * Parses the given InputSource and validates the resulting DOM. */ public Document parse(InputSource inputsource) throws SAXException, IOException { return verify(_WrappedBuilder.parse(inputsource)); } /** * Parses the given File and validates the resulting DOM. */ public Document parse(File file) throws SAXException, IOException { return verify(_WrappedBuilder.parse(file)); } /** * Parses the given InputStream and validates the resulting DOM. */ public Document parse(InputStream strm) throws SAXException, IOException { return verify(_WrappedBuilder.parse(strm)); } /** * Parses the given InputStream using the specified systemId and validates the resulting DOM. */ public Document parse(InputStream strm, String systemId) throws SAXException, IOException { return verify(_WrappedBuilder.parse(strm, systemId)); } /** * Parses the given url and validates the resulting DOM. */ public Document parse(String url) throws SAXException, IOException { return verify(_WrappedBuilder.parse(url)); } /** * @see DocumentBuilder#isNamespaceAware() */ public boolean isNamespaceAware() { return _WrappedBuilder.isNamespaceAware(); } /** * returns true always. */ public boolean isValidating() { return true; } /** * @see DocumentBuilder#setEntityResolver(EntityResolver) */ public void setEntityResolver(EntityResolver entityresolver) { _WrappedBuilder.setEntityResolver(entityresolver); _Verifier.setEntityResolver(entityresolver); } /** * @see DocumentBuilder#setErrorHandler(ErrorHandler) */ public void setErrorHandler(ErrorHandler errorhandler) { _WrappedBuilder.setErrorHandler(errorhandler); _Verifier.setErrorHandler(errorhandler); } /** * @see DocumentBuilder#newDocument() */ public Document newDocument() { return _WrappedBuilder.newDocument(); } /** * @see DocumentBuilder#getDOMImplementation() */ public DOMImplementation getDOMImplementation() { return _WrappedBuilder.getDOMImplementation(); } private Document verify(Document dom) throws SAXException, IOException { if(_Verifier.verify(dom)) return dom; else throw new SAXException("the document is invalid, but the ErrorHandler does not throw any Exception."); } } isorelax-20041111/org/iso_relax/jaxp/ValidatingDocumentBuilderFactory.java000066400000000000000000000073441125054436600266120ustar00rootroot00000000000000package org.iso_relax.jaxp; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.iso_relax.verifier.Schema; import org.iso_relax.verifier.VerifierConfigurationException; /** * Wraps another {@link DocumentBuilderFactory} and adds validation capability. * * @author Daisuke OKAJIMA */ public class ValidatingDocumentBuilderFactory extends DocumentBuilderFactory { protected Schema _Schema; protected DocumentBuilderFactory _WrappedFactory; private boolean validation = true; /** * creates a new instance that wraps the default DocumentBuilderFactory * @param schema the compiled Schema object. It can not be null. */ public ValidatingDocumentBuilderFactory(Schema schema) { this(DocumentBuilderFactory.newInstance(), schema); } /** * creates a new instance with an internal DocumentBuilderFactory and Schema. * @param wrapped internal DocumentBuilderFactory * @param schema compiled schema. */ public ValidatingDocumentBuilderFactory(DocumentBuilderFactory wrapped, Schema schema) { _WrappedFactory = wrapped; _Schema = schema; } /** * returns a new DOM parser. * If setValidating(false) is called previously, this method * simply returns the implementation of wrapped DocumentBuilder. */ public DocumentBuilder newDocumentBuilder() throws ParserConfigurationException { if(isValidating()) { try { return new ValidatingDocumentBuilder( _WrappedFactory.newDocumentBuilder(), _Schema.newVerifier()); } catch(VerifierConfigurationException ex) { throw new ParserConfigurationException(ex.getMessage()); } } else //if validation is disabled, we simply return the implementation of wrapped DocumentBuilder return _WrappedFactory.newDocumentBuilder(); } /** * @see DocumentBuilderFactory#setAttribute(String, Object) */ public void setAttribute(String name, Object value) { _WrappedFactory.setAttribute(name, value); } /** * @see DocumentBuilderFactory#getAttribute(String) */ public Object getAttribute(String name) { return _WrappedFactory.getAttribute(name); } public boolean isValidating() { return validation; } public void setValidating(boolean _validating) { this.validation = _validating; } public boolean isCoalescing() { return _WrappedFactory.isCoalescing(); } public boolean isExpandEntityReference() { return _WrappedFactory.isExpandEntityReferences(); } public boolean isIgnoringComments() { return _WrappedFactory.isIgnoringComments(); } public boolean isIgnoringElementContentWhitespace() { return _WrappedFactory.isIgnoringElementContentWhitespace(); } public boolean isNamespaceAware() { return _WrappedFactory.isNamespaceAware(); } public void setCoalescing(boolean coalescing) { _WrappedFactory.setCoalescing(coalescing); } public void setExpandEntityReference(boolean expandEntityRef) { _WrappedFactory.setExpandEntityReferences(expandEntityRef); } public void setIgnoringComments(boolean ignoreComments) { _WrappedFactory.setIgnoringComments(ignoreComments); } public void setIgnoringElementContentWhitespace(boolean whitespace) { _WrappedFactory.setIgnoringElementContentWhitespace(whitespace); } public void setNamespaceAware(boolean awareness) { _WrappedFactory.setNamespaceAware(awareness); } } isorelax-20041111/org/iso_relax/jaxp/ValidatingSAXParser.java000066400000000000000000000116231125054436600240000ustar00rootroot00000000000000package org.iso_relax.jaxp; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import javax.xml.parsers.SAXParser; import org.iso_relax.verifier.Verifier; import org.xml.sax.HandlerBase; import org.xml.sax.InputSource; import org.xml.sax.Parser; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; import org.xml.sax.XMLFilter; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; /** * Wrapper SAXParser with validation through JARV API. For the present, SAX1 * features are not supported. * * @author Daisuke OKAJIMA */ class ValidatingSAXParser extends SAXParser { protected SAXParser _WrappedParser; protected Verifier _Verifier; /** * creates a new instance with an internal SAXParser and Schema. * @param wrapped internal SAXParser * @param schema compiled schema. */ public ValidatingSAXParser(SAXParser wrapped, Verifier verifier) { _WrappedParser = wrapped; _Verifier = verifier; } /** * unsupported */ public Parser getParser() { throw new UnsupportedOperationException("getParser() method is not supported. Use getXMLReader()."); } /** * returns a new XMLReader for parsing and validating the input */ public XMLReader getXMLReader() throws SAXException { XMLFilter filter = _Verifier.getVerifierFilter(); filter.setParent(_WrappedParser.getXMLReader()); return filter; } /** * @see SAXParser#isNamespaceAware() */ public boolean isNamespaceAware() { return _WrappedParser.isNamespaceAware(); } /** * returns true always */ public boolean isValidating() { return true; } /** * @see SAXParser#setProperty(String, Object) */ public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { _WrappedParser.setProperty(name, value); } /** * @see SAXParser#getProperty(String) */ public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException { return _WrappedParser.getProperty(name); } //SAX1 features are not supported public void parse(File f, HandlerBase hb) { throw new UnsupportedOperationException("SAX1 features are not supported"); } public void parse(InputSource is, HandlerBase hb) { throw new UnsupportedOperationException("SAX1 features are not supported"); } public void parse(InputStream is, HandlerBase hb) { throw new UnsupportedOperationException("SAX1 features are not supported"); } public void parse(InputStream is, HandlerBase hb, String systemId) { throw new UnsupportedOperationException("SAX1 features are not supported"); } public void parse(String uri, HandlerBase hb) { throw new UnsupportedOperationException("SAX1 features are not supported"); } /** * parses and validates the given File using the given DefaultHandler */ public void parse(File f, DefaultHandler dh) throws SAXException, IOException { XMLReader reader = getXMLReader(); InputSource source = new InputSource(new FileInputStream(f)); reader.setContentHandler(dh); reader.parse(source); } /** * parses and validates the given InputSource using the given DefaultHandler */ public void parse(InputSource source, DefaultHandler dh) throws SAXException, IOException { XMLReader reader = getXMLReader(); reader.setContentHandler(dh); reader.parse(source); } /** * parses and validates the given InputSource using the given DefaultHandler */ public void parse(InputStream is, DefaultHandler dh) throws SAXException, IOException { XMLReader reader = getXMLReader(); InputSource source = new InputSource(is); reader.setContentHandler(dh); reader.parse(source); } /** * parses and validates the given InputSream using the given DefaultHandler and systemId */ public void parse(InputStream is, DefaultHandler dh, String systemId) throws SAXException, IOException { XMLReader reader = getXMLReader(); InputSource source = new InputSource(is); source.setSystemId(systemId); reader.setContentHandler(dh); reader.parse(source); } /** * parses and validates the given uri using the given DefaultHandler */ public void parse(String uri, DefaultHandler dh) throws SAXException, IOException { XMLReader reader = getXMLReader(); InputSource source = new InputSource(uri); reader.setContentHandler(dh); reader.parse(source); } } isorelax-20041111/org/iso_relax/jaxp/ValidatingSAXParserFactory.java000066400000000000000000000056241125054436600253340ustar00rootroot00000000000000package org.iso_relax.jaxp; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import org.iso_relax.verifier.Schema; import org.iso_relax.verifier.VerifierConfigurationException; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; /** * Wraps another {@link SAXParserFactory} and adds validation capability. * * @author Daisuke OKAJIMA */ public class ValidatingSAXParserFactory extends SAXParserFactory { protected SAXParserFactory _WrappedFactory; protected Schema _Schema; private boolean validation = true; /** * creates a new instance that wraps the default DocumentBuilderFactory * @param schema the compiled Schema object. It can not be null. */ public ValidatingSAXParserFactory(Schema schema) { this(SAXParserFactory.newInstance(), schema); } /** * creates a new instance with an internal SAXParserFactory and Schema. * @param wrapped internal SAXParser * @param schema compiled schema. */ public ValidatingSAXParserFactory(SAXParserFactory wrapped, Schema schema) { _WrappedFactory = wrapped; _Schema = schema; } /** * returns a new SAX parser. * If setValidating(false) is called previously, this method simply * returns the implementation of wrapped SAXParser. */ public SAXParser newSAXParser() throws ParserConfigurationException, SAXException { if(isValidating()) { try { return new ValidatingSAXParser( _WrappedFactory.newSAXParser(), _Schema.newVerifier()); } catch(VerifierConfigurationException ex) { throw new ParserConfigurationException(ex.getMessage()); } } else return _WrappedFactory.newSAXParser(); } /** * @see SAXParserFactory#setFeature(String, boolean) */ public void setFeature(String name, boolean value) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException { _WrappedFactory.setFeature(name, value); } /** * @see SAXParserFactory#getFeature(String) */ public boolean getFeature(String name) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException { return _WrappedFactory.getFeature(name); } public boolean isNamespaceAware() { return _WrappedFactory.isNamespaceAware(); } public void setNamespaceAware(boolean awareness) { _WrappedFactory.setNamespaceAware(awareness); } public boolean isValidating() { return validation; } public void setValidating(boolean validating) { validation = validating; } } isorelax-20041111/org/iso_relax/verifier/000077500000000000000000000000001125054436600201705ustar00rootroot00000000000000isorelax-20041111/org/iso_relax/verifier/Schema.java000066400000000000000000000012061125054436600222320ustar00rootroot00000000000000package org.iso_relax.verifier; /** * The compiled representation of schemas. * *

* Schema object must be thread-safe; multiple-threads can access * one Schema obejct at the same time. * *

* The schema object allows an application to "cache" a schema by compiling it * once and using it many times, possibly by different threads. */ public interface Schema { /** * creates a new Verifier object that validates documents with this schema. * * @return * a valid non-null instance of a Verifier. */ Verifier newVerifier() throws VerifierConfigurationException; } isorelax-20041111/org/iso_relax/verifier/Verifier.java000066400000000000000000000147371125054436600226220ustar00rootroot00000000000000package org.iso_relax.verifier; import java.io.File; import java.io.IOException; import org.w3c.dom.Node; import org.xml.sax.EntityResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; /** * An instance of this interface can validates documents. * *

* An instance of this interface can be obtained through the * {@link VerifierFactory#newVerifier} method or * {@link Schema#newVerifier} method. * Once it is created, an application can use one instance to validate * multiple documents. * *

* This interface is not thread-safe and not reentrant. * That is, only one thread can use it at any given time, and you can only * validate one document at any given time. * * @since Feb. 23, 2001 * @version Mar. 4, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) * @author Kohsuke KAWAGUCHI */ public interface Verifier { /** * a read-only feature that checks whether the implementation supports * getVerifierHandler method. * *

* Now a verifier implementation is required to support * VerifierHandler. Therefore an application doesn't need to * check this feature. * * @deprecated */ String FEATURE_HANDLER = "http://www.iso-relax.org/verifier/handler"; /** * a read-only feature that checks whether the implementation supports * getVerifierFilter method. * *

* Now a verifier implementation is required to support * VerifierFilter. * Therefore an application doesn't need to check this feature. * * @deprecated */ String FEATURE_FILTER = "http://www.iso-relax.org/verifier/filter"; /** * Checks whether a feature is supported or not. * *

* This method is modeled after SAX2. * * @param feature feature name */ boolean isFeature(String feature) throws SAXNotRecognizedException, SAXNotSupportedException; /** * Sets a value to a feature. * *

* This method is modeled after SAX2. * * @param feature feature name * @param value feature value */ void setFeature(String feature, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException; /** * Gets a property value * *

* This method is modeled after SAX2. * * @param property property name */ Object getProperty(String property) throws SAXNotRecognizedException, SAXNotSupportedException; /** * Sets a property value * *

* This method is modeled after SAX2. * * @param property property name * @param value property value */ void setProperty(String property, Object value) throws SAXNotRecognizedException, SAXNotSupportedException; /** * Sets a ErrorHandler that receives validation * errors/warnings. * *

* If no error handler is set explicitly, a verifier implementation * will not report any error/warning at all. However, the caller can * still obtain the result of validation through the return value. * *

* Conscious developers should always set an error handler explicitly * as the default behavior has been changed several times. * * @param handler * this object will receive errors/warning encountered * during the validation. */ void setErrorHandler(ErrorHandler handler); /** * Sets a EntityResolver to resolve external entity locations. * *

* The given entity resolver is used in the * {@link verify(String)} method and the * {@link verify(InputSource)} method. * * @param handler EntityResolver */ void setEntityResolver(EntityResolver handler); /** * validates an XML document. * * @param uri * URI of a document. * * @return * true if the document is valid. * false if otherwise. */ boolean verify(String uri) throws SAXException, IOException; /** * validates an XML document. * * @param source InputSource of a XML document to verify. * * @return * true if the document is valid. * false if otherwise. */ boolean verify(InputSource source) throws SAXException, IOException; /** * validates an XML document. * * @param file * File to be validated * * @return * true if the document is valid. * false if otherwise. */ boolean verify(File file) throws SAXException, IOException; /** * validates an XML document. * *

* An implementation is required to accept Document object * as the node parameter. If it also implements partial validation, * it can also accepts things like Element. * * @param node * the root DOM node of an XML document. * * @exception UnsupportedOperationException * If the node type of the node parameter is something which * this implementation does not support. * * @return * true if the document is valid. * false if otherwise. */ boolean verify(Node node) throws SAXException; /** * Gets a VerifierHandler. * *

* you can use the returned * VerifierHandler to validate documents * through SAX. * *

* Note that two different invocations of this method * can return the same value; this method does NOT * necessarily create a new VerifierHandler object. */ VerifierHandler getVerifierHandler() throws SAXException; /** * Gets a VerifierFilter. * *

* you can use the returned * VerifierHandler to validate documents * through SAX. * *

* Note that two different invocations of this method * can return the same value; this method does NOT * necessarily create a new VerifierFilter object. */ VerifierFilter getVerifierFilter() throws SAXException; } isorelax-20041111/org/iso_relax/verifier/VerifierConfigurationException.java000066400000000000000000000025601125054436600272200ustar00rootroot00000000000000package org.iso_relax.verifier; import java.io.PrintStream; import java.io.PrintWriter; /** * VerifierConfigurationException * * @since Feb. 23, 2001 * @version Apr. 17, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public class VerifierConfigurationException extends Exception { private Exception cause_ = null; public VerifierConfigurationException(String message) { super(message); } public VerifierConfigurationException(Exception e) { super(e.getMessage()); cause_ = e; } public VerifierConfigurationException(String message, Exception e) { super(message); cause_ = e; } public Exception getException() { if (cause_ != null) { return (cause_); } else { return (this); } } public Exception getCauseException() { return (cause_); } public void printStackTrace() { printStackTrace(new PrintWriter(System.err, true)); } public void printStackTrace(PrintStream out) { printStackTrace(new PrintWriter(out)); } public void printStackTrace(PrintWriter writer) { if (writer == null) { writer = new PrintWriter(System.err, true); } super.printStackTrace(writer); if (cause_ != null) { writer.println(); writer.println("StackTrace of Original Exception:"); cause_.printStackTrace(writer); } } } isorelax-20041111/org/iso_relax/verifier/VerifierException.java000066400000000000000000000021561125054436600244710ustar00rootroot00000000000000package org.iso_relax.verifier; import java.io.PrintStream; import java.io.PrintWriter; import org.xml.sax.SAXException; /** * VerifierException * * @since Feb. 23, 2001 * @version Mar. 4, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public class VerifierException extends SAXException { public VerifierException(String message) { super(message); } public VerifierException(Exception e) { super(e); } public VerifierException(String message, Exception e) { super(message,e); } public void printStackTrace() { printStackTrace(new PrintWriter(System.err, true)); } public void printStackTrace(PrintStream out) { printStackTrace(new PrintWriter(out)); } public void printStackTrace(PrintWriter writer) { if (writer == null) { writer = new PrintWriter(System.err, true); } super.printStackTrace(writer); Exception cause = super.getException(); if (cause != null) { writer.println(); writer.println("StackTrace of Original Exception:"); cause.printStackTrace(writer); } } } isorelax-20041111/org/iso_relax/verifier/VerifierFactory.java000066400000000000000000000316601125054436600241440ustar00rootroot00000000000000package org.iso_relax.verifier; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.Vector; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; /** * VerifierFactory * * @since Feb. 23, 2001 * @version Apr. 17, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) * @author Kohsuke KAWAGUCHI */ public abstract class VerifierFactory { /** * parses a schema at the specified location and returns a Verifier object * that validates documents by using that schema. * *

* Some of XML parsers accepts filenames as well as URLs, while others * reject them. Therefore, to parse a file as a schema, you should use * a File object. * * @param uri URI of a schema file */ public Verifier newVerifier(String uri) throws VerifierConfigurationException, SAXException, IOException { return compileSchema(uri).newVerifier(); } /** * parses a schema from the specified file and returns a Verifier object * that validates documents by using that schema. * * @param uri File of a schema file */ public Verifier newVerifier(File file) throws VerifierConfigurationException, SAXException, IOException { return compileSchema(file).newVerifier(); } /** * parses a schema from the specified InputStream and returns a Verifier object * that validates documents by using that schema. */ public Verifier newVerifier(InputStream stream) throws VerifierConfigurationException, SAXException, IOException { return compileSchema( stream, null ).newVerifier(); } /** * parses a schema from the specified InputStream and returns a Verifier object * that validates documents by using that schema. * * @param systemId * System ID of this stream. */ public Verifier newVerifier(InputStream stream, String systemId ) throws VerifierConfigurationException, SAXException, IOException { return compileSchema(stream,systemId).newVerifier(); } /** * parses a schema from the specified InputSource and returns a Verifier object * that validates documents by using that schema. * * @param source InputSource of a schema file */ public Verifier newVerifier(InputSource source) throws VerifierConfigurationException, SAXException, IOException { return compileSchema(source).newVerifier(); } /** * processes a schema into a Schema object, which is a compiled representation * of a schema. * * The obtained schema object can then be used concurrently across multiple * threads. */ public abstract Schema compileSchema( InputSource is ) throws VerifierConfigurationException, SAXException, IOException; /** * processes a schema into a Schema object, which is a compiled representation * of a schema. * * The obtained schema object can then be used concurrently across multiple * threads. * *

* Some of XML parsers accepts filenames as well as URLs, while others * reject them. Therefore, to parse a file as a schema, you should use * a File object. * * @param url * A source url of a schema file to be compiled. */ public Schema compileSchema( String url ) throws VerifierConfigurationException, SAXException, IOException { return compileSchema( new InputSource(url) ); } /** * processes a schema into a Schema object, which is a compiled representation * of a schema. * * The obtained schema object can then be used concurrently across multiple * threads. * * @param stream * A stream object that holds a schema. */ public Schema compileSchema( InputStream stream ) throws VerifierConfigurationException, SAXException, IOException { return compileSchema(stream,null); } /** * processes a schema into a Schema object, which is a compiled representation * of a schema. * * The obtained schema object can then be used concurrently across multiple * threads. * * @param systemId * The system Id of this input stream. */ public Schema compileSchema( InputStream stream, String systemId ) throws VerifierConfigurationException, SAXException, IOException { InputSource is = new InputSource(stream); is.setSystemId(systemId); return compileSchema(is); } /** * processes a schema into a Schema object, which is a compiled representation * of a schema. * * The obtained schema object can then be used concurrently across multiple * threads. * * @param file * A schema file to be compiled */ public Schema compileSchema( File f ) throws VerifierConfigurationException, SAXException, IOException { String uri = "file:" + f.getAbsolutePath(); if (File.separatorChar == '\\') { uri = uri.replace('\\', '/'); } return compileSchema(new InputSource(uri)); } /** * Indicates whether if the feature is supported, or not. * * @param feature feature name */ public boolean isFeature(String feature) throws SAXNotRecognizedException, SAXNotSupportedException { if (Verifier.FEATURE_HANDLER.equals(feature) || Verifier.FEATURE_FILTER.equals(feature)) return true; throw new SAXNotRecognizedException(feature); } /** * Sets feature value * * @param feature feature name * @param value feature value */ public void setFeature(String feature, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { throw new SAXNotRecognizedException(feature); } /** * Gets property value * * @param property property name */ public Object getProperty(String property) throws SAXNotRecognizedException, SAXNotSupportedException { throw new SAXNotRecognizedException(property); } /** * Sets property value * * @param property property name * @param value property value */ public void setProperty(String property, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { throw new SAXNotRecognizedException(property); } private EntityResolver resolver = null; /** * Sets an EntityResolver * * This entity resolver is used to resolve entities encountered while * parsing a schema. */ public void setEntityResolver( EntityResolver _resolver ) { this.resolver = _resolver; } /** * Gets the current entity resolver, which was set by * the SetEntityResolver method. */ public EntityResolver getEntityResolver() { return resolver; } /** * Creates a new instance of a VerifierFactory. * * @deprecated */ public static VerifierFactory newInstance() throws VerifierConfigurationException { return newInstance("http://www.xml.gr.jp/xmlns/relaxNamespace"); } /** * Creates a new instance of a VerifierFactory for the specified schema language. * * @param language * URI that specifies the schema language. * *

* It is preferable to use the namespace URI of the schema language * to designate the schema language. For example, * * * * * * * * * * * * * * * * * * * * * * * * * * *
URIlanguage
http://relaxng.org/ns/structure/0.9 * RELAX NG *
http://www.xml.gr.jp/xmlns/relaxCore * RELAX Core *
http://www.xml.gr.jp/xmlns/relaxNamespace * RELAX Namespace *
http://www.thaiopensource.com/trex * TREX *
http://www.w3.org/2001/XMLSchema * W3C XML Schema *
http://www.w3.org/XML/1998/namespace * XML DTD *
* * @param classLoader * This class loader is used to search the available implementation. * * @return * a non-null valid VerifierFactory instance. * * @exception VerifierConfigurationException * if no implementation is available for the specified language. */ public static VerifierFactory newInstance(String language,ClassLoader classLoader) throws VerifierConfigurationException { Iterator itr = providers( VerifierFactoryLoader.class, classLoader ); while(itr.hasNext()) { VerifierFactoryLoader loader = (VerifierFactoryLoader)itr.next(); try { VerifierFactory factory = loader.createFactory(language); if(factory!=null) return factory; } catch (Throwable t) {} // ignore any error } throw new VerifierConfigurationException("no validation engine available for: "+language); } public static VerifierFactory newInstance(String language) throws VerifierConfigurationException { return newInstance(language,VerifierFactoryLoader.class.getClassLoader()); } private static HashMap providerMap = new HashMap(); // K.K: the following providers method is copied from Apache Batik project. /***************************************************************************** * Copyright (C) The Apache Software Foundation. All rights reserved. * * ------------------------------------------------------------------------- * * This software is published under the terms of the Apache Software License * * version 1.1, a copy of which has been included with this distribution in * * the LICENSE file. * *****************************************************************************/ /* * version Service.java,v 1.1 2001/04/27 19:55:44 deweese Exp */ private static synchronized Iterator providers(Class cls,ClassLoader cl) { String serviceFile = "META-INF/services/"+cls.getName(); // System.out.println("File: " + serviceFile); Vector v = (Vector)providerMap.get(serviceFile); if (v != null) return v.iterator(); v = new Vector(); providerMap.put(serviceFile, v); Enumeration e; try { e = cl.getResources(serviceFile); } catch (IOException ioe) { return v.iterator(); } while (e.hasMoreElements()) { try { URL u = (URL)e.nextElement(); // System.out.println("URL: " + u); InputStream is = u.openStream(); Reader r = new InputStreamReader(is, "UTF-8"); BufferedReader br = new BufferedReader(r); String line = br.readLine(); while (line != null) { try { // First strip any comment... int idx = line.indexOf('#'); if (idx != -1) line = line.substring(0, idx); // Trim whitespace. line = line.trim(); // If nothing left then loop around... if (line.length() == 0) { line = br.readLine(); continue; } // System.out.println("Line: " + line); // Try and load the class Object obj = cl.loadClass(line).newInstance(); // stick it into our vector... v.add(obj); } catch (Exception ex) { // Just try the next line // ex.printStackTrace(); } line = br.readLine(); } } catch (Exception ex) { // Just try the next file... } } return v.iterator(); } } isorelax-20041111/org/iso_relax/verifier/VerifierFactoryLoader.java000066400000000000000000000012241125054436600252640ustar00rootroot00000000000000package org.iso_relax.verifier; /** * A class that provides information about the verifier implementation. * *

* Implementations of this interface are discovered through * META-INF/services, just like JAXP. This object then * provides VerifierFactory implementation for the specified schema language. * * @author Kohsuke KAWAGUCHI */ public interface VerifierFactoryLoader { /** * returns a VerifierFactory that supports the specified schema language, * or returns null if it's not supported. */ VerifierFactory createFactory( String schemaLanguage ); } isorelax-20041111/org/iso_relax/verifier/VerifierFilter.java000066400000000000000000000017001125054436600237520ustar00rootroot00000000000000package org.iso_relax.verifier; import org.xml.sax.XMLFilter; /** * XMLFilter implementation that validates a document. * *

* An instance of this interface can be obtained through the * {@link Verifier#getVerifierFilter} method. * *

* The implementation validates incoming SAX events and then pass it * to the successive SAX handlers. * * @since Feb. 23, 2001 * @version Feb. 24, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public interface VerifierFilter extends XMLFilter { /** * checks if the document was valid. * *

* This method can be only called after this handler receives * the endDocument event. * * @return * true if the document was valid, * false if not. * * @exception IllegalStateException * If this method is called before the endDocument event is dispatched. */ boolean isValid() throws IllegalStateException; } isorelax-20041111/org/iso_relax/verifier/VerifierHandler.java000066400000000000000000000021711125054436600241050ustar00rootroot00000000000000package org.iso_relax.verifier; import org.xml.sax.ContentHandler; /** * SAX2 ContentHandler implementation that validates a document. * *

* An instance of this interface can be obtained through the * {@link Verifier#getVerifierHandler} method. * *

* The implementation validates incoming SAX events. * The application can check the result by calling the isValid method. * * @since Feb. 23, 2001 * @version Feb. 24, 2001 * @author ASAMI, Tomoharu (asami@zeomtech.com) */ public interface VerifierHandler extends ContentHandler { /** * Checks if the document was valid. * *

* This method can be only called after this handler receives * the endDocument event. * *

* If you need to know the error at an earlier moment, * you should set an error handler to {@link Verifier}. * * @return * true if the document was valid, * false if not. * * @exception IllegalStateException * If this method is called before the endDocument event is dispatched. */ boolean isValid() throws IllegalStateException; } isorelax-20041111/org/iso_relax/verifier/impl/000077500000000000000000000000001125054436600211315ustar00rootroot00000000000000isorelax-20041111/org/iso_relax/verifier/impl/ForkContentHandler.java000066400000000000000000000060031125054436600255250ustar00rootroot00000000000000package org.iso_relax.verifier.impl; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.Locator; import org.xml.sax.SAXException; /** * ContentHandler that "forks" the incoming SAX2 events to * two ContentHandlers. * * * @version $Id: ForkContentHandler.java,v 1.3 2003/05/30 23:46:33 kkawa Exp $ * @author Kohsuke KAWAGUCHI */ public class ForkContentHandler implements ContentHandler { /** * Creates a ForkContentHandler. * * @param first * This handler will receive a SAX event first. * @param second * This handler will receive a SAX event after the first handler * receives it. */ public ForkContentHandler( ContentHandler first, ContentHandler second ) { lhs = first; rhs = second; } /** * Creates ForkContentHandlers so that the specified handlers * will receive SAX events in the order of the array. */ public static ContentHandler create( ContentHandler[] handlers ) { if(handlers.length==0) throw new IllegalArgumentException(); ContentHandler result = handlers[0]; for( int i=1; i * call the makeEvent method to use it. * * @author * ASAMI, Tomoharu (asami@zeomtech.com) * Kohsuke KAWAGUCHI */ public class SAXEventGenerator implements IDOMVisitor { private Node root_; private boolean needDocumentEmulation_ = true; private String systemID_; private String publicID_; private DTDHandler dtd_; private ContentHandler content_; private DeclHandler decl_; private LexicalHandler lexical_; private ErrorHandler error_; private final NamespaceSupport namespace_ = new NamespaceSupport(); public SAXEventGenerator(Node node) { root_ = node; DefaultHandler handler = new DefaultHandler(); dtd_ = handler; content_ = handler; error_ = handler; lexical_ = new LexicalHandlerBase(); decl_ = new DeclHandlerBase(); } public void setDocumentEmulation(boolean emulate) { needDocumentEmulation_ = emulate; } public void setDTDHandler(DTDHandler dtd) { dtd_ = dtd; } public void setContentHandler(ContentHandler content) { content_ = content; } public void setLexicalHandler(LexicalHandler lexical) { lexical_ = lexical; } public void setDeclHandler(DeclHandler decl) { decl_ = decl; } public void setErrorHandler(ErrorHandler error) { error_ = error; } public void makeEvent() throws SAXException { try { if (!(root_ instanceof Document) && needDocumentEmulation_) { emulateStartDocument(); UDOMVisitor.traverse(root_, this); emulateEndDocument(); } else { UDOMVisitor.traverse(root_, this); } } catch (DOMVisitorException e) { Exception cause = e.getCauseException(); if (cause == null) { throw (new SAXException(e.getMessage())); } else if (cause instanceof SAXException) { throw ((SAXException)cause); } else { throw (new SAXException(e.getMessage())); } } } public void makeEvent(ContentHandler handler) throws SAXException { setContentHandler(handler); makeEvent(); } public void emulateStartDocument() { try { _handleLocator(); content_.startDocument(); } catch (SAXException e) { _errorReport(e); } } public void emulateEndDocument() { try { content_.endDocument(); } catch (SAXException e) { _errorReport(e); } } public boolean enter(Element element) { try { namespace_.pushContext(); String namespaceURI = element.getNamespaceURI(); if (namespaceURI == null) { namespaceURI = ""; } String localName = element.getLocalName(); String qName = element.getTagName(); if(localName==null) localName = qName; NamedNodeMap attrMap = element.getAttributes(); AttributesImpl attrs = new AttributesImpl(); int size = attrMap.getLength(); for (int i = 0;i < size;i++) { Attr attr = (Attr)attrMap.item(i); String attrNamespaceURI = attr.getNamespaceURI(); if (attrNamespaceURI == null) { attrNamespaceURI = ""; } String attrLocalName = attr.getLocalName(); String attrQName = attr.getName(); if(attrLocalName==null) attrLocalName = attrQName; String attrValue = attr.getValue(); if (attrQName.startsWith("xmlns")) { String prefix; int index = attrQName.indexOf(':'); if (index == -1) { prefix = ""; } else { prefix = attrQName.substring(index + 1); } if (!namespace_.declarePrefix(prefix, attrValue)) { _errorReport("bad prefix = " + prefix); } else { content_.startPrefixMapping(prefix, attrValue); } } else { attrs.addAttribute( attrNamespaceURI, attrLocalName, attrQName, "CDATA", attrValue ); } } content_.startElement(namespaceURI, localName, qName, attrs); } catch (SAXException e) { _errorReport(e); } return (true); } public boolean enter(Attr attr) { return (false); } public boolean enter(Text text) { try { String data = text.getData(); content_.characters(data.toCharArray(), 0, data.length()); } catch (SAXException e) { _errorReport(e); } return (false); } public boolean enter(CDATASection cdata) { try { lexical_.startCDATA(); String data = cdata.getData(); content_.characters(data.toCharArray(), 0, data.length()); lexical_.endCDATA(); } catch (SAXException e) { _errorReport(e); } return (false); } public boolean enter(EntityReference entityRef) { try { lexical_.startEntity(entityRef.getNodeName()); } catch (SAXException e) { _errorReport(e); } return (true); } public boolean enter(Entity entity) { return (false); } public boolean enter(ProcessingInstruction pi) { try { content_.processingInstruction(pi.getTarget(), pi.getData()); } catch (SAXException e) { _errorReport(e); } return (false); } public boolean enter(Comment comment) { try { String data = comment.getData(); lexical_.comment(data.toCharArray(), 0, data.length()); } catch (SAXException e) { _errorReport(e); } return (false); } public boolean enter(Document doc) { try { _handleLocator(); content_.startDocument(); _handleDoctype(doc.getDoctype()); } catch (SAXException e) { _errorReport(e); } return (true); } private void _handleLocator() { if (systemID_ == null && publicID_ == null) { return; } _locatorEvent(systemID_, publicID_); } private void _locatorEvent(String systemID, String publicID) { LocatorImpl locator = new LocatorImpl(); locator.setSystemId(systemID_); locator.setPublicId(publicID_); locator.setLineNumber(-1); locator.setColumnNumber(-1); content_.setDocumentLocator(locator); } private void _handleDoctype(DocumentType doctype) { try { if (doctype == null) { return; } String systemID = doctype.getSystemId(); String publicID = doctype.getPublicId(); String internalSubset = doctype.getInternalSubset(); if (systemID != null) { lexical_.startDTD(doctype.getName(), publicID, systemID); if (internalSubset == null) { lexical_.endDTD(); _handleEntities(doctype); } else { _handleEntities(doctype); lexical_.endDTD(); } } else { _handleEntities(doctype); } } catch (SAXException e) { _errorReport(e); } } private void _handleEntities(DocumentType doctype) { try { NamedNodeMap entities = doctype.getEntities(); int nEntities = entities.getLength(); for (int i = 0;i < nEntities;i++) { Entity entity = (Entity)entities.item(i); String publicID = entity.getPublicId(); String systemID = entity.getSystemId(); String notationName = entity.getNotationName(); if (publicID != null || systemID != null) { _handleExternalEntity( entity.getNodeName(), publicID, systemID, notationName ); } else { _handleInternalEntity(entity); } } NamedNodeMap notations = doctype.getNotations(); int nNotations = notations.getLength(); for (int i = 0;i < nNotations;i++) { Notation notation = (Notation)notations.item(i); String publicID = notation.getPublicId(); String systemID = notation.getSystemId(); dtd_.notationDecl(notation.getNodeName(), publicID, systemID); } } catch (SAXException e) { _errorReport(e); } } private void _handleExternalEntity( String name, String publicID, String systemID, String notationName ) { try { if (notationName == null) { decl_.externalEntityDecl(name, publicID, systemID); } else { dtd_.unparsedEntityDecl( name, publicID, systemID, notationName ); } } catch (SAXException e) { _errorReport(e); } } private void _handleInternalEntity(Entity entity) { try { decl_.internalEntityDecl( entity.getNodeName(), UDOM.getXMLText(entity) ); } catch (SAXException e) { _errorReport(e); } } public boolean enter(DocumentType doctype) { return (false); } public boolean enter(DocumentFragment docfrag) { return (true); } public boolean enter(Notation notation) { return (false); } public boolean enter(Node node) { return (false); } public void leave(Element element) { try { String namespaceURI = element.getNamespaceURI(); if (namespaceURI == null) { namespaceURI = ""; } String localName = element.getLocalName(); String qName = element.getTagName(); if(localName==null) localName=qName; content_.endElement(namespaceURI, localName, qName); for (Enumeration e=namespace_.getDeclaredPrefixes(); e.hasMoreElements(); ) content_.endPrefixMapping( (String)e.nextElement() ); namespace_.popContext(); } catch (SAXException e) { _errorReport(e); } } public void leave(Attr attr) { } public void leave(Text text) { } public void leave(CDATASection cdata) { } public void leave(EntityReference entityRef) { try { lexical_.endEntity(entityRef.getNodeName()); } catch (SAXException e) { _errorReport(e); } } public void leave(Entity entity) { } public void leave(ProcessingInstruction pi) { } public void leave(Comment comment) { } public void leave(Document doc) { try { content_.endDocument(); } catch (SAXException e) { _errorReport(e); } } public void leave(DocumentType doctype) { } public void leave(DocumentFragment docfrag) { } public void leave(Notation notation) { } public void leave(Node node) { } private void _errorReport(String message) throws DOMVisitorException { _errorReport( new SAXParseException( message, publicID_, systemID_, -1, -1 ) ); } private void _errorReport(SAXException e) throws DOMVisitorException { try { SAXParseException parseException; if (e instanceof SAXParseException) { parseException = (SAXParseException)e; } else { parseException = new SAXParseException( e.getMessage(), publicID_, systemID_, -1, -1, e ); } error_.fatalError(parseException); throw new DOMVisitorException(e); } catch (SAXException ee) { throw new DOMVisitorException(ee); } } } isorelax-20041111/org/iso_relax/verifier/impl/VerifierFilterImpl.java000066400000000000000000000072751125054436600255520ustar00rootroot00000000000000package org.iso_relax.verifier.impl; import org.iso_relax.verifier.Verifier; import org.iso_relax.verifier.VerifierFilter; import org.iso_relax.verifier.VerifierHandler; import org.xml.sax.Attributes; import org.xml.sax.EntityResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.helpers.XMLFilterImpl; /** * plain vanilla {@link VerifierFilter} implementation. * *

* A verifier implementation can use this class to support VerifierFilter functionality. * *

* To use this class, implement the {@link Verifier#getVerifierFilter()} method * as follows: *

 * public VerifierFilter getVerifierFilter() throws SAXException {
 *   return new VerifierFilterImpl(getVerifierHandler());
 * }
 * 
* *

* Also, usually you may want to override setErrorHandler method so that * your VerifierHandler will send errors to that handler. * * @version $Id: VerifierFilterImpl.java,v 1.5 2003/05/30 23:46:33 kkawa Exp $ * @author Kohsuke KAWAGUCHI */ public class VerifierFilterImpl extends XMLFilterImpl implements VerifierFilter { public VerifierFilterImpl( Verifier _verifier ) throws SAXException { this.verifier = _verifier; this.core = verifier.getVerifierHandler(); } private final Verifier verifier; private final VerifierHandler core; public boolean isValid() { return core.isValid(); } public void setErrorHandler( ErrorHandler handler ) { super.setErrorHandler(handler); // we need to call the setErrorHandler method of the verifier, // so that the verifier handler will use this error handler from now on. verifier.setErrorHandler(handler); } public void setEntityResolver( EntityResolver resolver ) { super.setEntityResolver(resolver); verifier.setEntityResolver(resolver); } // // // ContentHandler events // // public void setDocumentLocator (Locator locator) { core.setDocumentLocator(locator); super.setDocumentLocator(locator); } public void startDocument() throws SAXException { core.startDocument(); super.startDocument(); } public void endDocument () throws SAXException { core.endDocument(); super.endDocument(); } public void startPrefixMapping (String prefix, String uri) throws SAXException { core.startPrefixMapping(prefix,uri); super.startPrefixMapping(prefix,uri); } public void endPrefixMapping (String prefix) throws SAXException { core.endPrefixMapping(prefix); super.endPrefixMapping(prefix); } public void startElement (String uri, String localName, String qName, Attributes attributes) throws SAXException { core.startElement(uri,localName,qName,attributes); super.startElement(uri,localName,qName,attributes); } public void endElement (String uri, String localName, String qName) throws SAXException { core.endElement(uri,localName,qName); super.endElement(uri,localName,qName); } public void characters (char ch[], int start, int length) throws SAXException { core.characters(ch,start,length); super.characters(ch,start,length); } public void ignorableWhitespace (char ch[], int start, int length) throws SAXException { core.ignorableWhitespace(ch,start,length); super.ignorableWhitespace(ch,start,length); } public void processingInstruction (String target, String data) throws SAXException { core.processingInstruction(target,data); super.processingInstruction(target,data); } public void skippedEntity (String name) throws SAXException { core.skippedEntity(name); super.skippedEntity(name); } } isorelax-20041111/org/iso_relax/verifier/impl/VerifierImpl.java000066400000000000000000000112231125054436600243700ustar00rootroot00000000000000package org.iso_relax.verifier.impl; import java.io.File; import java.io.IOException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; import org.iso_relax.verifier.Verifier; import org.iso_relax.verifier.VerifierConfigurationException; import org.iso_relax.verifier.VerifierFilter; import org.iso_relax.verifier.VerifierHandler; import org.w3c.dom.Node; import org.xml.sax.EntityResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader; /** * Partial implementation of {@link Verifier}. * *

* This class is useful as the base class of the verifier implementation. * *

* The only remaining method that has to be implemented by the derived * class is the getVerifierHandler method. Please be noted * that applications can call the setErrorHandler method * after the getVerifierHandler method and that change * should take effect. * * * @version $Id: VerifierImpl.java,v 1.4 2003/05/30 23:46:33 kkawa Exp $ * @author Kohsuke KAWAGUCHI */ public abstract class VerifierImpl implements Verifier { protected XMLReader reader; protected VerifierImpl() throws VerifierConfigurationException { prepareXMLReader(); } /** * Creates and sets a sole instance of XMLReader which will be used * by this verifier. */ protected void prepareXMLReader() throws VerifierConfigurationException { try { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); reader = factory.newSAXParser().getXMLReader(); } catch( SAXException e ) { throw new VerifierConfigurationException(e); } catch( ParserConfigurationException pce ) { throw new VerifierConfigurationException(pce); } } public boolean isFeature(String feature) throws SAXNotRecognizedException, SAXNotSupportedException { if (FEATURE_HANDLER.equals(feature) || FEATURE_FILTER.equals(feature)) return true; throw new SAXNotRecognizedException(feature); } public void setFeature(String feature, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { throw new SAXNotRecognizedException(feature); } public Object getProperty(String property) throws SAXNotRecognizedException, SAXNotSupportedException { throw new SAXNotRecognizedException(property); } public void setProperty(String property, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { throw new SAXNotRecognizedException(property); } // default error handler must not report any error. protected ErrorHandler errorHandler = new ErrorHandler(){ public void warning( SAXParseException e ) {} public void error( SAXParseException e ) {} public void fatalError( SAXParseException e ) {} }; public void setErrorHandler(ErrorHandler handler) { this.errorHandler = handler; } protected EntityResolver entityResolver; public void setEntityResolver(EntityResolver resolver ) { this.entityResolver = resolver; } public boolean verify(String uri) throws SAXException, IOException { return verify( new InputSource(uri) ); } public boolean verify(InputSource source) throws SAXException, IOException { VerifierHandler handler = getVerifierHandler(); reader.setErrorHandler(errorHandler); if(entityResolver!=null) reader.setEntityResolver(entityResolver); reader.setContentHandler(handler); reader.parse(source); return handler.isValid(); } public boolean verify(File f) throws SAXException, IOException { String uri = "file:" + f.getAbsolutePath(); if (File.separatorChar == '\\') { uri = uri.replace('\\', '/'); } return verify(new InputSource(uri)); } public boolean verify(Node node) throws SAXException { SAXEventGenerator generator = new SAXEventGenerator(node); // generate startDocument/endDocument events generator.setDocumentEmulation(true); generator.setErrorHandler(errorHandler); VerifierHandler handler = getVerifierHandler(); generator.makeEvent(handler); return handler.isValid(); } public abstract VerifierHandler getVerifierHandler() throws SAXException; private VerifierFilter filter; public VerifierFilter getVerifierFilter() throws SAXException { if(filter==null) filter = new VerifierFilterImpl(this); return filter; } }