当前位置: 首页>>代码示例>>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;未经允许,请勿转载。