IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope: Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  XML  >

Exploring XML Encryption, Part 1

Demonstrating the secure exchange of structured data

developerWorks

Return to article.


Listing 14. Authors the KeyInfo element
        
 /*
 	DW/BS
	20020204
	GenericKeyInfo.java
	Listing 14
	Authors the KeyInfo element.
 */
import org.w3c.dom.*;
public class GenericKeyInfo {
	// Element to hold complete XML Structure.
	protected Element keyInfo = null;
	protected Document doc = null;
	// Element will be appended in Document only once.
	protected boolean elementAppendedToDoc = false;
	
	// Default constructor.
	public GenericKeyInfo (Document document, String nsQlif, int typeNo) {
		doc = document;
		
		keyInfo = doc.createElement(nsQlif + ":KeyInfo");
		
		// Add the namespace attribute.
		keyInfo.setAttribute("xmlns:" + nsQlif, AlgoNames.getAlgoNSValue(typeNo));
	}// End GenericKeyInfo
	
	// Add KeyName child in KeyInfo
	public void setKeyName(String keyName) {
		Element tempElem = doc.createElement("KeyName");
		tempElem.appendChild(doc.createTextNode(keyName));
		keyInfo.appendChild(tempElem);
	}// End setKeyName()
	
	// Add KeyValue child in KeyInfo
	public void setKeyValue (String keyValue){
		Element tempElem = doc.createElement("KeyValue");
		tempElem.appendChild(doc.createTextNode(keyValue));
		keyInfo.appendChild(tempElem);
	}// End setKeyValue()
	
	// Set retrieval Method URI and and Its type.
	public void setRetrievalMethod (String uriValue, int typeNo) {
		Element tempElem = doc.createElement("RetrievalMethod");
		tempElem.setAttribute("URI", uriValue);
		tempElem.setAttribute("Type", AlgoNames.getAlgoNSValue(typeNo));
		keyInfo.appendChild(tempElem);
	}// End setRetrievalMethod() 
	
	// Return the complete XML structure as a Document Object.
	public Document getKeyInfo() {
		if (elementAppendedToDoc == false ) {
			doc.appendChild(keyInfo);
			elementAppendedToDoc = true;
		}
	 	return doc;
	}// End getKeyInfo()
} // end class KeyInfo
      

Return to article.

    关于 IBM 隐私条约 联系 IBM 使用条款