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


Java Result類代碼示例

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


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

示例1: readMode

import javax.xml.transform.Result; //導入依賴的package包/類
public static String readMode(FileObject fo) throws IOException {
    final InputStream is = fo.getInputStream();
    try {
        StringWriter w = new StringWriter();
        Source t = new StreamSource(DesignSupport.class.getResourceAsStream("polishing.xsl")); // NOI18N
        Transformer tr = TransformerFactory.newInstance().newTransformer(t);
        Source s = new StreamSource(is);
        Result r = new StreamResult(w);
        tr.transform(s, r);
        return w.toString();
    } catch (TransformerException ex) {
        throw new IOException(ex);
    } finally {
        is.close();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:DesignSupport.java

示例2: validation

import javax.xml.transform.Result; //導入依賴的package包/類
/**
	 * 利用xsd驗證xml
	 * @param xsdFile xsdFile
	 * @param xmlInput xmlInput
	 * @throws SAXException  SAXException
	 * @throws IOException IOException
	 */
	public static void validation(String xsdFile, InputStream xmlInput) throws SAXException, IOException
	{
		SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
		URL xsdURL = Validation.class.getClassLoader().getResource(xsdFile);
		if(xsdURL != null)
		{
			Schema schema = factory.newSchema(xsdURL);
			Validator validator = schema.newValidator();
//			validator.setErrorHandler(new AutoErrorHandler());

			Source source = new StreamSource(xmlInput);
			
			try(OutputStream resultOut = new FileOutputStream(new File(PathUtil.getRootDir(), xsdFile + ".xml")))
			{
				Result result = new StreamResult(resultOut);
				validator.validate(source, result);
			}
		}
		else
		{
			throw new FileNotFoundException(String.format("can not found xsd file [%s] from classpath.", xsdFile));
		}
	}
 
開發者ID:LinuxSuRen,項目名稱:phoenix.webui.framework,代碼行數:31,代碼來源:Validation.java

示例3: writeDocument

import javax.xml.transform.Result; //導入依賴的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

示例4: render

import javax.xml.transform.Result; //導入依賴的package包/類
/**
 * Renders an input file (XML or XSL-FO) into a PDF file. It uses the JAXP
 * transformer given to optionally transform the input document to XSL-FO.
 * The transformer may be an identity transformer in which case the input
 * must already be XSL-FO. The PDF is written to a byte array that is
 * returned as the method's result.
 * @param src Input XML or XSL-FO
 * @param transformer Transformer to use for optional transformation
 * @param response HTTP response object
 * @throws FOPException If an error occurs during the rendering of the
 * XSL-FO
 * @throws TransformerException If an error occurs during XSL
 * transformation
 * @throws IOException In case of an I/O problem
 */
public void render(Source src, Transformer transformer, HttpServletResponse response, String realpath)
            throws FOPException, TransformerException, IOException {

    FOUserAgent foUserAgent = getFOUserAgent(realpath);

    //Setup output
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    //Setup FOP
    fopFactory.setBaseURL(realpath);
    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);


    //Make sure the XSL transformation's result is piped through to FOP
    Result res = new SAXResult(fop.getDefaultHandler());

    //Start the transformation and rendering process
    transformer.transform(src, res);

    //Return the result
    sendPDF(out.toByteArray(), response);
}
 
開發者ID:malglam,項目名稱:Lester,代碼行數:38,代碼來源:CreatePDF.java

示例5: load

import javax.xml.transform.Result; //導入依賴的package包/類
public static @NotNull Optional<Schema> load(@NotNull JAXBContext context) {
  try {
    final List<ByteArrayOutputStream> outputs = new ArrayList<>();
    context.generateSchema(new SchemaOutputResolver() {
      @Override
      public @NotNull Result createOutput(@NotNull String namespace, @NotNull String suggestedFileName) {
        final ByteArrayOutputStream output = new ByteArrayOutputStream();
        outputs.add(output);
        final StreamResult result = new StreamResult(output);
        result.setSystemId("");
        return result;
      }
    });
    return Optional.ofNullable(
        SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
            .newSchema(outputs.stream()
                .map(ByteArrayOutputStream::toByteArray)
                .map(ByteArrayInputStream::new)
                .map(input -> new StreamSource(input, ""))
                .toArray(StreamSource[]::new))
    );
  } catch (IOException | SAXException e) {
    logger.error("Failed to load schema", e);
    return Optional.empty();
  }
}
 
開發者ID:nolequen,項目名稱:jmx-prometheus-exporter,代碼行數:27,代碼來源:SchemaGenerator.java

示例6: moduleDoc

import javax.xml.transform.Result; //導入依賴的package包/類
/**
 * CLI option: print the documentation for the specified module.
 * @param name
 * @throws TransformerException
 * @throws XPathExpressionException
 * @throws UnsupportedServiceException
 * @throws ServiceInstanciationException
 * @throws AmbiguousAliasException
 */
@CLIOption(value="-moduleDoc", stop=true)
public final void moduleDoc(String name) throws TransformerException, XPathExpressionException, UnsupportedServiceException, AmbiguousAliasException { 
	Document doc = getModuleDocumentation(name);
	// same ClassLoader as this class
	Source xslt = new StreamSource(getClass().getResourceAsStream(noColors ? "alvisnlp-doc2txt.xslt" : "alvisnlp-doc2ansi.xslt"));
	TransformerFactory transformerFactory = TransformerFactory.newInstance();
	Transformer transformer = transformerFactory.newTransformer(xslt);
	transformer.setParameter("name", bundle.getString(DocResourceConstants.MODULE_NAME).toUpperCase(locale));
	transformer.setParameter("synopsis", bundle.getString(DocResourceConstants.SYNOPSIS).toUpperCase(locale));
	transformer.setParameter("description", bundle.getString(DocResourceConstants.MODULE_DESCRIPTION).toUpperCase(locale));
	transformer.setParameter("parameters", bundle.getString(DocResourceConstants.MODULE_PARAMETERS).toUpperCase(locale));
	Source source = new DOMSource(doc);
	Result result = new StreamResult(System.out);
	transformer.transform(source, result);
}
 
開發者ID:Bibliome,項目名稱:alvisnlp,代碼行數:25,代碼來源:AbstractAlvisNLP.java

示例7: identityTransform

import javax.xml.transform.Result; //導入依賴的package包/類
/**
 * Performs identity transformation.
 */
public static <T extends Result>
T identityTransform(Source src, T result) throws TransformerException, SAXException, ParserConfigurationException, IOException {
    if (src instanceof StreamSource) {
        // work around a bug in JAXP in JDK6u4 and earlier where the namespace processing
        // is not turned on by default
        StreamSource ssrc = (StreamSource) src;
        TransformerHandler th = ((SAXTransformerFactory) transformerFactory.get()).newTransformerHandler();
        th.setResult(result);
        XMLReader reader = saxParserFactory.get().newSAXParser().getXMLReader();
        reader.setContentHandler(th);
        reader.setProperty(LEXICAL_HANDLER_PROPERTY, th);
        reader.parse(toInputSource(ssrc));
    } else {
        newTransformer().transform(src, result);
    }
    return result;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:XmlUtil.java

示例8: testcase02

import javax.xml.transform.Result; //導入依賴的package包/類
/**
 * SAXTFactory.newTransformerhandler() method which takes SAXSource as
 * argument can be set to XMLReader. SAXSource has input XML file as its
 * input source. XMLReader has a content handler which write out the result
 * to output file. Test verifies output file is same as golden file.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testcase02() throws Exception {
    String outputFile = USER_DIR + "saxtf002.out";
    String goldFile = GOLDEN_DIR + "saxtf002GF.out";

    try (FileOutputStream fos = new FileOutputStream(outputFile);
            FileInputStream fis = new FileInputStream(XSLT_FILE)) {
        XMLReader reader = XMLReaderFactory.createXMLReader();
        SAXTransformerFactory saxTFactory
                = (SAXTransformerFactory) TransformerFactory.newInstance();
        SAXSource ss = new SAXSource();
        ss.setInputSource(new InputSource(fis));

        TransformerHandler handler = saxTFactory.newTransformerHandler(ss);
        Result result = new StreamResult(fos);
        handler.setResult(result);
        reader.setContentHandler(handler);
        reader.parse(XML_FILE);
    }
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:30,代碼來源:SAXTFactoryTest.java

示例9: createOutputFile

import javax.xml.transform.Result; //導入依賴的package包/類
/**
     * Creates the {@link Result} object used by JAXB to generate a schema for the
     * namesapceUri namespace.
     * @param namespaceUri The namespace for the schema being generated
     * @param suggestedFileName the JAXB suggested file name for the schema file
     * @return the {@link Result} for JAXB to generate the schema into
     * @throws java.io.IOException thrown if on IO error occurs
     */
    public Result createOutputFile(String namespaceUri, String suggestedFileName) throws IOException {
        Result result;
        if (namespaceUri == null) {
            return null;
        }

        Holder<String> fileNameHolder = new Holder<String>();
        fileNameHolder.value = schemaPrefix + suggestedFileName;
        result = wsdlResolver.getSchemaOutput(namespaceUri, fileNameHolder);
//        System.out.println("schema file: "+fileNameHolder.value);
//        System.out.println("result: "+result);
        String schemaLoc;
        if (result == null)
            schemaLoc = fileNameHolder.value;
        else
            schemaLoc = relativize(result.getSystemId(), wsdlLocation);
        boolean isEmptyNs = namespaceUri.trim().equals("");
        if (!isEmptyNs) {
            com.sun.xml.internal.ws.wsdl.writer.document.xsd.Import _import = types.schema()._import();
            _import.namespace(namespaceUri);
            _import.schemaLocation(schemaLoc);
        }
        return result;
    }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:33,代碼來源:WSDLGenerator.java

示例10: xmlToString

import javax.xml.transform.Result; //導入依賴的package包/類
public static String xmlToString(Node node)
{
	try
	{
		Source source = new DOMSource(node);
		StringWriter writer = new StringWriter();
		Result result = new StreamResult(writer);
		Transformer transformer = TransformerFactory.newInstance().newTransformer();
		transformer.transform(source, result);
		return writer.toString();
	}
	catch( Exception e )
	{
		throw new RuntimeException(e);
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:17,代碼來源:XmlDocument.java

示例11: domSourceToString

import javax.xml.transform.Result; //導入依賴的package包/類
protected String domSourceToString() throws SQLException {
    try {
        DOMSource source = new DOMSource(this.asDOMResult.getNode());
        Transformer identity = TransformerFactory.newInstance().newTransformer();
        StringWriter stringOut = new StringWriter();
        Result result = new StreamResult(stringOut);
        identity.transform(source, result);

        return stringOut.toString();
    } catch (Throwable t) {
        SQLException sqlEx = SQLError.createSQLException(t.getMessage(), SQLError.SQL_STATE_ILLEGAL_ARGUMENT, this.exceptionInterceptor);
        sqlEx.initCause(t);

        throw sqlEx;
    }
}
 
開發者ID:Jugendhackt,項目名稱:OpenVertretung,代碼行數:17,代碼來源:JDBC4MysqlSQLXML.java

示例12: validate

import javax.xml.transform.Result; //導入依賴的package包/類
private void validate(final String xsdFile, final Source src, final Result result) throws Exception {
    try {
        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = sf.newSchema(new File(ValidatorTest.class.getResource(xsdFile).toURI()));

        // Get a Validator which can be used to validate instance document
        // against this grammar.
        Validator validator = schema.newValidator();
        ErrorHandler eh = new ErrorHandlerImpl();
        validator.setErrorHandler(eh);

        // Validate this instance document against the
        // Instance document supplied
        validator.validate(src, result);
    } catch (Exception ex) {
        throw ex;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:ValidatorTest.java

示例13: createResult

import javax.xml.transform.Result; //導入依賴的package包/類
/**
 * Retrieves a new Result for setting the XML value designated by this
 * SQLXML instance.
 *
 * @param resultClass The class of the result, or null.
 * @throws java.sql.SQLException if there is an error processing the XML
 *         value or the state is not writable
 * @return for setting the XML value designated by this SQLXML instance.
 */
protected <T extends Result>T createResult(
        Class<T> resultClass) throws SQLException {

    checkWritable();
    setWritable(false);
    setReadable(true);

    if (JAXBResult.class.isAssignableFrom(resultClass)) {

        // Must go first presently, since JAXBResult extends SAXResult
        // (purely as an implmentation detail) and it's not possible
        // to instantiate a valid JAXBResult with a Zero-Args
        // constructor(or any subclass thereof, due to the finality of
        // its private UnmarshallerHandler)
        // FALL THROUGH... will throw an exception
    } else if ((resultClass == null)
               || StreamResult.class.isAssignableFrom(resultClass)) {
        return createStreamResult(resultClass);
    } else if (DOMResult.class.isAssignableFrom(resultClass)) {
        return createDOMResult(resultClass);
    } else if (SAXResult.class.isAssignableFrom(resultClass)) {
        return createSAXResult(resultClass);
    } else if (StAXResult.class.isAssignableFrom(resultClass)) {
        return createStAXResult(resultClass);
    }

    throw JDBCUtil.invalidArgument("resultClass: " + resultClass);
}
 
開發者ID:Julien35,項目名稱:dev-courses,代碼行數:38,代碼來源:JDBCSQLXML.java

示例14: upsetTheNorm

import javax.xml.transform.Result; //導入依賴的package包/類
public InputStream upsetTheNorm(String xPath, boolean remove) {
	try {
		document = dbf.newDocumentBuilder().parse(new File(pathname));
		XPath xpath = xpf.newXPath();
		XPathExpression expression = xpath.compile(xPath);

		NodeList searchedNodes = (NodeList) expression.evaluate(document, XPathConstants.NODESET);
		if (searchedNodes == null) {
			System.out.println("bad path: " + xPath);
		} else {
			for (int i = 0; i < searchedNodes.getLength(); i++) {
				Node searched = searchedNodes.item(i);

				Node owningElement = (searched instanceof ElementImpl)
						? searched
						: ((AttrImpl) searched).getOwnerElement();

				Node containingParent = owningElement.getParentNode();

				if (remove) {
					containingParent.removeChild(owningElement);
				} else {
					containingParent.appendChild(owningElement.cloneNode(true));
				}

			}
		}

		Transformer t = tf.newTransformer();
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		Result result = new StreamResult(os);
		t.transform(new DOMSource(document), result);
		return new ByteArrayInputStream(os.toByteArray());
	} catch (ParserConfigurationException | IOException | SAXException |
			XPathExpressionException | TransformerException ex) {
		throw new RuntimeException(ex);
	}
}
 
開發者ID:CMSgov,項目名稱:qpp-conversion-tool,代碼行數:39,代碼來源:MarkupManipulator.java

示例15: write

import javax.xml.transform.Result; //導入依賴的package包/類
public static void write(Element el, OutputStream out) throws IOException {
    try {
        Transformer t = TransformerFactory.newInstance().newTransformer(
                new StreamSource(new StringReader(IDENTITY_XSLT_WITH_INDENT)));
        t.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // NOI18N
        t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        Source source = new DOMSource(el);
        Result result = new StreamResult(out);
        t.transform(source, result);
    } catch (Exception | TransformerFactoryConfigurationError e) {
        throw new IOException(e);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:XMLUtil.java


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