本文整理汇总了Java中com.google.enterprise.adaptor.Response.setContentType方法的典型用法代码示例。如果您正苦于以下问题:Java Response.setContentType方法的具体用法?Java Response.setContentType怎么用?Java Response.setContentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.enterprise.adaptor.Response
的用法示例。
在下文中一共展示了Response.setContentType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeHtmlResponse
import com.google.enterprise.adaptor.Response; //导入方法依赖的package包/类
private void writeHtmlResponse(Response response, Node node,
String header, String... body) throws IOException {
response.setContentType("text/html; charset=" + CHARSET.name());
Writer writer = new OutputStreamWriter(response.getOutputStream(),
CHARSET);
writer.write("<!DOCTYPE html>\n<html><head><title>");
writer.write(escapeContent(node.getName()));
writer.write("</title></head><body><h1>");
if (header != null) {
writer.write(escapeContent(header));
} else {
writer.write(escapeContent(node.getName()));
}
writer.write("</h1>");
for (String contentString : body) {
writer.write("<p>");
writer.write(escapeContent(contentString));
writer.write("</p>");
}
writer.write("</body></html>");
writer.flush();
}
示例2: getDocContent
import com.google.enterprise.adaptor.Response; //导入方法依赖的package包/类
@Override
public void getDocContent(Request req, Response resp) throws IOException {
log.entering("LdapAdaptor", "getDocContent", new Object[] {req, resp});
DocId id = req.getDocId();
ParsedDocId parsed = parseDocId(id);
if (parsed == null
|| !id.equals(makeDocId(parsed.serverNumber, parsed.dn))) {
log.warning(id + " is not a valid id generated by this adaptor.");
resp.respondNotFound();
return;
}
LdapPerson fetched;
try {
LdapServer server = servers.get(parsed.serverNumber);
fetched = server.fetchOne(parsed.dn);
if (null == fetched) {
log.finer("No results found for DN " + parsed.dn + "");
resp.respondNotFound();
log.exiting("LdapAdaptor", "getDocContent", 0);
return;
}
for (Entry<String, String> metadatum : fetched.asMetadata().entrySet()) {
resp.addMetadata(metadatum.getKey(), metadatum.getValue());
}
InputStream input = new ByteArrayInputStream(fetched.asDoc(
server.getDisplayTemplate()).getBytes(CHARSET));
resp.setContentType("text/html; charset=" + CHARSET.name() + "");
IOHelper.copyStream(input, resp.getOutputStream());
log.exiting("LdapAdaptor", "getDocContent", 1);
} catch (InterruptedNamingException e) {
log.exiting("LdapAdaptor", "getDocContent", 2);
throw new IOException(e);
}
}
示例3: doContainer
import com.google.enterprise.adaptor.Response; //导入方法依赖的package包/类
@VisibleForTesting
void doContainer(DocumentManagement documentManagement,
OpentextDocId opentextDocId, Node containerNode, Response response)
throws IOException {
List<Node> containerContents;
try {
// The second argument causes listNodes to return partial
// content, but that content includes the name.
containerContents = documentManagement.listNodes(containerNode.getID(),
true);
} catch (SOAPFaultException soapFaultException) {
if (isPermissionsFailure(soapFaultException)) {
log.log(Level.FINE, "{0}: {1}",
new Object[] {
soapFaultException.getFault().getFaultString(), opentextDocId });
response.respondNotFound();
} else {
log.log(Level.WARNING,
"Error retrieving container contents: " + opentextDocId,
soapFaultException);
}
return;
}
response.setContentType("text/html; charset=" + CHARSET.name());
Writer writer = new OutputStreamWriter(response.getOutputStream(),
CHARSET);
HtmlResponseWriter responseWriter = new HtmlResponseWriter(
writer, this.context.getDocIdEncoder(), ENGLISH);
responseWriter.start(opentextDocId.getDocId(),
opentextDocId.getDocId().getUniqueId());
for (Node node : containerContents) {
responseWriter.addLink(
getChildDocId(opentextDocId, node.getName(), node.getID()),
node.getName());
}
responseWriter.finish();
}
示例4: doNode
import com.google.enterprise.adaptor.Response; //导入方法依赖的package包/类
@VisibleForTesting
void doNode(DocumentManagement documentManagement,
OpentextDocId opentextDocId, Node node, Response response)
throws IOException {
response.setContentType("text/html; charset=" + CHARSET.name());
Writer writer = new OutputStreamWriter(response.getOutputStream(),
CHARSET);
writer.write("<!DOCTYPE html>\n<html><head><title>");
writer.write(escapeContent(node.getName()));
writer.write("</title></head><body><h1>");
writer.write(escapeContent(node.getName()));
writer.write("</h1>");
writer.write("</body></html>");
writer.flush();
}
示例5: createHtmlResponseWriter
import com.google.enterprise.adaptor.Response; //导入方法依赖的package包/类
private HtmlResponseWriter createHtmlResponseWriter(
Response response, long metadataLength) throws IOException {
response.setContentType("text/html; charset=utf-8");
// TODO(ejona): Get locale from request.
return new HtmlResponseWriter(response.getOutputStream(), CHARSET,
context.getDocIdEncoder(), Locale.ENGLISH,
maxIndexableSize - metadataLength, context.getDocIdPusher(),
executor);
}
示例6: getDocumentContent
import com.google.enterprise.adaptor.Response; //导入方法依赖的package包/类
/** Copies the Documentum document content into the response.
* @throws URISyntaxException */
private void getDocumentContent(Response resp, IDfSysObject sysObject,
DocId id, boolean returnContent)
throws DfException, IOException, URISyntaxException {
if (!markAllDocsAsPublic) {
getACL(resp, sysObject, id);
}
// Include document attributes as metadata.
getMetadata(resp, sysObject, id);
// If it is a virtual document, include links to the child documents.
if (sysObject.isVirtualDocument()) {
getVdocChildLinks(resp, sysObject, id);
}
// Return the content.
resp.setDisplayUrl(new URI(MessageFormat.format(displayUrl,
sysObject.getObjectId(), docIdToPath(id))));
if (returnContent) {
// getContent throws an exception when r_page_cnt is zero.
// The GSA does not support files larger than 2 GB.
// The GSA will not index empty documents with binary content types,
// so include the content type only when supplying content.
if (sysObject.getPageCount() > 0 && sysObject.getContentSize() > 0
&& sysObject.getContentSize() <= (2L << 30)) {
String contentType = sysObject.getFormat().getMIMEType();
logger.log(Level.FINER, "Content Type: {0}", contentType);
resp.setContentType(contentType);
try (InputStream inStream = sysObject.getContent()) {
IOHelper.copyStream(inStream, resp.getOutputStream());
}
} else {
// We must call getOutputStream to avoid a library error.
// TODO(jlacey): This document will not be indexed.
resp.getOutputStream();
}
}
}
示例7: createHtmlResponseWriter
import com.google.enterprise.adaptor.Response; //导入方法依赖的package包/类
private HtmlResponseWriter createHtmlResponseWriter(Response response)
throws IOException {
response.setContentType("text/html; charset=" + CHARSET.name());
Writer writer = new OutputStreamWriter(response.getOutputStream(), CHARSET);
// TODO(ejona): Get locale from request.
return new HtmlResponseWriter(writer, docIdEncoder, Locale.ENGLISH);
}