Package javax.xml.transform.stream

Examples of javax.xml.transform.stream.StreamSource


  private static void transformConfig(File config, String styleSheet, Result target)
      throws TransformerFactoryConfigurationError,
      TransformerConfigurationException, TransformerException {
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = tf.newTransformer(new StreamSource(MigrationUtil.class.getResourceAsStream(styleSheet)));
    t.setParameter("version", ApplicationInfo.getInstance().getReleaseNumber()); //$NON-NLS-1$
    t.transform(new StreamSource(config), target);
  }
View Full Code Here


        } else if (o instanceof OMElement) {
            OMElement omElement = (OMElement) o;
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                omElement.serialize(baos);
                return new StreamSource(new ByteArrayInputStream(baos.toByteArray()));
            } catch (XMLStreamException e) {
                handleException("Error converting to a StreamSource", e);
            }

        } else if (o instanceof OMText) {
            DataHandler dataHandler = (DataHandler) ((OMText) o).getDataHandler();
            if (dataHandler != null) {
                try {
                    return new StreamSource(dataHandler.getInputStream());
                } catch (IOException e) {
                    handleException("Error in reading content as a stream ");
                }
            }
        } else {
View Full Code Here

        public static String transform(String stylesheet,
                                       String srcXMLString,
                                       HashMap<String, String> params) throws Exception {
            StringWriter writer = new StringWriter();
            StreamResult result = new StreamResult( writer );
            Source src = new StreamSource( new StringReader( srcXMLString ) );
            transform( stylesheet,
                       src,
                       result,
                       params );
            return writer.toString();
View Full Code Here

            InputStream xslStream = null;

            try {
                InputStream in = XSLTransformation.class.getResourceAsStream( stylesheet );
                xslStream = new BufferedInputStream( in );
                StreamSource src = new StreamSource( xslStream );
                src.setSystemId( stylesheet );
                transformer = TransformerFactory.newInstance().newTransformer( src );
            } finally {
                if ( xslStream != null ) xslStream.close();
            }
View Full Code Here

    public static void closeSource(final Source source) {
      if (!(source instanceof StreamSource)) {
        return;
      }
     
      StreamSource stream = (StreamSource)source;
      try {
        if (stream.getInputStream() != null) {
          stream.getInputStream().close();
        }
      } catch (IOException e) {
      }
      try {
        if (stream.getReader() != null) {
          stream.getReader().close();
        }
      } catch (IOException e) {
      }
    }
View Full Code Here

    }
   
    @SuppressWarnings("unchecked")
  public <T extends Source> T getSource(Class<T> sourceClass) throws SQLException {
    if (sourceClass == null || sourceClass == StreamSource.class) {
      return (T)new StreamSource(getBinaryStream(), this.getStreamFactory().getSystemId());
    } else if (sourceClass == StAXSource.class) {
      XMLInputFactory factory = XMLInputFactory.newInstance();
      try {
        return (T) new StAXSource(factory.createXMLStreamReader(getBinaryStream()));
      } catch (XMLStreamException e) {
View Full Code Here

        List<Argument> arguments = this.procedure.getArguments();
       
        String style = (String)arguments.get(0).getArgumentValue().getValue();
        String action = (String)arguments.get(1).getArgumentValue().getValue();
        XMLType docObject = (XMLType)arguments.get(2).getArgumentValue().getValue();
        StreamSource source = null;
      try {
          source = convertToSource(docObject);
          String endpoint = (String)arguments.get(3).getArgumentValue().getValue();
         
          if (style == null) {
            style = executionFactory.getDefaultBinding().getBindingId();
          } else {
            try {
              Binding type = Binding.valueOf(style.toUpperCase());
              style = type.getBindingId();
            } catch (IllegalArgumentException e) {
              throw new TranslatorException(WSExecutionFactory.UTIL.getString("invalid_invocation", Arrays.toString(Binding.values()))); //$NON-NLS-1$
            }
          }
         
          Dispatch<StreamSource> dispatch = conn.createDispatch(style, endpoint, StreamSource.class, executionFactory.getDefaultServiceMode());
 
      if (Binding.HTTP.getBindingId().equals(style)) {
        if (action == null) {
          action = "POST"; //$NON-NLS-1$
        }
        dispatch.getRequestContext().put(MessageContext.HTTP_REQUEST_METHOD, action);
        if (source != null && !"POST".equalsIgnoreCase(action)) { //$NON-NLS-1$
          if (this.executionFactory.getXMLParamName() == null) {
            throw new WebServiceException(WSExecutionFactory.UTIL.getString("http_usage_error")); //$NON-NLS-1$
          }
          try {
            Transformer t = TransformerFactory.newInstance().newTransformer();
            StringWriter writer = new StringWriter();
            //TODO: prevent this from being too large
                t.transform(source, new StreamResult(writer));
            String param = Util.httpURLEncode(this.executionFactory.getXMLParamName())+"="+Util.httpURLEncode(writer.toString()); //$NON-NLS-1$
            endpoint = WSConnection.Util.appendQueryString(endpoint, param);
          } catch (TransformerException e) {
            throw new WebServiceException(e);
          }
        }
      } else {
        if (action != null) {
          dispatch.getRequestContext().put(Dispatch.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
          dispatch.getRequestContext().put(Dispatch.SOAPACTION_URI_PROPERTY, action);
        }
      }
     
      if (source == null) {
        // JBoss Native DispatchImpl throws exception when the source is null
        source = new StreamSource(new StringReader("<none/>")); //$NON-NLS-1$
      }
      this.returnValue = dispatch.invoke(source);
    } catch (SQLException e) {
      throw new TranslatorException(e);
    } catch (WebServiceException e) {
View Full Code Here

       
    @Test public void testGetSource() throws Exception {       
        SQLXMLImpl xml = new SQLXMLImpl(testStr);
        assertTrue(xml.getSource(null) instanceof StreamSource);
       
        StreamSource ss = (StreamSource)xml.getSource(null);
        assertEquals(testStr, new String(ObjectConverterUtil.convertToByteArray(ss.getInputStream()), Streamable.ENCODING));
    }
View Full Code Here

        "      </publishingInformation>\r\n" //$NON-NLS-1$
        "   </book>\r\n" + //$NON-NLS-1$
        "</Books:bookCollection>"; //$NON-NLS-1$
  
    public void testStreamSourceWithStream() throws Exception {
        StandardXMLTranslator translator = new StandardXMLTranslator(new StreamSource(new StringReader(sourceXML)));
        compareDocuments(sourceXML, translator.getString());
    }   
View Full Code Here

      try {
        if (value instanceof SQLXML) {
        return ((SQLXML)value).getSource(null);
        }
        if (value instanceof Clob) {
          return new StreamSource(((Clob)value).getCharacterStream());
        }
        if (value instanceof Blob) {
          return new StreamSource(((Blob)value).getBinaryStream());
        }
        if (value instanceof String) {
          return new StreamSource(new StringReader((String)value));
        }
      } catch (SQLException e) {
      throw new TeiidProcessingException(e);
    }
      throw new AssertionError("Unknown type"); //$NON-NLS-1$
View Full Code Here

TOP

Related Classes of javax.xml.transform.stream.StreamSource

Copyright © 2015 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.