List of usage examples for org.w3c.dom Element setTextContent
public void setTextContent(String textContent) throws DOMException;
From source file:com.bluexml.xforms.controller.mapping.MappingToolAlfrescoToForms.java
/** * @param transaction//www . ja va 2s. com * @param formName * @param alfrescoId * @param doc * @param alfrescoNodes * @param rootElement * @param initParams * @param formType * @throws ServletException */ private void getDataFormInstance(Document doc, Element rootElement, AlfrescoTransaction transaction, String formName, String alfrescoId, Map<String, GenericClass> alfrescoNodes, boolean formIsReadOnly, Map<String, String> initParams) throws ServletException { FormType formType = getFormType(formName); Element formElement = getForm(transaction, formType, alfrescoId, alfrescoNodes, doc, initParams, formIsReadOnly); VirtualResolver virtualResolver = new VirtualResolver(this); virtualResolver.prepareAlfrescoToXForms(formElement, formName); rootElement.appendChild(formElement); Element typeElement = doc.createElement(MsgId.INT_INSTANCE_SIDE_DATATYPE.getText()); typeElement.setTextContent(classTypeToString(getClassType(formType.getRealClass()))); rootElement.appendChild(typeElement); }
From source file:org.apache.cxf.cwiki.SiteExporter.java
public Future<?> loadPage(Element pageSumEl, final Set<String> allPages, final Set<Page> newPages) throws Exception { Document doc = DOMUtils.newDocument(); Element el = doc.createElementNS(SOAPNS, "ns1:getPage"); Element el2 = doc.createElement("in0"); el.appendChild(el2);/*from ww w . j a v a 2s. c o m*/ el2.setTextContent(loginToken); el2 = doc.createElement("in1"); el.appendChild(el2); el2.setTextContent(DOMUtils.getChildContent(pageSumEl, "id")); doc.appendChild(el); //make sure we only fire off about 15-20 or confluence may get a bit overloaded while (asyncCount.get() > 15) { Thread.sleep(10); } asyncCount.incrementAndGet(); Future<?> f = getDispatch().invokeAsync(doc, new AsyncHandler<Document>() { public void handleResponse(Response<Document> doc) { try { Page page = new Page(doc.get(), SiteExporter.this); page.setExporter(SiteExporter.this); Page oldPage = pages.put(page.getId(), page); if (oldPage == null || page.getModifiedTime().compare(oldPage.getModifiedTime()) > 0) { if (!modifiedPages.contains(page)) { modifiedPages.add(page); } if (oldPage == null) { //need to check parents to see if it has a {children} tag so we can re-render newPages.add(page); } } if (allPages.contains(page.getId())) { allPages.remove(page.getId()); } } catch (Exception e) { e.printStackTrace(); } finally { asyncCount.decrementAndGet(); } } }); return f; }
From source file:org.apache.cxf.cwiki.SiteExporter.java
public void loadBlog() throws Exception { System.out.println("Loading Blog entries for " + spaceKey); Document doc = DOMUtils.createDocument(); Element el = doc.createElementNS(SOAPNS, "ns1:getBlogEntries"); Element el2 = doc.createElement("in0"); el.appendChild(el2);//from w ww . ja va2s. c o m el2.setTextContent(loginToken); el2 = doc.createElement("in1"); el.appendChild(el2); el2.setTextContent(spaceKey); doc.appendChild(el); doc = getDispatch().invoke(doc); Map<String, BlogEntrySummary> oldBlog = new ConcurrentHashMap<String, BlogEntrySummary>(blog); Node nd = doc.getDocumentElement().getFirstChild().getFirstChild(); while (nd != null) { if (nd instanceof Element) { BlogEntrySummary entry = new BlogEntrySummary((Element) nd); entry.setVersion(getBlogVersion(entry.id)); BlogEntrySummary oldEntry = blog.put(entry.getId(), entry); System.out.println("Found Blog entry for " + entry.getTitle() + " " + entry.getPath()); if (oldEntry == null || oldEntry.getVersion() != entry.getVersion()) { System.out.println(" and it's modified"); modifiedBlog.add(entry); } else { System.out.println(" but it's not modified"); } oldBlog.remove(entry.getId()); } nd = nd.getNextSibling(); } for (String id : oldBlog.keySet()) { //these pages have been deleted BlogEntrySummary p = blog.remove(id); File file = new File(outputDir, p.getPath()); if (file.exists()) { callSvn("rm", file.getAbsolutePath()); svnCommitMessage.append("Deleted: " + file.getName() + "\n"); } if (file.exists()) { file.delete(); } } }
From source file:com.bluexml.xforms.controller.mapping.MappingToolAlfrescoToForms.java
/** * Gets the form.//from w w w.j a v a 2 s . c om * * @param transaction * the login * @param formType * the form type * @param alfrescoId * the alfresco id * @param alfrescoNodes * the alfresco nodes * @param formInstance * the form instance * @param initParams * * @return the form * * @throws ServletException */ private Element getForm(AlfrescoTransaction transaction, FormType formType, String alfrescoId, Map<String, GenericClass> alfrescoNodes, Document formInstance, Map<String, String> initParams, boolean formIsReadOnly) throws ServletException { GenericClass alfrescoClass = getAlfrescoClass(transaction, alfrescoId, alfrescoNodes); Element formElement = formInstance.createElement(formType.getName()); // List<FormFieldType> fields = formType.getField(); getFormFields(formInstance, formElement, fields, alfrescoClass, transaction, alfrescoId, initParams, formIsReadOnly); // List<ModelChoiceType> modelChoices = formType.getModelChoice(); getFormModelChoices(transaction, alfrescoNodes, formInstance, formElement, modelChoices, alfrescoClass, initParams, formIsReadOnly); // List<ReferenceType> references = formType.getReference(); getFormReferences(formInstance, formElement, references, alfrescoClass, transaction, alfrescoNodes, initParams, formIsReadOnly); Element idField = formInstance.createElement(MsgId.INT_INSTANCE_SIDEID.getText()); idField.setTextContent(alfrescoId); formElement.appendChild(idField); appendFieldForContent(transaction, formType, formInstance, formElement, alfrescoId); return formElement; }
From source file:de.qucosa.webapi.v1.DocumentResource.java
private void addHashValue(Element fileElement, DatastreamProfile dsp) { if ((fileElement == null) || (dsp == null)) return;/*from www . j a v a 2 s . c o m*/ String hashType = dsp.getDsChecksumType(); String hashValue = dsp.getDsChecksum(); if ((hashType != null) && (hashValue != null) && !hashType.isEmpty() && !hashValue.isEmpty()) { Element hashValueElement = fileElement.getOwnerDocument().createElement("HashValue"); Element typeElement = fileElement.getOwnerDocument().createElement("Type"); Element valueElement = fileElement.getOwnerDocument().createElement("Value"); fileElement.appendChild(hashValueElement); hashValueElement.appendChild(typeElement); hashValueElement.appendChild(valueElement); typeElement.setTextContent(hashType); valueElement.setTextContent(hashValue); } }
From source file:org.apache.cxf.cwiki.SiteExporter.java
private void loadAttachments(AbstractPage p) throws Exception { Document doc = DOMUtils.createDocument(); Element el = doc.createElementNS(SOAPNS, "ns1:getAttachments"); Element el2 = doc.createElement("in0"); el.appendChild(el2);//from w ww. j ava 2 s. com el2.setTextContent(loginToken); el2 = doc.createElement("in1"); el.appendChild(el2); el2.setTextContent(p.getId()); el.appendChild(el2); doc.appendChild(el); doc = getDispatch().invoke(doc); el = DOMUtils.getFirstElement(DOMUtils.getFirstElement(doc.getDocumentElement())); while (el != null) { try { String filename = DOMUtils.getChildContent(el, "fileName"); String durl = DOMUtils.getChildContent(el, "url"); String aid = DOMUtils.getChildContent(el, "id"); p.addAttachment(aid, filename); String dirName = p.getPath(); dirName = dirName.substring(0, dirName.lastIndexOf(".")) + ".data"; File file = new File(outputDir, dirName); if (!file.exists()) { callSvn("mkdir", file.getAbsolutePath()); file.mkdirs(); } filename = filename.replace(' ', '-'); file = new File(file, filename); boolean exists = file.exists(); FileOutputStream out = new FileOutputStream(file); URL url = new URL(durl); InputStream ins = url.openStream(); IOUtils.copy(ins, out); out.close(); ins.close(); if (!exists) { callSvn("add", file.getAbsolutePath()); svnCommitMessage.append("Added: " + dirName + "/" + file.getName() + "\n"); } else { svnCommitMessage.append("Modified: " + dirName + "/" + file.getName() + "\n"); } } catch (Exception e) { e.printStackTrace(); } el = DOMUtils.getNextElement(el); } }
From source file:org.apache.cxf.cwiki.SiteExporter.java
public void loadPages() throws Exception { Document doc = DOMUtils.newDocument(); Element el = doc.createElementNS(SOAPNS, "ns1:getPages"); Element el2 = doc.createElement("in0"); el.appendChild(el2);// w w w.jav a 2 s . c o m el2.setTextContent(loginToken); el2 = doc.createElement("in1"); el.appendChild(el2); el2.setTextContent(spaceKey); doc.appendChild(el); doc = getDispatch().invoke(doc); Set<String> allPages = new CopyOnWriteArraySet<String>(pages.keySet()); Set<Page> newPages = new CopyOnWriteArraySet<Page>(); List<Future<?>> futures = new ArrayList<Future<?>>(allPages.size()); // XMLUtils.printDOM(doc.getDocumentElement()); Node nd = doc.getDocumentElement().getFirstChild().getFirstChild(); while (nd != null) { if (nd instanceof Element) { futures.add(loadPage((Element) nd, allPages, newPages)); } nd = nd.getNextSibling(); } for (Future<?> f : futures) { //wait for all the pages to be done f.get(); } for (Page p : newPages) { //pages have been added, need to check checkForChildren(p); } for (String id : allPages) { //these pages have been deleted Page p = pages.remove(id); checkForChildren(p); File file = new File(outputDir, p.createFileName()); if (file.exists()) { callSvn("rm", file.getAbsolutePath()); svnCommitMessage.append("Deleted: " + file.getName() + "\n"); } if (file.exists()) { file.delete(); } } while (checkIncludes()) { // nothing } }
From source file:com.bluexml.xforms.controller.navigation.NavigationManager.java
/** * @param req/*w w w.j av a 2s . c om*/ * @param sessionId * @param pageId * @param statusDisplayedMsg * @param currentPage * @return * @throws IOException * @throws ServletException * @throws DOMException */ private Document loadXFormsDocument(HttpServletRequest req, String sessionId, String pageId, String statusDisplayedMsg, Page currentPage) throws IOException, ServletException, DOMException { String xformsString; String dataType = currentPage.getFormName(); FormTypeEnum formType = currentPage.getFormType(); boolean dataTypeSet = currentPage.isDataTypeSet(); String templateId = currentPage.getTemplate(); String pageLanguage = currentPage.getLanguage(); Map<String, String> initParams = currentPage.getInitParams(); xformsString = getXFormsString(formType, dataType, dataTypeSet, templateId, sessionId, pageId, req.getContextPath(), pageLanguage, initParams, req); Document doc; // try { // doc = org.chiba.xml.dom.DOMUtil.parseString(xformsString, true, false); // } catch (ParserConfigurationException e) { // throw new ServletException(e); // } catch (SAXException e) { // throw new ServletException(e); // } doc = DOMUtil.getDocumentFromString(xformsString); if (doc == null) { throw new RuntimeException("Unable to build the XForms document"); } Element docElt = doc.getDocumentElement(); // add CSS file if one is provided if (StringUtils.trimToNull(controller.getCssUrl()) != null) { Element head = DOMUtil.getChild(docElt, "xhtml:head"); Element css = doc.createElementNS("http://www.w3.org/1999/xhtml", "link"); css.setAttribute("rel", "stylesheet"); css.setAttribute("type", "text/css"); css.setAttribute("href", controller.getCssUrl()); head.appendChild(css); } // hide buttons if applicable if (currentPage.isShowSubmitButtons() == false) { String tagName = MsgId.INT_SUBMIT_BUTTONS_GROUP_ID.getText(); DOMUtil.removeEltInDescentByAttrValue(docElt, "id", tagName); } else { // #1181: individual hiding of submission buttons if (currentPage.isShowCancel() == false) { removeSubmitButton(docElt, MsgId.CAPTION_BUTTON_CANCEL); } if (currentPage.isShowDelete() == false) { removeSubmitButton(docElt, MsgId.CAPTION_BUTTON_DELETE); } if (currentPage.isShowValidate() == false) { removeSubmitButton(docElt, MsgId.CAPTION_BUTTON_SUBMIT); } } // add status message String statusMsg = statusDisplayedMsg; if (statusMsg != null) { String tagVal = MsgId.INT_CSS_STATUS_BAR_ID.getText(); Element status = DOMUtil.getEltInDescentByAttrValue(docElt, "id", tagVal); status.setTextContent(statusMsg); } return doc; }
From source file:com.bluexml.xforms.controller.mapping.MappingToolAlfrescoToForms.java
/** * Initialize a totally empty form instance. No object id is given. //$$ TRACE LOG * // w ww.j av a 2 s . c o m * @param formName * the form name * @param at * the alfresco transaction * @param isMassTagging * whether the instance is for a mass tagging * * @return the document * */ public Document newFormInstance(String formName, AlfrescoTransaction at, Map<String, String> initParams, boolean formIsReadOnly, boolean isMassTagging) { FormType formType = getFormType(formName); if (loggertrace.isTraceEnabled()) { logger.debug("Creating new form instance document for the controller; form: " + formName + ", read-only status: " + formIsReadOnly + ", formType found: " + formType.getName()); } if (formType == null) { throw new RuntimeException("Form '" + formName + "' not found in the mapping file."); } Document formInstance = documentBuilder.newDocument(); Element rootElement = formInstance.createElement("root"); // get the actual form structure Element formElement = newForm(formType, formInstance, at, new HashMap<String, GenericClass>(), initParams, formIsReadOnly, isMassTagging); VirtualResolver virtualResolver = new VirtualResolver(this); virtualResolver.prepareAlfrescoToXForms(formElement, formName); rootElement.appendChild(formElement); Element typeElement = formInstance.createElement(MsgId.INT_INSTANCE_SIDE_DATATYPE.getText()); typeElement.setTextContent(classTypeToString(getClassType(formType.getRealClass()))); rootElement.appendChild(typeElement); formInstance.appendChild(rootElement); return formInstance; }
From source file:com.bluexml.xforms.controller.mapping.MappingToolAlfrescoToForms.java
/** * Adds the section corresponding to a model choice into an XForms instance document. * /*from w w w .ja v a2s . co m*/ * @param formInstance * the XForms instance document being filled * @param modelChoiceReference * the parent node (its tag name is field id) that will receive the section created * here; the parent may end up having several sections (in which case the model * choice is multiple). * @param modelChoice * the description for the model choice in the mapping file * @param id * the id * @param label * the label * @param nodeDataType * the qualified name of the node as returned by Alfresco * @param at * @param an * @param initParams * @param formIsReadOnly * whether the form whose instance is being provided is read only * @param isMassTagging */ private void addModelChoiceItem(Document formInstance, Element modelChoiceReference, ModelChoiceType modelChoice, String id, String label, String nodeDataType, AlfrescoTransaction at, Map<String, GenericClass> an, Map<String, String> initParams, boolean formIsReadOnly, boolean isMassTagging) { Node subNode = formInstance.createElement(MsgId.INT_INSTANCE_ASSOCIATION_ITEM.getText()); if (isInline(modelChoice)) { Node formNode = null; if (StringUtils.trimToNull(id) == null) { formNode = newForm(getFormType(modelChoice.getTarget().get(0).getName()), formInstance, at, an, initParams, formIsReadOnly, isMassTagging); subNode.appendChild(formNode); } else { try { formNode = getForm(at, getFormType(modelChoice.getTarget().get(0).getName()), id, an, formInstance, initParams, formIsReadOnly); subNode.appendChild(formNode); } catch (ServletException e) { logger.error( "Error getting the instance section for model choice '" + modelChoice.getDisplayLabel() + "' supporting association '" + modelChoice.getAlfrescoName() + "'", e); } } } else { Element eltId = formInstance.createElement(MsgId.INT_INSTANCE_SIDEID.getText()); eltId.setTextContent(id); subNode.appendChild(eltId); Element eltLabel = formInstance.createElement(MsgId.INT_INSTANCE_SIDELABEL.getText()); eltLabel.setTextContent(StringUtils.trimToEmpty(label)); subNode.appendChild(eltLabel); Element eltEdit = formInstance.createElement(MsgId.INT_INSTANCE_SIDEEDIT.getText()); eltEdit.setTextContent(""); subNode.appendChild(eltEdit); // ** #1485 Element eltType = formInstance.createElement(MsgId.INT_INSTANCE_SIDETYPE.getText()); eltType.setTextContent(nodeDataType); subNode.appendChild(eltType); // ** #1485 } modelChoiceReference.appendChild(subNode); }