Index: core/src/main/java/com/xpn/xwiki/plugin/packaging/Package.java =================================================================== --- core/src/main/java/com/xpn/xwiki/plugin/packaging/Package.java (revision 2062) +++ core/src/main/java/com/xpn/xwiki/plugin/packaging/Package.java (working copy) @@ -46,96 +46,127 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; - -public class Package { +public class Package +{ private static final Log log = LogFactory.getLog(Package.class); - private String name = "My package"; - private String description = ""; - private String version = "1.0.0"; - private String licence = "LGPL"; - private String authorName = "XWiki"; - private List files = null; - private List customMappingFiles = null; - private List classFiles = null; + private String name = "My package"; + + private String description = ""; + + private String version = "1.0.0"; + + private String licence = "LGPL"; + + private String authorName = "XWiki"; + + private List files = null; + + private List customMappingFiles = null; + + private List classFiles = null; + private boolean backupPack = false; + private boolean withVersions = true; - private List documentFilters = new ArrayList(); + private List documentFilters = new ArrayList(); + public static final int OK = 0; + public static final int Right = 1; + public static final String DefaultPackageFileName = "package.xml"; + public static final String DefaultPluginName = "package"; - public String getName() { + public String getName() + { return name; } - public void setName(String name) { + public void setName(String name) + { this.name = name; } - public String getDescription() { + public String getDescription() + { return description; } - public void setDescription(String description) { + public void setDescription(String description) + { this.description = description; } - public String getVersion() { + public String getVersion() + { return version; } - public void setVersion(String version) { + public void setVersion(String version) + { this.version = version; } - public String getLicence() { + public String getLicence() + { return licence; } - public void setLicence(String licence) { + public void setLicence(String licence) + { this.licence = licence; } - public String getAuthorName() { + public String getAuthorName() + { return authorName; } - public void setAuthorName(String authorName) { + public void setAuthorName(String authorName) + { this.authorName = authorName; } - public boolean isBackupPack() { + public boolean isBackupPack() + { return backupPack; } - public void setBackupPack(boolean backupPack) { + public void setBackupPack(boolean backupPack) + { this.backupPack = backupPack; } - public List getFiles() { + public List getFiles() + { return files; } - public List getCustomMappingFiles() { + public List getCustomMappingFiles() + { return customMappingFiles; } - public boolean isWithVersions() { + public boolean isWithVersions() + { return withVersions; } - public void setWithVersions(boolean withVersions) { + public void setWithVersions(boolean withVersions) + { this.withVersions = withVersions; } - public void addDocumentFilter(Object filter) throws PackageException { + public void addDocumentFilter(Object filter) throws PackageException + { if (filter instanceof DocumentFilter) this.documentFilters.add(filter); else - throw new PackageException(PackageException.ERROR_PACKAGE_INVALID_FILTER, "Invalid Document Filter"); + throw new PackageException(PackageException.ERROR_PACKAGE_INVALID_FILTER, + "Invalid Document Filter"); } public Package() @@ -145,14 +176,15 @@ classFiles = new ArrayList(); } - public boolean add(XWikiDocument doc, int defaultAction, XWikiContext context) throws XWikiException { + public boolean add(XWikiDocument doc, int defaultAction, XWikiContext context) + throws XWikiException + { if (!context.getWiki().checkAccess("edit", doc, context)) return false; - for(int i = 0; i < files.size(); i++) - { - DocumentInfo di = (DocumentInfo)files.get(i); - if (di.getFullName().equals(doc.getFullName())&&(di.getLanguage().equals(doc.getLanguage()))) - { + for (int i = 0; i < files.size(); i++) { + DocumentInfo di = (DocumentInfo) files.get(i); + if (di.getFullName().equals(doc.getFullName()) + && (di.getLanguage().equals(doc.getLanguage()))) { if (defaultAction != DocumentInfo.ACTION_NOT_DEFINED) di.setAction(defaultAction); if (!doc.isNew()) @@ -169,11 +201,11 @@ DocumentInfo docinfo = new DocumentInfo(doc); docinfo.setAction(defaultAction); files.add(docinfo); - BaseClass bclass = doc.getxWikiClass(); - if (bclass.getProperties().length>0) { + BaseClass bclass = doc.getxWikiClass(); + if (bclass.getProperties().length > 0) { classFiles.add(docinfo); } - if (bclass.getCustomMapping()!=null) + if (bclass.getCustomMapping() != null) customMappingFiles.add(docinfo); return true; } catch (ExcludeDocumentException e) { @@ -182,60 +214,71 @@ } } - public boolean add(XWikiDocument doc, XWikiContext context) throws XWikiException { + public boolean add(XWikiDocument doc, XWikiContext context) throws XWikiException + { return add(doc, DocumentInfo.ACTION_NOT_DEFINED, context); } - public boolean updateDoc(String docFullName, int action, XWikiContext context) throws XWikiException { + public boolean updateDoc(String docFullName, int action, XWikiContext context) + throws XWikiException + { XWikiDocument doc = new XWikiDocument(); doc.setFullName(docFullName, context); return add(doc, action, context); } - public boolean add(String docFullName, int DefaultAction, XWikiContext context) throws XWikiException { + public boolean add(String docFullName, int DefaultAction, XWikiContext context) + throws XWikiException + { XWikiDocument doc = context.getWiki().getDocument(docFullName, context); add(doc, DefaultAction, context); List languages = doc.getTranslationList(context); - for (int i=0;i 0) ? (int) size : 4096); + byte[] data = new byte[4096]; + int Cnt; + while ((Cnt = zin.read(data, 0, 4096)) != -1) { + baos.write(data, 0, Cnt); + } + return new ByteArrayInputStream(baos.toByteArray()); + } + + private XWikiDocument readFromXML(String XmlFile) throws XWikiException + { XWikiDocument doc = new com.xpn.xwiki.doc.XWikiDocument(); if (backupPack && withVersions) doc.fromXML(XmlFile, true); @@ -556,14 +629,24 @@ return doc; } - private Document ReadZipInfoFile(ZipInputStream zis) throws IOException, DocumentException { - ZipEntry entry; - Document description; + private XWikiDocument readFromXML(InputStream is) throws XWikiException + { + XWikiDocument doc = new com.xpn.xwiki.doc.XWikiDocument(); + if (backupPack && withVersions) + doc.fromXML(is, true); + else { + doc.fromXML(is); + } + return doc; + } - while ((entry = zis.getNextEntry()) != null) - { - if(entry.getName().compareTo(DefaultPackageFileName) == 0) - { + private Document ReadZipInfoFile(ZipInputStream zis) throws IOException, DocumentException + { + ZipEntry entry; + Document description; + + while ((entry = zis.getNextEntry()) != null) { + if (entry.getName().compareTo(DefaultPackageFileName) == 0) { description = readPackage(zis); return description; } @@ -571,22 +654,23 @@ return null; } - private Document readPackage(InputStream is) throws IOException, DocumentException{ + private Document readPackage(InputStream is) throws IOException, DocumentException + { byte[] data = new byte[4096]; StringBuffer XmlFile = new StringBuffer(); int Cnt; while ((Cnt = is.read(data, 0, 4096)) != -1) { - XmlFile.append(new String(data, 0, Cnt)) ; + XmlFile.append(new String(data, 0, Cnt)); } return fromXml(XmlFile.toString()); } public String toXml(XWikiContext context) { - OutputFormat outputFormat = new OutputFormat("", true); + OutputFormat outputFormat = new OutputFormat("", true); outputFormat.setEncoding(context.getWiki().getEncoding()); StringWriter out = new StringWriter(); - XMLWriter writer = new XMLWriter( out, outputFormat ); + XMLWriter writer = new XMLWriter(out, outputFormat); try { writer.write(toXmlDocument()); return out.toString(); @@ -628,63 +712,71 @@ el.addText(new Boolean(backupPack).toString()); elInfos.add(el); - Element elfiles = new DOMElement("files"); docel.add(elfiles); - for (int i = 0; i < files.size(); i++) - { + for (int i = 0; i < files.size(); i++) { Element elfile = new DOMElement("file"); DocumentInfo di = (DocumentInfo) files.get(i); elfile.addAttribute("defaultAction", String.valueOf(di.getAction())); elfile.addAttribute("language", String.valueOf(di.getLanguage())); - elfile.addText(((DocumentInfo)(files.get(i))).getFullName()); + elfile.addText(((DocumentInfo) (files.get(i))).getFullName()); elfiles.add(elfile); } return doc; } - private void addInfosToZip(ZipOutputStream zos, XWikiContext context) { - try { - String zipname = DefaultPackageFileName; - ZipEntry zipentry = new ZipEntry(zipname); - zos.putNextEntry(zipentry); - zos.write(toXml(context).getBytes(context.getWiki().getEncoding())); - zos.closeEntry(); + private void addInfosToZip(ZipOutputStream zos, XWikiContext context) + { + try { + String zipname = DefaultPackageFileName; + ZipEntry zipentry = new ZipEntry(zipname); + zos.putNextEntry(zipentry); + zos.write(toXml(context).getBytes(context.getWiki().getEncoding())); + zos.closeEntry(); } catch (Exception e) { e.printStackTrace(); } } - public void addToZip(XWikiDocument doc, ZipOutputStream zos, boolean withVersions, XWikiContext context) throws IOException { - try { + public void addToZip(XWikiDocument doc, ZipOutputStream zos, boolean withVersions, + XWikiContext context) throws IOException + { + try { String zipname = doc.getSpace() + "/" + doc.getName(); String language = doc.getLanguage(); - if ((language!=null)&&(!language.equals(""))) + if ((language != null) && (!language.equals(""))) zipname += "." + language; ZipEntry zipentry = new ZipEntry(zipname); zos.putNextEntry(zipentry); - zos.write(doc.toXML(true, false, true, withVersions, context).getBytes(context.getWiki().getEncoding())); + zos.write(doc.toXML(true, false, true, withVersions, context).getBytes( + context.getWiki().getEncoding())); zos.closeEntry(); } catch (Exception e) { e.printStackTrace(); } } - public void addToDir(XWikiDocument doc, File dir, boolean withVersions, XWikiContext context) throws XWikiException { - try { + public void addToDir(XWikiDocument doc, File dir, boolean withVersions, XWikiContext context) + throws XWikiException + { + try { filter(doc, context); File spacedir = new File(dir, doc.getSpace()); if (!spacedir.exists()) { if (!spacedir.mkdirs()) { Object[] args = new Object[1]; args[0] = dir.toString(); - throw new XWikiException(XWikiException.MODULE_XWIKI ,XWikiException.ERROR_XWIKI_MKDIR, "Error creating directory {0}", null, args); + throw new XWikiException(XWikiException.MODULE_XWIKI, + XWikiException.ERROR_XWIKI_MKDIR, + "Error creating directory {0}", + null, + args); } } String filename = doc.getName(); String language = doc.getLanguage(); - if ((language!=null)&&(!language.equals(""))) + if ((language != null) && (!language.equals(""))) filename += "." + language; File file = new File(spacedir, filename); String xml = doc.toXML(true, false, true, withVersions, context); @@ -694,37 +786,42 @@ fos.close(); } catch (ExcludeDocumentException e) { log.info("Skip the document " + doc.getFullName()); - } - catch (Exception e) { + } catch (Exception e) { Object[] args = new Object[1]; args[0] = doc.getFullName(); - throw new XWikiException(XWikiException.MODULE_XWIKI_DOC,XWikiException.ERROR_XWIKI_DOC_EXPORT, "Error creating file {0}", e, args); + throw new XWikiException(XWikiException.MODULE_XWIKI_DOC, + XWikiException.ERROR_XWIKI_DOC_EXPORT, + "Error creating file {0}", + e, + args); } } - - private void addInfosToDir(File dir, XWikiContext context) { - try { - String filename = DefaultPackageFileName; - File file = new File(dir, filename); - FileOutputStream fos = new FileOutputStream(file); - fos.write(toXml(context).getBytes(context.getWiki().getEncoding())); - fos.flush(); - fos.close(); + private void addInfosToDir(File dir, XWikiContext context) + { + try { + String filename = DefaultPackageFileName; + File file = new File(dir, filename); + FileOutputStream fos = new FileOutputStream(file); + fos.write(toXml(context).getBytes(context.getWiki().getEncoding())); + fos.flush(); + fos.close(); } catch (Exception e) { e.printStackTrace(); } } - protected String getElementText(Element docel, String name) { - Element el = docel.element(name); - if (el==null) - return ""; - else - return el.getText(); - } + protected String getElementText(Element docel, String name) + { + Element el = docel.element(name); + if (el == null) + return ""; + else + return el.getText(); + } - protected Document fromXml(String xml) throws DocumentException { + protected Document fromXml(String xml) throws DocumentException + { SAXReader reader = new SAXReader(); Document domdoc; @@ -736,12 +833,11 @@ name = getElementText(infosEl, "name"); description = getElementText(infosEl, "description"); - licence = getElementText(infosEl, "licence"); + licence = getElementText(infosEl, "licence"); authorName = getElementText(infosEl, "author"); version = getElementText(infosEl, "version"); backupPack = new Boolean(getElementText(infosEl, "backupPack")).booleanValue(); - return domdoc; } @@ -750,28 +846,29 @@ } - public void addAllWikiDocuments(XWikiContext context) throws XWikiException { + public void addAllWikiDocuments(XWikiContext context) throws XWikiException + { XWiki wiki = context.getWiki(); List spaces = wiki.getSpaces(context); name = "Backup"; description = "on " + (new Date().toString()) + " by " + context.getUser(); - for(int i = 0; i < spaces.size(); i++) - { + for (int i = 0; i < spaces.size(); i++) { List DocsName = wiki.getSpaceDocsName((String) spaces.get(i), context); - for(int j = 0; j < DocsName.size(); j++) { - this.add(spaces.get(i) + "." + DocsName.get(j), DocumentInfo.ACTION_OVERWRITE, context); + for (int j = 0; j < DocsName.size(); j++) { + this.add(spaces.get(i) + "." + DocsName.get(j), DocumentInfo.ACTION_OVERWRITE, + context); } } this.backupPack = true; } - public void deleteAllWikiDocuments(XWikiContext context) throws XWikiException { + public void deleteAllWikiDocuments(XWikiContext context) throws XWikiException + { XWiki wiki = context.getWiki(); List spaces = wiki.getSpaces(context); - for(int i = 0; i < spaces.size(); i++) - { + for (int i = 0; i < spaces.size(); i++) { List DocsName = wiki.getSpaceDocsName((String) spaces.get(i), context); - for(int j = 0; j < DocsName.size(); j++) { + for (int j = 0; j < DocsName.size(); j++) { String docName = spaces.get(i) + "." + DocsName.get(j); XWikiDocument doc = wiki.getDocument(docName, context); wiki.deleteAllDocuments(doc, context); @@ -779,48 +876,51 @@ } } - - public String readFromDir(File dir, XWikiContext context) throws IOException, XWikiException { + public String readFromDir(File dir, XWikiContext context) throws IOException, XWikiException + { Document description = null; setBackupPack(true); int count = 0; try { File infofile = new File(dir, DefaultPackageFileName); description = readPackage(new FileInputStream(infofile)); - if (description==null) { - throw new PackageException(PackageException.ERROR_PACKAGE_NODESCRIPTION, "Cannot read package description file"); + if (description == null) { + throw new PackageException(PackageException.ERROR_PACKAGE_NODESCRIPTION, + "Cannot read package description file"); } Element docFiles = description.getRootElement(); Element infosFiles = docFiles.element("files"); - List ListFile = infosFiles.elements("file"); + List ListFile = infosFiles.elements("file"); if (log.isInfoEnabled()) - log.info("Package declares " + ListFile.size() + " documents"); - for (int i = 0; i < ListFile.size(); i++) - { - Element el = (Element)ListFile.get(i); + log.info("Package declares " + ListFile.size() + " documents"); + for (int i = 0; i < ListFile.size(); i++) { + Element el = (Element) ListFile.get(i); String defaultAction = el.attributeValue("defaultAction"); String language = el.attributeValue("language"); - if (language==null) - language = ""; + if (language == null) + language = ""; String docName = el.getStringValue(); XWikiDocument doc = new XWikiDocument(); doc.setFullName(docName, context); doc.setLanguage(language); if (log.isDebugEnabled()) - log.debug("Package adding document " + docName + " with language " + language); + log + .debug("Package adding document " + docName + " with language " + + language); File space = new File(dir, doc.getSpace()); String filename = doc.getName(); - if ((doc.getLanguage()!=null)&&(!doc.getLanguage().equals(""))) - filename += "." + doc.getLanguage(); + if ((doc.getLanguage() != null) && (!doc.getLanguage().equals(""))) + filename += "." + doc.getLanguage(); File docfile = new File(space, filename); - doc = readFromXML(readFromInputStream(new FileInputStream(docfile))); - if (doc==null) { + doc = readFromXML(new FileInputStream(docfile)); + if (doc == null) { if (log.isErrorEnabled()) - log.info("Package readFrom XML read null doc for " + docName + " language " + language); + log.info("Package readFrom XML read null doc for " + docName + + " language " + language); } DocumentInfo di = new DocumentInfo(doc); di.setAction(Integer.parseInt(defaultAction)); @@ -828,11 +928,11 @@ count++; } } catch (DocumentException e) { - throw new PackageException(PackageException.ERROR_PACKAGE_UNKNOWN, "Error when reading the XML"); + throw new PackageException(PackageException.ERROR_PACKAGE_UNKNOWN, + "Error when reading the XML"); } if (log.isInfoEnabled()) - log.info("Package read " + count + " documents"); + log.info("Package read " + count + " documents"); return ""; } } - Index: core/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java =================================================================== --- core/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java (revision 2062) +++ core/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java (working copy) @@ -26,7 +26,6 @@ package com.xpn.xwiki.doc; - import com.xpn.xwiki.XWiki; import com.xpn.xwiki.XWikiContext; import com.xpn.xwiki.XWikiException; @@ -73,6 +72,7 @@ import javax.servlet.http.HttpServletRequest; import java.io.IOException; +import java.io.InputStream; import java.io.StringReader; import java.io.StringWriter; import java.lang.ref.SoftReference; @@ -88,48 +88,75 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; - -public class XWikiDocument { +public class XWikiDocument +{ private static final Log log = LogFactory.getLog(XWikiDocument.class); private String title; + private String parent; + private String web; + private String name; + private String content; + private String meta; + private String format; + private String creator; + private String author; + private String contentAuthor; + private String customClass; + private Date contentUpdateDate; + private Date updateDate; + private Date creationDate; + private Version version; + private long id = 0; + private boolean mostRecent = false; + private boolean isNew = true; + private String template; + private String language; + private String defaultLanguage; + private int translation; + private String database; + private BaseObject tags; // Used to make sure the MetaData String is regenerated private boolean isContentDirty = true; + // Used to make sure the MetaData String is regenerated private boolean isMetaDataDirty = true; public static final int HAS_ATTACHMENTS = 1; + public static final int HAS_OBJECTS = 2; + public static final int HAS_CLASS = 4; private int elements = HAS_OBJECTS | HAS_ATTACHMENTS; // Meta Data private BaseClass xWikiClass; + private String xWikiClassXML; private Map xWikiObjects = new HashMap(); @@ -138,6 +165,7 @@ // Caching private boolean fromCache = false; + private ArrayList objectsToRemove = new ArrayList(); // Template by default assign to a view @@ -145,67 +173,74 @@ // private String validationScript; + private Object wikiNode; // We are using a SoftReference which will allow the archive to be - // discarded by the Garbage collector as long as the context is closed (usually during the request) + // discarded by the Garbage collector as long as the context is closed (usually during the + // request) private SoftReference archive; private XWikiStoreInterface store; - public XWikiStoreInterface getStore(XWikiContext context) { + public XWikiStoreInterface getStore(XWikiContext context) + { return context.getWiki().getStore(); } - public XWikiAttachmentStoreInterface getAttachmentStore(XWikiContext context) { + public XWikiAttachmentStoreInterface getAttachmentStore(XWikiContext context) + { return context.getWiki().getAttachmentStore(); } - public XWikiVersioningStoreInterface getVersioningStore(XWikiContext context) { + public XWikiVersioningStoreInterface getVersioningStore(XWikiContext context) + { return context.getWiki().getVersioningStore(); } - - public XWikiStoreInterface getStore() { + public XWikiStoreInterface getStore() + { return store; } - public void setStore(XWikiStoreInterface store) { + public void setStore(XWikiStoreInterface store) + { this.store = store; } - - public long getId() { + public long getId() + { if ((language == null) || language.trim().equals("")) id = getFullName().hashCode(); else id = (getFullName() + ":" + language).hashCode(); - //if (log.isDebugEnabled()) - // log.debug("ID: " + getFullName() + " " + language + ": " + id); + // if (log.isDebugEnabled()) + // log.debug("ID: " + getFullName() + " " + language + ": " + id); return id; } - public void setId(long id) { + public void setId(long id) + { this.id = id; } - - public String getSpace() { + public String getSpace() + { return web; } - public void setSpace(String space) { + public void setSpace(String space) + { this.web = space; } /** - * - * * @deprecated use {@link #getSpace()} instead of this function * @return the name of the space of the document */ - public String getWeb() { + public String getWeb() + { return web; } @@ -213,35 +248,41 @@ * @deprecated use {@link #setSpace(String)} instead of this function * @param web */ - public void setWeb(String web) { + public void setWeb(String web) + { this.web = web; } - - public String getVersion() { + public String getVersion() + { return getRCSVersion().toString(); } - public void setVersion(String version) { + public void setVersion(String version) + { this.version = new Version(version); } - public Version getRCSVersion() { + public Version getRCSVersion() + { if (version == null) { version = new Version("1.1"); } return version; } - public void setRCSVersion(Version version) { + public void setRCSVersion(Version version) + { this.version = version; } - public XWikiDocument() { + public XWikiDocument() + { this("Main", "WebHome"); } - public XWikiDocument(String web, String name) { + public XWikiDocument(String web, String name) + { this.web = web; int i1 = name.indexOf("."); @@ -252,11 +293,11 @@ this.name = name.substring(i1 + 1); } this.updateDate = new Date(); - updateDate.setTime((updateDate.getTime()/1000) * 1000); + updateDate.setTime((updateDate.getTime() / 1000) * 1000); this.contentUpdateDate = new Date(); - contentUpdateDate.setTime((contentUpdateDate.getTime()/1000) * 1000); + contentUpdateDate.setTime((contentUpdateDate.getTime() / 1000) * 1000); this.creationDate = new Date(); - creationDate.setTime((creationDate.getTime()/1000) * 1000); + creationDate.setTime((creationDate.getTime() / 1000) * 1000); this.parent = ""; this.content = "\n"; this.format = ""; @@ -267,26 +308,31 @@ this.customClass = ""; } - public XWikiDocument getParentDoc() { + public XWikiDocument getParentDoc() + { return new XWikiDocument(web, getParent()); } - public String getParent() { + public String getParent() + { return parent.trim(); } - public void setParent(String parent) { + public void setParent(String parent) + { if (!parent.equals(this.parent)) { setMetaDataDirty(true); } this.parent = parent; } - public String getContent() { + public String getContent() + { return content; } - public void setContent(String content) { + public void setContent(String content) + { if (!content.equals(this.content)) { setContentDirty(true); setWikiNode(null); @@ -294,11 +340,13 @@ this.content = content; } - public String getRenderedContent(XWikiContext context) throws XWikiException { + public String getRenderedContent(XWikiContext context) throws XWikiException + { return context.getWiki().getRenderingEngine().renderDocument(this, context); } - public String getRenderedContent(String text, XWikiContext context) { + public String getRenderedContent(String text, XWikiContext context) + { String result; HashMap backup = new HashMap(); try { @@ -311,21 +359,24 @@ return result; } - public String getEscapedContent(XWikiContext context) throws XWikiException { + public String getEscapedContent(XWikiContext context) throws XWikiException + { CharacterFilter filter = new CharacterFilter(); return filter.process(getTranslatedContent(context)); } - - public String getName() { + public String getName() + { return name; } - public void setName(String name) { + public void setName(String name) + { this.name = name; } - public String getFullName() { + public String getFullName() + { StringBuffer buf = new StringBuffer(); buf.append(getSpace()); buf.append("."); @@ -333,18 +384,21 @@ return buf.toString(); } - public void setFullName(String name) { + public void setFullName(String name) + { setFullName(name, null); } - public String getTitle() { + public String getTitle() + { if (title == null) return ""; else return title; } - public String getDisplayTitle() { + public String getDisplayTitle() + { String title = getTitle(); if (title.equals("")) { title = extractTitle(); @@ -355,7 +409,8 @@ return title; } - public String extractTitle() { + public String extractTitle() + { try { String content = getContent(); int i1 = 0; @@ -379,7 +434,8 @@ return ""; } - public void setTitle(String title) { + public void setTitle(String title) + { if (title == null) title = ""; if (!title.equals(this.title)) { @@ -388,120 +444,136 @@ this.title = title; } - public String getFormat() { + public String getFormat() + { if (format == null) return ""; else return format; } - public void setFormat(String format) { + public void setFormat(String format) + { this.format = format; if (!format.equals(this.format)) { setMetaDataDirty(true); } } - public String getAuthor() { + public String getAuthor() + { if (author == null) return ""; else return author.trim(); } - public String getContentAuthor() { + public String getContentAuthor() + { if (contentAuthor == null) return ""; else return contentAuthor.trim(); } - public void setAuthor(String author) { + public void setAuthor(String author) + { if (!getAuthor().equals(this.author)) { setMetaDataDirty(true); } this.author = author; } - public void setContentAuthor(String contentAuthor) { + public void setContentAuthor(String contentAuthor) + { if (!getContentAuthor().equals(this.contentAuthor)) { setMetaDataDirty(true); } this.contentAuthor = contentAuthor; } - public String getCreator() { + public String getCreator() + { if (creator == null) return ""; else return creator.trim(); } - public void setCreator(String creator) { + public void setCreator(String creator) + { if (!getCreator().equals(this.creator)) { setMetaDataDirty(true); } this.creator = creator; } - public Date getDate() { + public Date getDate() + { if (updateDate == null) return new Date(); else return updateDate; } - public void setDate(Date date) { + public void setDate(Date date) + { if ((date != null) && (!date.equals(this.updateDate))) { setMetaDataDirty(true); } // Make sure we drop milliseconds for consistency with the database - if (date!=null) - date.setTime((date.getTime()/1000) * 1000); + if (date != null) + date.setTime((date.getTime() / 1000) * 1000); this.updateDate = date; } - public Date getCreationDate() { + public Date getCreationDate() + { if (creationDate == null) return new Date(); else return creationDate; } - public void setCreationDate(Date date) { + public void setCreationDate(Date date) + { if ((date != null) && (!creationDate.equals(this.creationDate))) { setMetaDataDirty(true); } // Make sure we drop milliseconds for consistency with the database - if (date!=null) - date.setTime((date.getTime()/1000) * 1000); + if (date != null) + date.setTime((date.getTime() / 1000) * 1000); this.creationDate = date; } - public Date getContentUpdateDate() { + public Date getContentUpdateDate() + { if (contentUpdateDate == null) return new Date(); else return contentUpdateDate; } - public void setContentUpdateDate(Date date) { + public void setContentUpdateDate(Date date) + { if ((date != null) && (!date.equals(this.contentUpdateDate))) { setMetaDataDirty(true); } // Make sure we drop milliseconds for consistency with the database - if (date!=null) - date.setTime((date.getTime()/1000) * 1000); + if (date != null) + date.setTime((date.getTime() / 1000) * 1000); this.contentUpdateDate = date; } - public String getMeta() { + public String getMeta() + { return meta; } - public void setMeta(String meta) { + public void setMeta(String meta) + { if (meta == null) { if (this.meta != null) setMetaDataDirty(true); @@ -511,7 +583,8 @@ this.meta = meta; } - public void appendMeta(String meta) { + public void appendMeta(String meta) + { StringBuffer buf = new StringBuffer(this.meta); buf.append(meta); buf.append("\n"); @@ -519,11 +592,13 @@ setMetaDataDirty(true); } - public boolean isContentDirty() { + public boolean isContentDirty() + { return isContentDirty; } - public void incrementVersion() { + public void incrementVersion() + { if (version == null) version = new Version("1.1"); else { @@ -531,44 +606,65 @@ } } - public void setContentDirty(boolean contentDirty) { + public void setContentDirty(boolean contentDirty) + { isContentDirty = contentDirty; } - public boolean isMetaDataDirty() { + public boolean isMetaDataDirty() + { return isMetaDataDirty; } - public void setMetaDataDirty(boolean metaDataDirty) { + public void setMetaDataDirty(boolean metaDataDirty) + { isMetaDataDirty = metaDataDirty; } - public String getAttachmentURL(String filename, XWikiContext context) { + public String getAttachmentURL(String filename, XWikiContext context) + { return getAttachmentURL(filename, "download", context); } - public String getAttachmentURL(String filename, String action, XWikiContext context) { - URL url = context.getURLFactory().createAttachmentURL(filename, getSpace(), getName(), action, null, getDatabase(), context); + public String getAttachmentURL(String filename, String action, XWikiContext context) + { + URL url = + context.getURLFactory().createAttachmentURL(filename, getSpace(), getName(), action, + null, getDatabase(), context); return context.getURLFactory().getURL(url, context); } - public String getAttachmentURL(String filename, String action, String querystring, XWikiContext context) { - URL url = context.getURLFactory().createAttachmentURL(filename, getSpace(), getName(), action, querystring, getDatabase(), context); + public String getAttachmentURL(String filename, String action, String querystring, + XWikiContext context) + { + URL url = + context.getURLFactory().createAttachmentURL(filename, getSpace(), getName(), action, + querystring, getDatabase(), context); return context.getURLFactory().getURL(url, context); } - public String getAttachmentRevisionURL(String filename, String revision, XWikiContext context) { - URL url = context.getURLFactory().createAttachmentRevisionURL(filename, getSpace(), getName(), revision, null, getDatabase(), context); + public String getAttachmentRevisionURL(String filename, String revision, XWikiContext context) + { + URL url = + context.getURLFactory().createAttachmentRevisionURL(filename, getSpace(), getName(), + revision, null, getDatabase(), context); return context.getURLFactory().getURL(url, context); } - public String getAttachmentRevisionURL(String filename, String revision, String querystring, XWikiContext context) { - URL url = context.getURLFactory().createAttachmentRevisionURL(filename, getSpace(), getName(), revision, querystring, getDatabase(), context); + public String getAttachmentRevisionURL(String filename, String revision, String querystring, + XWikiContext context) + { + URL url = + context.getURLFactory().createAttachmentRevisionURL(filename, getSpace(), getName(), + revision, querystring, getDatabase(), context); return context.getURLFactory().getURL(url, context); } - public String getURL(String action, boolean redirect, XWikiContext context) { - URL url = context.getURLFactory().createURL(getSpace(), getName(), action, null, null, getDatabase(), context); + public String getURL(String action, boolean redirect, XWikiContext context) + { + URL url = + context.getURLFactory().createURL(getSpace(), getName(), action, null, null, + getDatabase(), context); if (redirect) { if (url == null) return null; @@ -578,108 +674,137 @@ return context.getURLFactory().getURL(url, context); } - public String getURL(String action, XWikiContext context) { + public String getURL(String action, XWikiContext context) + { return getURL(action, false, context); } - public String getURL(String action, String querystring, XWikiContext context) { - URL url = context.getURLFactory().createURL(getSpace(), getName(), action, - querystring, null, getDatabase(), context); + public String getURL(String action, String querystring, XWikiContext context) + { + URL url = + context.getURLFactory().createURL(getSpace(), getName(), action, querystring, null, + getDatabase(), context); return context.getURLFactory().getURL(url, context); } - public String getExternalURL(String action, XWikiContext context) { - URL url = context.getURLFactory().createExternalURL(getSpace(), getName(), action, - null, null, getDatabase(), context); + public String getExternalURL(String action, XWikiContext context) + { + URL url = + context.getURLFactory().createExternalURL(getSpace(), getName(), action, null, null, + getDatabase(), context); return url.toString(); } - public String getExternalURL(String action, String querystring, XWikiContext context) { - URL url = context.getURLFactory().createExternalURL(getSpace(), getName(), action, - querystring, null, getDatabase(), context); + public String getExternalURL(String action, String querystring, XWikiContext context) + { + URL url = + context.getURLFactory().createExternalURL(getSpace(), getName(), action, querystring, + null, getDatabase(), context); return url.toString(); } - - public String getParentURL(XWikiContext context) throws XWikiException { + public String getParentURL(XWikiContext context) throws XWikiException + { XWikiDocument doc = new XWikiDocument(); doc.setFullName(getParent(), context); - URL url = context.getURLFactory().createURL(doc.getSpace(), doc.getName(), "view", null, null, getDatabase(), context); + URL url = + context.getURLFactory().createURL(doc.getSpace(), doc.getName(), "view", null, null, + getDatabase(), context); return context.getURLFactory().getURL(url, context); } - public XWikiDocumentArchive getDocumentArchive(XWikiContext context) throws XWikiException { + public XWikiDocumentArchive getDocumentArchive(XWikiContext context) throws XWikiException + { loadArchive(context); return getDocumentArchive(); } /** - * return a wrapped version of an XWikiDocument. Prefer this function instead of new Document(XWikiDocument, XWikiContext) - * + * return a wrapped version of an XWikiDocument. Prefer this function instead of new + * Document(XWikiDocument, XWikiContext) + * * @param context * @return */ - public com.xpn.xwiki.api.Document newDocument(String customClassName, XWikiContext context) { + public com.xpn.xwiki.api.Document newDocument(String customClassName, XWikiContext context) + { if (!((customClassName == null) || (customClassName.equals("")))) try { - Class[] classes = new Class[] { XWikiDocument.class, XWikiContext.class }; - Object[] args = new Object[] { this, context }; - return (com.xpn.xwiki.api.Document) Class.forName(customClassName).getConstructor(classes).newInstance(args); + Class[] classes = new Class[] {XWikiDocument.class, XWikiContext.class}; + Object[] args = new Object[] {this, context}; + return (com.xpn.xwiki.api.Document) Class.forName(customClassName) + .getConstructor(classes).newInstance(args); } catch (InstantiationException e) { - e.printStackTrace(); // To change body of catch statement use File | Settings | File Templates. + e.printStackTrace(); // To change body of catch statement use File | Settings | + // File Templates. } catch (IllegalAccessException e) { - e.printStackTrace(); // To change body of catch statement use File | Settings | File Templates. + e.printStackTrace(); // To change body of catch statement use File | Settings | + // File Templates. } catch (ClassNotFoundException e) { - e.printStackTrace(); // To change body of catch statement use File | Settings | File Templates. + e.printStackTrace(); // To change body of catch statement use File | Settings | + // File Templates. } catch (NoSuchMethodException e) { - e.printStackTrace(); // To change body of catch statement use File | Settings | File Templates. + e.printStackTrace(); // To change body of catch statement use File | Settings | + // File Templates. } catch (InvocationTargetException e) { - e.printStackTrace(); // To change body of catch statement use File | Settings | File Templates. + e.printStackTrace(); // To change body of catch statement use File | Settings | + // File Templates. } return new com.xpn.xwiki.api.Document(this, context); } - public com.xpn.xwiki.api.Document newDocument(XWikiContext context) { + public com.xpn.xwiki.api.Document newDocument(XWikiContext context) + { String customClass = getCustomClass(); return newDocument(customClass, context); } - public void loadArchive(XWikiContext context) throws XWikiException { - if (archive==null) { - XWikiDocumentArchive arch = getVersioningStore(context).getXWikiDocumentArchive(this, context); + public void loadArchive(XWikiContext context) throws XWikiException + { + if (archive == null) { + XWikiDocumentArchive arch = + getVersioningStore(context).getXWikiDocumentArchive(this, context); // We are using a SoftReference which will allow the archive to be - // discarded by the Garbage collector as long as the context is closed (usually during the request) + // discarded by the Garbage collector as long as the context is closed (usually during + // the request) archive = new SoftReference(arch); } } - public XWikiDocumentArchive getDocumentArchive() { + public XWikiDocumentArchive getDocumentArchive() + { // We are using a SoftReference which will allow the archive to be - // discarded by the Garbage collector as long as the context is closed (usually during the request) - if (archive==null) - return null; + // discarded by the Garbage collector as long as the context is closed (usually during the + // request) + if (archive == null) + return null; else - return (XWikiDocumentArchive) archive.get(); + return (XWikiDocumentArchive) archive.get(); } - public void setDocumentArchive(XWikiDocumentArchive arch) { + public void setDocumentArchive(XWikiDocumentArchive arch) + { // We are using a SoftReference which will allow the archive to be - // discarded by the Garbage collector as long as the context is closed (usually during the request) - if (arch!=null) - this.archive = new SoftReference(arch); + // discarded by the Garbage collector as long as the context is closed (usually during the + // request) + if (arch != null) + this.archive = new SoftReference(arch); } - public void setDocumentArchive(String sarch) throws XWikiException { + public void setDocumentArchive(String sarch) throws XWikiException + { XWikiDocumentArchive xda = new XWikiDocumentArchive(getId()); xda.setArchive(sarch); setDocumentArchive(xda); } - public Version[] getRevisions(XWikiContext context) throws XWikiException { + public Version[] getRevisions(XWikiContext context) throws XWikiException + { return getVersioningStore(context).getXWikiDocVersions(this, context); } - public String[] getRecentRevisions(int nb, XWikiContext context) throws XWikiException { + public String[] getRecentRevisions(int nb, XWikiContext context) throws XWikiException + { try { Version[] revisions = getVersioningStore(context).getXWikiDocVersions(this, context); int length = nb; @@ -693,23 +818,25 @@ String[] recentrevs = new String[length]; for (int i = 1; i <= length; i++) - recentrevs[i - 1 - ] = revisions[revisions.length - i].toString(); + recentrevs[i - 1] = revisions[revisions.length - i].toString(); return recentrevs; } catch (Exception e) { return new String[0]; } } - public boolean isMostRecent() { + public boolean isMostRecent() + { return mostRecent; } - public void setMostRecent(boolean mostRecent) { + public void setMostRecent(boolean mostRecent) + { this.mostRecent = mostRecent; } - public BaseClass getxWikiClass() { + public BaseClass getxWikiClass() + { if (xWikiClass == null) { xWikiClass = new BaseClass(); xWikiClass.setName(getFullName()); @@ -717,23 +844,28 @@ return xWikiClass; } - public void setxWikiClass(BaseClass xWikiClass) { + public void setxWikiClass(BaseClass xWikiClass) + { this.xWikiClass = xWikiClass; } - public Map getxWikiObjects() { + public Map getxWikiObjects() + { return xWikiObjects; } - public void setxWikiObjects(Map xWikiObjects) { + public void setxWikiObjects(Map xWikiObjects) + { this.xWikiObjects = xWikiObjects; } - public BaseObject getxWikiObject() { + public BaseObject getxWikiObject() + { return getObject(getFullName()); } - public List getxWikiClasses(XWikiContext context) { + public List getxWikiClasses(XWikiContext context) + { List list = new ArrayList(); for (Iterator it = getxWikiObjects().keySet().iterator(); it.hasNext();) { String classname = (String) it.next(); @@ -753,7 +885,8 @@ return list; } - public int createNewObject(String classname, XWikiContext context) throws XWikiException { + public int createNewObject(String classname, XWikiContext context) throws XWikiException + { BaseObject object = BaseClass.newCustomClassInstance(classname, context); object.setName(getFullName()); object.setClassName(classname); @@ -763,13 +896,14 @@ setObjects(classname, objects); } objects.add(object); - int nb = objects.size() - 1; + int nb = objects.size() - 1; object.setNumber(nb); setContentDirty(true); return nb; } - public int getObjectNumbers(String classname) { + public int getObjectNumbers(String classname) + { try { return ((Vector) getxWikiObjects().get(classname)).size(); } catch (Exception e) { @@ -777,21 +911,24 @@ } } - public Vector getObjects(String classname) { - if (classname.indexOf(".")==-1) - classname = "XWiki." + classname; + public Vector getObjects(String classname) + { + if (classname.indexOf(".") == -1) + classname = "XWiki." + classname; return (Vector) getxWikiObjects().get(classname); } - public void setObjects(String classname, Vector objects) { - if (classname.indexOf(".")==-1) - classname = "XWiki." + classname; + public void setObjects(String classname, Vector objects) + { + if (classname.indexOf(".") == -1) + classname = "XWiki." + classname; getxWikiObjects().put(classname, objects); } - public BaseObject getObject(String classname) { - if (classname.indexOf(".")==-1) - classname = "XWiki." + classname; + public BaseObject getObject(String classname) + { + if (classname.indexOf(".") == -1) + classname = "XWiki." + classname; Vector objects = (Vector) getxWikiObjects().get(classname); if (objects == null) return null; @@ -803,23 +940,26 @@ return null; } - public BaseObject getObject(String classname, int nb) { + public BaseObject getObject(String classname, int nb) + { try { - if (classname.indexOf(".")==-1) - classname = "XWiki." + classname; + if (classname.indexOf(".") == -1) + classname = "XWiki." + classname; return (BaseObject) ((Vector) getxWikiObjects().get(classname)).get(nb); } catch (Exception e) { return null; } } - public BaseObject getObject(String classname, String key, String value) { + public BaseObject getObject(String classname, String key, String value) + { return getObject(classname, key, value, false); } - public BaseObject getObject(String classname, String key, String value, boolean failover) { - if (classname.indexOf(".")==-1) - classname = "XWiki." + classname; + public BaseObject getObject(String classname, String key, String value, boolean failover) + { + if (classname.indexOf(".") == -1) + classname = "XWiki." + classname; try { if (value == null) { if (failover) @@ -852,8 +992,8 @@ } } - - public void addObject(String classname, BaseObject object) { + public void addObject(String classname, BaseObject object) + { Vector vobj = getObjects(classname); if (vobj == null) setObject(classname, 0, object); @@ -862,7 +1002,8 @@ setContentDirty(true); } - public void setObject(String classname, int nb, BaseObject object) { + public void setObject(String classname, int nb, BaseObject object) + { Vector objects = null; objects = getObjects(classname); if (objects == null) { @@ -880,15 +1021,18 @@ /** * @return true if the document is a new one (ie it has never been saved) or false otherwise */ - public boolean isNew() { + public boolean isNew() + { return isNew; } - public void setNew(boolean aNew) { + public void setNew(boolean aNew) + { isNew = aNew; } - public void mergexWikiClass(XWikiDocument templatedoc) { + public void mergexWikiClass(XWikiDocument templatedoc) + { BaseClass bclass = getxWikiClass(); BaseClass tbclass = templatedoc.getxWikiClass(); if (tbclass != null) { @@ -901,7 +1045,8 @@ setContentDirty(true); } - public void mergexWikiObjects(XWikiDocument templatedoc) { + public void mergexWikiObjects(XWikiDocument templatedoc) + { // TODO: look for each object if it already exist and add it if it doesn't Iterator itobjects = templatedoc.getxWikiObjects().keySet().iterator(); while (itobjects.hasNext()) { @@ -932,7 +1077,8 @@ setContentDirty(true); } - public void clonexWikiObjects(XWikiDocument templatedoc) { + public void clonexWikiObjects(XWikiDocument templatedoc) + { // TODO: look for each object if it already exist and add it if it doesn't Iterator itobjects = templatedoc.getxWikiObjects().keySet().iterator(); while (itobjects.hasNext()) { @@ -951,28 +1097,33 @@ } } - - public String getTemplate() { - if (template==null) - return ""; + public String getTemplate() + { + if (template == null) + return ""; else - return template; + return template; } - public void setTemplate(String template) { + public void setTemplate(String template) + { this.template = template; setMetaDataDirty(true); } - public String displayPrettyName(String fieldname, XWikiContext context) { + public String displayPrettyName(String fieldname, XWikiContext context) + { return displayPrettyName(fieldname, false, true, context); } - public String displayPrettyName(String fieldname, boolean showMandatory, XWikiContext context) { + public String displayPrettyName(String fieldname, boolean showMandatory, XWikiContext context) + { return displayPrettyName(fieldname, false, true, context); } - public String displayPrettyName(String fieldname, boolean showMandatory, boolean before, XWikiContext context) { + public String displayPrettyName(String fieldname, boolean showMandatory, boolean before, + XWikiContext context) + { try { BaseObject object = getxWikiObject(); if (object == null) @@ -983,32 +1134,38 @@ } } - public String displayPrettyName(String fieldname, BaseObject obj, XWikiContext context) { + public String displayPrettyName(String fieldname, BaseObject obj, XWikiContext context) + { return displayPrettyName(fieldname, false, true, obj, context); } - public String displayPrettyName(String fieldname, boolean showMandatory, BaseObject obj, XWikiContext context) { + public String displayPrettyName(String fieldname, boolean showMandatory, BaseObject obj, + XWikiContext context) + { return displayPrettyName(fieldname, showMandatory, true, obj, context); } - public String displayPrettyName(String fieldname, boolean showMandatory, boolean before, BaseObject obj, XWikiContext context) { + public String displayPrettyName(String fieldname, boolean showMandatory, boolean before, + BaseObject obj, XWikiContext context) + { try { PropertyClass pclass = (PropertyClass) obj.getxWikiClass(context).get(fieldname); String dprettyName = ""; - if ((showMandatory)&&(pclass.getValidationRegExp()!=null)&&(!pclass.getValidationRegExp().equals(""))) { + if ((showMandatory) && (pclass.getValidationRegExp() != null) + && (!pclass.getValidationRegExp().equals(""))) { dprettyName = context.getWiki().addMandatory(context); } if (before) - return dprettyName + pclass.getPrettyName(); + return dprettyName + pclass.getPrettyName(); else - return pclass.getPrettyName() + dprettyName; - } - catch (Exception e) { + return pclass.getPrettyName() + dprettyName; + } catch (Exception e) { return ""; } } - public String displayTooltip(String fieldname, XWikiContext context) { + public String displayTooltip(String fieldname, XWikiContext context) + { try { BaseObject object = getxWikiObject(); if (object == null) @@ -1019,26 +1176,31 @@ } } - public String displayTooltip(String fieldname, BaseObject obj, XWikiContext context) { + public String displayTooltip(String fieldname, BaseObject obj, XWikiContext context) + { try { PropertyClass pclass = (PropertyClass) obj.getxWikiClass(context).get(fieldname); String tooltip = pclass.getTooltip(); - if ((tooltip!=null)&&(!tooltip.trim().equals(""))) { - String img = ""; + if ((tooltip != null) && (!tooltip.trim().equals(""))) { + String img = + ""; return context.getWiki().addTooltip(img, tooltip, context); } else - return ""; - } - catch (Exception e) { + return ""; + } catch (Exception e) { return ""; } } - public String display(String fieldname, String type, BaseObject obj, XWikiContext context) { + public String display(String fieldname, String type, BaseObject obj, XWikiContext context) + { return display(fieldname, type, "", obj, context); } - public String display(String fieldname, String type, String pref, BaseObject obj, XWikiContext context) { + public String display(String fieldname, String type, String pref, BaseObject obj, + XWikiContext context) + { HashMap backup = new HashMap(); try { backupContext(backup, context); @@ -1047,12 +1209,12 @@ type = type.toLowerCase(); StringBuffer result = new StringBuffer(); PropertyClass pclass = (PropertyClass) obj.getxWikiClass(context).get(fieldname); - String prefix = pref + obj.getxWikiClass(context).getName() + "_" + obj.getNumber() + "_"; + String prefix = + pref + obj.getxWikiClass(context).getName() + "_" + obj.getNumber() + "_"; - if (pclass.isCustomDisplayed(context)){ - pclass.displayCustom(result, fieldname, prefix, type, obj, context); - } - else if (type.equals("view")) { + if (pclass.isCustomDisplayed(context)) { + pclass.displayCustom(result, fieldname, prefix, type, obj, context); + } else if (type.equals("view")) { pclass.displayView(result, fieldname, prefix, obj, context); } else if (type.equals("rendered")) { String fcontent = pclass.displayView(fieldname, prefix, obj, context); @@ -1069,35 +1231,35 @@ } else if (type.equals("search")) { result.append("{pre}"); prefix = obj.getxWikiClass(context).getName() + "_"; - pclass.displaySearch(result, fieldname, prefix, (XWikiCriteria) context.get("query"), context); + pclass.displaySearch(result, fieldname, prefix, (XWikiCriteria) context + .get("query"), context); result.append("{/pre}"); } else { pclass.displayView(result, fieldname, prefix, obj, context); } return result.toString(); - } - catch (Exception ex) { + } catch (Exception ex) { log.warn("Exception showing field " + fieldname, ex); return ""; + } finally { + restoreContext(backup, context); } - finally { - restoreContext(backup, context); - } } - public String display(String fieldname, BaseObject obj, XWikiContext context) { + public String display(String fieldname, BaseObject obj, XWikiContext context) + { String type = null; try { type = (String) context.get("display"); + } catch (Exception e) { } - catch (Exception e) { - } if (type == null) type = "view"; return display(fieldname, type, obj, context); } - public String display(String fieldname, XWikiContext context) { + public String display(String fieldname, XWikiContext context) + { try { BaseObject object = getxWikiObject(); if (object == null) @@ -1108,11 +1270,13 @@ } } - public String display(String fieldname, String mode, XWikiContext context) { + public String display(String fieldname, String mode, XWikiContext context) + { return display(fieldname, mode, "", context); } - public String display(String fieldname, String mode, String prefix, XWikiContext context) { + public String display(String fieldname, String mode, String prefix, XWikiContext context) + { try { BaseObject object = getxWikiObject(); if (object == null) @@ -1126,11 +1290,14 @@ } } - public String displayForm(String className, String header, String format, XWikiContext context) { + 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) { + public String displayForm(String className, String header, String format, boolean linebreak, + XWikiContext context) + { Vector objects = getObjects(className); if (format.endsWith("\\n")) linebreak = true; @@ -1156,7 +1323,8 @@ PropertyClass pclass = (PropertyClass) it.next(); vcontext.put(pclass.getName(), pclass.getPrettyName()); } - result.append(XWikiVelocityRenderer.evaluate(header, context.getDoc().getFullName(), vcontext, context)); + result.append(XWikiVelocityRenderer.evaluate(header, context.getDoc().getFullName(), + vcontext, context)); if (linebreak) result.append("\n"); @@ -1169,7 +1337,8 @@ String name = (String) it.next(); vcontext.put(name, display(name, object, context)); } - result.append(XWikiVelocityRenderer.evaluate(format, context.getDoc().getFullName(), vcontext, context)); + result.append(XWikiVelocityRenderer.evaluate(format, context.getDoc() + .getFullName(), vcontext, context)); if (linebreak) result.append("\n"); } @@ -1177,7 +1346,8 @@ return result.toString(); } - public String displayForm(String className, XWikiContext context) { + public String displayForm(String className, XWikiContext context) + { Vector objects = getObjects(className); if (objects == null) return ""; @@ -1230,16 +1400,18 @@ return result.toString(); } - - public boolean isFromCache() { + public boolean isFromCache() + { return fromCache; } - public void setFromCache(boolean fromCache) { + public void setFromCache(boolean fromCache) + { this.fromCache = fromCache; } - public void readDocMetaFromForm(EditForm eform, XWikiContext context) throws XWikiException { + public void readDocMetaFromForm(EditForm eform, XWikiContext context) throws XWikiException + { String defaultLanguage = eform.getDefaultLanguage(); if (defaultLanguage != null) setDefaultLanguage(defaultLanguage); @@ -1251,7 +1423,7 @@ String creator = eform.getCreator(); if ((creator != null) && (!creator.equals(getCreator()))) { if ((getCreator().equals(context.getUser())) - || (context.getWiki().getRightService().hasAdminRights(context))) + || (context.getWiki().getRightService().hasAdminRights(context))) setCreator(creator); } @@ -1266,58 +1438,73 @@ /** * add tags to the document. + * * @param tags */ - public void setTags(String tags, XWikiContext context) throws XWikiException { + public void setTags(String tags, XWikiContext context) throws XWikiException + { loadTags(context); - - StaticListClass tagProp = (StaticListClass) this.tags.getxWikiClass(context).getField(XWikiConstant.TAG_CLASS_PROP_TAGS); + + StaticListClass tagProp = + (StaticListClass) this.tags.getxWikiClass(context).getField( + XWikiConstant.TAG_CLASS_PROP_TAGS); tagProp.fromString(tags); this.tags.safeput(XWikiConstant.TAG_CLASS_PROP_TAGS, tagProp.fromString(tags)); setMetaDataDirty(true); } - public String getTags(XWikiContext context){ + public String getTags(XWikiContext context) + { ListProperty prop = (ListProperty) getTagProperty(context); if (prop != null) return prop.getTextValue(); return null; } - public List getTagsList(XWikiContext context){ + public List getTagsList(XWikiContext context) + { List tagList = null; BaseProperty prop = getTagProperty(context); if (prop != null) tagList = (List) prop.getValue(); - + return tagList; } - private BaseProperty getTagProperty(XWikiContext context){ + private BaseProperty getTagProperty(XWikiContext context) + { loadTags(context); return ((BaseProperty) this.tags.safeget(XWikiConstant.TAG_CLASS_PROP_TAGS)); } - private void loadTags(XWikiContext context){ - if (this.tags == null){ + private void loadTags(XWikiContext context) + { + if (this.tags == null) { this.tags = getObject(XWikiConstant.TAG_CLASS, true, context); } } - public List getTagsPossibleValues(XWikiContext context){ + public List getTagsPossibleValues(XWikiContext context) + { loadTags(context); - String possibleValues = ((StaticListClass) this.tags.getxWikiClass(context).getField(XWikiConstant.TAG_CLASS_PROP_TAGS)).getValues(); + String possibleValues = + ((StaticListClass) this.tags.getxWikiClass(context).getField( + XWikiConstant.TAG_CLASS_PROP_TAGS)).getValues(); return ListClass.getListFromString(possibleValues); - //((BaseProperty) this.tags.safeget(XWikiConstant.TAG_CLASS_PROP_TAGS)).toString(); + // ((BaseProperty) this.tags.safeget(XWikiConstant.TAG_CLASS_PROP_TAGS)).toString(); } - public void readTranslationMetaFromForm(EditForm eform, XWikiContext context) throws XWikiException { + public void readTranslationMetaFromForm(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/
/\\r\\n/g", content); - content = context.getUtil().substitute("s/
/\r\n/g", content); + // content = context.getUtil().substitute("s/
/\\r\\n/g", + // content); + content = + context.getUtil().substitute("s/
/\r\n/g", content); setContent(content); } String title = eform.getTitle(); @@ -1325,7 +1512,8 @@ setTitle(title); } - public void readObjectsFromForm(EditForm eform, XWikiContext context) throws XWikiException { + public void readObjectsFromForm(EditForm eform, XWikiContext context) throws XWikiException + { Iterator itobj = getxWikiObjects().keySet().iterator(); while (itobj.hasNext()) { String name = (String) itobj.next(); @@ -1336,7 +1524,9 @@ BaseObject oldobject = getObject(name, i); if (oldobject != null) { BaseClass baseclass = oldobject.getxWikiClass(context); - BaseObject newobject = (BaseObject) baseclass.fromMap(eform.getObject(baseclass.getName() + "_" + i), oldobject); + BaseObject newobject = + (BaseObject) baseclass.fromMap(eform.getObject(baseclass.getName() + "_" + + i), oldobject); newobject.setNumber(oldobject.getNumber()); newobject.setName(getFullName()); newobjects.set(newobject.getNumber(), newobject); @@ -1346,47 +1536,43 @@ } setContentDirty(true); } - - public void readFromForm(EditForm eform, XWikiContext context) throws XWikiException { + + public void readFromForm(EditForm eform, XWikiContext context) throws XWikiException + { readDocMetaFromForm(eform, context); readTranslationMetaFromForm(eform, context); readObjectsFromForm(eform, context); } /* - 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 = getSpace() + "." + 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(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 = + * getSpace() + "." + 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(EditForm eform, XWikiContext context) throws XWikiException { + public void readFromTemplate(EditForm eform, XWikiContext context) throws XWikiException + { String template = eform.getTemplate(); readFromTemplate(template, context); } - public void readFromTemplate(String template, XWikiContext context) throws XWikiException { + 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); + 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 = getSpace() + "." + template; @@ -1395,8 +1581,11 @@ 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); + 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()); @@ -1413,7 +1602,8 @@ setxWikiObjects(new HashMap()); } // Merge the external objects - // Currently the choice is not to merge the base class and object because it is not + // 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); } @@ -1422,14 +1612,17 @@ setContentDirty(true); } - public void notify(XWikiNotificationRule rule, XWikiDocument newdoc, XWikiDocument olddoc, int event, XWikiContext context) { + 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() { + public Object clone() + { XWikiDocument doc = null; try { doc = (XWikiDocument) getClass().newInstance(); @@ -1476,22 +1669,24 @@ return doc; } - public void copyAttachments(XWikiDocument xWikiSourceDocument) { + 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); - if (newattachment.getAttachment_archive()!=null) - newattachment.getAttachment_archive().setAttachment(newattachment); - if (newattachment.getAttachment_content()!=null) - newattachment.getAttachment_content().setContentDirty(true); + if (newattachment.getAttachment_archive() != null) + newattachment.getAttachment_archive().setAttachment(newattachment); + if (newattachment.getAttachment_content() != null) + newattachment.getAttachment_content().setContentDirty(true); getAttachmentList().add(newattachment); } setContentDirty(true); } - public void loadAttachments(XWikiContext context) throws XWikiException { + public void loadAttachments(XWikiContext context) throws XWikiException + { Iterator attit = getAttachmentList().iterator(); while (attit.hasNext()) { XWikiAttachment attachment = (XWikiAttachment) attit.next(); @@ -1500,7 +1695,8 @@ } } - public boolean equals(Object object) { + public boolean equals(Object object) + { XWikiDocument doc = (XWikiDocument) object; if (!getName().equals(doc.getName())) return false; @@ -1558,7 +1754,7 @@ if (!getValidationScript().equals(doc.getValidationScript())) return false; - + if (!getxWikiClass().equals(doc.getxWikiClass())) return false; @@ -1584,7 +1780,8 @@ return true; } - public String toXML(Document doc, XWikiContext context) { + public String toXML(Document doc, XWikiContext context) + { OutputFormat outputFormat = new OutputFormat("", true); if ((context == null) || (context.getWiki() == null)) outputFormat.setEncoding("UTF-8"); @@ -1601,22 +1798,27 @@ } } - public String getXMLContent(XWikiContext context) throws XWikiException { + public String getXMLContent(XWikiContext context) throws XWikiException + { XWikiDocument tdoc = getTranslatedDocument(context); Document doc = tdoc.toXMLDocument(true, true, false, false, context); return toXML(doc, context); } - public String toXML(XWikiContext context) throws XWikiException { + public String toXML(XWikiContext context) throws XWikiException + { Document doc = toXMLDocument(context); return toXML(doc, context); } - public String toFullXML(XWikiContext context) throws XWikiException { + public String toFullXML(XWikiContext context) throws XWikiException + { return toXML(true, false, true, true, context); } - public void addToZip(ZipOutputStream zos, boolean withVersions, XWikiContext context) throws IOException { + public void addToZip(ZipOutputStream zos, boolean withVersions, XWikiContext context) + throws IOException + { try { String zipname = getSpace() + "/" + getName(); String language = getLanguage(); @@ -1631,28 +1833,30 @@ } } - public void addToZip(ZipOutputStream zos, XWikiContext context) throws IOException { + public void addToZip(ZipOutputStream zos, XWikiContext context) throws IOException + { addToZip(zos, true, context); } - public String toXML(boolean bWithObjects, boolean bWithRendering, - boolean bWithAttachmentContent, - boolean bWithVersions, - XWikiContext context) throws XWikiException { - Document doc = toXMLDocument(bWithObjects, bWithRendering, - bWithAttachmentContent, bWithVersions, context); + boolean bWithAttachmentContent, boolean bWithVersions, XWikiContext context) + throws XWikiException + { + Document doc = + toXMLDocument(bWithObjects, bWithRendering, bWithAttachmentContent, bWithVersions, + context); return toXML(doc, context); } - public Document toXMLDocument(XWikiContext context) throws XWikiException { + public Document toXMLDocument(XWikiContext context) throws XWikiException + { return toXMLDocument(true, false, false, false, context); } public Document toXMLDocument(boolean bWithObjects, boolean bWithRendering, - boolean bWithAttachmentContent, - boolean bWithVersions, - XWikiContext context) throws XWikiException { + boolean bWithAttachmentContent, boolean bWithVersions, XWikiContext context) + throws XWikiException + { Document doc = new DOMDocument(); Element docel = new DOMElement("xwikidoc"); doc.setRootElement(docel); @@ -1766,9 +1970,9 @@ // Add Content el = new DOMElement("content"); - //Filter filter = new CharacterFilter(); - //String newcontent = filter.process(getContent()); - //String newcontent = encodedXMLStringAsUTF8(getContent()); + // Filter filter = new CharacterFilter(); + // String newcontent = filter.process(getContent()); + // String newcontent = encodedXMLStringAsUTF8(getContent()); String newcontent = content; el.addText(newcontent); docel.add(el); @@ -1796,7 +2000,8 @@ return doc; } - protected String encodedXMLStringAsUTF8(String xmlString) { + protected String encodedXMLStringAsUTF8(String xmlString) + { if (xmlString == null) { return ""; } @@ -1842,7 +2047,8 @@ return result.toString(); } - protected String getElement(Element docel, String name) { + protected String getElement(Element docel, String name) + { Element el = docel.element(name); if (el == null) return ""; @@ -1850,12 +2056,18 @@ return el.getText(); } - public void fromXML(String xml) throws XWikiException { + public void fromXML(String xml) throws XWikiException + { fromXML(xml, false); } + public void fromXML(InputStream is) throws XWikiException + { + fromXML(is, false); + } - public void fromXML(String xml, boolean withArchive) throws XWikiException { + public void fromXML(String xml, boolean withArchive) throws XWikiException + { SAXReader reader = new SAXReader(); Document domdoc; @@ -1863,9 +2075,38 @@ StringReader in = new StringReader(xml); domdoc = reader.read(in); } catch (DocumentException e) { - throw new XWikiException(XWikiException.MODULE_XWIKI_DOC, XWikiException.ERROR_DOC_XML_PARSING, "Error parsing xml", e, null); + throw new XWikiException(XWikiException.MODULE_XWIKI_DOC, + XWikiException.ERROR_DOC_XML_PARSING, + "Error parsing xml", + e, + null); } + fromXML(domdoc, withArchive); + } + + public void fromXML(InputStream in, boolean withArchive) throws XWikiException + { + SAXReader reader = new SAXReader(); + Document domdoc; + + try { + domdoc = reader.read(in); + } catch (DocumentException e) { + log.error("Caught a Document Exception from SAXParser."); + throw new XWikiException(XWikiException.MODULE_XWIKI_DOC, + XWikiException.ERROR_DOC_XML_PARSING, + "Error parsing xml", + e, + null); + } + + fromXML(domdoc, withArchive); + } + + public void fromXML(Document domdoc, boolean withArchive) throws XWikiException + { + Element docel = domdoc.getRootElement(); setName(getElement(docel, "name")); setSpace(getElement(docel, "web")); @@ -1878,9 +2119,9 @@ setContent(getElement(docel, "content")); setLanguage(getElement(docel, "language")); setDefaultLanguage(getElement(docel, "defaultLanguage")); - setTitle(getElement(docel,"title")); - setDefaultTemplate(getElement(docel,"defaultTemplate")); - setValidationScript(getElement(docel,"validationScript")); + setTitle(getElement(docel, "title")); + setDefaultTemplate(getElement(docel, "defaultTemplate")); + setValidationScript(getElement(docel, "validationScript")); String strans = getElement(docel, "translation"); if ((strans == null) || strans.equals("")) @@ -1934,21 +2175,26 @@ setContentDirty(false); } - public void setAttachmentList(List list) { + public void setAttachmentList(List list) + { attachmentList = list; } - public List getAttachmentList() { + public List getAttachmentList() + { return attachmentList; } - public void saveAllAttachments(XWikiContext context) throws XWikiException { + public void saveAllAttachments(XWikiContext context) throws XWikiException + { for (int i = 0; i < attachmentList.size(); i++) { saveAttachmentContent((XWikiAttachment) attachmentList.get(i), context); } } - public void saveAttachmentsContent(List attachments, XWikiContext context) throws XWikiException { + public void saveAttachmentsContent(List attachments, XWikiContext context) + throws XWikiException + { String database = context.getDatabase(); try { // We might need to switch database to @@ -1956,26 +2202,28 @@ if (getDatabase() != null) context.setDatabase(getDatabase()); - context.getWiki().getAttachmentStore().saveAttachmentsContent(attachments, this, true, context, true); - }catch(java.lang.OutOfMemoryError e){ + context.getWiki().getAttachmentStore().saveAttachmentsContent(attachments, this, + true, context, true); + } catch (java.lang.OutOfMemoryError e) { throw new XWikiException(XWikiException.MODULE_XWIKI_APP, - XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE, - "Out Of Memory Exception"); - } - finally { + XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE, + "Out Of Memory Exception"); + } finally { if (database != null) context.setDatabase(database); } } - - public void saveAttachmentContent(XWikiAttachment attachment, XWikiContext context) throws XWikiException { + public void saveAttachmentContent(XWikiAttachment attachment, XWikiContext context) + throws XWikiException + { saveAttachmentContent(attachment, true, true, context); } - - protected void saveAttachmentContent(XWikiAttachment attachment, boolean bParentUpdate, boolean bTransaction, XWikiContext context) throws XWikiException { + protected void saveAttachmentContent(XWikiAttachment attachment, boolean bParentUpdate, + boolean bTransaction, XWikiContext context) throws XWikiException + { String database = context.getDatabase(); try { // We might need to switch database to @@ -1983,19 +2231,21 @@ if (getDatabase() != null) context.setDatabase(getDatabase()); - context.getWiki().getAttachmentStore().saveAttachmentContent(attachment, bParentUpdate, context, bTransaction); - }catch(java.lang.OutOfMemoryError e){ + context.getWiki().getAttachmentStore().saveAttachmentContent(attachment, + bParentUpdate, context, bTransaction); + } catch (java.lang.OutOfMemoryError e) { throw new XWikiException(XWikiException.MODULE_XWIKI_APP, - XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE, - "Out Of Memory Exception"); - } - finally { + XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE, + "Out Of Memory Exception"); + } finally { if (database != null) context.setDatabase(database); } } - public void loadAttachmentContent(XWikiAttachment attachment, XWikiContext context) throws XWikiException { + public void loadAttachmentContent(XWikiAttachment attachment, XWikiContext context) + throws XWikiException + { String database = context.getDatabase(); try { // We might need to switch database to @@ -2003,23 +2253,27 @@ if (getDatabase() != null) context.setDatabase(getDatabase()); - context.getWiki().getAttachmentStore().loadAttachmentContent(attachment, context, true); + context.getWiki().getAttachmentStore().loadAttachmentContent(attachment, context, + true); } finally { if (database != null) context.setDatabase(database); } } - public void deleteAttachment(XWikiAttachment attachment, XWikiContext context) throws XWikiException { + public void deleteAttachment(XWikiAttachment attachment, XWikiContext context) + throws XWikiException + { String database = context.getDatabase(); try { // We might need to switch database to // get the translated content if (getDatabase() != null) context.setDatabase(getDatabase()); - try{ - context.getWiki().getAttachmentStore().deleteXWikiAttachment(attachment, context, true); - }catch(java.lang.OutOfMemoryError e){ + try { + context.getWiki().getAttachmentStore().deleteXWikiAttachment(attachment, context, + true); + } catch (java.lang.OutOfMemoryError e) { throw new XWikiException(XWikiException.MODULE_XWIKI_APP, XWikiException.ERROR_XWIKI_APP_JAVA_HEAP_SPACE, "Out Of Memory Exception"); @@ -2031,15 +2285,18 @@ } } - public List getBacklinks(XWikiContext context) throws XWikiException { + public List getBacklinks(XWikiContext context) throws XWikiException + { return getStore(context).loadBacklinks(getFullName(), context, true); } - public List getLinks(XWikiContext context) throws XWikiException { + public List getLinks(XWikiContext context) throws XWikiException + { return getStore(context).loadLinks(getId(), context, true); } - public void renameProperties(String className, Map fieldsToRename) { + public void renameProperties(String className, Map fieldsToRename) + { Vector objects = getObjects(className); if (objects == null) return; @@ -2062,23 +2319,28 @@ setContentDirty(true); } - public void addObjectsToRemove(BaseObject object) { + public void addObjectsToRemove(BaseObject object) + { getObjectsToRemove().add(object); setContentDirty(true); } - public ArrayList getObjectsToRemove() { + public ArrayList getObjectsToRemove() + { return objectsToRemove; } - public void setObjectsToRemove(ArrayList objectsToRemove) { + public void setObjectsToRemove(ArrayList objectsToRemove) + { this.objectsToRemove = objectsToRemove; setContentDirty(true); } - public List getIncludedPages(XWikiContext context) { + public List getIncludedPages(XWikiContext context) + { try { - String pattern = "#include(Topic|InContext|Form|Macros|parseGroovyFromPage)\\([\"'](.*?)[\"']\\)"; + String pattern = + "#include(Topic|InContext|Form|Macros|parseGroovyFromPage)\\([\"'](.*?)[\"']\\)"; List list = context.getUtil().getMatches(getContent(), pattern, 2); for (int i = 0; i < list.size(); i++) { try { @@ -2101,11 +2363,13 @@ } } - public List getIncludedMacros(XWikiContext context) { + public List getIncludedMacros(XWikiContext context) + { return context.getWiki().getIncludedMacros(getSpace(), getContent(), context); } - public List getLinkedPages(XWikiContext context) { + public List getLinkedPages(XWikiContext context) + { try { String pattern = "\\[(.*?)\\]"; List newlist = new ArrayList(); @@ -2131,9 +2395,10 @@ } // Let's get rid of anything that's not a real link - if (name.trim().equals("") || (name.indexOf("$") != -1) || (name.indexOf("://") != -1) - || (name.indexOf("\"") != -1) || (name.indexOf("\'") != -1) - || (name.indexOf("..") != -1) || (name.indexOf(":") != -1) || (name.indexOf("=") != -1)) + if (name.trim().equals("") || (name.indexOf("$") != -1) + || (name.indexOf("://") != -1) || (name.indexOf("\"") != -1) + || (name.indexOf("\'") != -1) || (name.indexOf("..") != -1) + || (name.indexOf(":") != -1) || (name.indexOf("=") != -1)) continue; // generate the link @@ -2171,28 +2436,43 @@ } } - public String displayRendered(PropertyClass pclass, String prefix, BaseCollection object, XWikiContext context) throws XWikiException { + public String displayRendered(PropertyClass pclass, String prefix, BaseCollection object, + XWikiContext context) throws XWikiException + { String result = pclass.displayView(pclass.getName(), prefix, object, context); return getRenderedContent(result, context); } - public String displayView(PropertyClass pclass, String prefix, BaseCollection object, XWikiContext context) { - return (pclass == null) ? "" : pclass.displayView(pclass.getName(), prefix, object, context); + public String displayView(PropertyClass pclass, String prefix, BaseCollection object, + XWikiContext context) + { + return (pclass == null) ? "" : pclass.displayView(pclass.getName(), prefix, object, + context); } - public String displayEdit(PropertyClass pclass, String prefix, BaseCollection object, XWikiContext context) { - return (pclass == null) ? "" : pclass.displayEdit(pclass.getName(), prefix, object, context); + public String displayEdit(PropertyClass pclass, String prefix, BaseCollection object, + XWikiContext context) + { + return (pclass == null) ? "" : pclass.displayEdit(pclass.getName(), prefix, object, + context); } - public String displayHidden(PropertyClass pclass, String prefix, BaseCollection object, XWikiContext context) { - return (pclass == null) ? "" : pclass.displayHidden(pclass.getName(), prefix, object, context); + public String displayHidden(PropertyClass pclass, String prefix, BaseCollection object, + XWikiContext context) + { + return (pclass == null) ? "" : pclass.displayHidden(pclass.getName(), prefix, object, + context); } - public String displaySearch(PropertyClass pclass, String prefix, XWikiCriteria criteria, XWikiContext context) { - return (pclass == null) ? "" : pclass.displaySearch(pclass.getName(), prefix, criteria, context); + public String displaySearch(PropertyClass pclass, String prefix, XWikiCriteria criteria, + XWikiContext context) + { + return (pclass == null) ? "" : pclass.displaySearch(pclass.getName(), prefix, criteria, + context); } - public XWikiAttachment getAttachment(String filename) { + public XWikiAttachment getAttachment(String filename) + { List list = getAttachmentList(); for (int i = 0; i < list.size(); i++) { XWikiAttachment attach = (XWikiAttachment) list.get(i); @@ -2209,14 +2489,16 @@ return null; } - public BaseObject getFirstObject(String fieldname) { + public BaseObject getFirstObject(String fieldname) + { // Keeping this function with context null for compatibilit reasons // It should not be used, since it would miss properties which are only defined in the class // and not present in the object because the object was not updated return getFirstObject(fieldname, null); } - public BaseObject getFirstObject(String fieldname, XWikiContext context) { + public BaseObject getFirstObject(String fieldname, XWikiContext context) + { Collection objectscoll = getxWikiObjects().values(); if (objectscoll == null) return null; @@ -2227,7 +2509,7 @@ BaseObject obj = (BaseObject) itobjs2.next(); if (obj != null) { BaseClass bclass = obj.getxWikiClass(context); - if (bclass!=null) { + if (bclass != null) { Set set = bclass.getPropertyList(); if ((set != null) && set.contains(fieldname)) return obj; @@ -2241,21 +2523,24 @@ return null; } - public int getIntValue(String className, String fieldName) { + public int getIntValue(String className, String fieldName) + { BaseObject obj = getObject(className, 0); if (obj == null) return 0; return obj.getIntValue(fieldName); } - public long getLongValue(String className, String fieldName) { + public long getLongValue(String className, String fieldName) + { BaseObject obj = getObject(className, 0); if (obj == null) return 0; return obj.getLongValue(fieldName); } - public String getStringValue(String className, String fieldName) { + public String getStringValue(String className, String fieldName) + { BaseObject obj = getObject(className); if (obj == null) return ""; @@ -2266,7 +2551,8 @@ return result; } - public int getIntValue(String fieldName) { + public int getIntValue(String fieldName) + { BaseObject object = getFirstObject(fieldName, null); if (object == null) return 0; @@ -2274,7 +2560,8 @@ return object.getIntValue(fieldName); } - public long getLongValue(String fieldName) { + public long getLongValue(String fieldName) + { BaseObject object = getFirstObject(fieldName, null); if (object == null) return 0; @@ -2282,7 +2569,8 @@ return object.getLongValue(fieldName); } - public String getStringValue(String fieldName) { + public String getStringValue(String fieldName) + { BaseObject object = getFirstObject(fieldName, null); if (object == null) return ""; @@ -2294,8 +2582,8 @@ return result; } - - public void setStringValue(String className, String fieldName, String value) { + public void setStringValue(String className, String fieldName, String value) + { BaseObject bobject = getObject(className); if (bobject == null) { bobject = new BaseObject(); @@ -2307,14 +2595,16 @@ setContentDirty(true); } - public List getListValue(String className, String fieldName) { + public List getListValue(String className, String fieldName) + { BaseObject obj = getObject(className); if (obj == null) return new ArrayList(); return obj.getListValue(fieldName); } - public List getListValue(String fieldName) { + public List getListValue(String fieldName) + { BaseObject object = getFirstObject(fieldName, null); if (object == null) return new ArrayList(); @@ -2322,7 +2612,8 @@ return object.getListValue(fieldName); } - public void setListValue(String className, String fieldName, List value) { + public void setListValue(String className, String fieldName, List value) + { BaseObject bobject = getObject(className); if (bobject == null) { bobject = new BaseObject(); @@ -2334,7 +2625,8 @@ setContentDirty(true); } - public void setLargeStringValue(String className, String fieldName, String value) { + public void setLargeStringValue(String className, String fieldName, String value) + { BaseObject bobject = getObject(className); if (bobject == null) { bobject = new BaseObject(); @@ -2346,7 +2638,8 @@ setContentDirty(true); } - public void setIntValue(String className, String fieldName, int value) { + public void setIntValue(String className, String fieldName, int value) + { BaseObject bobject = getObject(className); if (bobject == null) { bobject = new BaseObject(); @@ -2358,17 +2651,18 @@ setContentDirty(true); } - - public String getDatabase() { + public String getDatabase() + { return database; } - public void setDatabase(String database) { + public void setDatabase(String database) + { this.database = database; } - - public void setFullName(String fullname, XWikiContext context) { + public void setFullName(String fullname, XWikiContext context) + { if (fullname == null) return; @@ -2399,44 +2693,53 @@ setContentDirty(true); } - public String getLanguage() { + public String getLanguage() + { if (language == null) return ""; else return language.trim(); } - public void setLanguage(String language) { + public void setLanguage(String language) + { this.language = language; } - public String getDefaultLanguage() { + public String getDefaultLanguage() + { if (defaultLanguage == null) return ""; else return defaultLanguage.trim(); } - public void setDefaultLanguage(String defaultLanguage) { + public void setDefaultLanguage(String defaultLanguage) + { this.defaultLanguage = defaultLanguage; setMetaDataDirty(true); } - public int getTranslation() { + public int getTranslation() + { return translation; } - public void setTranslation(int translation) { + public void setTranslation(int translation) + { this.translation = translation; setMetaDataDirty(true); } - public String getTranslatedContent(XWikiContext context) throws XWikiException { + public String getTranslatedContent(XWikiContext context) throws XWikiException + { String language = context.getWiki().getLanguagePreference(context); return getTranslatedContent(language, context); } - public String getTranslatedContent(String language, XWikiContext context) throws XWikiException { + public String getTranslatedContent(String language, XWikiContext context) + throws XWikiException + { XWikiDocument tdoc = getTranslatedDocument(language, context); String rev = (String) context.get("rev"); if ((rev == null) || (rev.length() == 0)) @@ -2446,12 +2749,15 @@ return cdoc.getContent(); } - public XWikiDocument getTranslatedDocument(XWikiContext context) throws XWikiException { + public XWikiDocument getTranslatedDocument(XWikiContext context) throws XWikiException + { String language = context.getWiki().getLanguagePreference(context); return getTranslatedDocument(language, context); } - public XWikiDocument getTranslatedDocument(String language, XWikiContext context) throws XWikiException { + public XWikiDocument getTranslatedDocument(String language, XWikiContext context) + throws XWikiException + { XWikiDocument tdoc = this; if (!((language == null) || (language.equals("")) || language.equals(defaultLanguage))) { @@ -2477,7 +2783,8 @@ return tdoc; } - public String getRealLanguage(XWikiContext context) throws XWikiException { + public String getRealLanguage(XWikiContext context) throws XWikiException + { String lang = getLanguage(); if ((lang.equals("") || lang.equals("default"))) return getDefaultLanguage(); @@ -2485,7 +2792,8 @@ return lang; } - public String getRealLanguage() { + public String getRealLanguage() + { String lang = getLanguage(); if ((lang.equals("") || lang.equals("default"))) return getDefaultLanguage(); @@ -2493,61 +2801,84 @@ return lang; } - public List getTranslationList(XWikiContext context) throws XWikiException { - return getStore().getTranslationList(this, context); + public List getTranslationList(XWikiContext context) throws XWikiException + { + return getStore().getTranslationList(this, context); } - public List getXMLDiff(XWikiDocument origdoc, XWikiDocument newdoc, XWikiContext context) throws XWikiException, DifferentiationFailedException { - return getDeltas(Diff.diff(ToString.stringToArray(origdoc.toXML(context)), ToString.stringToArray(newdoc.toXML(context)))); + public List getXMLDiff(XWikiDocument origdoc, XWikiDocument newdoc, XWikiContext context) + throws XWikiException, DifferentiationFailedException + { + return getDeltas(Diff.diff(ToString.stringToArray(origdoc.toXML(context)), ToString + .stringToArray(newdoc.toXML(context)))); } - public List getContentDiff(XWikiDocument origdoc, XWikiDocument newdoc, XWikiContext context) throws XWikiException, DifferentiationFailedException { - return getDeltas(Diff.diff(ToString.stringToArray(origdoc.getContent()), ToString.stringToArray(newdoc.getContent()))); + public List getContentDiff(XWikiDocument origdoc, XWikiDocument newdoc, XWikiContext context) + throws XWikiException, DifferentiationFailedException + { + return getDeltas(Diff.diff(ToString.stringToArray(origdoc.getContent()), ToString + .stringToArray(newdoc.getContent()))); } - public List getContentDiff(String origrev, String newrev, XWikiContext context) throws XWikiException, DifferentiationFailedException { + public List getContentDiff(String origrev, String newrev, XWikiContext context) + throws XWikiException, DifferentiationFailedException + { XWikiDocument origdoc = context.getWiki().getDocument(this, origrev, context); XWikiDocument newdoc = context.getWiki().getDocument(this, newrev, context); return getContentDiff(origdoc, newdoc, context); } - public List getContentDiff(String rev, XWikiContext context) throws XWikiException, DifferentiationFailedException { + public List getContentDiff(String rev, XWikiContext context) throws XWikiException, + DifferentiationFailedException + { XWikiDocument revdoc = context.getWiki().getDocument(this, rev, context); return getContentDiff(this, revdoc, context); } - public List getLastChanges(XWikiContext context) throws XWikiException, DifferentiationFailedException { + public List getLastChanges(XWikiContext context) throws XWikiException, + DifferentiationFailedException + { Version version = getRCSVersion(); String prev = "1." + (version.last() - 1); XWikiDocument prevdoc = context.getWiki().getDocument(this, prev, context); - return getDeltas(Diff.diff(ToString.stringToArray(getContent()), - ToString.stringToArray(prevdoc.getContent()))); + return getDeltas(Diff.diff(ToString.stringToArray(getContent()), ToString + .stringToArray(prevdoc.getContent()))); } - - public List getRenderedContentDiff(XWikiDocument origdoc, XWikiDocument newdoc, XWikiContext context) throws XWikiException, DifferentiationFailedException { + public List getRenderedContentDiff(XWikiDocument origdoc, XWikiDocument newdoc, + XWikiContext context) throws XWikiException, DifferentiationFailedException + { String content1, content2; - content1 = context.getWiki().getRenderingEngine().renderText(origdoc.getContent(), origdoc, context); - content2 = context.getWiki().getRenderingEngine().renderText(newdoc.getContent(), newdoc, context); + content1 = + context.getWiki().getRenderingEngine().renderText(origdoc.getContent(), origdoc, + context); + content2 = + context.getWiki().getRenderingEngine().renderText(newdoc.getContent(), newdoc, + context); - return getDeltas(Diff.diff(ToString.stringToArray(content1), - ToString.stringToArray(content2))); + return getDeltas(Diff.diff(ToString.stringToArray(content1), ToString + .stringToArray(content2))); } - public List getRenderedContentDiff(String origrev, String newrev, XWikiContext context) throws XWikiException, DifferentiationFailedException { + public List getRenderedContentDiff(String origrev, String newrev, XWikiContext context) + throws XWikiException, DifferentiationFailedException + { XWikiDocument origdoc = context.getWiki().getDocument(this, origrev, context); XWikiDocument newdoc = context.getWiki().getDocument(this, newrev, context); return getRenderedContentDiff(origdoc, newdoc, context); } - public List getRenderedContentDiff(String rev, XWikiContext context) throws XWikiException, DifferentiationFailedException { + public List getRenderedContentDiff(String rev, XWikiContext context) throws XWikiException, + DifferentiationFailedException + { XWikiDocument revdoc = context.getWiki().getDocument(this, rev, context); return getRenderedContentDiff(this, revdoc, context); } - protected List getDeltas(Revision rev) { + protected List getDeltas(Revision rev) + { ArrayList list = new ArrayList(); for (int i = 0; i < rev.size(); i++) { list.add(rev.getDelta(i)); @@ -2555,18 +2886,23 @@ return list; } - public List getMetaDataDiff(String origrev, String newrev, XWikiContext context) throws XWikiException { + public List getMetaDataDiff(String origrev, String newrev, XWikiContext context) + throws XWikiException + { XWikiDocument origdoc = context.getWiki().getDocument(this, origrev, context); XWikiDocument newdoc = context.getWiki().getDocument(this, newrev, context); return getMetaDataDiff(origdoc, newdoc, context); } - public List getMetaDataDiff(String rev, XWikiContext context) throws XWikiException { + public List getMetaDataDiff(String rev, XWikiContext context) throws XWikiException + { XWikiDocument revdoc = context.getWiki().getDocument(this, rev, context); return getMetaDataDiff(this, revdoc, context); } - public List getMetaDataDiff(XWikiDocument origdoc, XWikiDocument newdoc, XWikiContext context) throws XWikiException { + public List getMetaDataDiff(XWikiDocument origdoc, XWikiDocument newdoc, XWikiContext context) + throws XWikiException + { List list = new ArrayList(); if ((origdoc == null) || (newdoc == null)) @@ -2583,22 +2919,28 @@ if (!origdoc.getLanguage().equals(newdoc.getLanguage())) list.add(new MetaDataDiff("language", origdoc.getLanguage(), newdoc.getLanguage())); if (!origdoc.getDefaultLanguage().equals(newdoc.getDefaultLanguage())) - list.add(new MetaDataDiff("defaultLanguage", origdoc.getDefaultLanguage(), newdoc.getDefaultLanguage())); + list.add(new MetaDataDiff("defaultLanguage", origdoc.getDefaultLanguage(), newdoc + .getDefaultLanguage())); return list; } - public List getObjectDiff(String origrev, String newrev, XWikiContext context) throws XWikiException { + public List getObjectDiff(String origrev, String newrev, XWikiContext context) + throws XWikiException + { XWikiDocument origdoc = context.getWiki().getDocument(this, origrev, context); XWikiDocument newdoc = context.getWiki().getDocument(this, newrev, context); return getObjectDiff(origdoc, newdoc, context); } - public List getObjectDiff(String rev, XWikiContext context) throws XWikiException { + public List getObjectDiff(String rev, XWikiContext context) throws XWikiException + { XWikiDocument revdoc = context.getWiki().getDocument(this, rev, context); return getObjectDiff(this, revdoc, context); } - public List getObjectDiff(XWikiDocument origdoc, XWikiDocument newdoc, XWikiContext context) throws XWikiException { + public List getObjectDiff(XWikiDocument origdoc, XWikiDocument newdoc, XWikiContext context) + throws XWikiException + { ArrayList difflist = new ArrayList(); for (Iterator itobjs = origdoc.getxWikiObjects().values().iterator(); itobjs.hasNext();) { Vector objects = (Vector) itobjs.next(); @@ -2634,7 +2976,9 @@ return difflist; } - public List getClassDiff(XWikiDocument origdoc, XWikiDocument newdoc, XWikiContext context) throws XWikiException { + public List getClassDiff(XWikiDocument origdoc, XWikiDocument newdoc, XWikiContext context) + throws XWikiException + { ArrayList difflist = new ArrayList(); BaseClass origclass = origdoc.getxWikiClass(); BaseClass newclass = newdoc.getxWikiClass(); @@ -2649,25 +2993,29 @@ } /** - * @deprecated {@link #copyDocument(String docname, XWikiContext context)} - * Only do a copy and not a renaming + * @deprecated {@link #copyDocument(String docname, XWikiContext context)} Only do a copy and + * not a renaming * @param docname * @param context * @return * @throws XWikiException */ - public XWikiDocument renameDocument(String docname, XWikiContext context) throws XWikiException { + public XWikiDocument renameDocument(String docname, XWikiContext context) + throws XWikiException + { return copyDocument(docname, context); } - public XWikiDocument copyDocument(String docname, XWikiContext context) throws XWikiException { + public XWikiDocument copyDocument(String docname, XWikiContext context) throws XWikiException + { String oldname = getFullName(); loadAttachments(context); loadArchive(context); -/* if (oldname.equals(docname)) - return this; */ + /* + * if (oldname.equals(docname)) return this; + */ XWikiDocument newdoc = (XWikiDocument) clone(); newdoc.setFullName(docname, context); @@ -2684,10 +3032,12 @@ return newdoc; } - public XWikiLock getLock(XWikiContext context) throws XWikiException { + public XWikiLock getLock(XWikiContext context) throws XWikiException + { XWikiLock theLock = getStore(context).loadLock(getId(), context, true); if (theLock != null) { - int timeout = context.getWiki().getXWikiPreferenceAsInt("lock_Timeout", 30 * 60, context); + int timeout = + context.getWiki().getXWikiPreferenceAsInt("lock_Timeout", 30 * 60, context); if (theLock.getDate().getTime() + timeout * 1000 < new Date().getTime()) { getStore(context).deleteLock(theLock, context, true); theLock = null; @@ -2696,59 +3046,72 @@ return theLock; } - public void setLock(String userName, XWikiContext context) throws XWikiException { + public void setLock(String userName, XWikiContext context) throws XWikiException + { XWikiLock lock = new XWikiLock(getId(), userName); getStore(context).saveLock(lock, context, true); } - public void removeLock(XWikiContext context) throws XWikiException { + public void removeLock(XWikiContext context) throws XWikiException + { XWikiLock lock = getStore(context).loadLock(getId(), context, true); if (lock != null) { getStore(context).deleteLock(lock, context, true); } } - public void insertText(String text, String marker, XWikiContext context) throws XWikiException { + public void insertText(String text, String marker, XWikiContext context) + throws XWikiException + { setContent(StringUtils.replaceOnce(getContent(), marker, text + marker)); context.getWiki().saveDocument(this, context); } - public Object getWikiNode() { + public Object getWikiNode() + { return wikiNode; } - public void setWikiNode(Object wikiNode) { + public void setWikiNode(Object wikiNode) + { this.wikiNode = wikiNode; } - public String getxWikiClassXML() { + public String getxWikiClassXML() + { return xWikiClassXML; } - public void setxWikiClassXML(String xWikiClassXML) { + public void setxWikiClassXML(String xWikiClassXML) + { this.xWikiClassXML = xWikiClassXML; } - public int getElements() { + public int getElements() + { return elements; } - public void setElements(int elements) { + public void setElements(int elements) + { this.elements = elements; } - public void setElement(int element, boolean toggle) { + public void setElement(int element, boolean toggle) + { if (toggle) elements = elements | element; else elements = elements & (~element); } - public boolean hasElement(int element) { + public boolean hasElement(int element) + { return ((elements & element) == element); } - public String getDefaultEditURL(XWikiContext context) throws XWikiException { + public String getDefaultEditURL(XWikiContext context) throws XWikiException + { com.xpn.xwiki.XWiki xwiki = context.getWiki(); if (getContent().indexOf("includeForm(") != -1) { return getEditURL("inline", "", context); @@ -2758,7 +3121,9 @@ } } - public String getEditURL(String action, String mode, XWikiContext context) throws XWikiException { + public String getEditURL(String action, String mode, XWikiContext context) + throws XWikiException + { com.xpn.xwiki.XWiki xwiki = context.getWiki(); String language = ""; XWikiDocument tdoc = (XWikiDocument) context.get("tdoc"); @@ -2769,7 +3134,8 @@ return getEditURL(action, mode, language, context); } - public String getEditURL(String action, String mode, String language, XWikiContext context) { + public String getEditURL(String action, String mode, String language, XWikiContext context) + { StringBuffer editparams = new StringBuffer(); if (!mode.equals("")) { editparams.append("xpage="); @@ -2785,23 +3151,27 @@ return getURL(action, editparams.toString(), context); } - public String getDefaultTemplate() { - if (defaultTemplate==null) - return ""; + public String getDefaultTemplate() + { + if (defaultTemplate == null) + return ""; else - return defaultTemplate; + return defaultTemplate; } - public void setDefaultTemplate(String defaultTemplate) { + public void setDefaultTemplate(String defaultTemplate) + { this.defaultTemplate = defaultTemplate; setMetaDataDirty(true); } - public Vector getComments() { + public Vector getComments() + { return getComments(true); } - public Vector getComments(boolean asc) { + public Vector getComments(boolean asc) + { if (asc) return getObjects("XWiki.XWikiComments"); else { @@ -2816,36 +3186,42 @@ } } - public boolean isCurrentUserCreator(XWikiContext context) { + public boolean isCurrentUserCreator(XWikiContext context) + { return isCreator(context.getUser()); } - public boolean isCreator(String username) { + public boolean isCreator(String username) + { if (username.equals("XWiki.XWikiGuest")) - return false; - return username.equals(getCreator()); + return false; + return username.equals(getCreator()); } - public boolean isCurrentUserPage(XWikiContext context) { + public boolean isCurrentUserPage(XWikiContext context) + { String username = context.getUser(); if (username.equals("XWiki.XWikiGuest")) - return false; + return false; return context.getUser().equals(getFullName()); } - public boolean isCurrentLocalUserPage(XWikiContext context) { + public boolean isCurrentLocalUserPage(XWikiContext context) + { String username = context.getLocalUser(); if (username.equals("XWiki.XWikiGuest")) - return false; + return false; return context.getUser().equals(getFullName()); } - public void resetArchive(XWikiContext context) throws XWikiException { + public void resetArchive(XWikiContext context) throws XWikiException + { getVersioningStore(context).resetRCSArchive(this, true, context); } // This functions adds an object from an new object creation form - public BaseObject addObjectFromRequest(XWikiContext context) throws XWikiException { + public BaseObject addObjectFromRequest(XWikiContext context) throws XWikiException + { // Read info in object ObjectAddForm form = new ObjectAddForm(); form.setRequest((HttpServletRequest) context.getRequest()); @@ -2855,7 +3231,8 @@ int nb = createNewObject(className, context); BaseObject oldobject = getObject(className, nb); BaseClass baseclass = oldobject.getxWikiClass(context); - BaseObject newobject = (BaseObject) baseclass.fromMap(form.getObject(className), oldobject); + BaseObject newobject = + (BaseObject) baseclass.fromMap(form.getObject(className), oldobject); newobject.setNumber(oldobject.getNumber()); newobject.setName(getFullName()); setObject(className, nb, newobject); @@ -2863,25 +3240,33 @@ } // This functions adds an object from an new object creation form - public BaseObject addObjectFromRequest(String className, XWikiContext context) throws XWikiException { + public BaseObject addObjectFromRequest(String className, XWikiContext context) + throws XWikiException + { return addObjectFromRequest(className, "", 0, context); } // This functions adds an object from an new object creation form - public BaseObject addObjectFromRequest(String className, String prefix, XWikiContext context) throws XWikiException { + public BaseObject addObjectFromRequest(String className, String prefix, XWikiContext context) + throws XWikiException + { return addObjectFromRequest(className, prefix, 0, context); } // This functions adds multiple objects from an new objects creation form - public List addObjectsFromRequest(String className, XWikiContext context) throws XWikiException { + public List addObjectsFromRequest(String className, XWikiContext context) + throws XWikiException + { return addObjectsFromRequest(className, "", context); } // This functions adds multiple objects from an new objects creation form - public List addObjectsFromRequest(String className, String pref, XWikiContext context) throws XWikiException { + public List addObjectsFromRequest(String className, String pref, XWikiContext context) + throws XWikiException + { Map map = context.getRequest().getParameterMap(); List objectsNumberDone = new ArrayList(); - List objects = new ArrayList(); + List objects = new ArrayList(); Iterator it = map.keySet().iterator(); String start = pref + className + "_"; @@ -2890,26 +3275,34 @@ if (name.startsWith(start)) { int pos = name.indexOf("_", start.length() + 1); String prefix = name.substring(0, pos); - int num = Integer.decode(prefix.substring(prefix.lastIndexOf("_") + 1)).intValue(); - if (!objectsNumberDone.contains(new Integer(num))){ + int num = + Integer.decode(prefix.substring(prefix.lastIndexOf("_") + 1)).intValue(); + if (!objectsNumberDone.contains(new Integer(num))) { objectsNumberDone.add(new Integer(num)); objects.add(addObjectFromRequest(className, pref, num, context)); } } } - return objects; + return objects; } // This functions adds object from an new object creation form - public BaseObject addObjectFromRequest(String className, int num, XWikiContext context) throws XWikiException { + public BaseObject addObjectFromRequest(String className, int num, XWikiContext context) + throws XWikiException + { return addObjectFromRequest(className, "", num, context); } + // This functions adds object from an new object creation form - public BaseObject addObjectFromRequest(String className, String prefix, int num, XWikiContext context) throws XWikiException { + public BaseObject addObjectFromRequest(String className, String prefix, int num, + XWikiContext context) throws XWikiException + { int nb = createNewObject(className, context); BaseObject oldobject = getObject(className, nb); BaseClass baseclass = oldobject.getxWikiClass(context); - BaseObject newobject = (BaseObject) baseclass.fromMap(Util.getObject(context.getRequest(), prefix + className + "_" + num), oldobject); + BaseObject newobject = + (BaseObject) baseclass.fromMap(Util.getObject(context.getRequest(), prefix + + className + "_" + num), oldobject); newobject.setNumber(oldobject.getNumber()); newobject.setName(getFullName()); setObject(className, nb, newobject); @@ -2917,26 +3310,34 @@ } // This functions adds an object from an new object creation form - public BaseObject updateObjectFromRequest(String className, XWikiContext context) throws XWikiException { + public BaseObject updateObjectFromRequest(String className, XWikiContext context) + throws XWikiException + { return updateObjectFromRequest(className, "", context); } // This functions adds an object from an new object creation form - public BaseObject updateObjectFromRequest(String className, String prefix, XWikiContext context) throws XWikiException { + public BaseObject updateObjectFromRequest(String className, String prefix, + XWikiContext context) throws XWikiException + { return updateObjectFromRequest(className, prefix, 0, context); } // This functions adds an object from an new object creation form - public BaseObject updateObjectFromRequest(String className, String prefix, int num, XWikiContext context) throws XWikiException { + public BaseObject updateObjectFromRequest(String className, String prefix, int num, + XWikiContext context) throws XWikiException + { int nb; BaseObject oldobject = getObject(className, num); - if (oldobject==null) { + if (oldobject == null) { nb = createNewObject(className, context); oldobject = getObject(className, nb); } else - nb = oldobject.getNumber(); + nb = oldobject.getNumber(); BaseClass baseclass = oldobject.getxWikiClass(context); - BaseObject newobject = (BaseObject) baseclass.fromMap(Util.getObject(context.getRequest(), prefix + className + "_" + nb), oldobject); + BaseObject newobject = + (BaseObject) baseclass.fromMap(Util.getObject(context.getRequest(), prefix + + className + "_" + nb), oldobject); newobject.setNumber(oldobject.getNumber()); newobject.setName(getFullName()); setObject(className, nb, newobject); @@ -2944,15 +3345,19 @@ } // This functions adds an object from an new object creation form - public List updateObjectsFromRequest(String className, XWikiContext context) throws XWikiException { + public List updateObjectsFromRequest(String className, XWikiContext context) + throws XWikiException + { return updateObjectsFromRequest(className, "", context); } // This functions adds multiple objects from an new objects creation form - public List updateObjectsFromRequest(String className, String pref, XWikiContext context) throws XWikiException { + public List updateObjectsFromRequest(String className, String pref, XWikiContext context) + throws XWikiException + { Map map = context.getRequest().getParameterMap(); List objectsNumberDone = new ArrayList(); - List objects = new ArrayList(); + List objects = new ArrayList(); Iterator it = map.keySet().iterator(); String start = pref + className + "_"; @@ -2961,8 +3366,9 @@ if (name.startsWith(start)) { int pos = name.indexOf("_", start.length() + 1); String prefix = name.substring(0, pos); - int num = Integer.decode(prefix.substring(prefix.lastIndexOf("_") + 1)).intValue(); - if (!objectsNumberDone.contains(new Integer(num))){ + int num = + Integer.decode(prefix.substring(prefix.lastIndexOf("_") + 1)).intValue(); + if (!objectsNumberDone.contains(new Integer(num))) { objectsNumberDone.add(new Integer(num)); objects.add(updateObjectFromRequest(className, pref, num, context)); } @@ -2971,46 +3377,54 @@ return objects; } - public boolean isAdvancedContent() { - String[] matches = { "<%" , "#set", "#include", "#if", "public class", "/* Advanced content */", "## Advanced content", "/* Programmatic content */", "## Programmatic content" }; + public boolean isAdvancedContent() + { + String[] matches = + {"<%", "#set", "#include", "#if", "public class", "/* Advanced content */", + "## Advanced content", "/* Programmatic content */", "## Programmatic content"}; String content2 = content.toLowerCase(); - for (int i=0;i]*)>"; try { - Util util = new Util(); - List list = util.getMatches(content2, htmlregexp, 1); - if (list.size()>0) - return true; + Util util = new Util(); + List list = util.getMatches(content2, htmlregexp, 1); + if (list.size() > 0) + return true; } catch (MalformedPatternException e) { } return false; } - public boolean isProgrammaticContent() { - String[] matches = { "<%" , "\\$xwiki.xWiki", "$context.context", "$doc.document", "$xwiki.getXWiki()", "$context.getContext()", - "$doc.getDocument()", "WithProgrammingRights(", "/* Programmatic content */", "## Programmatic content", - "$xwiki.search(", "$xwiki.createUser", "$xwiki.createNewWiki", "$xwiki.addToAllGroup", "$xwiki.sendMessage", - "$xwiki.copyDocument", "$xwiki.copyWikiWeb", "$xwiki.parseGroovyFromString", "$doc.toXML()", "$doc.toXMLDocument()", - }; + public boolean isProgrammaticContent() + { + String[] matches = + {"<%", "\\$xwiki.xWiki", "$context.context", "$doc.document", "$xwiki.getXWiki()", + "$context.getContext()", "$doc.getDocument()", "WithProgrammingRights(", + "/* Programmatic content */", "## Programmatic content", "$xwiki.search(", + "$xwiki.createUser", "$xwiki.createNewWiki", "$xwiki.addToAllGroup", + "$xwiki.sendMessage", "$xwiki.copyDocument", "$xwiki.copyWikiWeb", + "$xwiki.parseGroovyFromString", "$doc.toXML()", "$doc.toXMLDocument()",}; String content2 = content.toLowerCase(); - for (int i=0;i nextLevel.length()) { // section level length is greater than next section level length (1.1 and 1) indexEnd = nextSection.getSectionIndex(); - break ; + break; } } String sectionContent = null; - if (indexStart < 0) indexStart = 0; - if (indexEnd == 0) sectionContent = getContent().substring(indexStart); - else sectionContent = getContent().substring(indexStart,indexEnd); // get section content + if (indexStart < 0) + indexStart = 0; + if (indexEnd == 0) + sectionContent = getContent().substring(indexStart); + else + sectionContent = getContent().substring(indexStart, indexEnd); // get section content return sectionContent; } // This function to update a section content in document - public String updateDocumentSection(int sectionNumber , String newSectionContent) throws XWikiException { + public String updateDocumentSection(int sectionNumber, String newSectionContent) + throws XWikiException + { StringBuffer newContent = new StringBuffer(); - // get document section that will be edited + // get document section that will be edited DocumentSection docSection = getDocumentSection(sectionNumber); int numberOfSection = getSplitSectionsAccordingToTitle().size(); int indexSection = docSection.getSectionIndex(); if (numberOfSection == 1) { - // there is only a sections in document + // there is only a sections in document String contentBegin = getContent().substring(0, indexSection); newContent = newContent.append(contentBegin).append(newSectionContent); return newContent.toString(); } else if (sectionNumber == numberOfSection) { - // edit lastest section that doesn't contain subtitle - String contentBegin = getContent().substring(0,indexSection); + // edit lastest section that doesn't contain subtitle + String contentBegin = getContent().substring(0, indexSection); newContent = newContent.append(contentBegin).append(newSectionContent); return newContent.toString(); } else { String sectionLevel = docSection.getSectionLevel(); int nextSectionIndex = 0; - // get index of next section - for (int i=sectionNumber; i < numberOfSection; i++) { + // get index of next section + for (int i = sectionNumber; i < numberOfSection; i++) { DocumentSection nextSection = getDocumentSection(i + 1); // get next section String nextSectionLevel = nextSection.getSectionLevel(); if (sectionLevel.equals(nextSectionLevel)) { @@ -3130,24 +3556,28 @@ break; } } - if (nextSectionIndex == 0) {// edit the last section - newContent = newContent.append(getContent().substring(0,indexSection)).append(newSectionContent); + if (nextSectionIndex == 0) {// edit the last section + newContent = + newContent.append(getContent().substring(0, indexSection)).append( + newSectionContent); return newContent.toString(); } else { String contentAfter = getContent().substring(nextSectionIndex); String contentBegin = getContent().substring(0, indexSection); - newContent = newContent.append(contentBegin).append(newSectionContent).append(contentAfter); + newContent = + newContent.append(contentBegin).append(newSectionContent) + .append(contentAfter); } return newContent.toString(); } } /** - * Computes a document hash, taking into account all document data: - * content, objects, attachments, metadata... - * TODO: cache the hash value, update only on modification. - */ - public String getVersionHashCode(XWikiContext context){ + * Computes a document hash, taking into account all document data: content, objects, + * attachments, metadata... TODO: cache the hash value, update only on modification. + */ + public String getVersionHashCode(XWikiContext context) + { MessageDigest md5 = null; try { @@ -3165,7 +3595,8 @@ StringBuffer sb = new StringBuffer(); for (int j = 0; j < array.length; ++j) { int b = array[j] & 0xFF; - if (b < 0x10) sb.append('0'); + if (b < 0x10) + sb.append('0'); sb.append(Integer.toHexString(b)); } return sb.toString(); @@ -3175,13 +3606,15 @@ return this.hashCode() + ""; } - public static String getInternalPropertyName(String propname, XWikiContext context) { - XWikiMessageTool msg = ((XWikiMessageTool)context.get("msg")); + public static String getInternalPropertyName(String propname, XWikiContext context) + { + XWikiMessageTool msg = ((XWikiMessageTool) context.get("msg")); String cpropname = StringUtils.capitalize(propname); - return (msg==null) ? cpropname : msg.get(cpropname); + return (msg == null) ? cpropname : msg.get(cpropname); } - public String getInternalProperty(String propname) { + public String getInternalProperty(String propname) + { String methodName = "get" + StringUtils.capitalize(propname); try { Method method = getClass().getDeclaredMethod(methodName, null); @@ -3191,35 +3624,41 @@ } } - public String getCustomClass() { + public String getCustomClass() + { if (customClass == null) return ""; return customClass; } - public void setCustomClass(String customClass) { + public void setCustomClass(String customClass) + { this.customClass = customClass; setMetaDataDirty(true); } - public void setValidationScript(String validationScript) { + public void setValidationScript(String validationScript) + { this.validationScript = validationScript; setMetaDataDirty(true); } - public String getValidationScript() { - if (validationScript==null) - return ""; + public String getValidationScript() + { + if (validationScript == null) + return ""; else - return validationScript; + return validationScript; } - public BaseObject newObject(String classname, XWikiContext context) throws XWikiException { + public BaseObject newObject(String classname, XWikiContext context) throws XWikiException + { int nb = createNewObject(classname, context); return getObject(classname, nb); } - public BaseObject getObject(String classname, boolean create, XWikiContext context) { + public BaseObject getObject(String classname, boolean create, XWikiContext context) + { try { BaseObject obj = getObject(classname); @@ -3236,14 +3675,15 @@ } } - - public boolean validate(XWikiContext context) throws XWikiException { + public boolean validate(XWikiContext context) throws XWikiException + { return validate(null, context); } - public boolean validate(String[] classNames, XWikiContext context) throws XWikiException { + public boolean validate(String[] classNames, XWikiContext context) throws XWikiException + { boolean isValid = true; - if ((classNames==null)||(classNames.length==0)) { + if ((classNames == null) || (classNames.length == 0)) { for (Iterator it = getxWikiObjects().keySet().iterator(); it.hasNext();) { String classname = (String) it.next(); BaseClass bclass = context.getWiki().getClass(classname, context); @@ -3257,9 +3697,9 @@ } } } else { - for (int i=0;i