📄 xwikidocument.java
字号:
public String display(String fieldname, BaseObject obj, XWikiContext context) {
String type = null;
try { type = (String) context.get("display"); }
catch (Exception e) {
};
if (type==null)
type = "view";
return display(fieldname, type, obj, context);
}
public String display(String fieldname, XWikiContext context) {
try {
BaseObject object = getxWikiObject();
if (object==null)
object = getFirstObject(fieldname);
return display(fieldname, object, context);
} catch (Exception e) {
return "";
}
}
public String display(String fieldname, String mode, XWikiContext context) {
try {
BaseObject object = getxWikiObject();
if (object==null)
object = getFirstObject(fieldname);
if (object==null)
return "";
else
return display(fieldname, mode, object, context);
} catch (Exception e) {
return "";
}
}
public String displayForm(String className,String header, String format, XWikiContext context) {
return displayForm(className, header, format, true, context);
}
public String displayForm(String className,String header, String format, boolean linebreak, XWikiContext context) {
Vector objects = getObjects(className);
if (format.endsWith("\\n"))
linebreak = true;
BaseObject firstobject = null;
Iterator foit = objects.iterator();
while ((firstobject==null)&&foit.hasNext()) {
firstobject = (BaseObject) foit.next();
}
if (firstobject==null)
return "";
BaseClass bclass = firstobject.getxWikiClass(context);
Collection fields = bclass.getFieldList();
if (fields.size()==0)
return "";
StringBuffer result = new StringBuffer();
XWikiVelocityRenderer renderer = new XWikiVelocityRenderer();
VelocityContext vcontext = new VelocityContext();
vcontext.put("formatter", new VelocityFormatter(vcontext));
for (Iterator it = fields.iterator();it.hasNext();) {
PropertyClass pclass = (PropertyClass) it.next();
vcontext.put(pclass.getName(), pclass.getPrettyName());
}
result.append(renderer.evaluate(header, context.getDoc().getFullName(), vcontext, context));
if (linebreak)
result.append("\n");
// display each line
for (int i=0;i<objects.size();i++) {
vcontext.put("id", new Integer(i+1));
BaseObject object = (BaseObject) objects.get(i);
if (object!=null) {
for (Iterator it = bclass.getPropertyList().iterator();it.hasNext();) {
String name = (String) it.next();
vcontext.put(name, display(name, object, context));
}
result.append(renderer.evaluate(format, context.getDoc().getFullName(), vcontext, context));
if (linebreak)
result.append("\n");
}
}
return result.toString();
}
public String displayForm(String className, XWikiContext context) {
Vector objects = getObjects(className);
if (objects==null)
return "";
BaseObject firstobject = null;
Iterator foit = objects.iterator();
while ((firstobject==null)&&foit.hasNext()) {
firstobject = (BaseObject) foit.next();
}
if (firstobject==null)
return "";
BaseClass bclass = firstobject.getxWikiClass(context);
Collection fields = bclass.getFieldList();
if (fields.size()==0)
return "";
StringBuffer result = new StringBuffer();
result.append("{table}\n");
boolean first = true;
for (Iterator it = fields.iterator();it.hasNext();) {
if (first==true)
first = false;
else
result.append("|");
PropertyClass pclass = (PropertyClass) it.next();
result.append(pclass.getPrettyName());
}
result.append("\n");
for (int i=0;i<objects.size();i++) {
BaseObject object = (BaseObject) objects.get(i);
if (object!=null) {
first = true;
for (Iterator it = bclass.getPropertyList().iterator();it.hasNext();) {
if (first==true)
first = false;
else
result.append("|");
String data = display((String)it.next(), object, context);
if (data.trim().equals(""))
result.append(" ");
else
result.append(data);
}
result.append("\n");
}
}
result.append("{table}\n");
return result.toString();
}
public boolean isFromCache() {
return fromCache;
}
public void setFromCache(boolean fromCache) {
this.fromCache = fromCache;
}
public void readFromForm(EditForm eform, XWikiContext context) throws XWikiException {
String content = eform.getContent();
if ((content!=null)&&(!content.equals(""))) {
// Cleanup in case we use HTMLAREA
// content = context.getUtil().substitute("s/<br class=\\\"htmlarea\\\"\\/>/\\r\\n/g", content);
content = context.getUtil().substitute("s/<br class=\"htmlarea\" \\/>/\r\n/g", content);
setContent(content);
}
String parent = eform.getParent();
if (parent!=null)
setParent(parent);
String creator = eform.getCreator();
if ((creator!=null)&&(!creator.equals(getCreator()))) {
if ((getCreator().equals(context.getUser()))
||(context.getWiki().getRightService().hasAdminRights(context)))
setCreator(creator);
}
String defaultLanguage = eform.getDefaultLanguage();
if (defaultLanguage!=null)
setDefaultLanguage(defaultLanguage);
// This is now done before
// readFromTemplate(eform, context);
Iterator itobj = getxWikiObjects().keySet().iterator();
while (itobj.hasNext()) {
String name = (String) itobj.next();
Vector bobjects = getObjects(name);
Vector newobjects = new Vector();
newobjects.setSize(bobjects.size());
for (int i=0;i<bobjects.size();i++) {
BaseObject oldobject = (BaseObject) getObject(name, i);
if (oldobject!=null)
{
BaseClass baseclass = oldobject.getxWikiClass(context);
BaseObject newobject = (BaseObject) baseclass.fromMap(eform.getObject(baseclass.getName() + "_" + i), oldobject);
newobject.setNumber(oldobject.getNumber());
newobject.setName(getFullName());
newobjects.set(newobject.getNumber(), newobject);
}
}
getxWikiObjects().put(name, newobjects);
}
}
/*
public void readFromTemplate(EditForm eform, XWikiContext context) throws XWikiException {
// Get the class from the template
String template = eform.getTemplate();
if ((template!=null)&&(!template.equals(""))) {
if (template.indexOf('.')==-1) {
template = getWeb() + "." + template;
}
XWiki xwiki = context.getWiki();
XWikiDocument templatedoc = xwiki.getDocument(template, context);
if (templatedoc.isNew()) {
Object[] args = { template, getFullName() };
throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_APP_TEMPLATE_DOES_NOT_EXIST,
"Template document {0} does not exist when adding to document {1}", null, args);
} else {
setTemplate(template);
mergexWikiObjects(templatedoc);
}
}
}
*/
public void readFromTemplate(PrepareEditForm eform, XWikiContext context) throws XWikiException {
String template = eform.getTemplate();
readFromTemplate(template, context);
}
public void readFromTemplate(String template, XWikiContext context) throws XWikiException {
if ((template!=null)&&(!template.equals(""))) {
String content = getContent();
if ((!content.equals("\n"))&&(!content.equals(""))&&!isNew()) {
Object[] args = { getFullName() };
throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_APP_DOCUMENT_NOT_EMPTY,
"Cannot add a template to document {0} because it already has content", null, args);
} else {
if (template.indexOf('.')==-1) {
template = getWeb() + "." + template;
}
XWiki xwiki = context.getWiki();
XWikiDocument templatedoc = xwiki.getDocument(template, context);
if (templatedoc.isNew()) {
Object[] args = { template, getFullName() };
throw new XWikiException( XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_APP_TEMPLATE_DOES_NOT_EXIST,
"Template document {0} does not exist when adding to document {1}", null, args);
} else {
setTemplate(template);
setContent(templatedoc.getContent());
if ((getParent()==null)||(getParent().equals(""))) {
String tparent = templatedoc.getParent();
if (tparent!=null)
setParent(tparent);
}
if (isNew()) {
// We might have received the object from the cache
// and the templace objects might have been copied already
// we need to remove them
setxWikiObjects(new HashMap());
}
// Merge the external objects
// Currently the choice is not to merge the base class and object because it is not
// the prefered way of using external classes and objects.
mergexWikiObjects(templatedoc);
}
}
}
}
public void notify(XWikiNotificationRule rule, XWikiDocument newdoc, XWikiDocument olddoc, int event, XWikiContext context) {
// Do nothing for the moment..
// A usefull thing here would be to look at any instances of a Notification Object
// with email addresses and send an email to warn that the document has been modified..
}
public Object clone() {
XWikiDocument doc = null;
try {
doc = (XWikiDocument) getClass().newInstance();
} catch (Exception e) {
// This should not happen
}
doc.setRCSArchive(getRCSArchive());
doc.setRCSVersion(getRCSVersion());
doc.setAuthor(getAuthor());
doc.setContent(getContent());
doc.setContentDirty(isContentDirty());
doc.setDate(getDate());
doc.setFormat(getFormat());
doc.setFromCache(isFromCache());
doc.setId(getId());
doc.setMeta(getMeta());
doc.setMetaDataDirty(isMetaDataDirty());
doc.setMostRecent(isMostRecent());
doc.setName(getName());
doc.setNew(isNew());
doc.setStore(getStore());
doc.setTemplate(getTemplate());
doc.setWeb(getWeb());
doc.setParent(getParent());
doc.setCreator(getCreator());
doc.setDefaultLanguage(getDefaultLanguage());
doc.setLanguage(getLanguage());
doc.setTranslation(getTranslation());
doc.setxWikiClass((BaseClass)getxWikiClass().clone());
doc.mergexWikiObjects(this);
doc.copyAttachments(this);
return doc;
}
public void copyAttachments(XWikiDocument xWikiSourceDocument) {
Iterator attit = xWikiSourceDocument.getAttachmentList().iterator();
while (attit.hasNext()) {
XWikiAttachment attachment = (XWikiAttachment) attit.next();
XWikiAttachment newattachment = (XWikiAttachment) attachment.clone();
newattachment.setDoc(this);
getAttachmentList().add(newattachment);
}
}
public boolean equals(Object object) {
XWikiDocument doc = (XWikiDocument) object;
if (!getName().equals(doc.getName()))
return false;
if (!getWeb().equals(doc.getWeb()))
return false;
if (!getAuthor().equals(doc.getAuthor()))
return false;
if (!getParent().equals(doc.getParent()))
return false;
if (!getCreator().equals(doc.getCreator()))
return false;
if (!getDefaultLanguage().equals(doc.getDefaultLanguage()))
return false;
if (!getLanguage().equals(doc.getLanguage()))
return false;
if (getTranslation()!=doc.getTranslation())
return false;
if (getDate().getTime() != doc.getDate().getTime())
return false;
if (getCreationDate().getTime() != doc.getCreationDate().getTime())
return false;
if (!getFormat().equals(doc.getFormat()))
return false;
if (!getContent().equals(doc.getContent()))
return false;
if (!getVersion().equals(doc.getVersion()))
return false;
try {
if (!getArchive().equals(doc.getArchive()))
return false;
} catch (XWikiException e) {
return false;
}
if (!getxWikiClass().equals(doc.getxWikiClass()))
return false;
Set list1 = getxWikiObjects().keySet();
Set list2 = doc.getxWikiObjects().keySet();
if (!list1.equals(list2))
return false;
for (Iterator it = list1.iterator();it.hasNext();) {
String name = (String) it.next();
Vector v1 = getObjects(name);
Vector v2 = doc.getObjects(name);
if (v1.size()!=v2.size())
return false;
for (int i=0;i<v1.size();i++) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -