org.apache.abdera.model.Document类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(144)

本文整理了Java中org.apache.abdera.model.Document类的一些代码示例,展示了Document类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Document类的具体详情如下:
包路径:org.apache.abdera.model.Document
类名称:Document

Document介绍

[英]The top level artifact of the Feed Object Model. The Parser component processes data from an InputStream and returns a Document instance. The type of Document returned depends on the XML format being parsed. The Feed Object Model supports four basic types of documents: FeedDocument, EntryDocument, ServiceDocument (Atom Publishing Protocol Introspection Documents) and XmlDocument (any arbitrary XML).
[中]提要对象模型的顶级工件。解析器组件处理来自InputStream的数据并返回文档实例。返回的文档类型取决于正在解析的XML格式。Feed对象模型支持四种基本类型的文档:FeedDocument、EntryDocument、ServiceDocument(Atom发布协议内省文档)和XmlDocument(任意XML)。

代码示例

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.abdera

@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;
}

代码示例来源:origin: org.apache.abdera/abdera-server

@SuppressWarnings("unchecked")
private String getCharsetFromBase(Base base) {
  if (base == null)
    return null;
  if (base instanceof Document) {
    return ((Document)base).getCharset();
  } else if (base instanceof Element) {
    return getCharsetFromBase(((Element)base).getDocument());
  }
  return null;
}

代码示例来源:origin: org.apache.abdera/abdera-extensions-json

private static void toJson(Document document, JSONStream jstream) throws IOException {
  jstream.startObject();
  jstream.writeField("base", document.getBaseUri());
  jstream.writeField("content-type", document.getContentType());
  jstream.writeField("etag", document.getEntityTag());
  jstream.writeField("language", document.getLanguage());
  jstream.writeField("slug", document.getSlug());
  jstream.writeField("last-modified", document.getLastModified());
  Element root = document.getRoot();
  if (root != null) {
    String rootname = root.getQName().getLocalPart();
    writeElement(rootname, document.getRoot(), jstream);
  }
  jstream.endObject();
}

代码示例来源:origin: stackoverflow.com

@RequestMapping("/document/{docId}")
public void downloadFile(@PathVariable Integer docId, @RequestParam(value="inline", required=false) Boolean inline, HttpServletResponse resp) throws IOException {

  Document doc = Document.findDocument(docId);

  File outputFile = new File(Constants.UPLOAD_DIR + "/" + docId);

  resp.reset();
  if (inline == null) {
    resp.setHeader("Content-Disposition", "attachment; filename=\"" + doc.getFilename() + "\"");
  }
  resp.setContentType(doc.getContentType());
  resp.setContentLength((int)outputFile.length());

  BufferedInputStream in = new BufferedInputStream(new FileInputStream(outputFile));

  FileCopyUtils.copy(in, resp.getOutputStream());
  resp.flushBuffer();

}

代码示例来源:origin: org.apache.abdera/abdera-server

/**
 * Return a document
 */
@SuppressWarnings("unchecked")
public static ResponseContext returnBase(Base base, int status, Date lastModified) {
  log.debug(Localizer.get("RETURNING.DOCUMENT"));
  BaseResponseContext response = new BaseResponseContext(base);
  response.setStatus(status);
  if (lastModified != null)
    response.setLastModified(lastModified);
  // response.setContentType(MimeTypeHelper.getMimeType(base));
  Document doc = base instanceof Document ? (Document)base : ((Element)base).getDocument();
  if (doc.getEntityTag() != null) {
    response.setEntityTag(doc.getEntityTag());
  } else if (doc.getLastModified() != null) {
    response.setLastModified(doc.getLastModified());
  }
  return response;
}

代码示例来源:origin: org.apache.abdera/abdera-server

/**
 * Retrieves the FOM Entry object from the request payload.
 */
@SuppressWarnings("unchecked")
protected Entry getEntryFromRequest(RequestContext request) throws ResponseContextException {
  Abdera abdera = request.getAbdera();
  Parser parser = abdera.getParser();
  Document<Entry> entry_doc;
  try {
    entry_doc = (Document<Entry>)request.getDocument(parser).clone();
  } catch (ParseException e) {
    throw new ResponseContextException(400, e);
  } catch (IOException e) {
    throw new ResponseContextException(500, e);
  }
  if (entry_doc == null) {
    return null;
  }
  return entry_doc.getRoot();
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.abdera

if (base instanceof Document) {
 Document doc = (Document)base;
 MimeType mt = doc.getContentType();
 type = (mt != null) ? mt.toString() : getMimeType(doc.getRoot());
} else if (base instanceof Element) {
 Element el = (Element)base;
 if (el.getDocument() != null) {
  MimeType mt = el.getDocument().getContentType();
  type = (mt != null) ? mt.toString() : null;

代码示例来源:origin: org.apache.abdera/abdera-extensions-json

response.setContentType("application/json");
  response.setCharacterEncoding("UTF-8");
  if (doc.getEntityTag() != null)
    response.setHeader("ETag", doc.getEntityTag().toString());
  if (doc.getLanguage() != null)
    response.setHeader("Content-Language", doc.getLanguage());
  if (doc.getLastModified() != null)
    response.setDateHeader("Last-Modified", doc.getLastModified().getTime());
  OutputStream out = response.getOutputStream();
  doc.writeTo("json", out);
} catch (Exception e) {
  response.sendError(500);

代码示例来源:origin: org.apache.abdera/abdera-parser

@SuppressWarnings("unchecked")
public void writeTo(Base base, OutputStream out, WriterOptions options) throws IOException {
  out = getCompressedOutputStream(out, options);
  String charset = options.getCharset();
  if (charset == null) {
    if (base instanceof Document)
      charset = ((Document)base).getCharset();
    else if (base instanceof Element) {
      Document doc = ((Element)base).getDocument();
      if (doc != null)
        charset = doc.getCharset();
    }
    if (charset == null)
      charset = "UTF-8";
  } else {
    Document doc = null;
    if (base instanceof Document)
      doc = (Document)base;
    else if (base instanceof Element)
      doc = ((Element)base).getDocument();
    if (doc != null)
      doc.setCharset(charset);
  }
  base.writeTo(new OutputStreamWriter(out, charset));
  finishCompressedOutputStream(out, options);
  if (options.getAutoClose())
    out.close();
}

代码示例来源:origin: org.apache.abdera/abdera-client

/**
 * Sends an HTTP PUT request to the specified URI.
 * 
 * @param uri The request URI
 * @param base A FOM Document or Element providing the payload of the request
 * @param options The request options
 */
public ClientResponse put(String uri, Base base, RequestOptions options) {
  if (options == null)
    options = getDefaultRequestOptions();
  if (base instanceof Document) {
    Document d = (Document)base;
    if (options.getSlug() == null && d.getSlug() != null)
      options.setSlug(d.getSlug());
    if (options.isConditionalPut()) {
      if (d.getEntityTag() != null)
        options.setIfMatch(d.getEntityTag());
      else if (d.getLastModified() != null)
        options.setIfUnmodifiedSince(d.getLastModified());
    }
  }
  return execute("PUT", uri, new BaseRequestEntity(base, options.isUseChunked()), options);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.abdera

public StreamBuilder startDocument(String xmlversion, String charset) {
 if (root != null)
  throw new IllegalStateException("Document already started");
 root = abdera.getFactory().newDocument();
 ((Document)root).setCharset(charset);
 current = root;
 return this;
}

代码示例来源:origin: org.fuzzydb.atom/org.fuzzydb.abdera.util

Document<Entry> updatedDoc = (Document<Entry>) request.getDocument(parser).clone();
if (updatedDoc == null || !ProviderHelper.isValidEntry(updatedDoc.getRoot())) {
  return makeExceptionResponse(HttpServletResponse.SC_BAD_REQUEST, "");
} else {

代码示例来源:origin: org.apache.abdera/abdera-core

if (base instanceof Document) {
  Document doc = (Document)base;
  MimeType mt = doc.getContentType();
  type = (mt != null) ? mt.toString() : getMimeType(doc.getRoot());
} else if (base instanceof Element) {
  Element el = (Element)base;
  if (el.getDocument() != null) {
    MimeType mt = el.getDocument().getContentType();
    type = (mt != null) ? mt.toString() : null;

代码示例来源:origin: org.apache.abdera/abdera-core

public StreamBuilder startDocument(String xmlversion, String charset) {
  if (root != null)
    throw new IllegalStateException("Document already started");
  root = abdera.getFactory().newDocument();
  ((Document)root).setCharset(charset);
  current = root;
  return this;
}

代码示例来源:origin: org.apache.abdera/abdera-core

@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;
}

代码示例来源:origin: org.fuzzydb.atom/org.fuzzydb.abdera.util

.getDocument(parser).clone();
if (entry_doc != null) {
  Entry entry = entry_doc.getRoot();
  if (!entry.getId().equals(orig_entry.getId())) {
    return new EmptyResponseContext(409);
      "edit");
  orig_entry.discard();
  Feed feed = get_feed_doc(abdera).getRoot();
  feed.insertEntry(entry);
  feed.setUpdated(new Date());

代码示例来源:origin: org.apache.abdera/abdera-parser

/**
 * Sets the content for this entry
 */
public Content setContent(InputStream in, String mediatype) {
  if (MimeTypeHelper.isText(mediatype)) {
    try {
      StringBuilder buf = new StringBuilder();
      String charset = MimeTypeHelper.getCharset(mediatype);
      Document doc = this.getDocument();
      charset = charset != null ? charset : doc != null ? doc.getCharset() : null;
      charset = charset != null ? charset : "UTF-8";
      InputStreamReader isr = new InputStreamReader(in, charset);
      char[] data = new char[500];
      int r = -1;
      while ((r = isr.read(data)) != -1) {
        buf.append(data, 0, r);
      }
      return setContent(buf.toString(), mediatype);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  } else {
    InputStreamDataSource ds = new InputStreamDataSource(in, mediatype);
    DataHandler dh = new DataHandler(ds);
    return setContent(dh, mediatype);
  }
}

代码示例来源:origin: org.xcmis/xcmis-restatom

private Response makeRepositoryInfoResponse(HttpServletRequest httpRequest, URI baseUri, String repositoryId)
{
 Service service = AbderaFactory.getInstance().getFactory().newService();
 service.declareNS(AtomCMIS.CMIS_NS_URI, AtomCMIS.CMIS_PREFIX);
 service.declareNS(AtomCMIS.CMISRA_NS_URI, AtomCMIS.CMISRA_PREFIX);
 addCmisRepository(httpRequest, service, repositoryId, baseUri);
 Document<Service> serviceDocument = service.getDocument();
 serviceDocument.setCharset("utf-8");
 ResponseContext abderaResponse = new BaseResponseContext<Document<Service>>(serviceDocument);
 abderaResponse.setStatus(200);
 return Response.ok(abderaResponse).header(HttpHeaders.CACHE_CONTROL, "no-cache")
   .type(MediaType.APPLICATION_ATOM_XML).build();
}

代码示例来源:origin: org.apache.abdera/abdera-security

public boolean isEncrypted(Document doc) throws SecurityException {
  Element el = doc.getRoot();
  return el.getQName().equals(Constants.ENCRYPTEDDATA);
}

代码示例来源:origin: org.fuzzydb.atom/org.fuzzydb.abdera.util

parser).clone();
if (entry_doc != null) {
  Entry entry = entry_doc.getRoot();
  if (!ProviderHelper.isValidEntry(entry)) {
    return new EmptyResponseContext(400);
  Feed feed = get_feed_doc(abdera).getRoot();
  feed.insertEntry(entry);
  feed.setUpdated(new Date());

相关文章