📄 xwikiservice.java
字号:
}
}
}
return false;
}
private boolean renderSkin(String filename, String skin, XWikiContext context) throws XWikiException {
XWiki xwiki = context.getWiki();
XWikiResponse response = context.getResponse();
try {
response.setDateHeader("Expires", (new Date()).getTime() + 30*24*3600*1000L);
String path = "/skins/" + skin + "/" + filename;
// Choose the right content type
String mimetype = context.getEngineContext().getMimeType(filename.toLowerCase());
if (mimetype!=null)
response.setContentType(mimetype);
else
response.setContentType("application/octet-stream");
// Sending the content of the file
InputStream is = context.getWiki().getResourceAsStream(path);
if (is==null)
return false;
byte[] data = new byte[65535];
while (is.read(data)!=-1) {
response.getOutputStream().write(data);
}
return true;
} catch (IOException e) {
if (skin.equals(xwiki.getDefaultBaseSkin(context)))
throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
XWikiException.ERROR_XWIKI_APP_SEND_RESPONSE_EXCEPTION,
"Exception while sending response", e);
else
return false;
}
}
public String renderAttach(XWikiContext context) throws XWikiException {
return "attach";
}
public String renderDownload(XWikiContext context) throws XWikiException {
XWikiRequest request = context.getRequest();
XWikiResponse response = context.getResponse();
XWikiDocument doc = context.getDoc();
String path = request.getRequestURI();
String filename = Utils.decode(path.substring(path.lastIndexOf("/")+1),context);
XWikiAttachment attachment = null;
if (request.getParameter("id")!=null) {
int id = Integer.parseInt(request.getParameter("id"));
attachment = (XWikiAttachment) doc.getAttachmentList().get(id);
}
else {
attachment = doc.getAttachment(filename);
}
if (attachment==null) {
Object[] args = { filename };
throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
XWikiException.ERROR_XWIKI_APP_ATTACHMENT_NOT_FOUND,
"Attachment {0} not found", null, args);
}
// Choose the right content type
String mimetype = attachment.getMimeType(context);
response.setContentType(mimetype);
response.setDateHeader("Last-Modified", attachment.getDate().getTime());
// Sending the content of the attachment
byte[] data = attachment.getContent(context);
response.setContentLength(data.length);
try {
response.getOutputStream().write(data);
} catch (IOException e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
XWikiException.ERROR_XWIKI_APP_SEND_RESPONSE_EXCEPTION,
"Exception while sending response", e);
}
return null;
}
public String renderDot(XWikiContext context) throws XWikiException {
XWikiRequest request = context.getRequest();
XWikiResponse response = context.getResponse();
String path = request.getRequestURI();
String filename = Utils.decode(path.substring(path.lastIndexOf("/")+1),context);
try {
((GraphVizPlugin)context.getWiki().getPlugin("graphviz",context)).outputDotImageFromFile(filename, context);
} catch (IOException e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
XWikiException.ERROR_XWIKI_APP_SEND_RESPONSE_EXCEPTION,
"Exception while sending response", e);
}
return null;
}
public String renderDelete(XWikiContext context) throws XWikiException {
XWiki xwiki = context.getWiki();
XWikiRequest request = context.getRequest();
XWikiResponse response = context.getResponse();
XWikiDocument doc = context.getDoc();
String confirm = request.getParameter("confirm");
if ((confirm!=null)&&(confirm.equals("1"))) {
return "deleted";
} else {
return "delete";
}
}
public String renderRegister(XWikiContext context) throws XWikiException {
return "register";
}
public String renderPreview(XWikiContext context) throws XWikiException {
XWikiRequest request = context.getRequest();
XWikiDocument doc = context.getDoc();
XWikiForm form = context.getForm();
VelocityContext vcontext = (VelocityContext) context.get("vcontext");
String language = ((EditForm)form).getLanguage();
XWikiDocument tdoc;
// Make sure it is not considered as new
XWikiDocument doc2 = (XWikiDocument)doc.clone();
context.put("doc", doc2);
if ((language==null)||(language.equals(""))||(language.equals("default"))||(language.equals(doc.getDefaultLanguage()))) {
tdoc = doc2;
context.put("tdoc", doc2);
vcontext.put("doc", new Document(doc2, context));
vcontext.put("tdoc", vcontext.get("doc"));
vcontext.put("cdoc", vcontext.get("doc"));
doc2.readFromTemplate(((EditForm)form).getTemplate(), context);
doc2.readFromForm((EditForm)form, context);
} else {
// Need to save parent and defaultLanguage if they have changed
tdoc = doc.getTranslatedDocument(language, context);
tdoc.setLanguage(language);
tdoc.setTranslation(1);
XWikiDocument tdoc2 = (XWikiDocument)tdoc.clone();
context.put("tdoc", tdoc2);
vcontext.put("tdoc", new Document(tdoc2, context));
vcontext.put("cdoc", vcontext.get("tdoc"));
tdoc2.readFromTemplate(((EditForm)form).getTemplate(), context);
tdoc2.readFromForm((EditForm)form, context);
}
return "preview";
}
public String renderEdit(XWikiContext context) throws XWikiException {
XWikiRequest request = context.getRequest();
XWikiDocument doc = context.getDoc();
XWikiForm form = context.getForm();
VelocityContext vcontext = (VelocityContext) context.get("vcontext");
XWikiDocument tdoc = (XWikiDocument) context.get("tdoc");
PrepareEditForm peform = (PrepareEditForm) form;
String parent = peform.getParent();
if (parent!=null)
doc.setParent(parent);
String creator = peform.getCreator();
if (creator!=null)
doc.setCreator(creator);
String defaultLanguage = peform.getDefaultLanguage();
if ((defaultLanguage!=null)&&!defaultLanguage.equals(""))
doc.setDefaultLanguage(defaultLanguage);
if (doc.getDefaultLanguage().equals(""))
doc.setDefaultLanguage(context.getWiki().getLanguagePreference(context));
String language = context.getWiki().getLanguagePreference(context);
String languagefromrequest = context.getRequest().getParameter("language");
String languagetoedit = ((languagefromrequest==null)||(languagefromrequest.equals(""))) ?
language : languagefromrequest;
if ((languagetoedit==null)||(languagetoedit.equals("default")))
languagetoedit = "";
if (doc.isNew()||(doc.getDefaultLanguage().equals(languagetoedit)))
languagetoedit = "";
if (languagetoedit.equals("")) {
// In this case the created document is going to be the default document
tdoc = doc;
context.put("tdoc", doc);
vcontext.put("tdoc", vcontext.get("doc"));
if (doc.isNew()) {
doc.setDefaultLanguage(language);
doc.setLanguage("");
}
} else {
// If the translated doc object is the same as the doc object
// this means the translated doc did not exists so we need to create it
if ((tdoc==doc)) {
tdoc = new XWikiDocument(doc.getWeb(), doc.getName());
tdoc.setLanguage(languagetoedit);
tdoc.setContent(doc.getContent());
tdoc.setAuthor(context.getUser());
tdoc.setStore(doc.getStore());
context.put("tdoc", tdoc);
vcontext.put("tdoc", new Document(tdoc, context));
}
}
/* Setup a lock */
try {
XWikiLock lock = tdoc.getLock(context);
if (lock == null || lock.getUserName().equals(context.getUser()) || peform.isLockForce())
tdoc.setLock(context.getUser(),context);
} catch (Exception e) {
// Lock should never make XWiki fail
// But we should log any related information
log.error("Exception while setting up lock", e);
}
XWikiDocument tdoc2 = (XWikiDocument) tdoc.clone();
context.put("tdoc", tdoc2);
vcontext.put("tdoc", new Document(tdoc2, context));
tdoc2.readFromTemplate(peform, context);
return "edit";
}
public String renderInline(XWikiContext context) throws XWikiException {
XWikiRequest request = context.getRequest();
XWikiDocument doc = context.getDoc();
XWikiForm form = context.getForm();
PrepareEditForm peform = (PrepareEditForm) form;
String parent = peform.getParent();
if (parent!=null)
doc.setParent(parent);
String creator = peform.getCreator();
if (creator!=null)
doc.setCreator(creator);
String defaultLanguage = peform.getDefaultLanguage();
if ((defaultLanguage!=null)&&!defaultLanguage.equals(""))
doc.setDefaultLanguage(defaultLanguage);
if (doc.getDefaultLanguage().equals(""))
doc.setDefaultLanguage(context.getWiki().getLanguagePreference(context));
doc.readFromTemplate(peform, context);
// Set display context to 'view'
context.put("display", "edit");
return "inline";
}
public String renderView(XWikiContext context) throws XWikiException {
XWikiRequest request = context.getRequest();
String rev = request.getParameter("rev");
if (rev!=null) {
context.put("rev", rev);
XWikiDocument doc = (XWikiDocument) context.get("doc");
XWikiDocument tdoc = (XWikiDocument) context.get("tdoc");
XWikiDocument rdoc = context.getWiki().getDocument(doc, rev, context);
XWikiDocument rtdoc = context.getWiki().getDocument(tdoc, rev, context);
context.put("tdoc", rtdoc);
context.put("cdoc", rdoc);
context.put("doc", rdoc);
VelocityContext vcontext = (VelocityContext) context.get("vcontext");
vcontext.put("doc", new Document(rdoc, context));
vcontext.put("cdoc", vcontext.get("doc"));
vcontext.put("tdoc", new Document(rtdoc, context));
}
return "view";
}
public String renderPDF(XWikiContext context) throws XWikiException {
context.setURLFactory(new PdfURLFactory(context));
PdfExportImpl pdfexport = new PdfExportImpl();
XWikiDocument doc = context.getDoc();
try {
context.getResponse().setContentType("application/pdf");
context.getResponse().addHeader("Content-disposition", "attachment; filename=" + doc.getWeb() + "_" + doc.getName() + ".pdf");
pdfexport.exportToPDF(doc, context.getResponse().getOutputStream(), context);
} catch (IOException e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
XWikiException.ERROR_XWIKI_APP_SEND_RESPONSE_EXCEPTION,
"Exception while sending response", e);
}
return null;
}
public String renderLifeblog(XWikiContext context) throws XWikiException {
XWikiRequest request = context.getRequest();
XWikiResponse response = context.getResponse();
LifeblogServices services = new LifeblogServices(context);
try {
// Check Authentication
if (!services.isAuthenticated()) {
response.setHeader("WWW-Authenticate", "WSSE realm=\"foo\", profile=\"UsernameToken\"");
response.sendError(401, "Unauthorized");
} else if (request.getPathInfo().equals("/lifeblog")) {
services.listUserBlogs();
}
} catch (IOException e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
XWikiException.ERROR_XWIKI_APP_SEND_RESPONSE_EXCEPTION,
"Exception while sending response", e);
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -