📄 xwikiservice.java
字号:
Iterator it = bclass.getFieldList().iterator();
while (it.hasNext()) {
PropertyClass property = (PropertyClass)it.next();
PropertyClass origproperty = (PropertyClass) property.clone();
String name = property.getName();
Map map = ((EditForm)form).getObject(name);
property.getxWikiClass(context).fromMap(map, property);
String newname = property.getName();
if (newname.indexOf(" ")!=-1) {
newname = newname.replaceAll(" ","");
property.setName(newname);
}
bclass2.addField(newname, property);
if (!newname.equals(name)) {
fieldsToRename.put(name, newname);
bclass2.addPropertyForRemoval(origproperty);
}
}
doc.renameProperties(bclass.getName(), fieldsToRename);
xwiki.saveDocument(doc, olddoc, context);
// We need to load all documents that use this property and rename it
if (fieldsToRename.size()>0) {
List list = xwiki.getStore().searchDocumentsNames(", BaseObject as obj where obj.name="
+ xwiki.getFullNameSQL() + " and obj.className='"
+ Utils.SQLFilter(bclass.getName()) + "' and " + xwiki.getFullNameSQL() + "<> '"
+ Utils.SQLFilter(bclass.getName()) + "'", context);
for (int i=0;i<list.size();i++) {
XWikiDocument doc2 = xwiki.getDocument((String)list.get(i), context);
doc2.renameProperties(bclass.getName(), fieldsToRename);
xwiki.saveDocument(doc2, doc2, context);
}
}
xwiki.flushCache();
// forward to edit
String redirect = Utils.getRedirect("edit", context);
sendRedirect(response, redirect);
return false;
}
public boolean actionDelete(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"))) {
String language = xwiki.getLanguagePreference(context);
if ((language==null)||(language.equals(""))||language.equals(doc.getDefaultLanguage())) {
// Delete all documents
List list = doc.getTranslationList(context);
for (int i=0;i<list.size();i++) {
String lang = (String) list.get(i);
XWikiDocument tdoc = doc.getTranslatedDocument(lang, context);
xwiki.deleteDocument(tdoc, context);
}
xwiki.deleteDocument(doc, context);
} else {
// Only delete the translation
XWikiDocument tdoc = doc.getTranslatedDocument(language, context);
xwiki.deleteDocument(tdoc, context);
}
return true;
} else {
String redirect = Utils.getRedirect(request, null);
if (redirect==null)
return true;
else {
sendRedirect(response, redirect);
return false;
}
}
}
public boolean actionRegister(XWikiContext context) throws XWikiException {
XWiki xwiki = context.getWiki();
XWikiRequest request = context.getRequest();
XWikiResponse response = context.getResponse();
XWikiDocument doc = context.getDoc();
String register = request.getParameter("register");
if ((register!=null)&&(register.equals("1"))) {
int useemail = xwiki.getXWikiPreferenceAsInt("use_email_verification", 0, context);
int result;
if (useemail==1)
result = xwiki.createUser(true, "edit", context);
else
result = xwiki.createUser(context);
VelocityContext vcontext = (VelocityContext) context.get("vcontext");
vcontext.put("reg", new Integer(result));
}
String redirect = Utils.getRedirect(request, null);
if (redirect==null)
return true;
else {
sendRedirect(response, redirect);
return false;
}
}
public boolean actionSave(XWikiContext context) throws XWikiException {
XWiki xwiki = context.getWiki();
XWikiRequest request = context.getRequest();
XWikiResponse response = context.getResponse();
XWikiDocument doc = context.getDoc();
XWikiForm form = context.getForm();
String language = ((EditForm)form).getLanguage();
String defaultLanguage = ((EditForm)form).getDefaultLanguage();
XWikiDocument tdoc;
if ((language==null)||(language.equals(""))||(language.equals("default"))||(language.equals(doc.getDefaultLanguage()))) {
// Need to save parent and defaultLanguage if they have changed
tdoc = doc;
} else {
tdoc = doc.getTranslatedDocument(language, context);
if (tdoc == doc) {
tdoc = new XWikiDocument(doc.getWeb(), doc.getName());
tdoc.setLanguage(language);
tdoc.setStore(doc.getStore());
}
tdoc.setTranslation(1);
}
XWikiDocument olddoc = (XWikiDocument) tdoc.clone();
tdoc.readFromTemplate(((EditForm)form).getTemplate(), context);
tdoc.readFromForm((EditForm)form, context);
// TODO: handle Author
String username = context.getUser();
tdoc.setAuthor(username);
if (tdoc.isNew())
tdoc.setCreator(username);
xwiki.saveDocument(tdoc, olddoc, context);
XWikiLock lock = tdoc.getLock(context);
if (lock != null && lock.getUserName().equals(username))
tdoc.removeLock(context);
// forward to view
String redirect = Utils.getRedirect("view", context);
sendRedirect(response, redirect);
return false;
}
public boolean actionRollback(XWikiContext context) throws XWikiException {
XWiki xwiki = context.getWiki();
XWikiRequest request = context.getRequest();
XWikiResponse response = context.getResponse();
XWikiDocument doc = context.getDoc();
RollbackForm form = (RollbackForm) context.getForm();
String rev = form.getRev();
String language = form.getLanguage();
XWikiDocument tdoc;
if ((language==null)||(language.equals(""))||(language.equals("default"))||(language.equals(doc.getDefaultLanguage()))) {
// Need to save parent and defaultLanguage if they have changed
tdoc = doc;
} else {
tdoc = doc.getTranslatedDocument(language, context);
if (tdoc == doc) {
tdoc = new XWikiDocument(doc.getWeb(), doc.getName());
tdoc.setLanguage(language);
}
tdoc.setTranslation(1);
}
XWikiDocument olddoc = (XWikiDocument) tdoc.clone();
XWikiDocument newdoc = xwiki.getDocument(tdoc, rev, context);
String username = context.getUser();
newdoc.setAuthor(username);
newdoc.setRCSVersion(tdoc.getRCSVersion());
xwiki.saveDocument(newdoc, olddoc, context);
// forward to view
String redirect = Utils.getRedirect("view", context);
sendRedirect(response, redirect);
return false;
}
public boolean actionCancel(XWikiContext context) throws XWikiException {
XWiki xwiki = context.getWiki();
XWikiRequest request = context.getRequest();
XWikiResponse response = context.getResponse();
XWikiDocument doc = context.getDoc();
XWikiForm form = context.getForm();
String language = ((EditForm)form).getLanguage();
String defaultLanguage = ((EditForm)form).getDefaultLanguage();
XWikiDocument tdoc;
if ((language==null)||(language.equals(""))||(language.equals("default"))||(language.equals(doc.getDefaultLanguage()))) {
// Need to save parent and defaultLanguage if they have changed
tdoc = doc;
} else {
tdoc = doc.getTranslatedDocument(language, context);
if (tdoc == doc) {
tdoc = new XWikiDocument(doc.getWeb(), doc.getName());
tdoc.setLanguage(language);
tdoc.setStore(doc.getStore());
}
tdoc.setTranslation(1);
}
String username = context.getUser();
XWikiLock lock = tdoc.getLock(context);
if (lock != null && lock.getUserName().equals(username))
tdoc.removeLock(context);
// forward to view
String redirect = Utils.getRedirect("view", context);
sendRedirect(response, redirect);
return false;
}
public boolean actionSkin(XWikiContext context) throws XWikiException {
return true;
}
/*
* Rendering of pages
*/
public String renderStatus(XWikiContext context) throws XWikiException {
XWiki xwiki = XWiki.getMainXWiki(context);
VelocityContext vcontext = XWikiVelocityRenderer.prepareContext(context);
vcontext.put("xwiki", xwiki);
return "status";
}
public String renderLogin(XWikiContext context) throws XWikiException {
return "login";
}
public String renderLoginerror(XWikiContext context) throws XWikiException {
return "login";
}
public String renderSkin(XWikiContext context) throws XWikiException {
XWiki xwiki = context.getWiki();
XWikiRequest request = context.getRequest();
XWikiResponse response = context.getResponse();
XWikiDocument doc = context.getDoc();
String path = request.getPathInfo();
String filename = Utils.decode(path.substring(path.lastIndexOf("/")+1),context);
if (renderSkin(filename, doc, context))
return null;
String baseskin = xwiki.getBaseSkin(context, true);
if (renderSkin(filename, baseskin, context))
return null;
XWikiDocument baseskindoc = xwiki.getDocument(baseskin, context);
if (renderSkin(filename, baseskindoc, context))
return null;
String defaultbaseskin = xwiki.getDefaultBaseSkin(context);
renderSkin(filename, defaultbaseskin, context);
return null;
}
private boolean renderSkin(String filename, XWikiDocument doc, XWikiContext context) throws XWikiException {
XWiki xwiki = context.getWiki();
XWikiResponse response = context.getResponse();
BaseObject object = doc.getObject("XWiki.XWikiSkins", 0);
String content = null;
if (object!=null) {
content = object.getStringValue(filename);
}
if ((content!=null)&&(!content.equals(""))) {
// Choose the right content type
response.setContentType(xwiki.getEngineContext().getMimeType(filename.toLowerCase()));
response.setDateHeader("Last-Modified", doc.getDate().getTime());
// Sending the content of the attachment
response.setContentLength(content.length());
try {
response.getWriter().write(content);
return true;
} catch (IOException e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
XWikiException.ERROR_XWIKI_APP_SEND_RESPONSE_EXCEPTION,
"Exception while sending response", e);
}
}
else {
XWikiAttachment attachment = doc.getAttachment(filename);
if (attachment!=null) {
// Sending the content of the attachment
byte[] data = attachment.getContent(context);
response.setContentType(xwiki.getEngineContext().getMimeType(filename.toLowerCase()));
response.setDateHeader("Last-Modified", attachment.getDate().getTime());
response.setContentLength(data.length);
try {
response.getOutputStream().write(data);
return true;
} catch (IOException e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
XWikiException.ERROR_XWIKI_APP_SEND_RESPONSE_EXCEPTION,
"Exception while sending response", e);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -