pax_global_header 0000666 0000000 0000000 00000000064 11250544366 0014520 g ustar 00root root 0000000 0000000 52 comment=3f4f8bb9cbf499ba3f7f429e231b35241b6391a3
isorelax-20041111/ 0000775 0000000 0000000 00000000000 11250544366 0013601 5 ustar 00root root 0000000 0000000 isorelax-20041111/jp/ 0000775 0000000 0000000 00000000000 11250544366 0014212 5 ustar 00root root 0000000 0000000 isorelax-20041111/jp/gr/ 0000775 0000000 0000000 00000000000 11250544366 0014622 5 ustar 00root root 0000000 0000000 isorelax-20041111/jp/gr/xml/ 0000775 0000000 0000000 00000000000 11250544366 0015422 5 ustar 00root root 0000000 0000000 isorelax-20041111/jp/gr/xml/relax/ 0000775 0000000 0000000 00000000000 11250544366 0016535 5 ustar 00root root 0000000 0000000 isorelax-20041111/jp/gr/xml/relax/dom/ 0000775 0000000 0000000 00000000000 11250544366 0017314 5 ustar 00root root 0000000 0000000 isorelax-20041111/jp/gr/xml/relax/dom/DOMVisitorException.java 0000664 0000000 0000000 00000002475 11250544366 0024045 0 ustar 00root root 0000000 0000000 package 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.java 0000664 0000000 0000000 00000004336 11250544366 0022275 0 ustar 00root root 0000000 0000000 package 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.java 0000664 0000000 0000000 00000001302 11250544366 0020717 0 ustar 00root root 0000000 0000000 package 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.java 0000664 0000000 0000000 00000006462 11250544366 0022313 0 ustar 00root root 0000000 0000000 package 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.java 0000664 0000000 0000000 00000017417 11250544366 0021611 0 ustar 00root root 0000000 0000000 package 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("" + tag + ">");
}
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("");
buffer_.append(pi.getTarget());
buffer_.append(" ");
buffer_.append(pi.getData());
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/ 0000775 0000000 0000000 00000000000 11250544366 0017310 5 ustar 00root root 0000000 0000000 isorelax-20041111/jp/gr/xml/relax/dtd/DTDVerifier.java_ 0000664 0000000 0000000 00000011442 11250544366 0022423 0 ustar 00root root 0000000 0000000 package 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_ 0000664 0000000 0000000 00000003156 11250544366 0023756 0 ustar 00root root 0000000 0000000 package 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/ 0000775 0000000 0000000 00000000000 11250544366 0017303 5 ustar 00root root 0000000 0000000 isorelax-20041111/jp/gr/xml/relax/lib/datatypes.mod 0000664 0000000 0000000 00000007050 11250544366 0022004 0 ustar 00root root 0000000 0000000
isorelax-20041111/jp/gr/xml/relax/lib/datatypes.rxm 0000664 0000000 0000000 00000012474 11250544366 0022041 0 ustar 00root root 0000000 0000000
isorelax-20041111/jp/gr/xml/relax/lib/relax.dtd 0000664 0000000 0000000 00000001137 11250544366 0021115 0 ustar 00root root 0000000 0000000
%relaxCore;
%relaxNamespace;
isorelax-20041111/jp/gr/xml/relax/lib/relax.rxg 0000664 0000000 0000000 00000003443 11250544366 0021144 0 ustar 00root root 0000000 0000000
isorelax-20041111/jp/gr/xml/relax/lib/relaxCore.dtd 0000664 0000000 0000000 00000022426 11250544366 0021732 0 ustar 00root root 0000000 0000000
%datatype-definitions;
isorelax-20041111/jp/gr/xml/relax/lib/relaxCore.rxm 0000664 0000000 0000000 00000030752 11250544366 0021766 0 ustar 00root root 0000000 0000000
]>
isorelax-20041111/jp/gr/xml/relax/lib/relaxNamespace.dtd 0000664 0000000 0000000 00000004637 11250544366 0022742 0 ustar 00root root 0000000 0000000
isorelax-20041111/jp/gr/xml/relax/lib/relaxNamespace.rxm 0000664 0000000 0000000 00000005543 11250544366 0022772 0 ustar 00root root 0000000 0000000
isorelax-20041111/jp/gr/xml/relax/lib/relaxNg.rxm 0000664 0000000 0000000 00000007536 11250544366 0021446 0 ustar 00root root 0000000 0000000
isorelax-20041111/jp/gr/xml/relax/sax/ 0000775 0000000 0000000 00000000000 11250544366 0017330 5 ustar 00root root 0000000 0000000 isorelax-20041111/jp/gr/xml/relax/sax/DOMSAXProducer.java 0000664 0000000 0000000 00000005451 11250544366 0022677 0 ustar 00root root 0000000 0000000 package 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.java 0000664 0000000 0000000 00000031521 11250544366 0024254 0 ustar 00root root 0000000 0000000 package 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.java 0000664 0000000 0000000 00000001145 11250544366 0022145 0 ustar 00root root 0000000 0000000 package 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.java 0000664 0000000 0000000 00000001513 11250544366 0023133 0 ustar 00root root 0000000 0000000 package 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.java 0000664 0000000 0000000 00000001471 11250544366 0023650 0 ustar 00root root 0000000 0000000 package 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.java 0000664 0000000 0000000 00000002262 11250544366 0023767 0 ustar 00root root 0000000 0000000 package 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.java 0000664 0000000 0000000 00000006726 11250544366 0024356 0 ustar 00root root 0000000 0000000 package 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/ 0000775 0000000 0000000 00000000000 11250544366 0017335 5 ustar 00root root 0000000 0000000 isorelax-20041111/jp/gr/xml/relax/xml/UXML.java 0000664 0000000 0000000 00000011254 11250544366 0020770 0 ustar 00root root 0000000 0000000 package 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/ 0000775 0000000 0000000 00000000000 11250544366 0014370 5 ustar 00root root 0000000 0000000 isorelax-20041111/org/iso_relax/ 0000775 0000000 0000000 00000000000 11250544366 0016355 5 ustar 00root root 0000000 0000000 isorelax-20041111/org/iso_relax/ant/ 0000775 0000000 0000000 00000000000 11250544366 0017137 5 ustar 00root root 0000000 0000000 isorelax-20041111/org/iso_relax/ant/ErrorHandlerImpl.java 0000664 0000000 0000000 00000002536 11250544366 0023221 0 ustar 00root root 0000000 0000000 package 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.java 0000664 0000000 0000000 00000010523 11250544366 0021370 0 ustar 00root root 0000000 0000000 package 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; i