protected org.w3c.dom.Document fomToDom(Document doc, SecurityOptions options) { org.w3c.dom.Document dom = null; if (doc != null) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); doc.writeTo(out); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating(false); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); dom = db.parse(in); } catch (Exception e) { } } return dom; }
private void toJson(OutputStream aout, Writer writer) throws Exception { Document<Element> doc = null; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); if (writer == null) super.writeTo(out); else super.writeTo(out, writer); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); doc = abdera.getParser().parse(in); } catch (Exception e) { } if (doc != null) { doc.writeTo("json", aout); } else { throw new RuntimeException("There was an error serializing the entry to JSON"); } } }
private void sign(OutputStream aout, Writer writer) throws Exception { Document<Element> doc = null; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); if (writer == null) super.writeTo(out); else super.writeTo(out, writer); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); doc = abdera.getParser().parse(in); } catch (Exception e) { } if (doc != null) { doc = signDocument(abdera, doc); doc.writeTo(aout); } else { super.writeTo(aout); } } }
private void encrypt(OutputStream aout, Writer writer) throws Exception { Document<Element> doc = null; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); if (writer == null) super.writeTo(out); else super.writeTo(out, writer); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); doc = abdera.getParser().parse(in); } catch (Exception e) { } if (doc != null) { Encryption enc = security.getEncryption(); EncryptionOptions options = initEncryptionOptions(request, response, enc, arg); doc = enc.encrypt(doc, options); } if (doc != null) doc.writeTo(aout); else throw new RuntimeException("There was an error encrypting the response"); } }
response.setDateHeader("Last-Modified", doc.getLastModified().getTime()); OutputStream out = response.getOutputStream(); doc.writeTo("json", out); } catch (Exception e) { response.sendError(500);