javax.xml.transform.TransformerException#printStackTrace ( )源码实例Demo

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

源代码1 项目: butterfly   文件: BaseRequestHandler.java
/**
 * Sends the response to the client.
 * @param request The original request.
 * @param response The response object we can use to send the data.
 * @param respBody The XML document of the response.
 * @return A response object for Spark
 */
protected Object sendResponse(final Request request, final Response response, final BaseXMLBuilder respBody) {
    // get the bytes of the XML document
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();

    try {
        final TransformerFactory transformerFactory = TransformerFactory.newInstance();
        final Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");

        final DOMSource source = new DOMSource(respBody.getDocument());
        final StreamResult result = new StreamResult(bos);
        transformer.transform(source, result);
    } catch (TransformerException e) {
        e.printStackTrace();
        return 500;
    }

    byte[] respBytes = bos.toByteArray();
    return this.sendBytesToClient(respBytes, request, response);
}
 
源代码2 项目: lams   文件: LearningDesignRepositoryServlet.java
/**
 * the format should be something like this: [ ['My Workspace', null, ['Mary Morgan Folder', null, ['3 activity
 * sequence','1024'] ], ['Organisations', null, ['Developers Playpen', null, ['Lesson Sequence Folder', null,
 * ['',null] ] ], ['MATH111', null, ['Lesson Sequence Folder', null, ['',null] ] ] ] ] ]
 */
@Override
public String toString() {
    // return '[' + convert() + ']';

    Document document = getDocument();

    try {
	DOMSource domSource = new DOMSource(document);
	StringWriter writer = new StringWriter();
	StreamResult result = new StreamResult(writer);
	TransformerFactory tf = TransformerFactory.newInstance();
	Transformer transformer = tf.newTransformer();
	transformer.transform(domSource, result);
	return writer.toString();
    } catch (TransformerException ex) {
	ex.printStackTrace();
	return null;
    }
}
 
源代码3 项目: wandora   文件: AbstractBossExtractor.java
protected String getStringFromDocument(Document doc) {
    try {
        DOMSource domSource = new DOMSource(doc);
        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);

        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.transform(domSource, result);

        return writer.toString();
    }

    catch(TransformerException ex) {
        ex.printStackTrace();
        return null;
    }
}
 
源代码4 项目: Siamese   文件: XMLFormatter.java
public String getXMLAsString() {
    this.dom.appendChild(this.root);
    try {
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
        StringWriter writer = new StringWriter();
        transformer.transform(new DOMSource(dom), new StreamResult(writer));
        return writer.toString();
    } catch (TransformerException e) {
        e.printStackTrace();
        return null;
    }
}
 
源代码5 项目: wandora   文件: AbstractZemantaExtractor.java
protected String getStringFromDocument(Document doc) {
    try {
        DOMSource domSource = new DOMSource(doc);
        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);

        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.transform(domSource, result);

        return writer.toString();
    }

    catch(TransformerException ex) {
        ex.printStackTrace();
        return null;
    }
}
 
源代码6 项目: wandora   文件: AbstractTagtheExtractor.java
protected String getStringFromDocument(Document doc) {
    try {
        DOMSource domSource = new DOMSource(doc);
        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);

        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.transform(domSource, result);

        return writer.toString();
    }

    catch(TransformerException ex) {
        ex.printStackTrace();
        return null;
    }
}
 
源代码7 项目: wandora   文件: AbstractBingExtractor.java
protected String getStringFromDocument(Document doc) {
    try {
        DOMSource domSource = new DOMSource(doc);
        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);

        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.transform(domSource, result);

        return writer.toString();
    }

    catch(TransformerException ex) {
        ex.printStackTrace();
        return null;
    }
}
 
源代码8 项目: iaf   文件: Utils.java
public static String source2String(Source source) {
       try
        {
           StringWriter writer = new StringWriter();
           StreamResult result = new StreamResult(writer);
           TransformerFactory tf = TransformerFactory.newInstance();
           Transformer transformer = tf.newTransformer();
           transformer.transform(source, result);
           writer.flush();
           return writer.toString();
        }
        catch(TransformerException ex)
        {
           ex.printStackTrace();
           return null;
        }		
}
 
源代码9 项目: wandora   文件: AbstractAlchemyExtractor.java
protected String getStringFromDocument(Document doc) {
    try {
        DOMSource domSource = new DOMSource(doc);
        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);

        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.transform(domSource, result);

        return writer.toString();
    }

    catch(TransformerException ex) {
        ex.printStackTrace();
        return null;
    }
}
 
源代码10 项目: cxf   文件: MessageProviderWithAddressingPolicy.java
public Source invoke(Source request) {
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    try {
        transformerFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
        /*
        tfactory.setAttribute("indent-number", "2");
         */
        Transformer serializer = transformerFactory.newTransformer();
        // Setup indenting to "pretty print"
        serializer.setOutputProperty(OutputKeys.INDENT, "yes");
        serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");

        StringWriter swriter = new StringWriter();
        serializer.transform(request, new StreamResult(swriter));
        swriter.flush();
        LOG.info("Provider received a request\n" + swriter.toString());

    } catch (TransformerException e) {
        e.printStackTrace();
    }
    return null;
}
 
源代码11 项目: wandora   文件: AbstractUClassifier.java
protected String getStringFromDocument(Document doc) {
    try {
        DOMSource domSource = new DOMSource(doc);
        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);

        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.transform(domSource, result);

        return writer.toString();
    }

    catch(TransformerException ex) {
        ex.printStackTrace();
        return null;
    }
}
 
源代码12 项目: wandora   文件: AbstractYahooTermExtractor.java
protected String getStringFromDocument(Document doc) {
    try {
        DOMSource domSource = new DOMSource(doc);
        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);

        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.transform(domSource, result);

        return writer.toString();
    }

    catch(TransformerException ex) {
        ex.printStackTrace();
        return null;
    }
}
 
源代码13 项目: TranskribusCore   文件: XmlUtils.java
public static Node selectNode(Element documentElement, String xpath)
{
	Node res = null;
	try {
		Node result = XPathAPI.selectSingleNode(documentElement, xpath);
		if (result!=null)
			res = result;
	} catch (TransformerException e) {
		e.printStackTrace();
	}
	return res;
}
 
源代码14 项目: ECTester   文件: BaseXMLTestWriter.java
@Override
public void end() {
    try {
        DOMSource domSource = new DOMSource(doc);
        StreamResult result = new StreamResult(output);
        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.transform(domSource, result);
    } catch (TransformerException e) {
        e.printStackTrace();
    }
}
 
源代码15 项目: jolie   文件: XmlUtils.java
public String transform( Value request )
	throws FaultException {
	try {
		StreamSource source = new StreamSource( new StringReader( request.getFirstChild( "source" ).strValue() ) );
		Transformer t = transformerFactory
			.newTransformer( new StreamSource( new StringReader( request.getFirstChild( "xslt" ).strValue() ) ) );
		StringWriter writer = new StringWriter();
		StreamResult result = new StreamResult( writer );
		t.transform( source, result );
		return writer.toString();
	} catch( TransformerException e ) {
		e.printStackTrace();
		throw new FaultException( e );
	}
}
 
源代码16 项目: ingestion   文件: XmlXpathDeserializer.java
public String nodeToString(Node node) {
    StringWriter writer = new StringWriter();
    TransformerFactory tfactory = TransformerFactory.newInstance();
    Transformer xform;
    try {
        xform = tfactory.newTransformer();
        xform.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        Source src = new DOMSource(node);
        Result result = new StreamResult(writer);
        xform.transform(src, result);
    } catch (TransformerException e) {
        e.printStackTrace();
    }
    return writer.toString();
}
 
源代码17 项目: mappwidget   文件: XMLUtils.java
public static void saveDoc(Document doc, String fileName)
{
	try
	{
		TransformerFactory transformerFactory = TransformerFactory.newInstance();
		Transformer transformer = transformerFactory.newTransformer();
		DOMSource source = new DOMSource(doc);

		StreamResult result = new StreamResult(new File(fileName));
		transformer.transform(source, result);
	} catch (TransformerException e)
	{
		e.printStackTrace();
	}
}
 
源代码18 项目: SEAL   文件: XMLUtil.java
static public Document cloneDocument(Document document) {
  if (document == null) return null;
  Document result = newDocument();
  try {
    identityTransformer.transform(new DOMSource( document), new DOMResult( result));
  } catch (TransformerException e) {
    e.printStackTrace();
  }
  return result;
}
 
源代码19 项目: Cynthia   文件: NewDataNotifyAccessSessionMySQL.java
public void run(){
	while (true) {
		UUID newfilterId = null;
		int filterCount = 0;
		
		synchronized (filterIdList) {
			if (filterIdList.size() == 0) {
				break;
			}
			newfilterId = filterIdList.remove(0);
		}
		
		if (newfilterId != null) {
			try {
				filterCount = getFilterCount(newfilterId, username);
			} catch (TransformerException e) {
				e.printStackTrace();
			}
		}
		
		synchronized (filterIdList) {
			filterDataCountMap.put(newfilterId, filterCount);
		}
	}
	countDown.countDown();
	
}
 
源代码20 项目: 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();
   }
}