List of usage examples for javax.xml.crypto OctetStreamData OctetStreamData
public OctetStreamData(InputStream octetStream, String uri, String mimeType)
OctetStreamData
. From source file:be.fedict.eid.applet.service.signer.asic.ASiCURIDereferencer.java
public Data dereference(URIReference uriReference, XMLCryptoContext context) throws URIReferenceException { if (null == uriReference) { throw new URIReferenceException("URIReference cannot be null"); }//from w w w. ja v a2 s . co m if (null == context) { throw new URIReferenceException("XMLCrytoContext cannot be null"); } String uri = uriReference.getURI(); try { uri = URLDecoder.decode(uri, "UTF-8"); } catch (UnsupportedEncodingException e) { LOG.warn("could not URL decode the uri: " + uri); } LOG.debug("dereference: " + uri); InputStream zipInputStream; if (null != this.tmpFile) { try { zipInputStream = new FileInputStream(this.tmpFile); } catch (FileNotFoundException e) { throw new URIReferenceException("file not found error: " + e.getMessage(), e); } } else { zipInputStream = new ByteArrayInputStream(this.data); } InputStream dataInputStream; try { dataInputStream = ODFUtil.findDataInputStream(zipInputStream, uri); } catch (IOException e) { throw new URIReferenceException("I/O error: " + e.getMessage(), e); } if (null == dataInputStream) { return this.baseUriDereferener.dereference(uriReference, context); } return new OctetStreamData(dataInputStream, uri, null); }
From source file:be.fedict.eid.applet.service.signer.ooxml.OOXMLURIDereferencer.java
public Data dereference(URIReference uriReference, XMLCryptoContext context) throws URIReferenceException { if (null == uriReference) { throw new NullPointerException("URIReference cannot be null"); }/*from ww w . ja va 2 s. com*/ if (null == context) { throw new NullPointerException("XMLCrytoContext cannot be null"); } String uri = uriReference.getURI(); try { uri = URLDecoder.decode(uri, "UTF-8"); } catch (UnsupportedEncodingException e) { LOG.warn("could not URL decode the uri: " + uri); } LOG.debug("dereference: " + uri); try { InputStream dataInputStream = findDataInputStream(uri); if (null == dataInputStream) { LOG.debug("cannot resolve, delegating to base DOM URI dereferencer: " + uri); return this.baseUriDereferencer.dereference(uriReference, context); } return new OctetStreamData(dataInputStream, uri, null); } catch (IOException e) { throw new URIReferenceException("I/O error: " + e.getMessage(), e); } }
From source file:be.fedict.eid.applet.service.signer.odf.ODFURIDereferencer.java
public Data dereference(URIReference uriReference, XMLCryptoContext context) throws URIReferenceException { if (null == uriReference) { throw new NullPointerException("URIReference cannot be null"); }/*from ww w. j a v a2 s . c o m*/ if (null == context) { throw new NullPointerException("XMLCrytoContext cannot be null"); } String uri = uriReference.getURI(); try { uri = URLDecoder.decode(uri, "UTF-8"); } catch (UnsupportedEncodingException e) { LOG.warn("could not URL decode the uri: " + uri); } LOG.debug("dereference: " + uri); try { InputStream dataInputStream = findDataInputStream(uri); if (null == dataInputStream) { LOG.debug("cannot resolve, delegating to base DOM URI dereferener: " + uri); return this.baseUriDereferener.dereference(uriReference, context); } if (uri.endsWith(".xml")) { /* * We parse the XML ourselves as we might need to resolve MathML * DTD. */ byte[] data = IOUtils.toByteArray(dataInputStream); if (0 == data.length) { return new OctetStreamData(dataInputStream, uri, null); } Document document = documentBuilder.parse(new ByteArrayInputStream(data)); XMLSignatureInput xmlSignatureInput = new XMLSignatureInput(document); ApacheNodeSetData apacheNodeSetData = new ApacheNodeSetData(xmlSignatureInput); return apacheNodeSetData; } return new OctetStreamData(dataInputStream, uri, null); } catch (IOException e) { throw new URIReferenceException("I/O error: " + e.getMessage(), e); } catch (SAXException e) { throw new URIReferenceException("SAX error: " + e.getMessage(), e); } }
From source file:org.apache.jcp.xml.dsig.internal.dom.DOMReference.java
private static Data copyDerefData(Data dereferencedData) { if (dereferencedData instanceof ApacheData) { // need to make a copy of the Data ApacheData ad = (ApacheData) dereferencedData; XMLSignatureInput xsi = ad.getXMLSignatureInput(); if (xsi.isNodeSet()) { try { final Set<Node> s = xsi.getNodeSet(); return new NodeSetData() { public Iterator iterator() { return s.iterator(); }/*www . j a va 2s. c o m*/ }; } catch (Exception e) { // log a warning log.warn("cannot cache dereferenced data: " + e); return null; } } else if (xsi.isElement()) { return new DOMSubTreeData(xsi.getSubNode(), xsi.isExcludeComments()); } else if (xsi.isOctetStream() || xsi.isByteArray()) { try { return new OctetStreamData(xsi.getOctetStream(), xsi.getSourceURI(), xsi.getMIMEType()); } catch (IOException ioe) { // log a warning log.warn("cannot cache dereferenced data: " + ioe); return null; } } } return dereferencedData; }
From source file:org.jcp.xml.dsig.internal.dom.DOMReference.java
private static Data copyDerefData(Data dereferencedData) { if (dereferencedData instanceof ApacheData) { // need to make a copy of the Data ApacheData ad = (ApacheData) dereferencedData; XMLSignatureInput xsi = ad.getXMLSignatureInput(); if (xsi.isNodeSet()) { try { final Set s = xsi.getNodeSet(); return new NodeSetData() { public Iterator iterator() { return s.iterator(); }//from w w w .java2 s.c o m }; } catch (Exception e) { // log a warning log.warn("cannot cache dereferenced data: " + e); return null; } } else if (xsi.isElement()) { return new DOMSubTreeData(xsi.getSubNode(), xsi.isExcludeComments()); } else if (xsi.isOctetStream() || xsi.isByteArray()) { try { return new OctetStreamData(xsi.getOctetStream(), xsi.getSourceURI(), xsi.getMIMEType()); } catch (IOException ioe) { // log a warning log.warn("cannot cache dereferenced data: " + ioe); return null; } } } return dereferencedData; }