@SuppressWarnings("unchecked") public <T extends Element> Document<T> getDocument() { if (doc == null) { if (pipein == null) return null; doc = abdera.getParser().parse(pipein); } return (Document<T>)doc; }
private <T extends Element> Document<T> getEntry(InputStream stream, RequestContext request) throws ParseException, IOException { Parser parser = request.getAbdera().getParser(); if (parser == null) throw new IllegalArgumentException("No Parser implementation was provided"); Document<?> document = parser.parse(stream, request.getResolvedUri().toString(), parser.getDefaultParserOptions()); return (Document<T>)document; }
/** * Get the response payload as a parsed Abdera FOM Document using the specified parser * * @param parser The parser */ public <T extends Element> Document<T> getDocument(Parser parser) throws ParseException { return getDocument(parser, parser.getDefaultParserOptions()); }
@SuppressWarnings("unchecked") public synchronized <T extends Element> Document<T> getDocument(Parser parser) throws ParseException, IOException { log.debug(Localizer.get("PARSING.REQUEST.DOCUMENT")); if (parser == null) parser = getAbdera().getParser(); if (parser == null) throw new IllegalArgumentException("No Parser implementation was provided"); if (document == null) document = getDocument(parser, parser.getDefaultParserOptions()); return (Document<T>)document; }
@SuppressWarnings("unchecked") public <T extends Element>Document<T> getDocument() { if (doc == null) { if (pipein == null) return null; doc = abdera.getParser().parse(pipein); } return doc; }
protected Element _parse(String value, IRI baseUri) throws ParseException, UnsupportedEncodingException { if (value == null) return null; FOMFactory fomfactory = (FOMFactory)factory; Parser parser = fomfactory.newParser(); ParserOptions options = parser.getDefaultParserOptions(); options.setFactory(fomfactory); Document doc = parser.parse(new StringReader(value), (baseUri != null) ? baseUri.toString() : null, options); return doc.getRoot(); }
private Entry getEntry(File entryFile) { if (!entryFile.exists() || !entryFile.isFile()) throw new RuntimeException(); try { FileInputStream fis = new FileInputStream(entryFile); Document<Entry> doc = abdera.getParser().parse(fis); Entry entry = doc.getRoot(); return entry; } catch (Exception e) { throw new RuntimeException(e); } }
public T readFrom(Class<T> clazz, Type t, Annotation[] a, MediaType mt, MultivaluedMap<String, String> headers, InputStream is) throws IOException { Parser parser = ATOM_ENGINE.getParser(); synchronized (parser) { ParserOptions options = parser.getDefaultParserOptions(); if (options != null) { options.setAutodetectCharset(autodetectCharset); } } Document<T> doc = parser.parse(is); return doc.getRoot(); }
private Entry getEntry(final File entryFile) { if (!entryFile.exists() || !entryFile.isFile()) { throw new RuntimeException(); } try { final FileInputStream fis = new FileInputStream(entryFile); final Document<Entry> doc = this.abdera.getParser().parse(fis); final Entry entry = doc.getRoot(); return entry; } catch (final Exception e) { throw new RuntimeException(e); } }
public T readFrom(Class<T> clazz, Type t, Annotation[] a, MediaType mt, MultivaluedMap<String, String> headers, InputStream is) throws IOException { Parser parser = ATOM_ENGINE.getParser(); synchronized (parser) { ParserOptions options = parser.getDefaultParserOptions(); if (options != null) { options.setAutodetectCharset(autodetectCharset); } } XMLStreamReader reader = StaxUtils.createXMLStreamReader(is); Document<T> doc = parser.parse(reader); return doc.getRoot(); }
protected Document domToFom(org.w3c.dom.Document dom, SecurityOptions options) { Document doc = null; if (dom != null) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); t.transform(new DOMSource(dom), new StreamResult(out)); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); doc = options.getParser().parse(in); } catch (Exception e) { } } return doc; }
public T readFrom(Class<T> clazz, Type t, Annotation[] a, MediaType mt, MultivaluedMap<String, String> headers, InputStream is) throws IOException { Parser parser = ATOM_ENGINE.getParser(); synchronized (parser) { ParserOptions options = parser.getDefaultParserOptions(); if (options != null) { options.setAutodetectCharset(autodetectCharset); } } XMLStreamReader reader = StaxUtils.createXMLStreamReader(is); Document<T> doc = parser.parse(reader); return doc.getRoot(); }
protected Element domToFom(org.w3c.dom.Element element, SecurityOptions options) { Element el = null; if (element != null) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); t.transform(new DOMSource(element), new StreamResult(out)); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); el = options.getParser().parse(in).getRoot(); } catch (Exception e) { } } return el; } }
try { if (options == null) options = parser.getDefaultParserOptions(); String charset = getCharacterEncoding(); if (charset != null) Document<T> doc = parser.parse(getReader(), base, options); EntityTag etag = getEntityTag(); if (etag != null)
private void parseEntry() { if (entry == null) { Document<Entry> doc = abdera.getParser().parse(new ByteArrayInputStream(content)); entry = doc.getRoot(); } } }
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"); } } }
Document document = parser.parse(new ByteArrayInputStream(baos.toByteArray())); entry.setContent(document.getRoot(), mediaType.toString());
@Override protected void runTest() throws Throwable { Document<Entry> document = abdera.getParser().parse( TestGetCategoriesByScheme.class.getResourceAsStream("entry-with-categories.xml")); Entry entry = document.getRoot(); List<Category> categories = entry.getCategories("http://www.example.org/"); assertThat(categories).hasSize(2); assertThat(categories.get(0).getTerm()).isEqualTo("term1"); assertThat(categories.get(1).getTerm()).isEqualTo("term2"); categories = entry.getCategories(null); assertThat(categories).hasSize(1); assertThat(categories.get(0).getTerm()).isEqualTo("other"); } }
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); } } }
@SuppressWarnings("unchecked") public synchronized <T extends Element> Document<T> getDocument(Parser parser, ParserOptions options) throws ParseException, IOException { log.debug(Localizer.get("PARSING.REQUEST.DOCUMENT")); if (parser == null) parser = getAbdera().getParser(); if (parser == null) throw new IllegalArgumentException("No Parser implementation was provided"); if (document == null) { document = parser.parse(getInputStream(), getResolvedUri().toString(), options); } return (Document<T>)document; }