List of usage examples for org.dom4j Element addAttribute
Element addAttribute(QName qName, String value);
From source file:com.ibm.cognos.API.java
License:Open Source License
public void addDataItem(String p_sName, String p_sExpression, boolean p_bAggregate, String p_sSort) { Element nSelection = (Element) oDocument.selectSingleNode("/report/queries/query/selection"); if (nSelection == null) { addSelection();//from w w w . j a va2s.com nSelection = (Element) oDocument.selectSingleNode("/report/queries/query/selection"); } // Create the dataItem element Element eDataItem = DocumentHelper.createElement("dataItem"); eDataItem.addAttribute("name", p_sName); // Add an aggregation element, if necessary if (p_bAggregate) { eDataItem.addAttribute("aggregate", "true"); } // Add the expression for the dataItem Element eExpression = DocumentHelper.createElement("expression"); eExpression.setText(p_sExpression); eDataItem.add(eExpression); // Add the dataItem to the selection element nSelection.add(eDataItem); // add the sort item to the report, if necessary if (p_sSort != null && !p_sSort.equals("")) { addDataItemSort(p_sName, p_sSort); } }
From source file:com.ibm.cognos.API.java
License:Open Source License
public void addListColumnRowSpan(String p_sName) { String sName = p_sName;// www . j a v a 2 s. c o m String quotChar = "\'"; if (sName.indexOf(quotChar) >= 0) { quotChar = "\""; } // Need to find the column corresponding to the referenced data item String elementString = "/report/layouts/layout/reportPages/page/pageBody/contents/list/" + "listColumns/listColumn/listColumnBody/contents/textItem/dataSource/" + "dataItemValue[@refDataItem=" + quotChar + sName + quotChar + "]"; Element n = (Element) oDocument.selectSingleNode(elementString); // Need to add a listColumnRowSpan node to listColumnBody for that // column (4 levels up) Element eColumnBody = n.getParent().getParent().getParent().getParent(); Element eListColumnRowSpan = DocumentHelper.createElement("listColumnRowSpan"); eListColumnRowSpan.addAttribute("refDataItem", sName); }
From source file:com.ibm.cognos.API.java
License:Open Source License
public void addListGroup(String p_sName) { Element n = (Element) oDocument.selectSingleNode( "/report/layouts/layout/reportPages/page/pageBody/contents/list/" + "listColumns/listGroups"); if (n == null) { addListGroups();//from w ww .j av a 2 s . com n = (Element) oDocument.selectSingleNode( "/report/layouts/layout/reportPages/page/pageBody/contents/list/" + "listColumns/listGroups"); } // Add the listGroup node to listGroups Element eListGroup = DocumentHelper.createElement("listGroup"); n.addAttribute("refDataItem", p_sName); n.add(eListGroup); }
From source file:com.ibm.cognos.API.java
License:Open Source License
public void addFilter() { Element n = (Element) oDocument.selectSingleNode("/report/queries/query/detailFilter"); if (n == null) { addDetailFilter();//from ww w. j av a 2 s . co m n = (Element) oDocument.selectSingleNode("/report/queries/query/detailFilter"); } Element eFilter = DocumentHelper.createElement("filter"); eFilter.addAttribute("use", "required"); n.add(eFilter); }
From source file:com.ibm.cognos.API.java
License:Open Source License
public void addDataItemSort(String p_sElementName, String p_sSort) { Element n = (Element) oDocument .selectSingleNode("/report/layouts/layout/reportPages/page/pageBody/contents/list/sortList"); if (n == null) { addSortList();// w w w. ja v a2 s. c o m n = (Element) oDocument .selectSingleNode("/report/layouts/layout/reportPages/page/pageBody/contents/list/sortList"); } Element eSort = DocumentHelper.createElement("sortItem"); eSort.addAttribute("refDataItem", p_sElementName); eSort.addAttribute("sortOrder", p_sSort); n.add(eSort); }
From source file:com.ibm.cognos.API.java
License:Open Source License
/** * addListColumn//w w w .ja v a2 s . c o m * * @param p_sName * @param position * (to insert in the default position pass 0 to this method) * (default position = insert after the last child element.) */ public void addListColumn(String p_sName, int position) { Element n = null; n = (Element) oDocument.selectSingleNode( "/report/layouts/layout/reportPages/page/pageBody/contents" + "/list/listColumns"); // Create an empty column node Element eCol = DocumentHelper.createElement("listColumn"); // Prepare all the bits to contain the column title Element eTitle = DocumentHelper.createElement("listColumnTitle"); Element eStyleTitle = buildStyle("lt"); Element eTContents = DocumentHelper.createElement("contents"); Element eTText = DocumentHelper.createElement("textItem"); Element eTSrc = DocumentHelper.createElement("dataSource"); Element eLabel = DocumentHelper.createElement("dataItemLabel"); eLabel.addAttribute("refDataItem", p_sName); // Prepare all the bits to contain the column data Element eBody = DocumentHelper.createElement("listColumnBody"); Element eStyle = buildStyle("lm"); Element eBContents = DocumentHelper.createElement("contents"); Element eBText = DocumentHelper.createElement("textItem"); Element eBSrc = DocumentHelper.createElement("dataSource"); Element eValue = DocumentHelper.createElement("dataItemValue"); eValue.addAttribute("refDataItem", p_sName); // Piece the Title together in the right order eTSrc.add(eLabel); eTText.add(eTSrc); eTContents.add(eTText); eTitle.add(eStyleTitle); eTitle.add(eTContents); // Piece the Body together eBSrc.add(eValue); eBText.add(eBSrc); eBContents.add(eBText); eBody.add(eStyle); eBody.add(eBContents); // Add the title and body to the column eCol.add(eTitle); eCol.add(eBody); if (position > 0) { n.content().add(position - 1, eCol); } else { n.add(eCol); } }
From source file:com.ikon.servlet.admin.StatsGraphServlet.java
License:Open Source License
/** * Convert a piechartdata to xml//from ww w . j a v a 2 s.c o m * * @author puspendu.banerjee@gmail.com */ public String repoStatsXML(final String title, final DefaultPieDataset dataset) throws IOException, ServletException { Document document = DocumentHelper.createDocument(); Element root = document.addElement("RepoStats"); root.addElement("Title").addCDATA(title); Element dataSetElement = root.addElement("DataSet"); for (int i = 0; i < dataset.getItemCount(); i++) { Element itemElement = dataSetElement.addElement("Item"); itemElement.addElement("name").addCDATA(dataset.getKey(i).toString()); itemElement.addAttribute("percent", dataset.getValue(i).toString()); dataSetElement.add(itemElement); } return document.asXML(); }
From source file:com.jaspersoft.jasperserver.export.ExporterImpl.java
License:Open Source License
protected void setOutputProperty(String property, String value) { Element propElement = indexRootElement.addElement(getPropertyElementName()); propElement.addAttribute(getPropertyNameAttribute(), property); if (value != null) { propElement.addAttribute(getPropertyValueAttribute(), value); }//from w w w.j ava 2s. c om }
From source file:com.jaspersoft.jasperserver.export.ExporterImpl.java
License:Open Source License
protected void createModuleElement(ExporterModule module) { Element moduleElement = indexRootElement.addElement(getIndexModuleElementName()); moduleElement.addAttribute(getIndexModuleIdAttributeName(), module.getId()); moduleIndexElements.put(module.getId(), moduleElement); }
From source file:com.jeeframework.util.xml.XMLProperties.java
License:Open Source License
/** * Return all values who's path matches the given property * name as a String array, or an empty array if the if there * are no children. This allows you to retrieve several values * with the same property name. For example, consider the * XML file entry:/*from w w w .j a v a 2 s . c om*/ * <pre> * <foo> * <bar> * <prop>some value</prop> * <prop>other value</prop> * <prop>last value</prop> * </bar> * </foo> * </pre> * If you call getProperties("foo.bar.prop") will return a string array containing * {"some value", "other value", "last value"}. * * @param name the name of the property to retrieve * @return all child property values for the given node name. */ public List<String> getProperties(String name, boolean asList) { List<String> result = new ArrayList<String>(); String[] propName = parsePropertyName(name); // Search for this property by traversing down the XML hierarchy, // stopping one short. Element element = document.getRootElement(); for (int i = 0; i < propName.length - 1; i++) { element = element.element(propName[i]); if (element == null) { // This node doesn't match this part of the property name which // indicates this property doesn't exist so return empty array. return result; } } // We found matching property, return names of children. Iterator<Element> iter = element.elementIterator(propName[propName.length - 1]); Element prop; String value; boolean updateEncryption = false; while (iter.hasNext()) { prop = iter.next(); // Empty strings are skipped. value = prop.getTextTrim(); if (!"".equals(value)) { // check to see if the property is marked as encrypted Attribute encrypted = prop.attribute(ENCRYPTED_ATTRIBUTE); if (encrypted != null) { value = EncryptUtil.desDecrypt(encryptKey, value); } else { // rewrite property as an encrypted value prop.addAttribute(ENCRYPTED_ATTRIBUTE, "true"); updateEncryption = true; } result.add(value); } } if (updateEncryption) { Log.info("Rewriting values for XML property " + name + " using encryption"); saveProperties(); } return result; }