當前位置: 首頁>>代碼示例>>Java>>正文


Java Source類代碼示例

本文整理匯總了Java中javax.xml.transform.Source的典型用法代碼示例。如果您正苦於以下問題:Java Source類的具體用法?Java Source怎麽用?Java Source使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Source類屬於javax.xml.transform包,在下文中一共展示了Source類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createReader

import javax.xml.transform.Source; //導入依賴的package包/類
private XMLReader createReader() throws SAXException {
    try {
        SAXParserFactory pfactory = SAXParserFactory.newInstance();
        pfactory.setValidating(true);
        pfactory.setNamespaceAware(true);

        // Enable schema validation
        SchemaFactory sfactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
        InputStream stream = Parser.class.getResourceAsStream("graphdocument.xsd");
        pfactory.setSchema(sfactory.newSchema(new Source[]{new StreamSource(stream)}));

        return pfactory.newSAXParser().getXMLReader();
    } catch (ParserConfigurationException ex) {
        throw new SAXException(ex);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:Parser.java

示例2: xmlFormat

import javax.xml.transform.Source; //導入依賴的package包/類
/**
 * xml 格式化
 *
 * @param xml 要格式化的 xml 字符串
 * @return 格式化後的新字符串
 */
public static String xmlFormat(String xml) {
    if (TextUtils.isEmpty(xml)) {
        return "Empty/Null xml content";
    }
    String message;
    try {
        Source xmlInput = new StreamSource(new StringReader(xml));
        StreamResult xmlOutput = new StreamResult(new StringWriter());
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.transform(xmlInput, xmlOutput);
        message = xmlOutput.getWriter().toString().replaceFirst(">", ">\n");
    } catch (TransformerException e) {
        message = xml;
    }
    return message;
}
 
開發者ID:xiaobailong24,項目名稱:MVVMArms,代碼行數:25,代碼來源:CharacterHandler.java

示例3: format

import javax.xml.transform.Source; //導入依賴的package包/類
@Override
public String format(String response) {
  try {
    Transformer serializer = SAXTransformerFactory.newInstance().newTransformer();
    serializer.setOutputProperty(OutputKeys.INDENT, "yes");
    serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
    Source xmlSource = new SAXSource(new InputSource(new ByteArrayInputStream(response.getBytes())));
    StreamResult res = new StreamResult(new ByteArrayOutputStream());
    serializer.transform(xmlSource, res);
    return new String(((ByteArrayOutputStream) res.getOutputStream()).toByteArray()).trim();
  } catch (Exception e) {
    e.printStackTrace();
    Logger.e(TAG, e.getMessage(), e);
    return response;
  }
}
 
開發者ID:jainsahab,項目名稱:AndroidSnooper,代碼行數:18,代碼來源:XmlFormatter.java

示例4: toReturnValue

import javax.xml.transform.Source; //導入依賴的package包/類
Object toReturnValue(Packet response) {
    try {
        Unmarshaller unmarshaller = jaxbcontext.createUnmarshaller();
        Message msg = response.getMessage();
        switch (mode) {
            case PAYLOAD:
                return msg.<Object>readPayloadAsJAXB(unmarshaller);
            case MESSAGE:
                Source result = msg.readEnvelopeAsSource();
                return unmarshaller.unmarshal(result);
            default:
                throw new WebServiceException("Unrecognized dispatch mode");
        }
    } catch (JAXBException e) {
        throw new WebServiceException(e);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:JAXBDispatch.java

示例5: resolve

import javax.xml.transform.Source; //導入依賴的package包/類
/**
 * Reads document description with a given doi from the Scopus API.
 *
 * 
 *         
 *
 */

public Source resolve(String href, String base) throws TransformerException {
    String doi = href.substring(href.indexOf(":") + 1);
    LOGGER.debug("Reading MCRContent with DOI " + doi);

    ScopusConnector connection = new ScopusConnector();
    try {
        MCRContent content = connection.getPublicationByDOI(doi);
        if (content == null) {
            return null;
        }
        MCRXSL2XMLTransformer transformer = new MCRXSL2XMLTransformer("xsl/scopus2mods.xsl");
        MCRContent mods = transformer.transform(content);
        LOGGER.debug("end resolving " + href);
        return mods.getSource();
    } catch (IOException e) {
        throw new TransformerException(e);
    }
}
 
開發者ID:ETspielberg,項目名稱:bibliometrics,代碼行數:27,代碼來源:MCRScopusDOIresolver.java

示例6: xmlToHtml

import javax.xml.transform.Source; //導入依賴的package包/類
/**
 * Transforms the XML content to XHTML/HTML format string with the XSL.
 *
 * @param payload  the XML payload to convert
 * @param xsltFile the XML stylesheet file
 * @return the transformed XHTML/HTML format string
 * @throws AlipayApiException problem converting XML to HTML
 */
public static String xmlToHtml(String payload, File xsltFile) throws AlipayApiException {
	String result = null;

	try {
		Source template = new StreamSource(xsltFile);
		Transformer transformer = TransformerFactory.newInstance().newTransformer(template);

		Properties props = transformer.getOutputProperties();
		props.setProperty(OutputKeys.OMIT_XML_DECLARATION, LOGIC_YES);
		transformer.setOutputProperties(props);

		StreamSource source = new StreamSource(new StringReader(payload));
		StreamResult sr = new StreamResult(new StringWriter());
		transformer.transform(source, sr);

		result = sr.getWriter().toString();
	} catch (TransformerException e) {
		throw new AlipayApiException("XML_TRANSFORM_ERROR", e);
	}

	return result;
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:31,代碼來源:XmlUtils.java

示例7: getSourceImpl

import javax.xml.transform.Source; //導入依賴的package包/類
/**
 * Returns a Source for reading the XML value designated by this SQLXML
 * instance. <p>
 *
 * @param sourceClass The class of the source, or null.  If null, then a
 *      DOMSource is returned.
 * @return a Source for reading the XML value.
 * @throws SQLException if there is an error processing the XML value
 *   or if the given <tt>sourceClass</tt> is not supported.
 */
protected <T extends Source>T getSourceImpl(
        Class<T> sourceClass) throws SQLException {

    if (JAXBSource.class.isAssignableFrom(sourceClass)) {

        // Must go first presently, since JAXBSource extends SAXSource
        // (purely as an implmentation detail) and it's not possible
        // to instantiate a valid JAXBSource with a Zero-Args
        // constructor(or any subclass thereof, due to the finality of
        // its private marshaller and context object attrbutes)
        // FALL THROUGH... will throw an exception
    } else if (StreamSource.class.isAssignableFrom(sourceClass)) {
        return createStreamSource(sourceClass);
    } else if ((sourceClass == null)
               || DOMSource.class.isAssignableFrom(sourceClass)) {
        return createDOMSource(sourceClass);
    } else if (SAXSource.class.isAssignableFrom(sourceClass)) {
        return createSAXSource(sourceClass);
    } else if (StAXSource.class.isAssignableFrom(sourceClass)) {
        return createStAXSource(sourceClass);
    }

    throw Util.invalidArgument("sourceClass: " + sourceClass);
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:35,代碼來源:JDBCSQLXML.java

示例8: formatXml

import javax.xml.transform.Source; //導入依賴的package包/類
public static String formatXml(String xml) {
    String formatted = null;
    if (xml == null || xml.trim().length() == 0) {
        return formatted;
    }
    try {
        Source xmlInput = new StreamSource(new StringReader(xml));
        StreamResult xmlOutput = new StreamResult(new StringWriter());
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",
                String.valueOf(XML_INDENT));
        transformer.transform(xmlInput, xmlOutput);
        formatted = xmlOutput.getWriter().toString().replaceFirst(">", ">"
                + XPrinter.lineSeparator);
    } catch (Exception e) {

    }
    return formatted;
}
 
開發者ID:lzmlsfe,項目名稱:19porn,代碼行數:21,代碼來源:LogFormat.java

示例9: writeDocument

import javax.xml.transform.Source; //導入依賴的package包/類
/**
 * Write an XML document to a Writer
 */
public static void writeDocument(Document doc, Writer writer)
                                                        throws IOException {
  final Source source = new DOMSource(doc);

  // Prepare the output file
  final Result result = new StreamResult(writer);

  // Write the DOM document to the file
  try {
    final Transformer xformer =
      TransformerFactory.newInstance().newTransformer();
    xformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
    xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); //$NON-NLS-1$ //$NON-NLS-2$
    xformer.transform(source, result);
  }
  catch (TransformerException e) {
    // FIXME: switch to IOException(Throwable) ctor in Java 1.6
    throw (IOException) new IOException().initCause(e);
  }
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:24,代碼來源:Builder.java

示例10: formatXml

import javax.xml.transform.Source; //導入依賴的package包/類
public static String formatXml(String xml) {
    String formatted = null;
    if (xml == null || xml.trim().length() == 0) {
        return formatted;
    }
    try {
        Source xmlInput = new StreamSource(new StringReader(xml));
        StreamResult xmlOutput = new StreamResult(new StringWriter());
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",
                String.valueOf(XML_INDENT));
        transformer.transform(xmlInput, xmlOutput);
        formatted = xmlOutput.getWriter().toString().replaceFirst(">", ">"
                + XPrinter.lineSeparator);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return formatted;
}
 
開發者ID:ruiqiao2017,項目名稱:Renrentou,代碼行數:21,代碼來源:LogFormat.java

示例11: xmlToHtml

import javax.xml.transform.Source; //導入依賴的package包/類
/**
    * Transforms the XML content to XHTML/HTML format string with the XSL.
    *
    * @param payload the XML payload to convert
    * @param xsltFile the XML stylesheet file
    * @return the transformed XHTML/HTML format string
    * @throws AlipayApiException problem converting XML to HTML
    */
   public static String xmlToHtml(String payload, File xsltFile)
throws AlipayApiException {
       String result = null;

       try {
           Source template = new StreamSource(xsltFile);
           Transformer transformer = TransformerFactory.newInstance()
                   .newTransformer(template);

           Properties props = transformer.getOutputProperties();
           props.setProperty(OutputKeys.OMIT_XML_DECLARATION, LOGIC_YES);
           transformer.setOutputProperties(props);

           StreamSource source = new StreamSource(new StringReader(payload));
           StreamResult sr = new StreamResult(new StringWriter());
           transformer.transform(source, sr);

           result = sr.getWriter().toString();
       } catch (TransformerException e) {
           throw new AlipayApiException("XML_TRANSFORM_ERROR", e);
       }

       return result;
   }
 
開發者ID:1991wangliang,項目名稱:pay,代碼行數:33,代碼來源:XmlUtils.java

示例12: putDocumentInCache

import javax.xml.transform.Source; //導入依賴的package包/類
/**
 * Put the source tree root node in the document cache.
 * TODO: This function needs to be a LOT more sophisticated.
 *
 * @param n The node to cache.
 * @param source The Source object to cache.
 */
public void putDocumentInCache(int n, Source source)
{

  int cachedNode = getNode(source);

  if (DTM.NULL != cachedNode)
  {
    if (!(cachedNode == n))
      throw new RuntimeException(
        "Programmer's Error!  "
        + "putDocumentInCache found reparse of doc: "
        + source.getSystemId());
    return;
  }
  if (null != source.getSystemId())
  {
    m_sourceTree.addElement(new SourceTree(n, source.getSystemId()));
  }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:SourceTreeManager.java

示例13: soapMessage2String

import javax.xml.transform.Source; //導入依賴的package包/類
/**
 * Gets the SOAP message pretty printed as escaped xml for displaying in
 * browser
 * 
 * @param msg
 * @return
 */
private String soapMessage2String(SOAPMessage msg) {
    if (msg == null)
        return "";

    try (ByteArrayOutputStream streamOut = new ByteArrayOutputStream();) {
        Transformer transformer = TransformerFactory.newInstance()
                .newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty(
                "{http://xml.apache.org/xslt}indent-amount", "2");
        Source sc = msg.getSOAPPart().getContent();
        StreamResult result = new StreamResult(streamOut);
        transformer.transform(sc, result);

        String strMessage = streamOut.toString();
        return escapeXmlString(strMessage);
    } catch (Exception e) {
        System.out.println("Exception in printing SOAP message: "
                + e.getMessage());
        return "";
    }

}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:31,代碼來源:VersionHandler.java

示例14: test

import javax.xml.transform.Source; //導入依賴的package包/類
@Test
public void test() {
    try {

        Source source = new StreamSource(util.BOMInputStream.createStream("UTF-16BE", this.getClass().getResourceAsStream("Hello.wsdl.data")),
                    this.getClass().getResource("Hello.wsdl.data").toExternalForm());
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        TransformerFactory factory = TransformerFactory.newInstance();
        Transformer transformer = factory.newTransformer();
        transformer.transform(source, new StreamResult(baos));
        System.out.println(new String(baos.toByteArray()));
        ByteArrayInputStream bis = new ByteArrayInputStream(baos.toByteArray());
        InputSource inSource = new InputSource(bis);

        XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
        xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE);
        XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(inSource.getSystemId(), inSource.getByteStream());
        while (reader.hasNext()) {
            reader.next();
        }
    } catch (Exception ex) {
        ex.printStackTrace(System.err);
        Assert.fail("Exception occured: " + ex.getMessage());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:Bug6388460.java

示例15: resolve

import javax.xml.transform.Source; //導入依賴的package包/類
/**
 * Reads document description from the CrossRef API.
 *
 * 
 *   @author Eike Spielberg      
 *
 */

public Source resolve(String href, String base) throws TransformerException {
    String id = href.substring(href.indexOf(":") + 1);
    MCRContent content = null;
    CrossRefConnector connection = new CrossRefConnector();
    try {
        MCRContent crossRefExport = connection.getPublicationByDOI(id);
        content = new MCRStringContent(XML.toString(new JSONObject(crossRefExport.asString()), "content"));
        LOGGER.debug("Reading MCRContent with DOI " + id);
        MCRXSL2XMLTransformer transformer = new MCRXSL2XMLTransformer("xsl/CrossRef2mods.xsl");
        MCRContent mods = transformer.transform(content);
        connection.close();
        return mods.getSource();
    } catch (Exception e) {
        throw new TransformerException(e);
    }
}
 
開發者ID:ETspielberg,項目名稱:bibliometrics,代碼行數:25,代碼來源:MCRCrossRefResolver.java


注:本文中的javax.xml.transform.Source類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。