| 97 | | // File imageFile = ImageHandler.getComplexDataFile(complexObs); |
|---|
| 98 | | // File metadataFile = new File(imageFile.getCanonicalPath() + ".xml"); |
|---|
| 99 | | // |
|---|
| 100 | | // if (!metadataFile.exists()) { |
|---|
| 101 | | // // Do something clever |
|---|
| 102 | | // return; |
|---|
| 103 | | // } |
|---|
| 104 | | // |
|---|
| 105 | | // if (!metadataFile.canRead()) { |
|---|
| 106 | | // // do something clever |
|---|
| 107 | | // return; |
|---|
| 108 | | // } |
|---|
| 109 | | // |
|---|
| 110 | | // try { |
|---|
| 111 | | // |
|---|
| 112 | | // |
|---|
| 113 | | // JSONArray jsonarray = new JSONArray(); |
|---|
| 114 | | // |
|---|
| 115 | | // for (int i = 0; i < annotation.getLength(); i++) { |
|---|
| 116 | | // JSONObject element = new JSONObject(); |
|---|
| 117 | | // Node node = annotation.item(i); |
|---|
| 118 | | // NamedNodeMap attributes = node.getAttributes(); |
|---|
| 119 | | // String text = node.getTextContent(); |
|---|
| 120 | | // String date = attributes.getNamedItem("date").getNodeValue(); |
|---|
| 121 | | // String user = attributes.getNamedItem("userid").getNodeValue(); |
|---|
| 122 | | // String xcoordinate = |
|---|
| 123 | | // attributes.getNamedItem("xcoordinate").getNodeValue(); |
|---|
| 124 | | // String ycoordinate = |
|---|
| 125 | | // attributes.getNamedItem("ycoordinate").getNodeValue(); |
|---|
| 126 | | // |
|---|
| 127 | | // Pixel original = new Pixel(Integer.parseInt(xcoordinate), |
|---|
| 128 | | // Integer.parseInt(ycoordinate)); |
|---|
| 129 | | // Pixel relative = original.convertFromOriginalSizeToZoomlevel(zoom, |
|---|
| 130 | | // Pixel.getDimensionsFromImageFile(imageFile)); |
|---|
| 131 | | // |
|---|
| 132 | | // element.put("x", relative.x); |
|---|
| 133 | | // element.put("y", relative.y); |
|---|
| 134 | | // date = Context.getDateFormat().format(new |
|---|
| 135 | | // Date(Long.parseLong(date))); |
|---|
| 136 | | // user = |
|---|
| 137 | | // Context.getUserService().getUser(Integer.parseInt(user)).getGivenName |
|---|
| 138 | | // (); |
|---|
| 139 | | // element.put("text", text + "<br/>Date: "+date+"<br/>User: "+user); |
|---|
| 140 | | // jsonarray.put(element); |
|---|
| 141 | | // } |
|---|
| 142 | | // |
|---|
| 143 | | // JSONObject json = new JSONObject(); |
|---|
| 144 | | // json.put("annotation", jsonarray); |
|---|
| 145 | | // log.info(json.toString(2)); |
|---|
| 146 | | // response.setContentType("text/json;charset=UTF-8"); |
|---|
| 147 | | // response.getOutputStream().println(json.toString()); |
|---|
| 148 | | // response.getOutputStream().close(); |
|---|
| 149 | | // |
|---|
| 150 | | // } catch (JSONException e) { |
|---|
| 151 | | // log.error(e.getMessage(), e); |
|---|
| 152 | | // throw new ServletException(e); |
|---|
| 153 | | // } catch (ParserConfigurationException e) { |
|---|
| 154 | | // log.error(e.getMessage(), e); |
|---|
| 155 | | // throw new ServletException(e); |
|---|
| 156 | | // } catch (SAXException e) { |
|---|
| 157 | | // log.error(e.getMessage(), e); |
|---|
| 158 | | // throw new ServletException(e); |
|---|
| 159 | | // } |
|---|
| 160 | | |
|---|
| 233 | | // |
|---|
| 234 | | // DocumentBuilderFactory factory = DocumentBuilderFactory |
|---|
| 235 | | // .newInstance(); |
|---|
| 236 | | // DocumentBuilder builder = factory.newDocumentBuilder(); |
|---|
| 237 | | // Document xmldoc; |
|---|
| 238 | | // |
|---|
| 239 | | // if (!metadataFile.exists()) { |
|---|
| 240 | | // metadataFile.createNewFile(); |
|---|
| 241 | | // DOMImplementation domImpl = builder.getDOMImplementation(); |
|---|
| 242 | | // xmldoc = domImpl.createDocument(null, "Annotations", null); |
|---|
| 243 | | // } else { |
|---|
| 244 | | // xmldoc = builder.parse(metadataFile); |
|---|
| 245 | | // } |
|---|
| 246 | | // if (!metadataFile.canWrite() || !metadataFile.canRead()) |
|---|
| 247 | | // throw new IOException("Insufficient R/W permissions"); |
|---|
| 248 | | // |
|---|
| 249 | | // Element root = xmldoc.getDocumentElement(); |
|---|
| 250 | | // Element e = xmldoc.createElementNS(null, "Annotation"); |
|---|
| 251 | | // Node n = xmldoc.createTextNode(message); |
|---|
| 252 | | // e.setAttributeNS(null, "xcoordinate", coordinate.x + ""); |
|---|
| 253 | | // e.setAttributeNS(null, "ycoordinate", coordinate.y + ""); |
|---|
| 254 | | // e.setAttributeNS(null, "userid", Context.getUserContext() |
|---|
| 255 | | // .getAuthenticatedUser().getUserId() |
|---|
| 256 | | // + ""); |
|---|
| 257 | | // e.setAttributeNS(null, "date", new Date().getTime() + ""); |
|---|
| 258 | | // e.appendChild(n); |
|---|
| 259 | | // root.appendChild(e); |
|---|
| 260 | | // |
|---|
| 261 | | // Transformer transformer = TransformerFactory.newInstance() |
|---|
| 262 | | // .newTransformer(); |
|---|
| 263 | | // transformer.setOutputProperty(OutputKeys.ENCODING, "UTF8"); |
|---|
| 264 | | // transformer.setOutputProperty(OutputKeys.INDENT, "yes"); |
|---|
| 265 | | // transformer.transform(new DOMSource(xmldoc), new StreamResult( |
|---|
| 266 | | // metadataFile)); |
|---|
| 267 | | // |
|---|
| 271 | | // } catch (ParserConfigurationException e) { |
|---|
| 272 | | // log.error(e.getMessage(), e); |
|---|
| 273 | | // throw new ServletException(e.getMessage(), e); |
|---|
| 274 | | // } catch (TransformerConfigurationException e) { |
|---|
| 275 | | // log.error(e.getMessage(), e); |
|---|
| 276 | | // throw new ServletException(e.getMessage(), e); |
|---|
| 277 | | // } catch (TransformerFactoryConfigurationError e) { |
|---|
| 278 | | // log.error(e.getMessage(), e); |
|---|
| 279 | | // throw new ServletException(e.getMessage(), e); |
|---|
| 280 | | // } catch (TransformerException e) { |
|---|
| 281 | | // log.error(e.getMessage(), e); |
|---|
| 282 | | // throw new ServletException(e.getMessage(), e); |
|---|
| 283 | | // } catch (SAXException e) { |
|---|
| 284 | | // log.error(e.getMessage(), e); |
|---|
| 285 | | // throw new ServletException(e.getMessage(), e); |
|---|
| 286 | | // } |
|---|