List of usage examples for org.dom4j Document addElement
Element addElement(String name);
Element
node with the given name to this branch and returns a reference to the new node. From source file:org.infoglue.cms.applications.common.actions.SimpleXmlServiceAction.java
License:Open Source License
public String doContentTypeDefinitions() throws Exception { List contentTypeDefinitions = getContentTypeDefinitions(); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("definitions"); TransactionHistoryController transactionHistoryController = TransactionHistoryController.getController(); for (Iterator i = contentTypeDefinitions.iterator(); i.hasNext();) { ContentTypeDefinitionVO vo = (ContentTypeDefinitionVO) i.next(); if (vo.getType().compareTo(ContentTypeDefinitionVO.CONTENT) == 0) { TransactionHistoryVO transactionHistoryVO = transactionHistoryController .getLatestTransactionHistoryVOForEntity(ContentTypeDefinitionImpl.class, vo.getContentTypeDefinitionId()); Element definition = DocumentHelper.createElement("definition"); definition.addAttribute("id", "" + vo.getContentTypeDefinitionId()) .addAttribute("type", "" + vo.getType()).addAttribute("name", vo.getName()); if (transactionHistoryVO != null) definition.addAttribute("mod", formatDate(transactionHistoryVO.getTransactionDateTime())); Element schemaValue = definition.addElement("schemaValue"); schemaValue.addCDATA(vo.getSchemaValue()); root.add(definition);//from www . j ava 2s .c o m } } return out(getFormattedDocument(doc)); }
From source file:org.infoglue.cms.applications.common.actions.SimpleXmlServiceAction.java
License:Open Source License
public String doExecute() throws Exception { if (useTemplate) return "success"; Timer t = new Timer(); if (!logger.isInfoEnabled()) t.setActive(false);// w ww . ja va 2 s . c o m Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("tree"); INodeSupplier sup; if (repositoryId == null) { List repositories = RepositoryController.getController() .getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), false); for (Iterator i = repositories.iterator(); i.hasNext();) { RepositoryVO r = (RepositoryVO) i.next(); BaseEntityVO entityVO = getRootEntityVO(r.getId(), this.getInfoGluePrincipal()); String src = action + "?repositoryId=" + r.getId() + urlArgSeparator + "parent=" + entityVO.getId(); if (createAction && src.length() > 0) src += urlArgSeparator + "createAction=true"; if (action.length() > 0 && src.length() > 0) src += urlArgSeparator + "action=" + action; String allowedContentTypeIdsUrlEncodedString = getAllowedContentTypeIdsAsUrlEncodedString(); logger.info("allowedContentTypeIdsUrlEncodedString1:" + allowedContentTypeIdsUrlEncodedString); if (allowedContentTypeIdsUrlEncodedString.length() > 0 && src.length() > 0) src += urlArgSeparator + allowedContentTypeIdsUrlEncodedString; logger.info("src:" + src); String text = r.getName(); Element element = root.addElement("tree"); element.addAttribute("id", "" + r.getId()).addAttribute("repositoryId", "" + r.getId()) .addAttribute("text", encode(text)).addAttribute("src", src) .addAttribute("hasChildren", "true").addAttribute("type", TYPE_REPOSITORY); } out(getFormattedDocument(doc)); t.printElapsedTime("End 3"); return null; } sup = getNodeSupplier(); if (parent == null) { BaseNode node = sup.getRootNode(); String text = node.getTitle(); String type = TYPE_FOLDER; String src = action + "?repositoryId=" + repositoryId + urlArgSeparator + "parent=" + node.getId(); if (createAction && src.length() > 0) src += urlArgSeparator + "createAction=true"; if (action.length() > 0 && src.length() > 0) src += urlArgSeparator + "action=" + action; String allowedContentTypeIdsUrlEncodedString = getAllowedContentTypeIdsAsUrlEncodedString(); logger.info("allowedContentTypeIdsUrlEncodedString2:" + allowedContentTypeIdsUrlEncodedString); if (allowedContentTypeIdsUrlEncodedString.length() > 0 && src.length() > 0) src += urlArgSeparator + allowedContentTypeIdsUrlEncodedString; //logger.info("src2:" + src); Element elm = root.addElement("tree"); elm.addAttribute("id", "" + node.getId()).addAttribute("repositoryId", "" + repositoryId) .addAttribute("text", encode(text)).addAttribute("src", src) .addAttribute("isHidden", (String) node.getParameters().get("isHidden")) .addAttribute("hasChildren", "true").addAttribute("type", type); if (node.getParameters().containsKey("contentTypeDefinitionId")) elm.addAttribute("contentTypeDefinitionId", (String) node.getParameters().get("contentTypeDefinitionId")); if (node.getParameters().containsKey("isProtected")) elm.addAttribute("isProtected", (String) node.getParameters().get("isProtected")); if (node.getParameters().containsKey("stateId")) elm.addAttribute("stateId", (String) node.getParameters().get("stateId")); out(getFormattedDocument(doc)); t.printElapsedTime("End 2"); return null; } if (parent.intValue() > -1) { Collection containerNodes = sup.getChildContainerNodes(parent); Collection childNodes = sup.getChildLeafNodes(parent); t.printElapsedTime("1.1"); ContentController contentController = ContentController.getContentController(); ContentVersionController contentVersionController = ContentVersionController .getContentVersionController(); Iterator it = containerNodes.iterator(); while (it.hasNext()) { t.printElapsedTime("1.2"); BaseNode theNode = (BaseNode) it.next(); if (theNode.isContainer() && sup.hasChildren()) { theNode.setChildren(sup.hasChildren(theNode.getId())); } t.printElapsedTime("1.3"); // String src = theNode.hasChildren() ? action + "?repositoryId=" + repositoryId + urlArgSeparator + "parent=" + theNode.getId(): ""; String src = action + "?repositoryId=" + repositoryId + urlArgSeparator + "parent=" + theNode.getId(); if (createAction && src.length() > 0) src += urlArgSeparator + "createAction=true"; if (createAction && src.length() > 0) src += urlArgSeparator + "showLeafs=" + showLeafs; if (action.length() > 0 && src.length() > 0) src += urlArgSeparator + "action=" + action; String allowedContentTypeIdsUrlEncodedString = getAllowedContentTypeIdsAsUrlEncodedString(); if (allowedContentTypeIdsUrlEncodedString.length() > 0 && src.length() > 0) src += urlArgSeparator + allowedContentTypeIdsUrlEncodedString; Element elm = root.addElement("tree"); elm.addAttribute("id", "" + theNode.getId()).addAttribute("parent", "" + parent) .addAttribute("repositoryId", "" + repositoryId) .addAttribute("text", encode(theNode.getTitle())).addAttribute("src", src) .addAttribute("isHidden", (String) theNode.getParameters().get("isHidden")) .addAttribute("type", TYPE_FOLDER).addAttribute("hasChildren", "" + theNode.hasChildren()); if (theNode.getParameters().containsKey("contentTypeDefinitionId")) elm.addAttribute("contentTypeDefinitionId", "" + theNode.getParameters().get("contentTypeDefinitionId")); if (theNode.getParameters().containsKey("isProtected")) elm.addAttribute("isProtected", (String) theNode.getParameters().get("isProtected")); if (theNode.getParameters().containsKey("stateId")) elm.addAttribute("stateId", (String) theNode.getParameters().get("stateId")); if (createAction) elm.addAttribute("action", makeAction(theNode)); } it = childNodes.iterator(); while (it.hasNext()) { BaseNode theNode = (BaseNode) it.next(); String text = theNode.getTitle(); String action = makeAction(theNode); String type = TYPE_ITEM; Element elm = root.addElement("tree"); elm.addAttribute("id", "" + theNode.getId()).addAttribute("parent", "" + parent) .addAttribute("repositoryId", "" + repositoryId).addAttribute("text", encode(text)) .addAttribute("type", type); if (theNode.getParameters().containsKey("contentTypeDefinitionId")) elm.addAttribute("contentTypeDefinitionId", "" + theNode.getParameters().get("contentTypeDefinitionId")); if (theNode.getParameters().containsKey("isProtected")) elm.addAttribute("isProtected", (String) theNode.getParameters().get("isProtected")); if (theNode.getParameters().containsKey("stateId")) elm.addAttribute("stateId", (String) theNode.getParameters().get("stateId")); if (createAction) elm.addAttribute("action", action); else { ContentVersionVO activeVersion = contentVersionController.getLatestActiveContentVersionVO( theNode.getId(), LanguageController.getController().getMasterLanguage(repositoryId).getLanguageId()); if (activeVersion != null && !useTemplate) { elm.addAttribute("activeVersion", "" + activeVersion.getContentVersionId()); elm.addAttribute("activeVersionStateId", "" + activeVersion.getStateId()); elm.addAttribute("activeVersionModifier", "" + activeVersion.getVersionModifier()); } } t.printElapsedTime("1.4"); //TODO - this was a quickfix only if (!useTemplate && sup.getClass().getName().indexOf("Content") > -1) { if (theNode.getParameters().containsKey("contentTypeDefinitionId")) elm.addAttribute("contentTypeId", "" + theNode.getParameters().get("contentTypeDefinitionId")); else { try { ContentTypeDefinitionVO contentTypeDefinitionVO = contentController .getContentTypeDefinition(theNode.getId()); if (contentTypeDefinitionVO != null) elm.addAttribute("contentTypeId", "" + contentTypeDefinitionVO.getContentTypeDefinitionId()); } catch (Exception e) { logger.error("The content " + theNode.getTitle() + " (" + theNode.getId() + " ) points to a removed content type perhaps: " + e.getMessage()); } } t.printElapsedTime("1.5"); } } t.printElapsedTime("1.6"); out(getFormattedDocument(doc)); t.printElapsedTime("End 1"); return null; } return null; }
From source file:org.infoglue.cms.applications.contenttool.actions.ContentTreeXMLAction.java
License:Open Source License
public String doContentVersions() throws Exception { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("contentVersions"); Collection availableLanguages = ContentController.getContentController().getRepositoryLanguages(parent); for (Iterator i = availableLanguages.iterator(); i.hasNext();) { LanguageVO lvo = (LanguageVO) i.next(); ContentVersionVO vo = getLatestContentVersionVO(parent, lvo.getLanguageId()); if (vo != null) root.add(getContentVersionElement(vo)); }// w ww . j a va2s . c om ContentVersionController contentVersionController = ContentVersionController.getContentVersionController(); return out(getFormattedDocument(doc)); }
From source file:org.infoglue.cms.applications.contenttool.actions.ContentTreeXMLAction.java
License:Open Source License
public String doContentTypeDefinitions() throws Exception { List contentTypeDefinitions = getContentTypeDefinitions(); Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("definitions"); TransactionHistoryController transactionHistoryController = TransactionHistoryController.getController(); for (Iterator i = contentTypeDefinitions.iterator(); i.hasNext();) { ContentTypeDefinitionVO vo = (ContentTypeDefinitionVO) i.next(); if (vo.getType().compareTo(ContentTypeDefinitionVO.CONTENT) == 0) { TransactionHistoryVO transactionHistoryVO = transactionHistoryController .getLatestTransactionHistoryVOForEntity(ContentTypeDefinitionImpl.class, vo.getContentTypeDefinitionId()); Element definition = DocumentHelper.createElement("definition"); definition.addAttribute("id", "" + vo.getContentTypeDefinitionId()) .addAttribute("type", "" + vo.getType()).addAttribute("name", vo.getName()); if (transactionHistoryVO != null) definition.addAttribute("mod", formatDate(transactionHistoryVO.getTransactionDateTime())); Element schemaValue = definition.addElement("schemaValue"); schemaValue.addCDATA(vo.getSchemaValue()); root.add(definition);/*from w w w.ja v a 2s . c o m*/ } } return out(getFormattedDocument(doc)); }
From source file:org.infoglue.cms.applications.contenttool.actions.ContentTreeXMLAction.java
License:Open Source License
public String doExecute() throws Exception { if (useTemplate) return "success"; Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("tree"); INodeSupplier sup;/*from w w w . ja v a 2 s .co m*/ // VisualFormatter vf = new VisualFormatter(); // TransactionHistoryController transactionHistoryController = TransactionHistoryController.getController(); if (repositoryId == null) { List repositories = RepositoryController.getController() .getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), false); for (Iterator i = repositories.iterator(); i.hasNext();) { RepositoryVO r = (RepositoryVO) i.next(); ContentVO contentVO = ContentControllerProxy.getController().getRootContentVO(r.getId(), this.getInfoGluePrincipal().getName()); String src = action + "?repositoryId=" + r.getId() + urlArgSeparator + "parent=" + contentVO.getId(); if (createAction && src.length() > 0) src += urlArgSeparator + "createAction=true"; if (action.length() > 0 && src.length() > 0) src += urlArgSeparator + "action=" + action; String allowedContentTypeIdsUrlEncodedString = getAllowedContentTypeIdsAsUrlEncodedString(); if (allowedContentTypeIdsUrlEncodedString.length() > 0 && src.length() > 0) src += urlArgSeparator + allowedContentTypeIdsUrlEncodedString; String text = r.getName(); Element element = root.addElement("tree"); element.addAttribute("id", "" + r.getId()).addAttribute("repositoryId", "" + r.getId()) .addAttribute("text", text).addAttribute("src", src).addAttribute("type", TYPE_REPOSITORY); } out(getFormattedDocument(doc)); return null; } sup = getNodeSupplier(); ((ContentNodeSupplier) sup).setShowLeafs(showLeafs.compareTo("yes") == 0); ((ContentNodeSupplier) sup).setAllowedContentTypeIds(allowedContentTypeIds); if (parent == null) { BaseNode node = sup.getRootNode(); String text = node.getTitle(); String type = TYPE_FOLDER; String src = action + "?repositoryId=" + repositoryId + urlArgSeparator + "parent=" + node.getId(); if (createAction && src.length() > 0) src += urlArgSeparator + "createAction=true"; if (action.length() > 0 && src.length() > 0) src += urlArgSeparator + "action=" + action; String allowedContentTypeIdsUrlEncodedString = getAllowedContentTypeIdsAsUrlEncodedString(); if (allowedContentTypeIdsUrlEncodedString.length() > 0 && src.length() > 0) src += urlArgSeparator + allowedContentTypeIdsUrlEncodedString; Element elm = root.addElement("tree"); elm.addAttribute("id", "" + node.getId()).addAttribute("repositoryId", "" + repositoryId) .addAttribute("text", text).addAttribute("src", src).addAttribute("type", type); out(getFormattedDocument(doc)); return null; } if (parent.intValue() > -1) { Collection containerNodes = sup.getChildContainerNodes(parent); Collection childNodes = sup.getChildLeafNodes(parent); ContentController contentController = ContentController.getContentController(); ContentVersionController contentVersionController = ContentVersionController .getContentVersionController(); Iterator it = containerNodes.iterator(); while (it.hasNext()) { BaseNode theNode = (BaseNode) it.next(); if (theNode.isContainer() && sup.hasChildren()) { theNode.setChildren(sup.hasChildren(theNode.getId())); } String src = theNode.hasChildren() ? action + "?repositoryId=" + repositoryId + urlArgSeparator + "parent=" + theNode.getId() : ""; if (createAction && src.length() > 0) src += urlArgSeparator + "createAction=true"; if (createAction && src.length() > 0) src += urlArgSeparator + "showLeafs=" + showLeafs; if (action.length() > 0 && src.length() > 0) src += urlArgSeparator + "action=" + action; String allowedContentTypeIdsUrlEncodedString = getAllowedContentTypeIdsAsUrlEncodedString(); if (allowedContentTypeIdsUrlEncodedString.length() > 0 && src.length() > 0) src += urlArgSeparator + allowedContentTypeIdsUrlEncodedString; Element elm = root.addElement("tree"); elm.addAttribute("id", "" + theNode.getId()).addAttribute("parent", "" + parent) .addAttribute("repositoryId", "" + repositoryId).addAttribute("text", theNode.getTitle()) .addAttribute("src", src).addAttribute("type", TYPE_FOLDER); if (createAction) elm.addAttribute("action", makeAction(theNode)); } it = childNodes.iterator(); while (it.hasNext()) { BaseNode theNode = (BaseNode) it.next(); String text = theNode.getTitle(); String action = makeAction(theNode); String type = TYPE_ITEM; Element elm = root.addElement("tree"); elm.addAttribute("id", "" + theNode.getId()).addAttribute("parent", "" + parent) .addAttribute("repositoryId", "" + repositoryId).addAttribute("text", text) .addAttribute("type", type); if (createAction) elm.addAttribute("action", action); else { ContentVersionVO activeVersion = contentVersionController.getLatestActiveContentVersionVO( theNode.getId(), LanguageController.getController().getMasterLanguage(repositoryId).getLanguageId()); if (activeVersion != null && !useTemplate) elm.addAttribute("activeVersion", "" + activeVersion.getContentVersionId()); } if (!useTemplate) elm.addAttribute("contentTypeId", "" + contentController .getContentTypeDefinition(theNode.getId()).getContentTypeDefinitionId()); } out(getFormattedDocument(doc)); return null; } return null; }
From source file:org.infoglue.cms.util.dom.DOMBuilder.java
License:Open Source License
/** * This method adds an element with a given name to a given document. *///from w w w .j a v a2s.c o m public Element addElement(Document document, String elementName) { Element newElement = document.addElement(elementName); return newElement; }
From source file:org.jasig.portal.io.xml.dlm.FragmentDefinitionExporter.java
License:Apache License
@Override protected Element exportDataElement(String id) { final FragmentDefinition fragmentDefinition = fragmentDefinitionDao.getFragmentDefinition(id); if (fragmentDefinition == null) { return null; }/*from w w w . j ava 2 s . co m*/ final org.dom4j.Document fragmentDefDoc = new org.dom4j.DocumentFactory().createDocument(); final Element fragmentDefElement = fragmentDefDoc.addElement("fragment-definition"); fragmentDefElement.addNamespace("dlm", "http://www.uportal.org/layout/dlm"); fragmentDefElement.addAttribute("script", "classpath://org/jasig/portal/io/import-fragment-definition_v3-1.crn"); fragmentDefinition.toElement(fragmentDefElement); return fragmentDefElement; }
From source file:org.jboss.as.ee.deployment.spi.DeploymentMetaData.java
License:Open Source License
public Document getDocument() { Document document = DocumentHelper.createDocument(); Element root = document.addElement("jboss-deployment-plan"); root.addElement("deployment-name").addText(deploymentName); root.addComment("Note, deployment-entry elements are not used by the DeploymentManager"); root.addComment("The DeploymentManager relies on the the entry naming convention"); Iterator it = entryList.iterator(); while (it.hasNext()) { Entry entry = (Entry) it.next(); Element element = root.addElement("deployment-entry"); element.addElement("archive-name").addText(entry.archiveName); element.addElement("descriptor-name").addText(entry.descriptorName); }// w w w. jav a 2 s . c o m return document; }
From source file:org.jboss.deployment.spi.DeploymentMetaData.java
License:Open Source License
public Document getDocument() { Document document = DocumentHelper.createDocument(); Element root = document.addElement("jboss-deployment-plan"); root.addElement("deployment-name").addText(deploymentName); root.addComment("Note, deployment-entry elements are not used by the DeploymentManager"); root.addComment("The DeploymentManager relies on the the entry nameing convention"); Iterator it = entryList.iterator(); while (it.hasNext()) { Entry entry = (Entry) it.next(); Element element = root.addElement("deployment-entry"); element.addElement("archive-name").addText(entry.archiveName); element.addElement("descriptor-name").addText(entry.descriptorName); }//from w ww. jav a2s . c o m return document; }
From source file:org.jbpm.gd.common.editor.AbstractContentProvider.java
License:Open Source License
protected void write(RootContainer rootContainer, Writer writer) { try {//www . j av a2 s. com Document document = DocumentHelper.createDocument(); Element root = document.addElement("root-container"); write(rootContainer, root); XMLWriter xmlWriter = new XMLWriter(writer, OutputFormat.createPrettyPrint()); xmlWriter.write(document); } catch (IOException e) { e.printStackTrace(new PrintWriter(writer)); } }