de.bsd.x2svg.parsers
Class DtdParser

java.lang.Object
  extended by de.bsd.x2svg.parsers.DtdParser
All Implemented Interfaces:
InputParser

public class DtdParser
extends java.lang.Object
implements InputParser

A parser that reads Document Type Descriptions (DTDs)

Author:
hwr@pilhuhn.de

Field Summary
private  boolean alsoAttributes
           
private  java.io.File dtdFile
           
private  java.lang.String dtdRootName
           
private static java.lang.String FILE_SUFFIX_STRING
           
private static java.lang.String MODE_STRING
           
private  boolean shouldGuessDtdRootName
           
private  int treeDepth
           
 
Constructor Summary
DtdParser()
           
 
Method Summary
private  void addAttributes(Container cont, com.wutka.dtd.DTDElement element)
          Extract the attributes from the element.
 java.lang.String getFileSuffix()
          Return the file suffix this parser reacts upon
 java.lang.String getMode()
          Our mode is 'dtd'
 java.lang.String getSpecificHelp()
          Additional help for this parser
private  Container parse(Container parent, com.wutka.dtd.DTD dtd, com.wutka.dtd.DTDElement root, int level)
          Recursively pare the DTD and fill its data into containers.
private  Container parse(Container parent, com.wutka.dtd.DTD dtd, com.wutka.dtd.DTDItem root, int level)
          Recursively parse the DTD and fill its data into containers (This method deals with DTDItem, rather than DTDElement).
 Container parseInput()
          Parse the input.
private  void setCardinality(Container cont, com.wutka.dtd.DTDCardinal cardinal)
          Set the cardinality of the container depending on the DTD cardinality
private  void setContentModel(Container cont, com.wutka.dtd.DTDItem item)
          Set the content model in the container from the passed item
 void setDebug()
          Tells the parer to set the debug mode.
 void setInputFile(java.io.File inputFile)
          Sets the input file to work on
 void setParserOptions(java.lang.String[] options)
          Set the parser specific options.
 void setWithAttributes(boolean value)
          Tells the parser that parsing attributes of elements is wanted.
 void setWithElementComments(boolean value)
          Tells the parser that parsing comments for elements (and possibly attributes) is desired.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_STRING

private static final java.lang.String MODE_STRING
See Also:
Constant Field Values

FILE_SUFFIX_STRING

private static final java.lang.String FILE_SUFFIX_STRING
See Also:
Constant Field Values

dtdFile

private java.io.File dtdFile

dtdRootName

private java.lang.String dtdRootName

shouldGuessDtdRootName

private boolean shouldGuessDtdRootName

treeDepth

private int treeDepth

alsoAttributes

private boolean alsoAttributes
Constructor Detail

DtdParser

public DtdParser()
Method Detail

parseInput

public Container parseInput()
                     throws java.io.IOException,
                            ParserProblemException
Parse the input. The dtdFile and dtdRootElement need to be set previously.If the dtdRootElement is null or empty, the parser will then try to guess it

Specified by:
parseInput in interface InputParser
Returns:
container tree of this DTD starting at the element specified in dtdRootName
Throws:
ParserProblemException - If a problem with the passed DTD is found
java.io.IOException - if the underlying DTDParser encounters a problem.
See Also:
Container

parse

private Container parse(Container parent,
                        com.wutka.dtd.DTD dtd,
                        com.wutka.dtd.DTDItem root,
                        int level)
                 throws ParserProblemException
Recursively parse the DTD and fill its data into containers (This method deals with DTDItem, rather than DTDElement).

Parameters:
parent - The parent container where our stuff will be appended to
dtd - The DTD to use
root - The 'current' root item of this part of the DTD tree
level - How deep do we want the generated tree to be? 0=root element only
Returns:
container tree of this DTD starting at the root element
Throws:
ParserProblemException - If a DTD element that is referred to can not be found.

parse

private Container parse(Container parent,
                        com.wutka.dtd.DTD dtd,
                        com.wutka.dtd.DTDElement root,
                        int level)
                 throws ParserProblemException
Recursively pare the DTD and fill its data into containers.

Parameters:
parent - the parent container of those that will be created on this round. null if it is the parent is the tree root.
dtd - The DTD to use
root - The 'current' root element of this part of the DTD tree
level - How deep do we want the generated tree to be? 0=root element only
Returns:
container tree of this DTD starting at the root element
Throws:
ParserProblemException - If a DTD element that is referred to can not be found.

addAttributes

private void addAttributes(Container cont,
                           com.wutka.dtd.DTDElement element)
Extract the attributes from the element. We currently only use their name

Parameters:
cont - Container to put the attributes into
element - The element from where the attributes get pulled.

setCardinality

private void setCardinality(Container cont,
                            com.wutka.dtd.DTDCardinal cardinal)
Set the cardinality of the container depending on the DTD cardinality

Parameters:
cont - The container to fill
cardinal - The cardinality of the DTD

setContentModel

private void setContentModel(Container cont,
                             com.wutka.dtd.DTDItem item)
Set the content model in the container from the passed item

Parameters:
cont - The container to fill
item - The DTDitem from where information is obtained

setInputFile

public void setInputFile(java.io.File inputFile)
Sets the input file to work on

Specified by:
setInputFile in interface InputParser
Parameters:
inputFile - a valid file object to work on

setParserOptions

public void setParserOptions(java.lang.String[] options)
Set the parser specific options. These are: [-d depth] [root-element]

Specified by:
setParserOptions in interface InputParser
Parameters:
options - array of individual option parts as passed on the command line.

getSpecificHelp

public java.lang.String getSpecificHelp()
Additional help for this parser

Specified by:
getSpecificHelp in interface InputParser
Returns:
a help string or null if no help is available.

getFileSuffix

public java.lang.String getFileSuffix()
Description copied from interface: InputParser
Return the file suffix this parser reacts upon

Specified by:
getFileSuffix in interface InputParser
Returns:
the file suffix

getMode

public java.lang.String getMode()
Our mode is 'dtd'

Specified by:
getMode in interface InputParser
Returns:
the mode string

setDebug

public void setDebug()
Description copied from interface: InputParser
Tells the parer to set the debug mode. It depends on the individual parser if it actually has a debug mode.

Specified by:
setDebug in interface InputParser

setWithAttributes

public void setWithAttributes(boolean value)
Description copied from interface: InputParser
Tells the parser that parsing attributes of elements is wanted. It depends on the individual parser if it acutally can parse them. For example the DtdParser is able to do this, while the PropertiesParser is not.

Specified by:
setWithAttributes in interface InputParser
Parameters:
value - The value to set this to.

setWithElementComments

public void setWithElementComments(boolean value)
Description copied from interface: InputParser
Tells the parser that parsing comments for elements (and possibly attributes) is desired.
It depends on the individual parser if it actually can parse them

Specified by:
setWithElementComments in interface InputParser
Parameters:
value - The value to set this to.


x2svg version 1.2.1