@SuppressWarnings("unchecked") public <T extends Base> String getMimeType(T base) { Element element = base instanceof Element ? (Element)base : base instanceof Document ? ((Document)base).getRoot() : null; QName qname = element != null ? element.getQName() : null; return element != null && qname != null ? mimetypes.get(qname) : null; }
@SuppressWarnings("unchecked") public <T extends Base> String getMimeType(T base) { Element element = base instanceof Element ? (Element)base : base instanceof Document ? ((Document)base).getRoot() : null; QName qname = element != null ? element.getQName() : null; return element != null && qname != null ? mimetypes.get(qname) : null; }
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); } }
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); } }
private void parseEntry() { if (entry == null) { Document<Entry> doc = abdera.getParser().parse(new ByteArrayInputStream(content)); entry = doc.getRoot(); } } }
public <T extends Base> String getMimeType(T base) { Element element = base instanceof Element ? (Element)base : ((Document<?>)base).getRoot(); String namespace = element.getQName().getNamespaceURI(); synchronized (factories) { for (ExtensionFactory factory : factories) { if (factory.handlesNamespace(namespace)) return factory.getMimeType(base); } } return null; }
public <T extends Base> String getMimeType(T base) { Element element = base instanceof Element ? (Element)base : ((Document)base).getRoot(); String namespace = element.getQName().getNamespaceURI(); synchronized(factories) { for (ExtensionFactory factory : factories) { if (factory.handlesNamespace(namespace)) return factory.getMimeType(base); } } return null; }
public Feed addArchiveNode( Feed feed ) { Factory factory = feed.getFactory(); Element root = feed.getDocument().getRoot(); Element elementArchive = factory.newExtensionElement( new QName( ARCHIVE_NS, ARCHIVE, ARCHIVE_PREFIX ), root ); elementArchive.setParentElement( root ); return feed; } }
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 String createKey(RequestContext request) throws IOException { String slug = request.getSlug(); if (slug == null) { slug = ((Entry)request.getDocument().getRoot()).getTitle(); } return Sanitizer.sanitize(slug, "", true, Normalizer.Form.D); }
private Entry getAbderaEntry(RequestContext request) { Abdera abdera = request.getAbdera(); String entry_id = getEntryID(request); Document<Feed> feed = get_feed_doc(abdera); try { return feed.getRoot().getEntry(entry_id); } catch (Exception e) { // ignore } return null; }
/** * Creates the ResponseContext for a GET feed request. By default, a BaseResponseContext is returned. The Etag * header will be set. */ protected ResponseContext buildGetFeedResponse(Feed feed) { Document<Feed> document = feed.getDocument(); AbstractResponseContext rc = new BaseResponseContext<Document<Feed>>(document); rc.setEntityTag(calculateEntityTag(document.getRoot())); return rc; }
private String createKey(final RequestContext request) throws IOException { String slug = request.getSlug(); if (slug == null) { slug = ((Entry) request.getDocument().getRoot()).getTitle(); } return Sanitizer.sanitize(slug, "", true, Normalizer.Form.D); }
/** * {@inheritDoc} */ public Element readFrom(Class<Element> clazz, Type type, Annotation[] anno, MediaType mediaType, MultivaluedMap<String, String> headers, InputStream is) throws IOException, WebApplicationException { Parser parser = AbderaFactory.getInstance().getFactory().newParser(); Document<Element> doc = parser.parse(is); return doc.getRoot(); }
private Entry getEntry(String endpointAddress, String acceptType) throws Exception { CloseableHttpClient client = HttpClientBuilder.create().build(); HttpGet get = new HttpGet(endpointAddress); get.setHeader("Content-Type", "*/*"); if (acceptType != null) { get.setHeader("Accept", acceptType); } try { CloseableHttpResponse response = client.execute(get); Document<Entry> doc = abdera.getParser().parse(copyIn(response.getEntity().getContent())); return doc.getRoot(); } finally { get.releaseConnection(); } }
private Entry hydrateEntry(PersistedEntry persistedEntry, Abdera abderaReference) { final Document<Entry> hydratedEntryDocument = abderaReference.getParser().parse( new StringReader( persistedEntry.getEntryBody() ) ); Entry entry = null; if (hydratedEntryDocument != null) { entry = hydratedEntryDocument.getRoot(); entry.setUpdated(persistedEntry.getDateLastUpdated()); entry.setPublished(persistedEntry.getCreationDate()); } return entry; }
private Entry hydrateEntry(PersistedEntry persistedEntry, Abdera abderaReference) { final Document<Entry> hydratedEntryDocument = abderaReference.getParser().parse(new StringReader(persistedEntry.getEntryBody())); Entry entry = null; if (hydratedEntryDocument != null) { entry = hydratedEntryDocument.getRoot(); entry.setUpdated(persistedEntry.getDateLastUpdated()); entry.setPublished(persistedEntry.getCreationDate()); } return entry; }
private Entry hydrateEntry(PersistedEntry persistedEntry, Abdera abderaReference) { final Document<Entry> hydratedEntryDocument = abderaReference.getParser().parse( new StringReader(persistedEntry.getEntryBody())); Entry entry = null; if (hydratedEntryDocument != null) { entry = hydratedEntryDocument.getRoot(); entry.setUpdated(persistedEntry.getDateLastUpdated()); entry.setPublished(persistedEntry.getCreationDate()); } return entry; }
public ResponseContext getFeed(RequestContext request) { Abdera abdera = request.getAbdera(); Document<Feed> feed = get_feed_doc(abdera); AbstractResponseContext rc; rc = new BaseResponseContext<Document<Feed>>(feed); rc.setEntityTag(calculateEntityTag(feed.getRoot())); return rc; }
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(); }