xmlsignatureinput.java
来自「JAVA 所有包」· Java 代码 · 共 613 行 · 第 1/2 页
JAVA
613 行
* Determines if the object has been set up with a Node set * * @return true is the object has been set up with a Node set */ public boolean isNodeSet() { return (( (this._inputOctetStreamProxy == null) && (this._inputNodeSet != null) ) || isNodeSet); } /** * Determines if the object has been set up with an Element * * @return true is the object has been set up with a Node set */ public boolean isElement() { return ((this._inputOctetStreamProxy==null)&& (this._subNode!=null) && (this._inputNodeSet==null) && !isNodeSet ); } /** * Determines if the object has been set up with an octet stream * * @return true is the object has been set up with an octet stream */ public boolean isOctetStream() { return ( ((this._inputOctetStreamProxy != null) || bytes!=null) && ((this._inputNodeSet == null) && _subNode ==null)); } /** * Determines if the object has been set up with a ByteArray * * @return true is the object has been set up with an octet stream */ public boolean isByteArray() { return ( (bytes!=null) && ((this._inputNodeSet == null) && _subNode ==null)); } /** * Is the object correctly set up? * * @return true if the object has been set up correctly */ public boolean isInitialized() { return (this.isOctetStream() || this.isNodeSet()); } /** * Returns MIMEType * * @return MIMEType */ public String getMIMEType() { return this._MIMEType; } /** * Sets MIMEType * * @param MIMEType */ public void setMIMEType(String MIMEType) { this._MIMEType = MIMEType; } /** * Return SourceURI * * @return SourceURI */ public String getSourceURI() { return this._SourceURI; } /** * Sets SourceURI * * @param SourceURI */ public void setSourceURI(String SourceURI) { this._SourceURI = SourceURI; } /** * Method toString * @inheritDoc * */ public String toString() { if (this.isNodeSet()) { return "XMLSignatureInput/NodeSet/" + this._inputNodeSet.size() + " nodes/" + this.getSourceURI(); } if (this.isElement()) { return "XMLSignatureInput/Element/" + this._subNode + " exclude "+ this.excludeNode + " comments:" + this.excludeComments +"/" + this.getSourceURI(); } try { return "XMLSignatureInput/OctetStream/" + this.getBytes().length + " octets/" + this.getSourceURI(); } catch (Exception ex) { return "XMLSignatureInput/OctetStream//" + this.getSourceURI(); } } /** * Method getHTMLRepresentation * * @throws XMLSignatureException * @return The HTML representation for this XMLSignature */ public String getHTMLRepresentation() throws XMLSignatureException { XMLSignatureInputDebugger db = new XMLSignatureInputDebugger(this); return db.getHTMLRepresentation(); } /** * Method getHTMLRepresentation * * @param inclusiveNamespaces * @throws XMLSignatureException * @return The HTML representation for this XMLSignature */ public String getHTMLRepresentation(Set inclusiveNamespaces) throws XMLSignatureException { XMLSignatureInputDebugger db = new XMLSignatureInputDebugger( this, inclusiveNamespaces); return db.getHTMLRepresentation(); } /** * Gets the exclude node of this XMLSignatureInput * @return Returns the excludeNode. */ public Node getExcludeNode() { return excludeNode; } /** * Sets the exclude node of this XMLSignatureInput * @param excludeNode The excludeNode to set. */ public void setExcludeNode(Node excludeNode) { this.excludeNode = excludeNode; } /** * Gets the node of this XMLSignatureInput * @return The excludeNode set. */ public Node getSubNode() { return _subNode; } /** * @return Returns the excludeComments. */ public boolean isExcludeComments() { return excludeComments; } /** * @param excludeComments The excludeComments to set. */ public void setExcludeComments(boolean excludeComments) { this.excludeComments = excludeComments; } /** * @param diOs * @throws IOException * @throws CanonicalizationException */ public void updateOutputStream(OutputStream diOs) throws CanonicalizationException, IOException { if (diOs==outputStream) { return; } if (bytes!=null) { diOs.write(bytes); return; }else if (_inputOctetStreamProxy==null) { Canonicalizer20010315OmitComments c14nizer = new Canonicalizer20010315OmitComments(); c14nizer.setWriter(diOs); c14nizer.engineCanonicalize(this); return; } else { InputStream is = getResetableInputStream(); if (bytes!=null) { //already read write it, can be rea. diOs.write(bytes,0,bytes.length); return; } is.reset(); int num; byte[] bytesT = new byte[1024]; while ((num=is.read(bytesT))>0) { diOs.write(bytesT,0,num); } } } /** * @param os */ public void setOutputStream(OutputStream os) { outputStream=os; } protected InputStream getResetableInputStream() throws IOException{ if ((_inputOctetStreamProxy instanceof ByteArrayInputStream) ) { if (!_inputOctetStreamProxy.markSupported()) { throw new RuntimeException("Accepted as Markable but not truly been"+_inputOctetStreamProxy); } return _inputOctetStreamProxy; } if (bytes!=null) { _inputOctetStreamProxy=new ByteArrayInputStream(bytes); return _inputOctetStreamProxy; } if (_inputOctetStreamProxy ==null) return null; if (_inputOctetStreamProxy.markSupported()) { if (log.isLoggable(java.util.logging.Level.INFO)) log.log(java.util.logging.Level.INFO, "Mark Suported but not used as reset"); } bytes=JavaUtils.getBytesFromStream(_inputOctetStreamProxy); _inputOctetStreamProxy.close(); _inputOctetStreamProxy=new ByteArrayInputStream(bytes); return _inputOctetStreamProxy; } /** * @param filter */ public void addNodeFilter(NodeFilter filter) { if (isOctetStream()) { try { convertToNodes(); } catch (Exception e) { throw new XMLSecurityRuntimeException("signature.XMLSignatureInput.nodesetReference",e); } } nodeFilters.add(filter); } /** * @return the node filters */ public List getNodeFilters() { // TODO Auto-generated method stub return nodeFilters; } /** * @param b */ public void setNodeSet(boolean b) { isNodeSet=b; } void convertToNodes() throws CanonicalizationException, ParserConfigurationException, IOException, SAXException{ DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); dfactory.setValidating(false); dfactory.setNamespaceAware(true); DocumentBuilder db = dfactory.newDocumentBuilder(); // select all nodes, also the comments. try { db.setErrorHandler(new com.sun.org.apache.xml.internal.security.utils .IgnoreAllErrorHandler()); Document doc = db.parse(this.getOctetStream()); XMLUtils.circumventBug2650(doc); this._subNode=doc.getDocumentElement(); } catch (SAXException ex) { // if a not-wellformed nodeset exists, put a container around it... ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write("<container>".getBytes()); baos.write(this.getBytes()); baos.write("</container>".getBytes()); byte result[] = baos.toByteArray(); Document document = db.parse(new ByteArrayInputStream(result)); this._subNode=document.getDocumentElement().getFirstChild().getFirstChild(); } this._inputOctetStreamProxy=null; this.bytes=null; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?