List of usage examples for org.dom4j DocumentHelper createElement
public static Element createElement(String name)
From source file:org.onesocialweb.openfire.registration.handler.IQRegisterHandler.java
License:Open Source License
public void initialize(XMPPServer server) { super.initialize(server); userManager = server.getUserManager(); rosterManager = server.getRosterManager(); if (probeResult == null) { // Create the basic element of the probeResult which contains the basic registration // information (e.g. username, passoword and email) probeResult = DocumentHelper.createElement(QName.get("query", "jabber:iq:register")); probeResult.addElement("username"); probeResult.addElement("password"); probeResult.addElement("email"); probeResult.addElement("name"); probeResult.addElement("code"); // Create the registration form to include in the probeResult. The form will include // the basic information plus name and visibility of name and email. // TODO Future versions could allow plugin modules to add new fields to the form XDataFormImpl registrationForm = new XDataFormImpl(DataForm.TYPE_FORM); registrationForm.setTitle("XMPP Client Registration"); registrationForm.addInstruction("Please provide the following information"); XFormFieldImpl field = new XFormFieldImpl("FORM_TYPE"); field.setType(FormField.TYPE_HIDDEN); field.addValue("jabber:iq:register"); registrationForm.addField(field); field = new XFormFieldImpl("username"); field.setType(FormField.TYPE_TEXT_SINGLE); field.setLabel("Username"); field.setRequired(true);/* w ww .j av a 2 s . com*/ registrationForm.addField(field); field = new XFormFieldImpl("name"); field.setType(FormField.TYPE_TEXT_SINGLE); field.setLabel("Full name"); if (UserManager.getUserProvider().isNameRequired()) { field.setRequired(true); } registrationForm.addField(field); field = new XFormFieldImpl("email"); field.setType(FormField.TYPE_TEXT_SINGLE); field.setLabel("Email"); if (UserManager.getUserProvider().isEmailRequired()) { field.setRequired(true); } registrationForm.addField(field); field = new XFormFieldImpl("password"); field.setType(FormField.TYPE_TEXT_PRIVATE); field.setLabel("Password"); field.setRequired(true); registrationForm.addField(field); field = new XFormFieldImpl("code"); field.setType(FormField.TYPE_TEXT_SINGLE); field.setLabel("Invite Code"); field.setRequired(true); registrationForm.addField(field); // Add the registration form to the probe result. probeResult.add(registrationForm.asXMLElement()); } // See if in-band registration should be enabled (default is true). registrationEnabled = JiveGlobals.getBooleanProperty("register.inband", true); // See if users can change their passwords (default is true). canChangePassword = JiveGlobals.getBooleanProperty("register.password", true); }
From source file:org.openadaptor.auxil.convertor.map.Dom4JDocumentMapFacadeTestCase.java
License:Open Source License
private Element generateTestBook(String bookTitle, String bookLanguage, String bookPrice) { Element book = DocumentHelper.createElement("book"); Element price = DocumentHelper.createElement("price"); Element title = DocumentHelper.createElement("title"); title.setText(bookTitle);//from ww w. j a v a2s . c o m if (bookLanguage != null) { title.addAttribute("lang", bookLanguage); } if (bookPrice != null) { price.setText(bookPrice); } book.add(title); book.add(price); return book; }
From source file:org.openadaptor.auxil.processor.map.AttributeMapProcessorTestCase.java
License:Open Source License
private Document buildXmlDocument(String root) { Document doc = DocumentHelper.createDocument(); Element rootElement = DocumentHelper.createElement(root); doc.setRootElement(rootElement);//from ww w . ja v a 2 s. co m rootElement.add(createElement(KEY_ONE, VALUE_ONE)); rootElement.add(createElement(KEY_TWO, VALUE_TWO)); rootElement.add(createElement(KEY_ONE, "AnotherValue")); Element l1 = createElement(KEY_L_1, VAL_L_1); l1.add(createElement(KEY_L_2_1, VAL_L_2_1)); l1.add(createElement(KEY_L_2_2, VAL_L_2_2)); rootElement.add(l1); return doc; }
From source file:org.openadaptor.auxil.processor.map.AttributeMapProcessorTestCase.java
License:Open Source License
private Element createElement(String name, String value) { Element element = DocumentHelper.createElement(name); element.setText(value); return element; }
From source file:org.openadaptor.util.XmlUtils.java
License:Open Source License
public static org.dom4j.Node create(String xpath, org.dom4j.Document document) { org.dom4j.Node result = null; LocationPath lp = getLocationPath(xpath); if (lp != null) { List steps = lp.getSteps(); Step lastStep = removeLeaf(steps); String parentXpath = toXPath(steps, lp.isAbsolute()); //log.debug("Parent XPath: "+parentXpath); org.dom4j.Node parent = document.selectSingleNode(parentXpath); if (parent == null) { //log.debug("Parent does not exist, need to recursively create "); parent = create(parentXpath, document); }/* w ww . j av a 2s. co m*/ if (parent == null) { //Have to give up. throw new RuntimeException("Failed to create node for xpath: " + xpath); } else { //log.debug("Parent exists. Now need to add the last bit:" +lastStep.getText()); //log.debug("Axis is: "+Axis.lookup(lastStep.getAxis())); String txt = lastStep.getText(); String name = txt.substring(txt.indexOf("::") + "::".length()); //+1 since "::" is two chars long. if (parent instanceof Element) { Element parentElement = (Element) parent; switch (lastStep.getAxis()) { case Axis.ATTRIBUTE: Attribute newAttribute = DocumentHelper.createAttribute(null, name, ""); parentElement.add(newAttribute); result = newAttribute; break; default: Element element = DocumentHelper.createElement(name); parentElement.add(element); result = element; break; } } else { throw new RuntimeException("Cannot create child of non-Element parent. XPath was: " + xpath); } } } else { throw new RuntimeException("Failed to resolve XPath String: " + xpath); } return result; }
From source file:org.opencms.configuration.preferences.A_CmsPreference.java
License:Open Source License
/** * @see org.opencms.configuration.preferences.I_CmsPreference#createConfigurationItem() *//*w w w . ja va 2 s .c o m*/ public Element createConfigurationItem() { CmsXmlContentProperty prop = getPropertyDefinition(); Element elem = DocumentHelper.createElement(CmsWorkplaceConfiguration.N_PREFERENCE); for (String[] attrToSet : new String[][] { { I_CmsXmlConfiguration.A_NAME, getName() }, { I_CmsXmlConfiguration.A_VALUE, getDefaultValue() }, { CmsWorkplaceConfiguration.A_NICE_NAME, prop.getNiceName() }, { CmsWorkplaceConfiguration.A_DESCRIPTION, prop.getDescription() }, { CmsWorkplaceConfiguration.A_WIDGET, prop.getWidget() }, { CmsWorkplaceConfiguration.A_WIDGET_CONFIG, prop.getWidgetConfiguration() }, { CmsWorkplaceConfiguration.A_RULE_REGEX, prop.getRuleRegex() }, { CmsWorkplaceConfiguration.A_ERROR, prop.getError() } }) { String attrName = attrToSet[0]; String value = attrToSet[1]; if (value != null) { elem.addAttribute(attrName, value); } } return elem; }
From source file:org.opencms.xml.CmsXmlValidationErrorHandler.java
License:Open Source License
/** * Constructor from superclass.<p> */ public CmsXmlValidationErrorHandler() { super(); m_warnings = DocumentHelper.createElement("warnings"); }
From source file:org.pentaho.platform.dataaccess.client.ConnectionServiceClient.java
License:Open Source License
/** * Generates a SOAP request for an Axis service. * @param params/*w ww . j ava2 s . co m*/ * @return */ protected String getRequestXml(Parameter... params) { Document doc = DocumentHelper.createDocument(); Element envelopeNode = DocumentHelper.createElement("soapenv:Envelope"); //$NON-NLS-1$ envelopeNode.addAttribute("xmlns:soapenv", "http://www.w3.org/2003/05/soap-envelope"); //$NON-NLS-1$ //$NON-NLS-2$ envelopeNode.addAttribute("xmlns:wsa", "http://www.w3.org/2005/08/addressing"); //$NON-NLS-1$ //$NON-NLS-2$ envelopeNode.addAttribute("xmlns:pho", //$NON-NLS-1$ "http://impl.service.wizard.datasource.dataaccess.platform.pentaho.org"); //$NON-NLS-1$ doc.add(envelopeNode); // create a Body node Element bodyNode = DocumentHelper.createElement("soapenv:Body"); //$NON-NLS-1$ envelopeNode.add(bodyNode); if (params == null || params.length == 0) { return doc.asXML(); } // create a parameter called 'parameters' Element parametersNode = DocumentHelper.createElement("pho:parameters"); //$NON-NLS-1$ bodyNode.add(parametersNode); for (Parameter param : params) { // create a parameter called 'name' Element nameNode = DocumentHelper.createElement("pho:" + param.getName()); //$NON-NLS-1$ parametersNode.add(nameNode); nameNode.setText(param.getValue().toString()); nameNode.addAttribute("type", param.getValue().getClass().getCanonicalName()); //$NON-NLS-1$ } return doc.asXML(); }
From source file:org.pentaho.platform.dataaccess.client.ConnectionServiceClient.java
License:Open Source License
/** * Returns XML for a connection object suitable for submitting to the connection web service * @param connection Connection object to be encoded as XML * @return XML serialization of the connection object *///from ww w.ja v a 2 s.c om protected String getConnectionXml(IConnection connection) { Document doc = DocumentHelper.createDocument(); // create a SOAP envelope and specify namespaces Element envelopeNode = DocumentHelper.createElement("soapenv:Envelope"); //$NON-NLS-1$ envelopeNode.addAttribute("xmlns:soapenv", "http://www.w3.org/2003/05/soap-envelope"); //$NON-NLS-1$ //$NON-NLS-2$ envelopeNode.addAttribute("xmlns:wsa", "http://www.w3.org/2005/08/addressing"); //$NON-NLS-1$ //$NON-NLS-2$ envelopeNode.addAttribute("xmlns:pho", //$NON-NLS-1$ "http://impl.service.wizard.datasource.dataaccess.platform.pentaho.org"); //$NON-NLS-1$ doc.add(envelopeNode); // create a Body node Element bodyNode = DocumentHelper.createElement("soapenv:Body"); //$NON-NLS-1$ envelopeNode.add(bodyNode); // create a parameter called 'connection' Element parameterNode = DocumentHelper.createElement("pho:connection"); //$NON-NLS-1$ bodyNode.add(parameterNode); // create a Connection node with a type of org.pentaho.platform.dataaccess.datasource.beans.Connection Element connectionNode = DocumentHelper.createElement("pho:Connection"); //$NON-NLS-1$ connectionNode.addAttribute("type", "org.pentaho.platform.dataaccess.datasource.beans.Connection"); //$NON-NLS-1$ //$NON-NLS-2$ parameterNode.add(connectionNode); // add the driver class of the connection Element node = DocumentHelper.createElement("driverClass"); //$NON-NLS-1$ node.setText(connection.getDriverClass()); connectionNode.add(node); // add the name of the connection node = DocumentHelper.createElement("name"); //$NON-NLS-1$ node.setText(connection.getName()); connectionNode.add(node); // add the password for the connection node = DocumentHelper.createElement("password"); //$NON-NLS-1$ node.setText(connection.getPassword()); connectionNode.add(node); // add the url of the connection node = DocumentHelper.createElement("url"); //$NON-NLS-1$ node.setText(connection.getUrl()); connectionNode.add(node); // add the user name for the connection node = DocumentHelper.createElement("username"); //$NON-NLS-1$ node.setText(connection.getUsername()); connectionNode.add(node); // return the XML return doc.asXML(); }
From source file:org.pentaho.platform.plugin.adhoc.AdhocWebServiceInteractXml.java
License:Open Source License
public static Document convertXml(final Document reportXml) { // get the list of headers List<String> headerList = new ArrayList<String>(); List<?> nodes = reportXml.selectNodes("/report/groupheader/@name"); //$NON-NLS-1$ // find all the unique group header names Iterator<?> it = nodes.iterator(); Attribute attr;//w ww.ja v a2s .c om String name; while (it.hasNext()) { // we only need to go until we get the first duplicate attr = (Attribute) it.next(); name = attr.getText(); if (!"dummy".equals(name)) { //$NON-NLS-1$ if (!headerList.contains(name)) { headerList.add(name); System.out.println(name); } else { break; } } } String headerNames[] = new String[headerList.size()]; String headerValues[] = new String[headerList.size()]; Element headerNodes[] = new Element[headerList.size()]; String columnHeaders[] = new String[0]; Element columnHeaderNodes[] = new Element[0]; headerList.toArray(headerNames); for (int idx = 0; idx < headerValues.length; idx++) { headerValues[idx] = ""; //$NON-NLS-1$ } Document reportDoc = DocumentHelper.createDocument(); Element reportNode = DocumentHelper.createElement("report"); //$NON-NLS-1$ reportDoc.setRootElement(reportNode); // process the top-level nodes nodes = reportXml.selectNodes("/report/*"); //$NON-NLS-1$ Node node; // go thru all the nodes it = nodes.iterator(); while (it.hasNext()) { node = (Node) it.next(); name = node.getName(); if ("groupheader".equals(name)) { //$NON-NLS-1$ // process the group headers // get the group header name String headerName = node.selectSingleNode("@name").getText(); //$NON-NLS-1$ if (!"dummy".equals(headerName)) { //$NON-NLS-1$ // find the header index String headerValue = node.selectSingleNode("element[1]").getText();//$NON-NLS-1$ int headerIdx = -1; for (int idx = 0; idx < headerNames.length; idx++) { if (headerNames[idx].equals(headerName)) { headerIdx = idx; break; } } if (!headerValues[headerIdx].equals(headerValue)) { // this is a new header value headerValues[headerIdx] = headerValue; // find the parent node Element parentNode; if (headerIdx == 0) { parentNode = reportNode; } else { parentNode = headerNodes[headerIdx - 1]; } // create a group header node for this Element headerNode = DocumentHelper.createElement("groupheader");//$NON-NLS-1$ parentNode.add(headerNode); headerNodes[headerIdx] = headerNode; // create the name attribute attr = DocumentHelper.createAttribute(headerNode, "name", headerName);//$NON-NLS-1$ headerNode.add(attr); // create the value node Element elementNode = DocumentHelper.createElement("element");//$NON-NLS-1$ headerNode.add(elementNode); attr = DocumentHelper.createAttribute(elementNode, "name", headerName);//$NON-NLS-1$ elementNode.add(attr); elementNode.setText(headerValue); } } // see if there are any column headers List<?> elements = node.selectNodes("element");//$NON-NLS-1$ if (elements.size() == 0) { elements = node.selectNodes("band/element");//$NON-NLS-1$ } if (elements.size() > 1) { // there are column headers here, get them and store them for the next set of rows columnHeaders = new String[elements.size() - 1]; columnHeaderNodes = new Element[elements.size() - 1]; for (int idx = 1; idx < elements.size(); idx++) { columnHeaders[idx - 1] = ((Element) elements.get(idx)).getText(); } } } else if ("items".equals(name)) {//$NON-NLS-1$ // process items (rows) // get the parent node, this should always be the last one on the list Element parentNode; if (headerNodes.length == 0) { parentNode = reportNode; } else { parentNode = headerNodes[headerNodes.length - 1]; } // create the items node Element itemsNode = DocumentHelper.createElement("items");//$NON-NLS-1$ parentNode.add(itemsNode); // create the headers node Element headersNode = DocumentHelper.createElement("headers");//$NON-NLS-1$ itemsNode.add(headersNode); // create the rows node Element itemBandsNode = DocumentHelper.createElement("itembands");//$NON-NLS-1$ itemsNode.add(itemBandsNode); for (int idx = 0; idx < columnHeaders.length; idx++) { Element headerNode = DocumentHelper.createElement("header");//$NON-NLS-1$ headerNode.setText(columnHeaders[idx]); headersNode.add(headerNode); columnHeaderNodes[idx] = headerNode; } // now copy the item bands over List<?> itembands = node.selectNodes("itemband");//$NON-NLS-1$ Iterator<?> bands = itembands.iterator(); boolean first = true; while (bands.hasNext()) { Element itemband = (Element) bands.next(); Element itemBandNode = DocumentHelper.createElement("itemband");//$NON-NLS-1$ itemBandsNode.add(itemBandNode); List<?> elementList = itemband.selectNodes("element");//$NON-NLS-1$ Iterator<?> elements = elementList.iterator(); int idx = 0; while (elements.hasNext()) { Element element = (Element) elements.next(); Element elementNode = DocumentHelper.createElement("element");//$NON-NLS-1$ itemBandNode.add(elementNode); elementNode.setText(element.getText()); name = element.selectSingleNode("@name").getText();//$NON-NLS-1$ if (name.endsWith("Element")) {//$NON-NLS-1$ name = name.substring(0, name.length() - "Element".length());//$NON-NLS-1$ } attr = DocumentHelper.createAttribute(elementNode, "name", name);//$NON-NLS-1$ elementNode.add(attr); if (first) { // copy the item name over to the column header attr = DocumentHelper.createAttribute(columnHeaderNodes[idx], "name", name);//$NON-NLS-1$ columnHeaderNodes[idx].add(attr); } idx++; } first = false; } } } return reportDoc; }