Java Code Examples for javax.xml.parsers.ParserConfigurationException#printStackTrace()

The following examples show how to use javax.xml.parsers.ParserConfigurationException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConQATOutputParser.java    From JDeodorant with MIT License 6 votes vote down vote up
public ConQATOutputParser(IJavaProject iJavaProject, String cloneOutputFilePath) throws InvalidInputFileException {
	super(iJavaProject, cloneOutputFilePath);
	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	factory.setIgnoringElementContentWhitespace(true);
	try {
		DocumentBuilder builder = factory.newDocumentBuilder();
		File file = new File(this.getToolOutputFilePath());
		this.document = builder.parse(file);
		NodeList cloneClassesNodeList = document.getElementsByTagName("cloneClass");
		if (cloneClassesNodeList.getLength() != 0) {
			this.setCloneGroupCount(cloneClassesNodeList.getLength());
		} else {			
			this.document = null;
			throw new InvalidInputFileException();
		}
	} catch (IOException ioex) {
		ioex.printStackTrace();
	} catch (SAXException saxe) {
		saxe.printStackTrace();
	} catch (ParserConfigurationException e) {
		e.printStackTrace();
	}
}
 
Example 2
Source File: Bug6582545Test.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testAttributeCaching() {

    File xmlFile = new File(getClass().getResource("Bug6582545.xml").getFile());

    try {
        DocumentBuilderFactory aDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
        xmlParser = aDocumentBuilderFactory.newDocumentBuilder();

        // works fine with JDK 1.4.2, 1.5
        // does not work with JDK 1.6
        document = xmlParser.parse(xmlFile);
        printNode(FWS1);
    } catch (SAXException saxException) {
        saxException.printStackTrace();
    } catch (ParserConfigurationException parserConfigurationException) {
        parserConfigurationException.printStackTrace();
    } catch (IOException ioException) {
        ioException.printStackTrace();
    } catch (IllegalArgumentException illegalArgumentException) {
        illegalArgumentException.printStackTrace();
    }
}
 
Example 3
Source File: JobDiagnoser.java    From hadoop-gpu with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor. It initializes the report document.
 */
public JobDiagnoser () throws Exception {
  
  /*
   * Initialize the report document, make it ready to add the child report elements 
   */
  DocumentBuilder builder = null;
  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  try{
    builder = factory.newDocumentBuilder();
    this._report = builder.newDocument();
  } catch (ParserConfigurationException e) {
    e.printStackTrace();
  }
    
  // Insert Root Element
  Element root = (Element) this._report.createElement("PostExPerformanceDiagnosticReport");
  this._report.appendChild(root);
}
 
Example 4
Source File: PListBuilder.java    From Connect-SDK-Android-Core with Apache License 2.0 6 votes vote down vote up
public PListBuilder() {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder;
        builder = factory.newDocumentBuilder();
        DOMImplementation di = builder.getDOMImplementation();
        dt = di.createDocumentType("plist",
                "-//Apple//DTD PLIST 1.0//EN",
                "http://www.apple.com/DTDs/PropertyList-1.0.dtd");

        doc = di.createDocument("", "plist", dt);
        doc.setXmlStandalone(true);

        root = doc.getDocumentElement();
        root.setAttribute("version", "1.0");

        rootDict = doc.createElement("dict");
        root.appendChild(rootDict);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 5
Source File: OBEXFtpUtils.java    From boogie-board-sync-sdk-android with MIT License 5 votes vote down vote up
/**
 * Converts a OBEX server response to an ArrayList of Items
 *
 * @param response - Response from the server.
 * @return ArrayList<OBEXFtpFolderListingItem>
 */

public static ArrayList<OBEXFtpFolderListingItem> parseXML(byte[] response) {

    String rawXML = new String(response);

    // Cut out anything before the XML document actually starts.
    rawXML = rawXML.substring(rawXML.indexOf("<?xml"), rawXML.length());

    // get the factory
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    Document dom = null;

    try {

        // Using factory get an instance of document builder
        DocumentBuilder db = dbf.newDocumentBuilder();

        // parse using builder to get DOM representation of the XML file
        dom = db.parse(new InputSource(new StringReader(rawXML)));

    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
    } catch (SAXException se) {
        se.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

    if (dom != null)
        return parseDocument(dom);

    return null;
}
 
Example 6
Source File: Bug6710741Test.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testWorkaround() {
    Document doc;
    try {
        doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
        Element el = doc.createElement("x");
        doc.appendChild(el);
        DOMImplementationLS ls = (DOMImplementationLS) doc.getImplementation().getFeature("LS", "3.0");
        System.out.println(ls.createLSSerializer().writeToString(doc));
    } catch (ParserConfigurationException ex) {
        ex.printStackTrace();
        Assert.fail(ex.getMessage());
    }
}
 
Example 7
Source File: ReadRules.java    From GraphiteReceiver with Apache License 2.0 5 votes vote down vote up
public ReadRules(String path){
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {
        DocumentBuilder db = dbf.newDocumentBuilder();
        this.dom = db.parse(path);
        this.readXml();
    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
    } catch (SAXException se) {
        se.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}
 
Example 8
Source File: SpreedlyGatewayAccountUpdate.java    From spreedly-java with MIT License 5 votes vote down vote up
public SpreedlyGatewayAccountUpdate() {
	try {
		documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
	} catch (ParserConfigurationException e) {
		e.printStackTrace();
	}
}
 
Example 9
Source File: XMLRipperOutput.java    From AndroidRipper with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public String outputStepAndPlannedTasks(IEvent e, ActivityDescription a, TaskList t) {
	try {
		Document doc = this.buildStepAndPlannedTasksDocument(e, a, t);
		return this.XML2String(doc);
	} catch (ParserConfigurationException pex) {
		pex.printStackTrace();
	}
	
	return null;
}
 
Example 10
Source File: XMLFormatter.java    From Siamese with GNU General Public License v3.0 5 votes vote down vote up
private void initialise() {
    // instance of a DocumentBuilderFactory
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {
        // use factory to get an instance of document builder
        DocumentBuilder db = dbf.newDocumentBuilder();
        // create instance of DOM
        this.dom = db.newDocument();
        // create the root element
        this.root = this.dom.createElement("CLONECLASSES");
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 11
Source File: DigitalSignature.java    From yawl with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static org.w3c.dom.Document ConvertStringToDocument(String Doc)	
{
	
	org.w3c.dom.Document document = null;				
	
	try
	{			
		DocumentBuilderFactory Factory = DocumentBuilderFactory.newInstance();								
		DocumentBuilder DocBuild = Factory.newDocumentBuilder();								
				
		StringBuffer Buffer = new StringBuffer(Doc);
		ByteArrayInputStream DocArray = new ByteArrayInputStream(Buffer.toString().getBytes("UTF-8"));
		document = DocBuild.parse(DocArray);
	
	}
	catch(ParserConfigurationException pce)
	{
		pce.printStackTrace();
		System.exit(0);
	}
	catch(org.xml.sax.SAXException se)
	{
		se.printStackTrace();
		System.exit(0);
	}
	catch(IOException ioe)
	{	ioe.printStackTrace();			
		System.exit(0);
	}
 	return document;
	
}
 
Example 12
Source File: Bug6879614Test.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testAttributeCaching() {
    File xmlFile = new File(getClass().getResource("Bug6879614.xml").getFile());
    DocumentBuilderFactory _documentBuilderFactory = DocumentBuilderFactory.newInstance();
    _documentBuilderFactory.setValidating(false);
    _documentBuilderFactory.setIgnoringComments(true);
    _documentBuilderFactory.setIgnoringElementContentWhitespace(true);
    _documentBuilderFactory.setCoalescing(true);
    _documentBuilderFactory.setExpandEntityReferences(true);
    _documentBuilderFactory.setNamespaceAware(true);
    DocumentBuilder _documentBuilder = null;
    try {
        _documentBuilder = _documentBuilderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
    }

    Document xmlDoc = null;
    try {
        xmlDoc = _documentBuilder.parse(xmlFile);
        if (xmlDoc == null) {
            System.out.println("Hello!!!, there is a problem here");
        } else {
            System.out.println("Good, the parsing went through fine.");
        }
    } catch (SAXException se) {
        se.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}
 
Example 13
Source File: Maven.java    From IJava with MIT License 5 votes vote down vote up
private Path readConfiguredLocalRepositoryPath(Path settingsXmlPath) throws IOException, SAXException {
    if (!Files.isRegularFile(settingsXmlPath))
        return null;

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(false);

    DocumentBuilder builder;
    try {
        builder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        // We are configuring the factory, the configuration will be fine...
        e.printStackTrace();
        return null;
    }

    try (InputStream in = Files.newInputStream(settingsXmlPath)) {
        Document settingsDoc = builder.parse(in);
        NodeList settings = settingsDoc.getElementsByTagName("settings");
        if (settings.getLength() == 0)
            return null;

        for (int i = 0; i < settings.getLength(); i++) {
            Node setting = settings.item(i);
            switch (setting.getNodeName()) {
                case "localRepository":
                    String localRepository = setting.getTextContent();
                    localRepository = this.replaceMavenVars(localRepository);
                    return Paths.get(localRepository);
            }
        }
    }

    return null;
}
 
Example 14
Source File: XMLRipperOutput.java    From AndroidRipper with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public String outputActivityDescription(ActivityDescription ad) {
	try {
		Document doc = this.buildActivityDescriptionDocument(ad);
		return this.XML2String(doc);
	} catch (ParserConfigurationException pex) {
		pex.printStackTrace();
	}
	
	return null;
}
 
Example 15
Source File: BPELConnectsToTypePlugin.java    From container with Apache License 2.0 5 votes vote down vote up
public BPELConnectsToTypePlugin() {
    try {
        this.handler = new BPELConnectsToPluginHandler();
    } catch (final ParserConfigurationException e) {
        e.printStackTrace();
    }
}
 
Example 16
Source File: GUI.java    From pdfxtk with Apache License 2.0 4 votes vote down vote up
protected void saveWrapper() throws IOException 
{
	File outFile;

	int returnVal = fcOut.showSaveDialog(fcOut);//fc.showOpenDialog(fc);
	
	if (returnVal != JFileChooser.APPROVE_OPTION) return;
		
	if(fcOut.getFileFilter().getDescription().equals
		("Extensible Markup Language (.xml)"))
	{
		// add .xml to end of file name
		// IF IT'S NOT ALREADY THERE
	}
	
	outFile = fcOut.getSelectedFile();
		
	org.w3c.dom.Document resultDocument;
	
	// copied from ProcessFile.setUpXML
	try
       {
           DocumentBuilderFactory myFactory = DocumentBuilderFactory.newInstance();
           DocumentBuilder myDocBuilder = myFactory.newDocumentBuilder();
           DOMImplementation myDOMImpl = myDocBuilder.getDOMImplementation();
           //org.w3c.dom.Document 
           resultDocument = 
               myDOMImpl.createDocument("at.ac.tuwien.dbai.pdfwrap", "pdf-wrapper", null);
       }
       catch (ParserConfigurationException e)
       {
           e.printStackTrace();
           return;
       }
	
       // make sure any text box contents are saved
       wrapperGraphPanel.updateStatusBarControls();
       
       Element docElement = resultDocument.getDocumentElement();
       
       String granularity = "block";
       if (segmentationMode == PageProcessor.PP_MERGED_LINES)
       	granularity = "line";
       if (segmentationMode == PageProcessor.PP_LINE)
       	granularity = "raw-line";
       
       docElement.setAttribute("granularity", granularity);
       docElement.setAttribute("process-spaces", Boolean.toString(processSpaces));
       docElement.setAttribute("process-ruling-lines", Boolean.toString(rulingLines));
       docElement.setAttribute("area-based", "true");
       docElement.setAttribute("output", "true");
       
       pageDG.addAsXMLGraph
       	(resultDocument, docElement, false);
       
	boolean toConsole = false;
	String encoding = "UTF-8";
	
	Writer output = null;
       if( toConsole )
       {
           output = new OutputStreamWriter( System.out );
       }
       else
       {
           if( encoding != null )
           {
               output = new OutputStreamWriter(
                   new FileOutputStream( outFile ), encoding );
           }
           else
           {
               //use default encoding
               output = new OutputStreamWriter(
                   new FileOutputStream( outFile ) );
           }
           //System.out.println("using out put file: " + outFile);
       }
       //System.out.println("resultDocument: " + resultDocument);
       ProcessFile.serializeXML(resultDocument, output);
       
       if( output != null )
       {
           output.close();
       }
}
 
Example 17
Source File: LSParserTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testDOMConfiguration() {

    final DOMErrorHandler handler = new DOMErrorHandler() {
        public boolean handleError(final DOMError error) {
            return false;
        }
    };

    final LSResourceResolver resolver = new LSResourceResolver() {
        public LSInput resolveResource(final String type, final String namespaceURI, final String publicId, final String systemId, final String baseURI) {
            return null;
        }
    };

    final Object[][] values = {
            // parameter, value
            { "canonical-form", Boolean.FALSE }, { "cdata-sections", Boolean.FALSE }, { "cdata-sections", Boolean.TRUE },
            { "check-character-normalization", Boolean.FALSE }, { "comments", Boolean.FALSE }, { "comments", Boolean.TRUE },
            { "datatype-normalization", Boolean.FALSE }, { "entities", Boolean.FALSE }, { "entities", Boolean.TRUE }, { "error-handler", handler },
            { "infoset", Boolean.TRUE }, { "namespaces", Boolean.TRUE }, { "namespace-declarations", Boolean.TRUE },
            { "namespace-declarations", Boolean.FALSE }, { "normalize-characters", Boolean.FALSE }, { "split-cdata-sections", Boolean.TRUE },
            { "split-cdata-sections", Boolean.FALSE }, { "validate", Boolean.FALSE }, { "validate-if-schema", Boolean.FALSE },
            { "well-formed", Boolean.TRUE }, { "element-content-whitespace", Boolean.TRUE },

            { "charset-overrides-xml-encoding", Boolean.TRUE }, { "charset-overrides-xml-encoding", Boolean.FALSE }, { "disallow-doctype", Boolean.FALSE },
            { "ignore-unknown-character-denormalizations", Boolean.TRUE }, { "resource-resolver", resolver }, { "resource-resolver", null },
            { "supported-media-types-only", Boolean.FALSE }, };

    DOMImplementation domImpl = null;
    try {
        domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
    } catch (ParserConfigurationException parserConfigurationException) {
        parserConfigurationException.printStackTrace();
        Assert.fail(parserConfigurationException.toString());
    }

    DOMImplementationLS lsImpl = (DOMImplementationLS) domImpl.getFeature("LS", "3.0");

    LSParser lsParser = lsImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);

    DOMConfiguration config = lsParser.getDomConfig();

    for (int i = values.length; --i >= 0;) {
        Object val = values[i][1];
        String param = (String) values[i][0];
        try {
            config.setParameter(param, val);
            Object returned = config.getParameter(param);
            Assert.assertEquals(val, returned, "'" + param + "' is set to " + returned + ", but expected " + val);
            System.out.println("set '" + param + "'" + " to '" + val + "'" + " and returned '" + returned + "'");
        } catch (DOMException e) {
            String settings = "setting '" + param + "' to " + val;
            System.err.println(settings);
            e.printStackTrace();
            Assert.fail(settings + ", " + e.toString());
        }
    }
}
 
Example 18
Source File: ModifyXMLFile.java    From maven-framework-project with MIT License 4 votes vote down vote up
public static void main(String argv[]) {
 
   try {
	DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
	DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
	Document doc = docBuilder.parse(ClassLoader.getSystemResourceAsStream("file.xml"));

	// Get the root element
	//Node company = doc.getFirstChild();

	// Get the staff element , it may not working if tag has spaces, or
	// whatever weird characters in front...it's better to use
	// getElementsByTagName() to get it directly.
	// Node staff = company.getFirstChild();

	// Get the staff element by tag name directly
	Node staff = doc.getElementsByTagName("staff").item(0);

	// update staff attribute
	NamedNodeMap attr = staff.getAttributes();
	Node nodeAttr = attr.getNamedItem("id");
	nodeAttr.setTextContent("2");

	// append a new node to staff
	Element age = doc.createElement("age");
	age.appendChild(doc.createTextNode("28"));
	staff.appendChild(age);

	// loop the staff child node
	NodeList list = staff.getChildNodes();

	for (int i = 0; i < list.getLength(); i++) {

          Node node = list.item(i);

	   // get the salary element, and update the value
	   if ("salary".equals(node.getNodeName())) {
		node.setTextContent("2000000");
	   }

                  //remove firstname
	   if ("firstname".equals(node.getNodeName())) {
		staff.removeChild(node);
	   }

	}

	// write the content into xml file
	TransformerFactory transformerFactory = TransformerFactory.newInstance();
	Transformer transformer = transformerFactory.newTransformer();
	DOMSource source = new DOMSource(doc);
	StreamResult result = new StreamResult(new File("target/file.xml"));
	transformer.transform(source, result);

	System.out.println("Done");

   } catch (ParserConfigurationException pce) {
	pce.printStackTrace();
   } catch (TransformerException tfe) {
	tfe.printStackTrace();
   } catch (IOException ioe) {
	ioe.printStackTrace();
   } catch (SAXException sae) {
	sae.printStackTrace();
   }
}
 
Example 19
Source File: AsposeMavenProjectManager.java    From Aspose.OCR-for-Java with MIT License 4 votes vote down vote up
public void addMavenDependenciesInProject(NodeList addTheseDependencies) {
    String mavenPomXmlfile = AsposeMavenUtil.getPOMXmlFile(projectHandle);

    VirtualFile vf_mavenPomXmlfilel = LocalFileSystem.getInstance().findFileByPath(mavenPomXmlfile);


    try {
        Document pomDocument = getXmlDocument(mavenPomXmlfile);

        Node dependenciesNode = pomDocument.getElementsByTagName("dependencies").item(0);


        if (addTheseDependencies != null && addTheseDependencies.getLength() > 0) {
            for (int n = 0; n < addTheseDependencies.getLength(); n++) {
                String artifactId = addTheseDependencies.item(n).getFirstChild().getNextSibling().getNextSibling().getNextSibling().getFirstChild().getNodeValue();

                XPathFactory xPathfactory = XPathFactory.newInstance();
                XPath xpath = xPathfactory.newXPath();
                String expression = "//artifactId[text()='" + artifactId + "']";

                XPathExpression xPathExpr = xpath.compile(expression);

                Node dependencyAlreadyExist = (Node) xPathExpr.evaluate(pomDocument, XPathConstants.NODE);

                if (dependencyAlreadyExist != null) {
                    Node dependencies = pomDocument.getElementsByTagName("dependencies").item(0);
                    dependencies.removeChild(dependencyAlreadyExist.getParentNode());
                }

                Node importedNode = pomDocument.importNode(addTheseDependencies.item(n), true);
                dependenciesNode.appendChild(importedNode);


            }
        }
        removeEmptyLinesfromDOM(pomDocument);
        writeXmlDocumentToVirtualFile(vf_mavenPomXmlfilel, pomDocument);

    } catch (IOException io) {
        io.printStackTrace();
    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
    } catch (SAXException sae) {
        sae.printStackTrace();
    } catch (XPathExpressionException e) {
        e.printStackTrace();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
Example 20
Source File: LSSerializerTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testXML11() {

    /**
     * XML 1.1 document to parse.
     */
    final String XML11_DOCUMENT = "<?xml version=\"1.1\" encoding=\"UTF-16\"?>\n" + "<hello>" + "world" + "<child><children/><children/></child>"
            + "</hello>";

    /**JDK-8035467
     * no newline in default output
     */
    final String XML11_DOCUMENT_OUTPUT =
            "<?xml version=\"1.1\" encoding=\"UTF-16\"?>"
            + "<hello>"
            + "world"
            + "<child><children/><children/></child>"
            + "</hello>";

    // it all begins with a Document
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = null;
    try {
        documentBuilder = documentBuilderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException parserConfigurationException) {
        parserConfigurationException.printStackTrace();
        Assert.fail(parserConfigurationException.toString());
    }
    Document document = null;

    StringReader stringReader = new StringReader(XML11_DOCUMENT);
    InputSource inputSource = new InputSource(stringReader);
    try {
        document = documentBuilder.parse(inputSource);
    } catch (SAXException saxException) {
        saxException.printStackTrace();
        Assert.fail(saxException.toString());
    } catch (IOException ioException) {
        ioException.printStackTrace();
        Assert.fail(ioException.toString());
    }

    // query DOM Interfaces to get to a LSSerializer
    DOMImplementation domImplementation = documentBuilder.getDOMImplementation();
    DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation;
    LSSerializer lsSerializer = domImplementationLS.createLSSerializer();

    System.out.println("Serializer is: " + lsSerializer.getClass().getName() + " " + lsSerializer);

    // get default serialization
    String defaultSerialization = lsSerializer.writeToString(document);

    System.out.println("XML 1.1 serialization = \"" + defaultSerialization + "\"");

    // output should == input
    Assert.assertEquals(XML11_DOCUMENT_OUTPUT, defaultSerialization, "Invalid serialization of XML 1.1 document: ");
}