List of usage examples for org.dom4j Element addAttribute
Element addAttribute(QName qName, String value);
From source file:com.dtolabs.shared.resources.ResourceXMLGenerator.java
License:Apache License
/** * Create entity tag based on resourceType of entity, and add common attributes * * @param root element// w w w . ja v a2 s .c om * @param entity entity * * @return element */ private Element genEntityCommon(final Element root, final ResourceXMLParser.Entity entity) { final Element tag = root.addElement(entity.getResourceType()); tag.addAttribute(COMMON_NAME, entity.getName()); tag.addAttribute(COMMON_DESCRIPTION, notNull(entity.getProperty(COMMON_DESCRIPTION))); tag.addAttribute(COMMON_TAGS, notNull(entity.getProperty(COMMON_TAGS))); return tag; }
From source file:com.eurelis.opencms.ant.task.ManifestBuilderTask.java
License:Open Source License
private void addPropertiesToTree(Element root, String propFilePath) { try {//from w ww.ja v a 2 s . c o m Properties props = new Properties(); if (new File(propFilePath).exists()) props.load(new FileInputStream(propFilePath)); if (!props.isEmpty()) { for (Object keyObject : props.keySet()) { try { String key = (String) keyObject; if (key == null) continue; String value = props.getProperty(key); if (value == null) continue; if (value.length() > 0) { if (key.contains("EurelisProperty")) { continue; } Element property = root.addElement("property"); property.addElement("name") .addText(key.matches("^.*\\.[is]$") ? key.substring(0, key.length() - 2) : key); property.addElement("value").add(new FlyweightCDATA(value)); if (key.endsWith(".s")) property.addAttribute("type", "shared"); } } catch (Exception e) { log(e, Project.MSG_ERR); e.printStackTrace(); } } } } catch (Exception e) { log(e, Project.MSG_ERR); e.printStackTrace(); } }
From source file:com.eurelis.opencms.workflows.workflows.A_OSWorkflowManager.java
License:Open Source License
/** * Get the OpenCMS RFS OSWorkflow configuration file and update it with the given filepath. * //from w w w.ja v a 2 s . c om * @param listOfWorkflowsFilepath * the path of the file containing the list of available workflow descriptions * @return the path in RFS of the updated file * @throws DocumentException * this exception is thrown if an error occurs during the parsing of the document * @throws IOException * this exception is thrown if a problem occurs during overwriting of the config file */ private String updateOSWorkflowConfigFile(String listOfWorkflowsFilepath) throws CmsException, DocumentException, IOException { // get file path String configFilePath = this.getWebINFPath() + ModuleSharedVariables.SYSTEM_FILE_SEPARATOR + OSWORKFLOWCONFIGFILE_RFSFILEPATH; File listOfWorkflowsFile = new File(listOfWorkflowsFilepath); // Load Jdom parser SAXReader reader = new SAXReader(); Document document = reader.read(configFilePath); Node propertyNode = document.selectSingleNode(OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_XPATH); if (propertyNode != null) { if (propertyNode.getNodeType() == Node.ELEMENT_NODE) { // convert Node into element Element propertyElement = (Element) propertyNode; // update the Attribute Attribute valueAttribute = propertyElement .attribute(OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_ATTRIBUTNAME); valueAttribute.setValue(listOfWorkflowsFile.toURI().toString()); } else { LOGGER.debug("the node with Xpath " + OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_XPATH + " in the file " + configFilePath + " doesn't correspond to an element"); } } else { Node parentNode = document.selectSingleNode(OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_PARENT_XPATH); if (parentNode != null) { if (parentNode.getNodeType() == Node.ELEMENT_NODE) { // convert Node into element Element parentElement = (Element) parentNode; // add new property Element propertyElement = parentElement.addElement("property"); // add attributs propertyElement.addAttribute("key", "resource"); propertyElement.addAttribute("value", listOfWorkflowsFile.toURI().toString()); } else { LOGGER.debug("the node with Xpath " + OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_XPATH + " in the file " + configFilePath + " doesn't correspond to an element"); } } else { LOGGER.debug("the node with Xpath " + OSWORKFLOWCONFIGFILE_PROPERTYTOUPDATE_PARENT_XPATH + " in the file " + configFilePath + " has not been found."); } } /* * Get a string of the resulting file */ // creating of a buffer that will collect result ByteArrayOutputStream xmlContent = new ByteArrayOutputStream(); // Pretty print the document to xmlContent OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(xmlContent, format); writer.write(document); writer.flush(); writer.close(); // get the config file content as a String String documentContent = new String(xmlContent.toByteArray()); /* * Overwrite the config file */ FileWriter.writeFile(configFilePath, documentContent); return configFilePath; }
From source file:com.ewcms.util.XMLUtil.java
License:Open Source License
/** * // w w w . j a va2 s. c o m * * @param thisElement * @param attributeName * @param attributeValue */ public void addAttribute(Element thisElement, String attributeName, String attributeValue) { thisElement.addAttribute(attributeName, attributeValue); }
From source file:com.ewcms.util.XMLUtil.java
License:Open Source License
/** * // w ww. jav a 2 s.c o m * * @param thisElement * @param attributeNames * @param attributeValues */ public void addAttributes(Element thisElement, String[] attributeNames, String[] attributeValues) { for (int i = 0; i < attributeNames.length; i++) { thisElement.addAttribute(attributeNames[i], attributeValues[i]); } }
From source file:com.ewcms.web.FcfAction.java
License:Open Source License
public void createArticle() throws Exception { if (EwcmsContextHolder.getContext().getSite() == null) return;// w w w . j ava2 s. c o m Integer siteId = EwcmsContextHolder.getContext().getSite().getId(); XMLUtil xml = new XMLUtil(); Element graph = xml.addRoot("graph"); // xml.addAttribute(graph, "caption", ""); //xml.addAttribute(graph, "subCaption", getYear().toString()); xml.addAttribute(graph, "basefontsize", "12"); // xml.addAttribute(graph, "xAxisName", ""); xml.addAttribute(graph, "showNames", "1"); xml.addAttribute(graph, "decimalPrecision", "0");// ?0? // xml.addAttribute(graph, "showValues", "0");// ? xml.addAttribute(graph, "formatNumberScale", "0"); Map<Integer, Long> map = documentFac.findCreateArticleFcfChart(getYearCreate(), siteId); Iterator<Entry<Integer, Long>> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry<Integer, Long> m = (Map.Entry<Integer, Long>) it.next(); Integer key = m.getKey(); Long total = (Long) map.get(key); Element set = xml.addNode(graph, "set"); set.addAttribute("name", String.format("%02d", key) + ""); set.addAttribute("value", total.toString()); //set.addAttribute("color", Integer.toHexString((int) (Math.random() * 255 * 255 * 255)).toUpperCase()); set.addAttribute("color", "FF0000"); } Struts2Util.renderHtml(xml.getXML(), "encoding:UTF-8", "no-cache:false"); }
From source file:com.ewcms.web.FcfAction.java
License:Open Source License
public void releaseArticle() throws Exception { if (EwcmsContextHolder.getContext().getSite() == null) return;/* w w w.j a va 2 s. c o m*/ Integer siteId = EwcmsContextHolder.getContext().getSite().getId(); XMLUtil xml = new XMLUtil(); Element graph = xml.addRoot("graph"); xml.addAttribute(graph, "basefontsize", "12"); xml.addAttribute(graph, "showNames", "1"); xml.addAttribute(graph, "decimalPrecision", "0"); xml.addAttribute(graph, "formatNumberScale", "0"); Map<Integer, Long> map = documentFac.findReleaseArticleFcfChart(getYearRelease(), siteId); Iterator<Entry<Integer, Long>> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry<Integer, Long> m = (Map.Entry<Integer, Long>) it.next(); Integer key = m.getKey(); Long total = (Long) map.get(key); Element set = xml.addNode(graph, "set"); set.addAttribute("name", String.format("%02d", key) + ""); set.addAttribute("value", total.toString()); //set.addAttribute("color", Integer.toHexString((int) (Math.random() * 255 * 255 * 255)).toUpperCase()); set.addAttribute("color", "FF0000"); } Struts2Util.renderHtml(xml.getXML(), "encoding:UTF-8", "no-cache:false"); }
From source file:com.ewcms.web.FcfAction.java
License:Open Source License
public void releaseArticlePerson() throws Exception { if (EwcmsContextHolder.getContext().getSite() == null) return;// w w w. j av a 2 s . co m Integer siteId = EwcmsContextHolder.getContext().getSite().getId(); XMLUtil xml = new XMLUtil(); Element graph = xml.addRoot("graph"); xml.addAttribute(graph, "basefontsize", "12"); xml.addAttribute(graph, "showNames", "1"); xml.addAttribute(graph, "decimalPrecision", "0"); xml.addAttribute(graph, "formatNumberScale", "0"); Map<String, Long> map = documentFac.findReleaseArticlePersonFcfChart(getYearPerson(), siteId); Iterator<Entry<String, Long>> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, Long> m = (Map.Entry<String, Long>) it.next(); String key = m.getKey(); Long total = (Long) map.get(key); Element set = xml.addNode(graph, "set"); set.addAttribute("name", key); set.addAttribute("value", total.toString()); set.addAttribute("color", Integer.toHexString((int) (Math.random() * 255 * 255 * 255)).toUpperCase()); } Struts2Util.renderHtml(xml.getXML(), "encoding:UTF-8", "no-cache:false"); }
From source file:com.example.sample.pMainActivity.java
License:Apache License
public Document createXMLDocument() { Document doc = null;// w ww . j av a2 s . c o m doc = DocumentHelper.createDocument(); doc.addComment("edited with XMLSpy v2005 rel. 3 U (http://www.altova.com) by ()"); // doc.addDocType("class","//By Jack Chen","saveXML.xsd"); Element root = doc.addElement("class"); Element company = root.addElement("company"); Element person = company.addElement("person"); person.addAttribute("id", "11"); person.addElement("name").setText("Jack Chen"); person.addElement("sex").setText(""); person.addElement("date").setText("2001-04-01"); person.addElement("email").setText("chen@163.com"); person.addElement("QQ").setText("2366001"); return doc; }
From source file:com.flaptor.hounder.indexer.HtmlParser.java
License:Apache License
/** * Parses a tag to produce a field./*from w w w . ja v a2 s .c om*/ * @param doc the doc to modify * @throw exception on error, signaling the main method to return no document. */ private void processTag(Document doc, final String tagName, final String fieldName) throws Exception { Node bodyElement = doc.selectSingleNode("/*/" + tagName); if (null == bodyElement) { logger.warn("Content element missing from document. I was expecting a '" + tagName + "'. Will not add '" + fieldName + "' field."); return; } Node destElement = doc.selectSingleNode("//field[@name='" + fieldName + "']"); if (null != destElement) { logger.warn("Parsed element '" + fieldName + "' already present in document. Will not overwrite."); return; } ParseOutput out = parser.parse("", bodyElement.getText().getBytes("UTF-8"), "UTF-8"); for (String field : extraFields) { String content = out.getField(field); if (null == content) { logger.debug("had document without " + field + " field. Continuing with other fields."); continue; } Element docField = DocumentHelper.createElement("field"); docField.addText(content); docField.addAttribute("name", field); docField.addAttribute("indexed", Boolean.toString(INDEXED)); docField.addAttribute("stored", Boolean.toString(STORED)); docField.addAttribute("tokenized", "true"); bodyElement.getParent().add(docField); } String text = out.getText(); Element field = DocumentHelper.createElement("field"); field.addText(text); field.addAttribute("name", fieldName); field.addAttribute("indexed", Boolean.toString(INDEXED)); field.addAttribute("stored", Boolean.toString(STORED)); field.addAttribute("tokenized", "true"); bodyElement.getParent().add(field); }