Search in sources :

Example 1 with DOMParser

use of com.sun.org.apache.xerces.internal.parsers.DOMParser in project cogtool by cogtool.

the class BalsamiqButtonAPIConverter method parseBalsamiqFile.

/** Helper function used by importDesign.
	 * This method is used to parse the tags of each .bmml file in the 
	 * directory. The file represents a {@link File} in the directory.
     * 
     * @param  inputFile the specified directory or file
     * @see              the new design in the project window.
     */
public void parseBalsamiqFile(File inputFile) throws IOException {
    String fileName = inputFile.getName();
    int lastIndex = fileName.lastIndexOf(".");
    fileName = (lastIndex == -1) ? fileName : fileName.substring(0, lastIndex);
    /* Check to make sure that this frame has not been created yet. Cycles 
		 * by transitions may exist in the design and these files do not need 
		 * to be parsed more than once. */
    if (!visitedFramesNames.contains(fileName)) {
        visitedFramesNames.add(fileName);
        // Create a Xerces DOM Parser. A DOM Parser can parse an XML file
        // and create a tree representation of it. This same parser method
        // is used in ImportCogTool.java to import from CogTool XML.
        DOMParser parser = new DOMParser();
        InputStream fis = new FileInputStream(inputFile);
        Reader input = new InputStreamReader(fis, "UTF-8");
        // Parse the Document and traverse the DOM
        try {
            parser.parse(new InputSource(input));
        } catch (SAXException e) {
            throw new RcvrImportException("Not a valid XML file to parse.");
        }
        //Traverse the xml tags in the tree beginning at the root, the document
        Document document = parser.getDocument();
        parseFrame(document, fileName);
    }
}
Also used : InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) RcvrImportException(edu.cmu.cs.hcii.cogtool.util.RcvrImportException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) DOMParser(com.sun.org.apache.xerces.internal.parsers.DOMParser) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException)

Aggregations

DOMParser (com.sun.org.apache.xerces.internal.parsers.DOMParser)1 RcvrImportException (edu.cmu.cs.hcii.cogtool.util.RcvrImportException)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 Document (org.w3c.dom.Document)1 InputSource (org.xml.sax.InputSource)1 SAXException (org.xml.sax.SAXException)1