Changeset 1600
- Timestamp:
- 18/10/06 21:36:49 (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/DiscoveryServiceSkeleton.java
r1575 r1600 111 111 discoveryserviceapi.PresentType requestContent = request.getDoPresent(); 112 112 PresentAgent agent = new PresentAgent( requestContent.getDocument() ); 113 if ( requestContent.isSetFormat() ) 114 { 115 agent.setFormat( requestContent.getFormat().toString() ); 116 } 113 117 114 118 try … … 131 135 } 132 136 133 134 } 137 /** 138 * Auto generated method signature 139 140 * @param param2 141 142 */ 143 public discoveryserviceapi.DoAuthorSearchReturnDocument doAuthorSearch 144 (discoveryserviceapi.DoAuthorSearchDocument param2 ) 145 146 { 147 //Todo fill this with the necessary business logic 148 throw new java.lang.UnsupportedOperationException(); 149 } 150 151 152 /** 153 * Auto generated method signature 154 155 * @param param4 156 157 */ 158 public discoveryserviceapi.DoParameterSearchReturnDocument doParameterSearch 159 (discoveryserviceapi.DoParameterSearchDocument param4 ) 160 161 { 162 //Todo fill this with the necessary business logic 163 throw new java.lang.UnsupportedOperationException(); 164 } 165 166 167 /** 168 * Auto generated method signature 169 170 * @param param6 171 172 */ 173 public discoveryserviceapi.DoSpatioTemporalSearchReturnDocument doSpatioTemporalSearch 174 (discoveryserviceapi.DoSpatioTemporalSearchDocument param6 ) 175 176 { 177 //Todo fill this with the necessary business logic 178 throw new java.lang.UnsupportedOperationException(); 179 } 180 } 135 181 -
TI01-discovery/trunk/ws-Discovery2/src/ndg/services/discovery/PresentAgent.java
r1558 r1600 6 6 import java.util.Properties; 7 7 8 import java.io.BufferedReader; 9 import java.io.InputStreamReader; 10 import java.io.IOException; 8 import java.io.*; 11 9 12 10 import org.apache.xmlrpc.XmlRpc; 13 11 import org.apache.xmlrpc.XmlRpcClient; 12 13 import javax.xml.parsers.DocumentBuilderFactory; 14 import javax.xml.parsers.DocumentBuilder; 15 import org.xml.sax.InputSource; 16 import org.w3c.dom.*; 17 import org.apache.xml.serialize.OutputFormat; 18 import org.apache.xml.serialize.XMLSerializer; 19 20 14 21 15 22 /** … … 24 31 // Input parameters 25 32 String documentName; 33 String format = "payload"; //default 26 34 27 35 /** … … 49 57 50 58 /** 59 * Sets the format in which to present the document 60 * @param s String containing format (eg. payload, ndgdoc, dc) 61 */ 62 public void setFormat(String s) 63 { 64 this.format = s; 65 } 66 67 /** 51 68 * Executes the remote getDocumentAsString method and returns document as a String 52 69 * @return String containing XML document … … 57 74 PresentSummary result = new PresentSummary(); 58 75 59 StringreturnDoc = null;76 byte[] returnDoc = null; 60 77 XmlRpc.setEncoding("UTF-8"); 61 78 … … 83 100 84 101 //1. Execute the remote getDocumentAsString() 85 System.out.println( "before : returnDoc is " + returnDoc );86 102 Vector getDocumentAsStringParams = new Vector(); 87 103 getDocumentAsStringParams.addElement( this.documentName ); 88 104 getDocumentAsStringParams.addElement( options ); 89 returnDoc = ( String)xmlrpc.execute( "getDocumentAsString", getDocumentAsStringParams );105 returnDoc = (byte[])xmlrpc.execute( "getDocument", getDocumentAsStringParams ); 90 106 91 107 if (returnDoc != null) … … 93 109 result.setStatus( true ); 94 110 result.setStatusMessage( "Success" ); 95 result.setDocument( returnDoc ); 111 112 if ( this.format.equals("payload") ) 113 { 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 ); 124 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++) 131 { 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 } 143 } 144 } 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."); 152 } 96 153 } 97 154 else {
Note: See TracChangeset
for help on using the changeset viewer.