19 | | The Java REP reference implementation provides some helpers to the Resource Providers. The stubs for RPI and RAI methods are given in the example code. |
20 | | |
21 | | === RPI methods: === |
22 | | * public List<String> publishResourceDescription(String descriptionString) |
23 | | * public List<String> publishResourceDescription(ResourceDescription desc) |
24 | | * public String updateResourceDescription(String resourceID, ResourceDescription description) |
25 | | * public String deleteResourceDescription(List<String> resourceIDs) |
| 19 | The Java REP reference implementation provides some helpers to Resource Providers. |
| 20 | The stubs for RPI and RAI methods are given in the example code. |
33 | | '''GET''' requests are handled by its method: |
34 | | * public Representation represent(Variant variant) |
35 | | This method returns the Observation & Measurement value in XML/RDF format. |
| 29 | '''GET''' requests are handled by the method toXML(). This method returns the Observation & Measurement value in XML/RDF format. |
| 30 | |
| 31 | {{{ |
| 32 | @Get("xml") |
| 33 | public Representation toXml() { |
| 34 | try { |
| 35 | DomRepresentation representation = new DomRepresentation( |
| 36 | MediaType.TEXT_XML); |
| 37 | |
| 38 | // read the Observation & Measurement value from the respective file |
| 39 | String fileName = "./xml/sensors/" + sensorName + ".rdf"; |
| 40 | |
| 41 | File file = new File(fileName); |
| 42 | |
| 43 | DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
| 44 | DocumentBuilder db = dbf.newDocumentBuilder(); |
| 45 | |
| 46 | // Generate a DOM document |
| 47 | Document doc = db.parse(file); |
| 48 | doc.normalize(); |
| 49 | representation.setDocument(doc); |
| 50 | |
| 51 | // Returns the XML representation of this document. |
| 52 | return representation; |
| 53 | |
| 54 | } catch (IOException e) { |
| 55 | e.printStackTrace(); |
| 56 | } catch (ParserConfigurationException e) { |
| 57 | e.printStackTrace(); |
| 58 | } catch (SAXException e) { |
| 59 | e.printStackTrace(); |
| 60 | } |
| 61 | return null; |
| 62 | } |
| 63 | }}} |
| 64 | |