List of usage examples for org.dom4j DocumentHelper createElement
public static Element createElement(String name)
From source file:jp.aegif.alfresco.online_webdav.PropPatchMethod.java
License:Open Source License
/** * Generates the error tag//w ww . jav a2 s .co m * * @param xml XMLWriter */ protected void generateError(XMLWriter xml) { try { // Output the start of the error element Attributes nullAttr = getDAVHelper().getNullAttributes(); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_ERROR, WebDAV.XML_NS_ERROR, nullAttr); // Output error xml.write(DocumentHelper.createElement(WebDAV.XML_NS_CANNOT_MODIFY_PROTECTED_PROPERTY)); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_ERROR, WebDAV.XML_NS_ERROR); } catch (Exception ex) { // Convert to a runtime exception throw new AlfrescoRuntimeException("XML processing error", ex); } }
From source file:jp.aegif.alfresco.online_webdav.WebDAVMethod.java
License:Open Source License
/** * Generates the lock discovery XML response * //from w w w. j a v a2 s. c om * @param xml XMLWriter * @param lockNode NodeRef * @param emptyNamespace boolean True if namespace should be empty. Used to avoid bugs in WebDAV clients. * @param scope String lock scope * @param depth String lock depth * @param lToken String locktoken * @param owner String lock owner * @param expiryDate the date/time the lock should expire */ protected void generateLockDiscoveryXML(XMLWriter xml, FileInfo lockNodeInfo, boolean emptyNamespace, String scope, String depth, String lToken, String owner, Date expiryDate) throws Exception { Attributes nullAttr = getDAVHelper().getNullAttributes(); String ns = emptyNamespace ? "" : WebDAV.DAV_NS; if (lockNodeInfo != null) { // Output the XML response xml.startElement(ns, WebDAV.XML_LOCK_DISCOVERY, emptyNamespace ? WebDAV.XML_LOCK_DISCOVERY : WebDAV.XML_NS_LOCK_DISCOVERY, nullAttr); xml.startElement(ns, WebDAV.XML_ACTIVE_LOCK, emptyNamespace ? WebDAV.XML_ACTIVE_LOCK : WebDAV.XML_NS_ACTIVE_LOCK, nullAttr); xml.startElement(ns, WebDAV.XML_LOCK_TYPE, emptyNamespace ? WebDAV.XML_LOCK_TYPE : WebDAV.XML_NS_LOCK_TYPE, nullAttr); xml.write(DocumentHelper.createElement(emptyNamespace ? WebDAV.XML_WRITE : WebDAV.XML_NS_WRITE)); xml.endElement(ns, WebDAV.XML_LOCK_TYPE, emptyNamespace ? WebDAV.XML_LOCK_TYPE : WebDAV.XML_NS_LOCK_TYPE); xml.startElement(ns, WebDAV.XML_LOCK_SCOPE, emptyNamespace ? WebDAV.XML_LOCK_SCOPE : WebDAV.XML_NS_LOCK_SCOPE, nullAttr); xml.write(DocumentHelper.createElement(emptyNamespace ? scope : WebDAV.DAV_NS_PREFIX + scope)); xml.endElement(ns, WebDAV.XML_LOCK_SCOPE, emptyNamespace ? WebDAV.XML_LOCK_SCOPE : WebDAV.XML_NS_LOCK_SCOPE); // NOTE: We only support one level of lock at the moment xml.startElement(ns, WebDAV.XML_DEPTH, emptyNamespace ? WebDAV.XML_DEPTH : WebDAV.XML_NS_DEPTH, nullAttr); xml.write(depth); xml.endElement(ns, WebDAV.XML_DEPTH, emptyNamespace ? WebDAV.XML_DEPTH : WebDAV.XML_NS_DEPTH); xml.startElement(ns, WebDAV.XML_OWNER, emptyNamespace ? WebDAV.XML_OWNER : WebDAV.XML_NS_OWNER, nullAttr); xml.write(owner); xml.endElement(ns, WebDAV.XML_OWNER, emptyNamespace ? WebDAV.XML_OWNER : WebDAV.XML_NS_OWNER); xml.startElement(ns, WebDAV.XML_TIMEOUT, emptyNamespace ? WebDAV.XML_TIMEOUT : WebDAV.XML_NS_TIMEOUT, nullAttr); // Output the expiry time String strTimeout = WebDAV.INFINITE; if (expiryDate != null) { long timeoutRemaining = (expiryDate.getTime() - System.currentTimeMillis()) / 1000L; strTimeout = WebDAV.SECOND + timeoutRemaining; } xml.write(strTimeout); xml.endElement(ns, WebDAV.XML_TIMEOUT, emptyNamespace ? WebDAV.XML_TIMEOUT : WebDAV.XML_NS_TIMEOUT); xml.startElement(ns, WebDAV.XML_LOCK_TOKEN, emptyNamespace ? WebDAV.XML_LOCK_TOKEN : WebDAV.XML_NS_LOCK_TOKEN, nullAttr); xml.startElement(ns, WebDAV.XML_HREF, emptyNamespace ? WebDAV.XML_HREF : WebDAV.XML_NS_HREF, nullAttr); xml.write(lToken); xml.endElement(ns, WebDAV.XML_HREF, emptyNamespace ? WebDAV.XML_HREF : WebDAV.XML_NS_HREF); xml.endElement(ns, WebDAV.XML_LOCK_TOKEN, emptyNamespace ? WebDAV.XML_LOCK_TOKEN : WebDAV.XML_NS_LOCK_TOKEN); xml.endElement(ns, WebDAV.XML_ACTIVE_LOCK, emptyNamespace ? WebDAV.XML_ACTIVE_LOCK : WebDAV.XML_NS_ACTIVE_LOCK); xml.endElement(ns, WebDAV.XML_LOCK_DISCOVERY, emptyNamespace ? WebDAV.XML_LOCK_DISCOVERY : WebDAV.XML_NS_LOCK_DISCOVERY); } }
From source file:lost.tok.Author.java
License:Open Source License
/** * Creating an author XML element/*from ww w .j av a 2 s .c o m*/ * * @return Element of Author */ public Element toXML() { Element e = DocumentHelper.createElement("author"); //$NON-NLS-1$ e.addText(getName()); return e; }
From source file:lost.tok.html.DiscConflictPage.java
License:Open Source License
@Override protected String getBody() { Element body = DocumentHelper.createElement("div"); //$NON-NLS-1$ body.addAttribute("id", "conflict"); //$NON-NLS-1$ //$NON-NLS-2$ body.addAttribute("class", "main_content"); //$NON-NLS-1$ //$NON-NLS-2$ // main title of Discussion conflict page body.addElement("h1").addText(Messages.getString("DiscConflictPage.ChooseDiscussion")); //$NON-NLS-1$ //$NON-NLS-2$ for (int i = 0; i < info.size(); i++) { // 1. extract information from the info object DiscussionPage dPage = info.getDPage(i); Link link = info.getLink(i);//w w w . ja v a 2s.c o m Discussion disc = link.getLinkedDiscussion(); String text = info.getLinkText(i); // 2. Add the i'th discussion title Element div = body.addElement("div"); //$NON-NLS-1$ div.addElement("h2").addText(link.getDisplayLinkType() + ": " + link.getSubject()); //$NON-NLS-1$ //$NON-NLS-2$ // 3. Add the i'th excerption's text Element quoteElm = div.addElement("blockquote"); //$NON-NLS-1$ quoteElm.addAttribute("class", "sublink"); //$NON-NLS-1$ //$NON-NLS-2$ quoteElm.addAttribute("cite", getPathTo(dPage)); //$NON-NLS-1$ quoteElm.addElement("p").addText(text); //$NON-NLS-1$ // 4. Add the link to the discussion + creator's name Element p = div.addElement("p"); //$NON-NLS-1$ Element linkElm = p.addElement("a"); //$NON-NLS-1$ linkElm.addAttribute("href", getPathTo(dPage)); //$NON-NLS-1$ linkElm.addText(disc.getDiscName()); p.addText(Messages.getString("DiscConflictPage.CreatedBy")); //$NON-NLS-1$ p.addElement("em").addText(disc.getCreatorName()); //$NON-NLS-1$ } return GeneralFunctions.elementToString(body); }
From source file:lost.tok.html.DiscussionPage.java
License:Open Source License
@Override protected String getBody() { Element body = DocumentHelper.createElement("div"); //$NON-NLS-1$ body.addAttribute("id", "discussion"); //$NON-NLS-1$ //$NON-NLS-2$ body.addAttribute("class", "main_content"); //$NON-NLS-1$ //$NON-NLS-2$ body.addElement("h1").addText(disc.getDiscName()); //$NON-NLS-1$ body.addText(Messages.getString("DiscussionPage.CreatedBy")); //$NON-NLS-1$ body.addElement("em").addText(disc.getCreatorName()); //$NON-NLS-1$ body.addElement("p").addText(disc.getDescription()); //$NON-NLS-1$ if (disc.getLink() != null) body.add(getLinkInfoElement());//from w w w. j av a 2 s .c o m Element opinionList = body.addElement("ol"); //$NON-NLS-1$ for (Opinion o : disc.getOpinions()) { Element listItem = opinionList.addElement("li"); //$NON-NLS-1$ listItem.add(getOpinionElement(o)); } // TODO(Shay, low): Consider adding related root and source files return GeneralFunctions.elementToString(body); }
From source file:lost.tok.html.DiscussionPage.java
License:Open Source License
/** * Returns a div element containing all the information related to the discussion's link *///from ww w.ja v a 2 s .c om private Element getLinkInfoElement() { Element div = DocumentHelper.createElement("div"); //$NON-NLS-1$ Link l = disc.getLink(); div.addAttribute("class", "linkInfo"); //$NON-NLS-1$ //$NON-NLS-2$ div.addElement("h2").addText(l.getSubject()); //$NON-NLS-1$ Element typeElement = div.addElement("p"); //$NON-NLS-1$ typeElement.addText(Messages.getString("DiscussionPage.linkType")); //$NON-NLS-1$ typeElement.addElement("em").addText(l.getDisplayLinkType()); //$NON-NLS-1$ Element sublinksList = div.addElement("ul"); //$NON-NLS-1$ for (SubLink sl : l.getSubLinkList()) { LinkedList<Excerption> excerptions = new LinkedList<Excerption>(); for (Excerption e : sl.getExcerption()) excerptions.add(e); String eText = Excerption.concat(excerptions); Source src = sl.getLinkedSource(); Element listItem = sublinksList.addElement("li"); //$NON-NLS-1$ Element quoteElm = listItem.addElement("blockquote"); //$NON-NLS-1$ quoteElm.addAttribute("class", "sublink"); //$NON-NLS-1$ //$NON-NLS-2$ quoteElm.addAttribute("cite", getPathToSrc(src)); //$NON-NLS-1$ quoteElm.addElement("p").addText(eText); //$NON-NLS-1$ Element srcLinkParagraph = listItem.addElement("p"); //$NON-NLS-1$ srcLinkParagraph.addText(Messages.getString("DiscussionPage.Source")).add(getLinkSrcElm(src)); //$NON-NLS-1$ } return div; }
From source file:lost.tok.html.DiscussionPage.java
License:Open Source License
/** * Creates a div element describing the given opinion * @param o the opinion to generate html div for * @return a div element that contains all the information relating the opinion *//* ww w .j a v a 2 s . c om*/ private Element getOpinionElement(Opinion o) { Element div = DocumentHelper.createElement("div"); //$NON-NLS-1$ // 1. Create the title Element opTitle = div.addElement("h2"); //$NON-NLS-1$ opTitle.addText(o.getName()); opTitle.addAttribute("id", "discItem" + o.getId()); //$NON-NLS-1$ //$NON-NLS-2$ Quote[] quotes = disc.getSortedQuotes(o.getName()); // add quotes only if there are any if (quotes.length > 0) { Element quotesList = div.addElement("ul"); //$NON-NLS-1$ // 2. Add the quotes for (Quote q : quotes) { // TODO(Shay, medium-low): Sort the quotes according to author importance Element listItem = quotesList.addElement("li"); //$NON-NLS-1$ listItem.add(getQuoteElement(q)); } } // TODO(Shay, low): Consider adding relation data return div; }
From source file:lost.tok.html.DiscussionPage.java
License:Open Source License
/** * Creates a div element describing the given quote * @param q the quote to generate html div for * @return a div element that contains all the information relating the quote *//* w ww. j a v a 2s .c om*/ private Element getQuoteElement(Quote q) { Element div = DocumentHelper.createElement("div"); //$NON-NLS-1$ // 1. Get the quote's text and find a good title for it String qText = q.getText(); int actualLen = qText.indexOf(' ', QUOTE_TITLE_LENGTH); actualLen = (actualLen != -1) ? actualLen : qText.length(); String qTitle = qText.substring(0, actualLen); // 2. Get the src we should link to Source src = q.getSource(); // 3. Add the title Element quoteTitle = div.addElement("h3"); //$NON-NLS-1$ quoteTitle.addText(qTitle); quoteTitle.addAttribute("id", "discItem" + q.getID()); //$NON-NLS-1$ //$NON-NLS-2$ // 4. Add the quote itself Element quoteElm = div.addElement("blockquote"); //$NON-NLS-1$ quoteElm.addAttribute("class", "quote"); //$NON-NLS-1$ //$NON-NLS-2$ quoteElm.addAttribute("cite", getPathToSrc(src)); //$NON-NLS-1$ quoteElm.addElement("p").addText(qText); //$NON-NLS-1$ // 5. Add a comment, if there is one if (!q.getComment().equals("")) //$NON-NLS-1$ { Element pComment = div.addElement("p"); //$NON-NLS-1$ pComment.addText(Messages.getString("DiscussionPage.Comment")); //$NON-NLS-1$ pComment.addElement("em").addText(q.getComment()); //$NON-NLS-1$ quoteElm.addAttribute("title", q.getComment()); //$NON-NLS-1$ } // 6. Add a link to the related source Element srcLinkParagraph = div.addElement("p"); //$NON-NLS-1$ srcLinkParagraph.addText(Messages.getString("DiscussionPage.From")).add(getLinkSrcElm(src)); //$NON-NLS-1$ // TODO(Shay, low): 7. Consider adding relation data return div; }
From source file:lost.tok.html.DiscussionPage.java
License:Open Source License
/** * Returns a paragraph Element linking to the selected source * @param src the source to link to/*from w w w .j a v a 2 s . com*/ * @return a p element which can be added to the page */ private Element getLinkSrcElm(Source src) { Element cite = DocumentHelper.createElement("cite"); //$NON-NLS-1$ Element srcLink = cite.addElement("a"); //$NON-NLS-1$ srcLink.addAttribute("href", getPathToSrc(src)); //$NON-NLS-1$ srcLink.addText(src.getTitle()); cite.addText(Messages.getString("DiscussionPage.by")); //$NON-NLS-1$ cite.addElement("em").addText(src.getAuthor()); //$NON-NLS-1$ return cite; }
From source file:lost.tok.html.IndexPage.java
License:Open Source License
@Override protected String getBody() { Element body = DocumentHelper.createElement("div"); //$NON-NLS-1$ body.addAttribute("id", "index"); //$NON-NLS-1$ //$NON-NLS-2$ body.addAttribute("class", "main_content"); //$NON-NLS-1$ //$NON-NLS-2$ body.addElement("h1").addText(tok.getProject().getName()); //$NON-NLS-1$ Element author = body.addElement("p").addText(Messages.getString("IndexPage.CreatedBy")); //$NON-NLS-1$ //$NON-NLS-2$ author.addElement("em").addText(tok.getProjectCreator()); //$NON-NLS-1$ body.add(getSourcesElement(true));// w w w . j a v a 2s. co m body.add(getSourcesElement(false)); body.add(getDiscussionElement()); return GeneralFunctions.elementToString(body); }