Changeset 1751
- Timestamp:
- 23/11/06 17:13:23 (14 years ago)
- Location:
- TI01-discovery/trunk/ws-Discovery2/src/ndg/services/discovery
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TI01-discovery/trunk/ws-Discovery2/src/ndg/services/discovery/PresentAgent.java
r1604 r1751 30 30 31 31 // Input parameters 32 String documentName; 33 String format = "payload"; //default 32 Vector documentNames; 33 String format = "original"; //default 34 35 // Output holder 36 Vector returnDocs; 34 37 35 38 /** … … 42 45 * @param documentName String containing name (eg. /db/dif/badc/somedoc.xml) 43 46 */ 44 public PresentAgent( String documentName)47 public PresentAgent(Vector documentNames) 45 48 { 46 this.documentName = documentName;49 this.documentNames = documentNames; 47 50 } 48 51 … … 51 54 * @param s String containing name (eg. /db/dif/badc/somedoc.xml) 52 55 */ 53 public void setDocumentName (Strings)56 public void setDocumentNames(Vector documentNames) 54 57 { 55 this.documentName =s;58 this.documentNames = documentNames; 56 59 } 57 60 … … 99 102 options.put("process-xsl-pi", "no"); 100 103 101 //1. Execute the remote getDocumentAsString() 102 Vector getDocumentAsStringParams = new Vector(); 103 getDocumentAsStringParams.addElement( this.documentName ); 104 getDocumentAsStringParams.addElement( options ); 105 returnDoc = (byte[])xmlrpc.execute( "getDocument", getDocumentAsStringParams ); 104 //0. For each document requested, do an XMLRPC call to fetch it 105 Iterator it = this.documentNames.iterator(); 106 returnDocs = new Vector(); 106 107 107 if (returnDoc != null)108 while ( it.hasNext() ) 108 109 { 109 result.setStatus( true ); 110 result.setStatusMessage( "Success" ); 110 //1. Execute the remote getDocumentAsString() 111 Vector getDocumentAsStringParams = new Vector(); 112 getDocumentAsStringParams.addElement( (String)it.next() ); 113 getDocumentAsStringParams.addElement( options ); 114 returnDoc = (byte[])xmlrpc.execute( "getDocument", getDocumentAsStringParams ); 111 115 112 if ( this.format.equals("payload"))116 if (returnDoc != null) 113 117 { 114 // Return the payload, i.e. the contents of the first "doc" element 115 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 116 DocumentBuilder builder = factory.newDocumentBuilder(); 117 Document root = builder.parse( 118 new InputSource ( 119 new ByteArrayInputStream( 120 returnDoc 121 ) 122 ) 123 ); 118 result.setStatus( true ); 119 result.setStatusMessage( "Success" ); 124 120 125 NodeList docNodes = root.getElementsByTagName("doc"); 126 // Assuming payload is contained within 1st doc element... 127 Element docElem = (Element)docNodes.item(0); 128 NodeList payloadNodes = docElem.getChildNodes(); 129 // Could be text nodes too, so need to test for type = Element 130 for (int i=0; i<payloadNodes.getLength(); i++) 121 if ( this.format.equals("ndgDoc") ) 131 122 { 132 Node thisNode = payloadNodes.item(i); 133 if ( thisNode.getNodeType() == Node.ELEMENT_NODE ) 134 { 135 // Serialize it 136 OutputFormat format = new OutputFormat( root ); 137 format.setOmitXMLDeclaration( true ); 138 StringWriter writer = new StringWriter(); 139 XMLSerializer output = new XMLSerializer(writer, format); 140 output.serialize( (Element)thisNode ); 141 result.setDocument( writer.toString() ); 142 } 123 returnDocs.add( new String( returnDoc ) ); 124 } 125 else 126 { 127 throw new Exception("Format " + this.format + " not implemented."); 143 128 } 144 129 } 145 else if ( this.format.equals("ndgDoc") ) 146 { 147 result.setDocument( new String( returnDoc ) ); 148 } 149 else 150 { 151 throw new Exception("Format " + this.format + " not implemented."); 130 else { 131 throw new Exception("Got null response from getDocumentAsString()"); 152 132 } 153 133 } 154 else { 155 throw new Exception("Got null response from getDocumentAsString()"); 156 } 157 134 result.setDocuments( returnDocs ); 158 135 } 159 136 catch (Exception e) … … 162 139 result.setStatusMessage( "Error retrieving document : " + e.toString() ); 163 140 } 141 142 164 143 return result; 165 144 } -
TI01-discovery/trunk/ws-Discovery2/src/ndg/services/discovery/PresentSummary.java
r1558 r1751 1 1 package ndg.services.discovery; 2 3 import java.util.Vector; 2 4 3 5 /** … … 10 12 private boolean status; 11 13 private String statusMessage; 12 private String document;14 private Vector documents; 13 15 14 16 /** Default no-arg constructor */ … … 22 24 * @param documents String containing XML document 23 25 */ 24 public PresentSummary( boolean status, String statusMessage, String document) {26 public PresentSummary( boolean status, String statusMessage, Vector docs ) { 25 27 this.status = status; 26 28 this.statusMessage = statusMessage; 27 this.document = document;29 this.documents = docs; 28 30 } 29 31 … … 78 80 79 81 /** 80 * Sets the String containing the XML document retrieved by the present. 81 * @param s String containing XML document 82 * Sets the Vector containing the documents. 83 * Each element should contain a string, which in turn should contain 84 * the XML document payload. 85 * @param v Vector containing 1 element for each document 82 86 */ 83 public void setDocument (String s)87 public void setDocuments(Vector v) 84 88 { 85 this.document = s;89 this.documents = v; 86 90 } 87 91 88 92 /** 89 * Returns the String containing XML document retrieved by present.90 * @return String containing XMLdocument93 * Returns the Vector containing Hashtable of info for each matched document. 94 * @return Vector one element per matched document 91 95 */ 92 public String getDocument()96 public Vector getDocuments() 93 97 { 94 return this.document ;98 return this.documents; 95 99 } 96 100
Note: See TracChangeset
for help on using the changeset viewer.