private FOMFactory getFomFactory(ParserOptions options) { FOMFactory factory = (options != null && options.getFactory() != null) ? (FOMFactory)options.getFactory() : null; if (factory == null) { Factory f = getFactory(); factory = (f instanceof FOMFactory) ? (FOMFactory)f : new FOMFactory(); } return factory; }
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(); }
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(); }
public Service readFrom(Class<Service> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> headers, InputStream stream) throws IOException, WebApplicationException { Parser parser = null; if (mediaType.equals(MediaType.APPLICATION_JSON_TYPE) || mediaType.getSubtype().endsWith("+json")) { parser = Abdera.getInstance().getParserFactory().getParser("json"); } else { parser = Abdera.getInstance().getParser(); } Document<Service> document = parser.parse(stream); return document.getRoot(); }
@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> getDocument(FOMBuilder builder, IRI base, ParserOptions options) throws ParseException { Document<T> document = builder.getFomDocument(); try { if (base != null) document.setBaseUri(base.toString()); if (options != null && options.getCharset() != null) ((OMDocument)document).setCharsetEncoding(options.getCharset()); if (options != null) document.setMustPreserveWhitespace(options.getMustPreserveWhitespace()); } catch (Exception e) { if (!(e instanceof ParseException)) e = new ParseException(e); throw (ParseException)e; } return 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()); }
/** * Method next. * * @return Returns int. * @throws OMException */ public int next() throws OMException { try { return super.next(); } catch (OMException e) { // TODO: transforming the OMException here is not ideal! throw new ParseException(e); } }
public <T extends Element> Document<T> parse(ReadableByteChannel buf, String base, ParserOptions options) throws ParseException { String charset = options.getCharset(); return parse(Channels.newReader(buf, charset != null ? charset : "utf-8"), base, options); }
public synchronized Parser setDefaultParserOptions(ParserOptions options) { // Ok, we need to make a defensive copy of the options, since otherwise // the caller still has access to the object, which means our access to // it isn't certain to be thread safe. try { this.options = (options != null) ? (ParserOptions)options.clone() : initDefaultParserOptions(); return this; } catch (CloneNotSupportedException cnse) { // This shouldn't actually happen throw new RuntimeException(cnse); } }
private void translateQName() { if (parserOptions.isQNameAliasMappingEnabled()) { Map<QName,QName> map = parserOptions.getQNameAliasMap(); if (map != null) { altQName = map.get(super.getName()); } } }
/** * Registers a NamedParser implementation */ public AbderaConfiguration addNamedParser(NamedParser parser) { Map<String,NamedParser> parsers = getNamedParsers(); parsers.put(parser.getName(), parser); return this; }
FOMStAXFilter(XMLStreamReader parent, ParserOptions parserOptions) { super(parent); this.parserOptions = parserOptions; if (parserOptions != null) { ParseFilter parseFilter = parserOptions.getParseFilter(); if (parseFilter != null) { ignoreWhitespace = parseFilter.getIgnoreWhitespace(); ignoreComments = parseFilter.getIgnoreComments(); ignorePI = parseFilter.getIgnoreProcessingInstructions(); attributeMap = new int[8]; } } resetEvent(); }
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(); }
public Entry readFrom(Class<Entry> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> headers, InputStream stream) throws IOException, WebApplicationException { Parser parser = null; if (mediaType.equals(MediaType.APPLICATION_JSON_TYPE) || mediaType.getSubtype().endsWith("+json")) { parser = Abdera.getInstance().getParserFactory().getParser("json"); } else { parser = Abdera.getInstance().getParser(); } Document<Entry> document = parser.parse(stream); return document.getRoot(); }
@SuppressWarnings("unchecked") public <T extends Element>Document<T> getDocument() { if (doc == null) { if (pipein == null) return null; doc = abdera.getParser().parse(pipein); } return doc; }
public synchronized ParserOptions getDefaultParserOptions() { if (options == null) options = initDefaultParserOptions(); // Make a copy of the options, so that changes to it don't result in // changes to the Parser's defaults. Also, this allows us to remain // thread safe without having to make ParseOptions implementations // synchronized. try { return (ParserOptions)options.clone(); } catch (CloneNotSupportedException cnse) { // This shouldn't actually happen throw new RuntimeException(cnse); } }
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(); }
public Feed readFrom(Class<Feed> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> headers, InputStream stream) throws IOException, WebApplicationException { Parser parser = null; if (mediaType.equals(MediaType.APPLICATION_JSON_TYPE) || mediaType.getSubtype().endsWith("+json")) { parser = Abdera.getInstance().getParserFactory().getParser("json"); } else { parser = Abdera.getInstance().getParser(); } Document<Feed> document = parser.parse(stream); return document.getRoot(); }
public Categories readFrom(Class<Categories> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> headers, InputStream stream) throws IOException, WebApplicationException { Parser parser = null; if (mediaType.equals(MediaType.APPLICATION_JSON_TYPE) || mediaType.getSubtype().endsWith("+json")) { parser = Abdera.getInstance().getParserFactory().getParser("json"); } else { parser = Abdera.getInstance().getParser(); } Document<Categories> document = parser.parse(stream); return document.getRoot(); }