List of usage examples for org.dom4j Namespace Namespace
public Namespace(String prefix, String uri)
From source file:org.etudes.jforum.view.admin.ImportExportAction.java
License:Apache License
/** * creates the LOM metadata element/*from ww w . j a v a2s .c o m*/ * * @param elename * - element name * @param qname * - qualified name * @return - returns the metadata element */ private Element createLOMElement(String elename, String qname) { Element imsmdlom = DocumentHelper.createElement(elename); imsmdlom.setQName(new QName(qname, new Namespace("imsmd", IMSMD_NAMESPACE_URI))); return imsmdlom; }
From source file:org.intalio.tempo.workflow.fds.dispatches.EscalateDispatcher.java
License:Open Source License
public Document dispatchRequest(Document request) throws InvalidInputFormatException { Namespace ns = new Namespace(NS_PREFIX, NS_URI); Element rootElement = request.getRootElement(); userProcessNamespace = rootElement.getNamespaceURI(); userProcessPrefix = rootElement.getNamespacePrefix(); List nodes = DocumentHelper.createXPath("//*").selectNodes(request); for (int i = 0; i < nodes.size(); ++i) { Element element = (Element) nodes.get(i); element.remove(element.getNamespaceForURI(userProcessNamespace)); element.setQName(new QName(element.getName(), ns)); }//from www . j a va 2 s .c o m rootElement.setQName(new QName("escalateTaskRequest", ns)); // TODO: fix this in VC! return request; }
From source file:org.intalio.tempo.workflow.fds.dispatches.EscalateDispatcher.java
License:Open Source License
public Document dispatchResponse(Document response) throws InvalidInputFormatException { // TODO: process the TMP response Namespace ns = new Namespace(userProcessPrefix, userProcessNamespace); response.getRootElement().setName("escalateResponse"); List nodes = DocumentHelper.createXPath("//*").selectNodes(response); for (int i = 0; i < nodes.size(); ++i) { Element element = (Element) nodes.get(i); element.remove(element.getNamespaceForURI(NS_URI)); element.setQName(new QName(element.getName(), ns)); }/*from www .ja v a 2s. c o m*/ return response; }
From source file:org.intalio.tempo.workflow.fds.dispatches.NotifyDispatcher.java
License:Open Source License
public Document dispatchRequest(Document request) throws InvalidInputFormatException { Element rootElement = request.getRootElement(); userProcessNamespace = rootElement.getNamespaceURI(); Namespace ns = new Namespace("tms", TMS_NS); rootElement.setQName(new QName("createTaskRequest", ns)); Element metadataElement = rootElement.element("metadata"); metadataElement.setQName(new QName("metadata", ns)); metadataElement.detach();// ww w .jav a 2 s . co m Element taskElement = rootElement.addElement("task"); taskElement.setQName(new QName("task", ns)); taskElement.add(metadataElement); if (metadataElement.selectSingleNode("taskId") == null) { Element taskIdElement = metadataElement.addElement(new QName("taskId", ns)); taskIdElement.setText(generateUID()); } if (metadataElement.selectSingleNode("taskType") == null) { Element taskTypeElement = metadataElement.addElement(new QName("taskType", ns)); taskTypeElement.setText("NOTIFICATION"); } Element inputElement = rootElement.element("input"); inputElement.setQName(new QName("input", ns)); //inputElement.addNamespace("fe", userProcessNamespace); inputElement.detach(); taskElement.add(inputElement); //TODO remove from TMS. Not needed rootElement.addElement("participantToken"); /* * Now, change the namespace the * input, to TMS_NS. */ XPath xpath = DocumentHelper.createXPath("/tms:createTaskRequest/tms:task/tms:input//*"); HashMap map = MessageConstants._nsMap; map.put("tms", TMS_NS); xpath.setNamespaceURIs(MessageConstants._nsMap); List allTaskInputElements = xpath.selectNodes(request); xpath = DocumentHelper.createXPath("//*"); List allBody = xpath.selectNodes(request); int size = allBody.size(); LOG.debug(allTaskInputElements.size() + ":" + size); for (int i = 0; i < size; ++i) { Node node = (Node) allBody.get(i); if (!allTaskInputElements.contains(node)) { Element element = (Element) node; element.remove(element.getNamespaceForURI(userProcessNamespace)); element.setQName(new QName(element.getName(), ns)); } } return request; }
From source file:org.jasig.portal.layout.dlm.RDBMDistributedLayoutStore.java
License:Apache License
@Override @SuppressWarnings("unchecked") @Transactional//from w ww .jav a 2s. co m public void importLayout(org.dom4j.Element layout) { if (layout.getNamespaceForPrefix("dlm") == null) { layout.add(new Namespace("dlm", "http://www.uportal.org/layout/dlm")); } //Remove comments from the DOM they break import final List<org.dom4j.Node> comments = layout.selectNodes("//comment()"); for (final org.dom4j.Node comment : comments) { comment.detach(); } //Get a ref to the prefs element and then remove it from the layout final org.dom4j.Node preferencesElement = layout.selectSingleNode("preferences"); if (preferencesElement != null) { preferencesElement.getParent().remove(preferencesElement); } final String ownerUsername = layout.valueOf("@username"); //Get a ref to the profile element and then remove it from the layout final org.dom4j.Node profileElement = layout.selectSingleNode("profile"); if (profileElement != null) { profileElement.getParent().remove(profileElement); final org.dom4j.Document profileDocument = new org.dom4j.DocumentFactory().createDocument(); profileDocument.setRootElement((org.dom4j.Element) profileElement); profileDocument.setName(ownerUsername + ".profile"); final DocumentSource profileSource = new DocumentSource(profileElement); this.portalDataHandlerService.importData(profileSource); } final IPerson person = new PersonImpl(); person.setUserName(ownerUsername); int ownerId; try { //Can't just pass true for create here, if the user actually exists the create flag also updates the user data ownerId = this.userIdentityStore.getPortalUID(person); } catch (final AuthorizationException t) { if (this.errorOnMissingUser) { throw new RuntimeException("Unrecognized user " + person.getUserName() + "; you must import users before their layouts or set org.jasig.portal.io.layout.errorOnMissingUser to false.", t); } //Create the missing user ownerId = this.userIdentityStore.getPortalUID(person, true); } if (ownerId == -1) { throw new RuntimeException("Unrecognized user " + person.getUserName() + "; you must import users before their layouts or set org.jasig.portal.io.layout.errorOnMissingUser to false."); } person.setID(ownerId); IUserProfile profile = null; try { person.setSecurityContext(new BrokenSecurityContext()); profile = this.getUserProfileByFname(person, "default"); } catch (final Throwable t) { throw new RuntimeException("Failed to load profile for " + person.getUserName() + "; This user must have a profile for import to continue.", t); } // (6) Add database Ids & (5) Add dlm:plfID ... int nextId = 1; for (final Iterator<org.dom4j.Element> it = (Iterator<org.dom4j.Element>) layout .selectNodes("folder | dlm:* | channel").iterator(); it.hasNext();) { nextId = this.addIdAttributesIfNecessary(it.next(), nextId); } // Now update UP_USER... this.jdbcOperations.update("UPDATE up_user SET next_struct_id = ? WHERE user_id = ?", nextId, person.getID()); // (4) Convert external DLM pathrefs to internal form (noderefs)... for (final Iterator<org.dom4j.Attribute> itr = (Iterator<org.dom4j.Attribute>) layout .selectNodes("//@dlm:origin").iterator(); itr.hasNext();) { final org.dom4j.Attribute a = itr.next(); final Noderef dlmNoderef = nodeReferenceFactory.getNoderefFromPathref(ownerUsername, a.getValue(), null, true, layout); if (dlmNoderef != null) { // Change the value only if we have a valid pathref... a.setValue(dlmNoderef.toString()); // For dlm:origin only, also use the noderef as the ID attribute... a.getParent().addAttribute("ID", dlmNoderef.toString()); } else { // At least insure the value is between 1 and 35 characters a.setValue(BAD_PATHREF_MESSAGE); } } for (final Iterator<org.dom4j.Attribute> itr = (Iterator<org.dom4j.Attribute>) layout .selectNodes("//@dlm:target").iterator(); itr.hasNext();) { final org.dom4j.Attribute a = itr.next(); final Noderef dlmNoderef = nodeReferenceFactory.getNoderefFromPathref(ownerUsername, a.getValue(), null, true, layout); // Put in the correct value, or at least insure the value is between 1 and 35 characters a.setValue(dlmNoderef != null ? dlmNoderef.toString() : BAD_PATHREF_MESSAGE); } for (final Iterator<org.dom4j.Attribute> names = (Iterator<org.dom4j.Attribute>) layout .selectNodes("//dlm:*/@name").iterator(); names.hasNext();) { final org.dom4j.Attribute a = names.next(); final String value = a.getValue().trim(); if (!VALID_PATHREF_PATTERN.matcher(value).matches()) { /* Don't send it to getDlmNoderef if we know in advance it's not * going to work; saves annoying/misleading log messages and * possibly some processing. NOTE this is _only_ a problem with * the name attribute of some dlm:* elements, which seems to go * unused intentionally in some circumstances */ continue; } final org.dom4j.Attribute fname = a.getParent().attribute("fname"); Noderef dlmNoderef = null; if (fname != null) { dlmNoderef = nodeReferenceFactory.getNoderefFromPathref(ownerUsername, value, fname.getValue(), false, layout); // Remove the fname attribute now that we're done w/ it... fname.getParent().remove(fname); } else { dlmNoderef = nodeReferenceFactory.getNoderefFromPathref(ownerUsername, value, null, true, layout); } // Put in the correct value, or at least insure the value is between 1 and 35 characters a.setValue(dlmNoderef != null ? dlmNoderef.toString() : BAD_PATHREF_MESSAGE); } // (3) Restore chanID attributes on <channel> elements... for (final Iterator<org.dom4j.Element> it = (Iterator<org.dom4j.Element>) layout.selectNodes("//channel") .iterator(); it.hasNext();) { final org.dom4j.Element c = it.next(); final String fname = c.valueOf("@fname"); final IPortletDefinition cd = this.portletDefinitionRegistry.getPortletDefinitionByFname(fname); if (cd == null) { final String msg = "No portlet with fname=" + fname + " exists referenced by node " + c.valueOf("@ID") + " from layout for " + ownerUsername; if (errorOnMissingPortlet) { throw new IllegalArgumentException(msg); } else { logger.warn(msg); //Remove the bad channel node c.getParent().remove(c); } } else { c.addAttribute("chanID", String.valueOf(cd.getPortletDefinitionId().getStringId())); } } // (2) Restore locale info... // (This step doesn't appear to be needed for imports) // (1) Process structure & theme attributes... Document layoutDom = null; try { final int structureStylesheetId = profile.getStructureStylesheetId(); this.loadStylesheetUserPreferencesAttributes(person, profile, layout, structureStylesheetId, "structure"); final int themeStylesheetId = profile.getThemeStylesheetId(); this.loadStylesheetUserPreferencesAttributes(person, profile, layout, themeStylesheetId, "theme"); // From this point forward we need the user's PLF set as DLM expects it... for (final Iterator<org.dom4j.Text> it = (Iterator<org.dom4j.Text>) layout .selectNodes("descendant::text()").iterator(); it.hasNext();) { // How many years have we used Java & XML, and this still isn't easy? final org.dom4j.Text txt = it.next(); if (txt.getText().trim().length() == 0) { txt.getParent().remove(txt); } } final org.dom4j.Element copy = layout.createCopy(); final org.dom4j.Document doc = this.fac.createDocument(copy); doc.normalize(); layoutDom = this.writer.get().write(doc); person.setAttribute(Constants.PLF, layoutDom); } catch (final Throwable t) { throw new RuntimeException("Unable to set UserPreferences for user: " + person.getUserName(), t); } // Finally store the layout... try { this.setUserLayout(person, profile, layoutDom, true, true); } catch (final Throwable t) { final String msg = "Unable to persist layout for user: " + ownerUsername; throw new RuntimeException(msg, t); } if (preferencesElement != null) { final int ownerUserId = this.userIdentityStore.getPortalUserId(ownerUsername); //TODO this assumes a single layout, when multi-layout support exists portlet entities will need to be re-worked to allow for a layout id to be associated with the entity //track which entities from the user's pre-existing set are touched (all non-touched entities will be removed) final Set<IPortletEntity> oldPortletEntities = new LinkedHashSet<IPortletEntity>( this.portletEntityDao.getPortletEntitiesForUser(ownerUserId)); final List<org.dom4j.Element> entries = preferencesElement.selectNodes("entry"); for (final org.dom4j.Element entry : entries) { final String dlmPathRef = entry.attributeValue("entity"); final String fname = entry.attributeValue("channel"); final String prefName = entry.attributeValue("name"); final Noderef dlmNoderef = nodeReferenceFactory.getNoderefFromPathref(person.getUserName(), dlmPathRef, fname, false, layout); if (dlmNoderef != null && fname != null) { final IPortletEntity portletEntity = this.getPortletEntity(fname, dlmNoderef.toString(), ownerUserId); oldPortletEntities.remove(portletEntity); final List<IPortletPreference> portletPreferences = portletEntity.getPortletPreferences(); final List<org.dom4j.Element> valueElements = entry.selectNodes("value"); final List<String> values = new ArrayList<String>(valueElements.size()); for (final org.dom4j.Element valueElement : valueElements) { values.add(valueElement.getText()); } portletPreferences.add( new PortletPreferenceImpl(prefName, false, values.toArray(new String[values.size()]))); this.portletEntityDao.updatePortletEntity(portletEntity); } } //Delete all portlet preferences for entities that were not imported for (final IPortletEntity portletEntity : oldPortletEntities) { portletEntity.setPortletPreferences(null); if (portletEntityRegistry.shouldBePersisted(portletEntity)) { this.portletEntityDao.updatePortletEntity(portletEntity); } else { this.portletEntityDao.deletePortletEntity(portletEntity); } } } }
From source file:org.jboss.tools.jbpm.convert.bpmnto.util.DomXmlWriter.java
License:Open Source License
public static Document createDomTree(boolean useNamespace, String url, String rootElementName) { Document document = DocumentHelper.createDocument(); Element root = null;//from w ww . j a va 2s . c o m if (useNamespace) { Namespace jbpmNamespace = new Namespace(null, url); root = document.addElement(rootElementName, jbpmNamespace.getURI()); } else { root = document.addElement(rootElementName); } root.addText(System.getProperty("line.separator")); return document; }
From source file:org.jinglenodes.credit.ChargeServiceProcessor.java
License:Open Source License
public ChargeServiceProcessor(final String elementName, final String xmlns) { this.xmlns = xmlns; this.requestElement = DocumentHelper.createElement(new QName(elementName, new Namespace("", xmlns))); }
From source file:org.jinglenodes.credit.CreditServiceProcessor.java
License:Open Source License
public CreditServiceProcessor(final String elementName, final String xmlns) { this.xmlns = xmlns; this.requestElement = DocumentHelper.createElement(new QName(elementName, new Namespace("", xmlns))); }
From source file:org.jinglenodes.relay.RelayEventIQ.java
License:Open Source License
public Element getChildElement() { final Element element = DocumentHelper.createElement(new QName(ELEMENT_NAME, new Namespace("", NAMESPACE))); if (event != null) { element.addAttribute("event", event); }//w ww . j a va2s. c om if (event != null) { element.addAttribute("time", event); } if (channelId != null) { element.addAttribute("id", channelId); } return element; }
From source file:org.jinglenodes.relay.RelayIQ.java
License:Open Source License
public Element getChildElement() { final Element element = DocumentHelper.createElement(new QName(ELEMENT_NAME, new Namespace("", NAMESPACE))); if (host != null) { element.addAttribute("host", host); }/*from w w w . j av a2 s. c om*/ element.addAttribute("localport", localport); element.addAttribute("remoteport", remoteport); if (channelId != null) { element.addAttribute("id", channelId); } if (protocol != null) { element.addAttribute("protocol", protocol); } return element; }