org.xml.sax.SAXException#printStackTrace ( )源码实例Demo

下面列出了org.xml.sax.SAXException#printStackTrace ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-8   文件: ParserContext.java
public ParserContext( XSOMParser owner, XMLParser parser ) {
    this.owner = owner;
    this.parser = parser;

    try {
        parse(new InputSource(ParserContext.class.getResource("datatypes.xsd").toExternalForm()));

        SchemaImpl xs = (SchemaImpl)
            schemaSet.getSchema("http://www.w3.org/2001/XMLSchema");
        xs.addSimpleType(schemaSet.anySimpleType,true);
        xs.addComplexType(schemaSet.anyType,true);
    } catch( SAXException e ) {
        // this must be a bug of XSOM
        if(e.getException()!=null)
            e.getException().printStackTrace();
        else
            e.printStackTrace();
        throw new InternalError();
    }
}
 
源代码2 项目: gemfirexd-oss   文件: JUnitXMLParser.java
public JUnitResultData parseXmlFile(File xmlFile){
  this.xmlFile = xmlFile;
  //get the factory
  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  JUnitResultData returnResultsForFile = 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(xmlFile);
    returnResultsForFile = parseDocument();
    returnResultsForFile.setJunitResultfile(xmlFile);

  }catch(ParserConfigurationException pce) {
    pce.printStackTrace();
  }catch(SAXException se) {
    se.printStackTrace();
  }catch(IOException ioe) {
    ioe.printStackTrace();
  }
  return returnResultsForFile;
}
 
public void writeOldPath(String path)
{
    try
    {
        AttributesImpl attributes = new AttributesImpl();
       
        writer.startElement(TransferDestinationReportModel.TRANSFER_REPORT_MODEL_1_0_URI, TransferDestinationReportModel.LOCALNAME_TRANSFER_OLD_PATH, PREFIX + ":" + TransferDestinationReportModel.LOCALNAME_TRANSFER_OLD_PATH, attributes);        
        writer.characters(path.toCharArray(), 0, path.length());
        writer.endElement(TransferDestinationReportModel.TRANSFER_REPORT_MODEL_1_0_URI, TransferDestinationReportModel.LOCALNAME_TRANSFER_OLD_PATH, PREFIX + ":" + TransferDestinationReportModel.LOCALNAME_TRANSFER_OLD_PATH);        
    }
    catch (SAXException se)
    {
        // TODO Auto-generated catch block
        se.printStackTrace();
    }    
}
 
public NodeList getDependenciesFromPOM(String mavenPomXmlfile, String excludeGroup) {

        try {

            Document pomDocument = getXmlDocument(mavenPomXmlfile);

            XPathFactory xPathfactory = XPathFactory.newInstance();
            XPath xpath = xPathfactory.newXPath();
            String expression = "//dependency[child::groupId[text()!='" + excludeGroup + "']]";
            XPathExpression xPathExpr = xpath.compile(expression);
            NodeList nl = (NodeList) xPathExpr.evaluate(pomDocument, XPathConstants.NODESET);
            if (nl != null && nl.getLength() > 0) {
                return nl;
            }
        } catch (IOException io) {
            io.printStackTrace();
        } catch (ParserConfigurationException pce) {
            pce.printStackTrace();
        } catch (SAXException sae) {
            sae.printStackTrace();
        } catch (XPathExpressionException e) {
            e.printStackTrace();
        }
        return null;
    }
 
源代码5 项目: gemfirexd-oss   文件: JUnitXMLParser.java
public JUnitResultData parseXmlFile(File xmlFile){
  this.xmlFile = xmlFile;
  //get the factory
  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  JUnitResultData returnResultsForFile = 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(xmlFile);
    returnResultsForFile = parseDocument();
    returnResultsForFile.setJunitResultfile(xmlFile);

  }catch(ParserConfigurationException pce) {
    pce.printStackTrace();
  }catch(SAXException se) {
    se.printStackTrace();
  }catch(IOException ioe) {
    ioe.printStackTrace();
  }
  return returnResultsForFile;
}
 
源代码6 项目: openjdk-jdk8u   文件: ParserContext.java
public ParserContext( XSOMParser owner, XMLParser parser ) {
    this.owner = owner;
    this.parser = parser;

    try {
        parse(new InputSource(ParserContext.class.getResource("datatypes.xsd").toExternalForm()));

        SchemaImpl xs = (SchemaImpl)
            schemaSet.getSchema("http://www.w3.org/2001/XMLSchema");
        xs.addSimpleType(schemaSet.anySimpleType,true);
        xs.addComplexType(schemaSet.anyType,true);
    } catch( SAXException e ) {
        // this must be a bug of XSOM
        if(e.getException()!=null)
            e.getException().printStackTrace();
        else
            e.printStackTrace();
        throw new InternalError();
    }
}
 
源代码7 项目: JDeodorant   文件: ConQATOutputParser.java
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();
	}
}
 
源代码8 项目: openjdk-jdk9   文件: Bug6967214Test.java
@Test
public void test() {
    try {
        File dir = new File(Bug6967214Test.class.getResource("Bug6967214").getPath());
        File files[] = dir.listFiles();
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        for (int i = 0; i < files.length; i++) {
            try {
                System.out.println(files[i].getName());
                Schema schema = schemaFactory.newSchema(new StreamSource(files[i]));
                Assert.fail("should report error");
            } catch (org.xml.sax.SAXParseException spe) {
                continue;
            }
        }
    } catch (SAXException e) {
        e.printStackTrace();

    }
}
 
源代码9 项目: openjdk-jdk9   文件: Bug6582545Test.java
@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();
    }
}
 
@Override
public void writeChangeState(String state)
{
    try
    {
        AttributesImpl attributes = new AttributesImpl();
        attributes.addAttribute(TransferDestinationReportModel.TRANSFER_REPORT_MODEL_1_0_URI, "state", "state", "String", state);
        attributes.addAttribute(TransferReportModel.TRANSFER_REPORT_MODEL_1_0_URI, "date", "date", "dateTime", ISO8601DateFormat.format(new Date()));
    
        writer.startElement(TransferDestinationReportModel.TRANSFER_REPORT_MODEL_1_0_URI, TransferDestinationReportModel.LOCALNAME_TRANSFER_STATE, PREFIX + ":" + TransferDestinationReportModel.LOCALNAME_TRANSFER_STATE, attributes);        
        writer.endElement(TransferDestinationReportModel.TRANSFER_REPORT_MODEL_1_0_URI, TransferDestinationReportModel.LOCALNAME_TRANSFER_STATE, PREFIX + ":" + TransferDestinationReportModel.LOCALNAME_TRANSFER_STATE);        
    }
    catch (SAXException se)
    {
        // TODO Auto-generated catch block
        se.printStackTrace();
    } 
}
 
@Override
public void writeCreated(NodeRef sourceNodeRef, NodeRef newNode, NodeRef newParentNodeRef, String newPath)
{
    try
    {
        AttributesImpl attributes = new AttributesImpl();
        attributes.addAttribute(TransferReportModel.TRANSFER_REPORT_MODEL_1_0_URI, "date", "date", "dateTime", ISO8601DateFormat.format(new Date()));
        attributes.addAttribute(TransferReportModel.TRANSFER_REPORT_MODEL_1_0_URI, "sourceNodeRef", "sourceNodeRef", "string", sourceNodeRef.toString());
        attributes.addAttribute(TransferReportModel.TRANSFER_REPORT_MODEL_1_0_URI, "destinationNodeRef", "destinationNodeRef", "string", newNode.toString());
        attributes.addAttribute(TransferReportModel.TRANSFER_REPORT_MODEL_1_0_URI, "parentNodeRef", "parentNodeRef", "string", newParentNodeRef.toString());
         
        writer.startElement(TransferDestinationReportModel.TRANSFER_REPORT_MODEL_1_0_URI, TransferDestinationReportModel.LOCALNAME_TRANSFER_CREATED, PREFIX + ":" + TransferDestinationReportModel.LOCALNAME_TRANSFER_CREATED, attributes);        
        writeDestinationPath(newPath);
        writer.endElement(TransferDestinationReportModel.TRANSFER_REPORT_MODEL_1_0_URI, TransferDestinationReportModel.LOCALNAME_TRANSFER_CREATED, PREFIX + ":" + TransferDestinationReportModel.LOCALNAME_TRANSFER_CREATED);        
    }
    catch (SAXException se)
    {
        // TODO Auto-generated catch block
        se.printStackTrace();
    }     
}
 
源代码12 项目: gama   文件: Reader.java
public void parseXmlFile() {
	final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	try {
		final DocumentBuilder db = dbf.newDocumentBuilder();
		final Document dom = db.parse(myStream);
		this.sims = this.readSimulation(dom);
	} catch (final ParserConfigurationException pce) {
		pce.printStackTrace();
	} catch (final SAXException se) {
		se.printStackTrace();
	} catch (final IOException ioe) {
		ioe.printStackTrace();
	}
}
 
源代码13 项目: openjdk-jdk9   文件: Bug6970890Test.java
@Test
public void test_reH16() {
    try {
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(new StreamSource(Bug6970890Test.class.getResourceAsStream("Bug6970890_1.xsd")));

    } catch (SAXException e) {
        e.printStackTrace();
        Assert.fail("The - character is a valid character range at the beginning or end of a positive character group");

    }
}
 
源代码14 项目: openjdk-jdk9   文件: Bug6963468Test.java
@Test
public void testInstance() throws ParserConfigurationException, SAXException, IOException {
    System.out.println(Bug6963468Test.class.getResource("Bug6963468.xsd").getPath());
    File schemaFile = new File(Bug6963468Test.class.getResource("Bug6963468.xsd").getPath());
    SAXParser parser = createParser(schemaFile);

    try {
        parser.parse(Bug6963468Test.class.getResource("Bug6963468.xml").getPath(), new DefaultHandler());
    } catch (SAXException e) {
        e.printStackTrace();
        Assert.fail("Fatal Error: " + strException(e));
    }

}
 
源代码15 项目: openjdk-jdk9   文件: Bug6879614Test.java
@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();
    }
}
 
private void addMavenConfiguration(final VirtualFile miscxml, String mavenMiscXmlfile) {
    try {
        Document pomDocument = getXmlDocument(mavenMiscXmlfile);

        // Get the root (Project Node) element
        Node projectNode = pomDocument.getFirstChild();
        Element component = pomDocument.createElement("component");
        component.setAttribute("name", "MavenProjectsManager");
        projectNode.appendChild(component);
        Element option = pomDocument.createElement("option");
        option.setAttribute("name", "originalFiles");
        component.appendChild(option);
        Element list = pomDocument.createElement("list");
        option.appendChild(list);
        Element listOption = pomDocument.createElement("option");
        listOption.setAttribute("value", "$PROJECT_DIR$/pom.xml");
        list.appendChild(listOption);

        // Write the content into misc xml file
        AsposeMavenProjectManager.getInstance().writeXmlDocumentToVirtualFile(miscxml, pomDocument);
    } catch (IOException io) {
        io.printStackTrace();
    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
    } catch (SAXException sae) {
        sae.printStackTrace();
    }
}
 
源代码17 项目: openjdk-jdk8u-backup   文件: SchemaCompilerImpl.java
public void parseSchema(InputSource source) {
    checkAbsoluteness(source.getSystemId());
    try {
        forest.parse(source,true);
    } catch (SAXException e) {
        // parsers are required to report an error to ErrorHandler,
        // so we should never see this error.
        e.printStackTrace();
    }
}
 
源代码18 项目: maven-framework-project   文件: ModifyXMLFile.java
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();
   }
}
 
源代码19 项目: openjdk-systemtest   文件: SummaryGenerator.java
public static void main (String[] args) {
	try { 
		DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
		Document doc = docBuilder.parse (new File(args[0]));
		doc.getDocumentElement ().normalize ();
		NodeList listOfTestResults = doc.getElementsByTagName("TestResult");
		String testPath = ""; 
		String message = ""; 
		StringBuffer resultSummary = new StringBuffer(); 

		for(int s=0; s<listOfTestResults.getLength() ; s++) {
			Node aResult = listOfTestResults.item(s);
			if(aResult.getNodeType() == Node.ELEMENT_NODE) {
				Element aResultElement = (Element) aResult; 
				testPath = aResultElement.getAttribute("url"); 
				NodeList ns = aResultElement.getElementsByTagName("ResultProperties"); 
				if ( ns != null) {
					Node resultPropertiesNode = ns.item(0);
					if (resultPropertiesNode != null) {
						if(resultPropertiesNode.getNodeType() == Node.ELEMENT_NODE) {
							Element aResultPropertiesElement = (Element) resultPropertiesNode; 
							NodeList properties = aResultPropertiesElement.getElementsByTagName("Property"); 
							for (int  i = 0 ; i < properties.getLength(); i++) {
								Node aProperty = properties.item(i); 
								if(aProperty.getNodeType() == Node.ELEMENT_NODE) {
									Element aPropertyElement = (Element) aProperty; 
									String name = aPropertyElement.getAttribute("name"); 
									if ( name != null && name.equals("execStatus")) {
										message = aPropertyElement.getAttribute("value"); 
										resultSummary.append(testPath + "   " + message + "\n");
										break; 
									}
								}
							}
						}
					}
				}
			}
		}
		FileWriter fw = new FileWriter(new File("summary.txt")); 
		fw.write(resultSummary.toString());
		fw.close();
		System.out.println(resultSummary.toString());
	} catch (SAXParseException err) {
		System.out.println ("Error processing XML JCK output report" + err.getMessage ());
		err.printStackTrace();
	}catch (SAXException e) {
		System.out.println ("Error processing XML JCK output report" + e.getMessage ());
		e.printStackTrace();
	}catch (Throwable t) {
		t.printStackTrace ();
	}
}
 
/** Simple unit test. Attempt coroutine parsing of document indicated
 * by first argument (as a URI), report progress.
 */
public static void _main(String args[])
{
  System.out.println("Starting...");

  CoroutineManager co = new CoroutineManager();
  int appCoroutineID = co.co_joinCoroutineSet(-1);
  if (appCoroutineID == -1)
  {
    System.out.println("ERROR: Couldn't allocate coroutine number.\n");
    return;
  }
  IncrementalSAXSource parser=
    createIncrementalSAXSource();

  // Use a serializer as our sample output
  com.sun.org.apache.xml.internal.serialize.XMLSerializer trace;
  trace=new com.sun.org.apache.xml.internal.serialize.XMLSerializer(System.out,null);
  parser.setContentHandler(trace);
  parser.setLexicalHandler(trace);

  // Tell coroutine to begin parsing, run while parsing is in progress

  for(int arg=0;arg<args.length;++arg)
  {
    try
    {
      InputSource source = new InputSource(args[arg]);
      Object result=null;
      boolean more=true;
      parser.startParse(source);
      for(result = parser.deliverMoreNodes(more);
          result==Boolean.TRUE;
          result = parser.deliverMoreNodes(more))
      {
        System.out.println("\nSome parsing successful, trying more.\n");

        // Special test: Terminate parsing early.
        if(arg+1<args.length && "!".equals(args[arg+1]))
        {
          ++arg;
          more=false;
        }

      }

      if (result instanceof Boolean && ((Boolean)result)==Boolean.FALSE)
      {
        System.out.println("\nParser ended (EOF or on request).\n");
      }
      else if (result == null) {
        System.out.println("\nUNEXPECTED: Parser says shut down prematurely.\n");
      }
      else if (result instanceof Exception) {
        throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException((Exception)result);
        //          System.out.println("\nParser threw exception:");
        //          ((Exception)result).printStackTrace();
      }

    }

    catch(SAXException e)
    {
      e.printStackTrace();
    }
  }

}