Class Converter
java.lang.Object
org.exolab.castor.xml.dtd.Converter
Class containing methods to parse and convert XML DTD
documents to corresponding XML Schema documents. Also contains simple command
line interface to read an XML DTD file and create corresponding XML Schema
object.
- Version:
- $Revision: 8519 $ $Date: 2006-04-14 04:14:43 -0600 (Fri, 14 Apr 2006) $
- Author:
- Alexander Totok
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconvertAttribute(Attribute dtdAttribute, Schema schema) Convert DTD Attribute declaration to Schema Attribute Declaration.convertContentParticle(ContentParticle dtdContent, Schema schema) Method to convertContentParticleobject, used to implement element content in the DTD object model, to the corresponding object in the Schema object model: eitherGrouporElementDecl.convertDTDElementToSchemaElement(Element dtdElement, Schema schema) Convert DTD Element declaration to Schema Element Declaration.convertDTDObjectToSchemaObject(DTDdocument dtd, String targetNamespace, Map nameSpaceMap) Convert DTD document object to corresponding Schema object.voidconvertDTDtoSchema(Reader reader, Writer writer) Convert DTD document to corresponding XML Schema document.voidconvertDTDtoSchema(Reader reader, Writer writer, String targetNameSpace, Map<String, String> nameSpaceMap) Convert DTD document to corresponding XML Schema document.protected static booleanisNameSpacePrefix(String nameSpacePrefix2test) static voidSimple command line interface to read an XML DTD file and create corresponding XML Schema file.voidmarshalSchema(Schema schema, Writer writer) Marshals XML Schema to output char stream.Parses text of a DTD document and returns corresponding DTD document object.parseNamespace(String nameSpaceArg) voidprocess(Reader in, Writer out, String encoding, String targetNamespace, Map<String, String> namespaces) voidprocess(String dtdFile, String schemaFile, String encoding, String targetNamespace, Map<String, String> namespaces)
-
Field Details
-
NAME_SPACE_PREFIX_KEY
- See Also:
-
NAME_SPACE_KEY
- See Also:
-
DEFAULT_NAME_SPACE_PREFIX
- See Also:
-
DEFAULT_NAME_SPACE
- See Also:
-
-
Constructor Details
-
Converter
public Converter()
-
-
Method Details
-
main
public static void main(String[] args) throws IOException, DTDException, SchemaException, SAXException Simple command line interface to read an XML DTD file and create corresponding XML Schema file. Usage:java org.exolab.castor.xml.dtd.Converter dtd_file xsd_file [character_encoding] [-tns=[TNS_PREFIX:]NAMESPACE_URI] [-xmlns=[TNS_PREFIX:]NAMESPACE_URI]* dtd_file: name of the input DTD file xsd_file: name of the output Schema file character_encoding: name of the character encoding, if not specified, ASCII is chosenHelp message is provided.- Throws:
DTDException- if the input DTD document is malformed.SchemaException- if Schema object can not be created.SAXException- if an error occured during marshalling of schema object constructed from the DTD document.IOException
-
process
public void process(String dtdFile, String schemaFile, String encoding, String targetNamespace, Map<String, String> namespaces) throws SchemaException, DTDException, IOException, SAXException- Parameters:
dtdFile- Location of the DTD file.schemaFile- Location of the XML schema file.encoding- (Optional) encoding.targetNamespace- (Optional) target name space.namespaces- (Optional) XML name spaces.- Throws:
SchemaExceptionDTDExceptionIOExceptionSAXException
-
process
public void process(Reader in, Writer out, String encoding, String targetNamespace, Map<String, String> namespaces) throws SchemaException, DTDException, IOException, SAXException- Parameters:
in- Location of the DTD file.out- Location of the XML schema file.encoding- (Optional) encoding.targetNamespace- (Optional) target name space.namespaces- (Optional) XML name spaces.- Throws:
SchemaExceptionDTDExceptionIOExceptionSAXException
-
parseNamespace
-
isNameSpacePrefix
-
convertDTDtoSchema
public void convertDTDtoSchema(Reader reader, Writer writer, String targetNameSpace, Map<String, String> nameSpaceMap) throws DTDException, SchemaException, IOException, SAXExceptionConvert DTD document to corresponding XML Schema document.- Parameters:
reader- reader of the input DTD document.writer- writer to the output Schema document.nameSpaceMap- (Optional) XML name space declarations for the XML schema.targetNameSpaceMap- (Optional) XML target name space for the XML schema.- Throws:
DTDException- if the DTD document is syntactically or semantically not correct.SchemaException- if Schema object can not be created.IOException- if there is an I/O problem with the reader or writer.SAXException- if an error occured during schema object marshalling.
-
convertDTDtoSchema
public void convertDTDtoSchema(Reader reader, Writer writer) throws DTDException, SchemaException, IOException, SAXException Convert DTD document to corresponding XML Schema document.- Parameters:
reader- reader of the input DTD document.writer- writer to the output Schema document.- Throws:
DTDException- if the DTD document is syntactically or semanticly not correct.SchemaException- if Schema object can not be created.IOException- if there is an I/O problem with the reader or writer.SAXException- if an error occured during schema object marshalling.
-
parseDTD
Parses text of a DTD document and returns corresponding DTD document object. It is left to constructor of the reader to set up character encoding correctly. This means that method read of the reader is used to get next character, assuming it returns appropriate values.- Parameters:
reader- input char stream reader. It is recommended to use classjava.io.InputStreamReaderas a reader, which allows to set desired character encoding.- Returns:
- DTD document object corresponding to the input text of a DTD document.
- Throws:
DTDException- if the DTD document is syntactically or semanticly not correct.
-
convertDTDObjectToSchemaObject
public Schema convertDTDObjectToSchemaObject(DTDdocument dtd, String targetNamespace, Map nameSpaceMap) throws DTDException, SchemaException Convert DTD document object to corresponding Schema object.- Parameters:
dtd- input XML DTD document object.nameSpacePrefix-nameSpace-- Returns:
- corresponding XML Schema object.
- Throws:
DTDException- if the input DTD document is malformed.SchemaException- if Schema object can not be created.
-
convertDTDElementToSchemaElement
public ElementDecl convertDTDElementToSchemaElement(Element dtdElement, Schema schema) throws DTDException, SchemaException Convert DTD Element declaration to Schema Element Declaration.- Parameters:
dtdElement- DTD Element declaration.schema- Schema owning Element declaration.- Returns:
- corresponding Schema Element declaration.
- Throws:
DTDException- if the input DTD Element Declaration is malformed.SchemaException- if unable to construct returnElementDeclobject from the input DTDElementobject.
-
convertContentParticle
public Particle convertContentParticle(ContentParticle dtdContent, Schema schema) throws DTDException, SchemaException Method to convertContentParticleobject, used to implement element content in the DTD object model, to the corresponding object in the Schema object model: eitherGrouporElementDecl.- Parameters:
dtdContent- inputContentParticleobject.- Returns:
- object returned is an instance of either
Groupclass orElementDeclclass. - Throws:
DTDException- if the input ContentParticle is malformed.SchemaException- if unable to construct return content object from a given ContentParticle
-
convertAttribute
Convert DTD Attribute declaration to Schema Attribute Declaration.- Parameters:
dtdAttribute- DTD Attribute declaration.schema- Schema owning Element of this Attribute.- Returns:
- corresponding Schema Attribute declaration.
- Throws:
DTDException- if the input DTD Attribute Declaration is malformed.
-
marshalSchema
Marshals XML Schema to output char stream.- Parameters:
schema- XML Schema object to marshal.writer- output char stream to marshal Schema to.- Throws:
IOException- if there is an I/O problem with the writer.SAXException- if an error occured during schema marshalling.
-