List of usage examples for org.dom4j Element attribute
Attribute attribute(QName qName);
From source file:com.wabacus.config.database.datasource.ProxoolDataSource.java
License:Open Source License
private void changePassword(String configfile, boolean actiontype) { if (!configfile.toLowerCase().endsWith(".xml")) { throw new WabacusConfigLoadingException("?" + configfile + "???wabacus??.xml?proxool??"); }/*from ww w. ja v a 2 s. c om*/ Document doc = XmlAssistant.getInstance().loadXmlDocument(configfile); Element root = doc.getRootElement(); Element eleDriverProp = root.element("driver-properties"); if (eleDriverProp == null) return; List lstProps = eleDriverProp.elements("property"); if (lstProps == null || lstProps.size() == 0) { return; } Element elePasswordProp = null; for (int i = 0; i < lstProps.size(); i++) { if ("password".equalsIgnoreCase(((Element) lstProps.get(i)).attributeValue("name").trim())) { elePasswordProp = (Element) lstProps.get(i); } } if (elePasswordProp == null) return; String password = elePasswordProp.attributeValue("value"); password = password == null ? "" : password.trim(); if (password.equals("")) return; boolean shouldsave = false; if (actiontype) { if (DesEncryptTools.KEY_OBJ == null) return;//wabacus.cfg.xml? if (password.startsWith("{3DES}")) { if (DesEncryptTools.IS_NEWKEY) { throw new WabacusConfigLoadingException("??" + configfile + "????"); } } else if (!password.equals("")) { password = "{3DES}" + DesEncryptTools.encrypt(password); shouldsave = true; } } else { if (password.startsWith("{3DES}")) { if (DesEncryptTools.IS_NEWKEY) { throw new WabacusConfigLoadingException("??" + configfile + "????"); } if (DesEncryptTools.KEY_OBJ == null) { throw new WabacusConfigLoadingException("wabacus.cfg.xml," + configfile + "?"); } password = DesEncryptTools.decrypt(password.substring("{3DES}".length())); shouldsave = true; } } if (shouldsave) { Attribute attrPass = elePasswordProp.attribute("value"); attrPass.setValue(password); try { XmlAssistant.getInstance().saveDocumentToXmlFile(configfile, doc); } catch (IOException e) { log.warn(configfile + "????", e); } } }
From source file:com.webarch.common.io.xml.XMLDao.java
License:Apache License
/** * @param xPath/*from www . java2 s .co m*/ * @param attributeName ???xpath */ @Override public XMLEditor removeAttribute(String xPath, final String attributeName) { super.addModifier(xPath, new ElementModifier() { @Override public Element modifyElement(Element element) throws Exception { element.remove(element.attribute(attributeName)); return element; } }); return this; }
From source file:com.webarch.common.io.xml.XMLDao.java
License:Apache License
/** * @param xPath/*from ww w .j a v a 2 s .c o m*/ * @param attributeNames key ?? value */ public XMLEditor removeAttributes(String xPath, final Set<String> attributeNames) { super.addModifier(xPath, new ElementModifier() { @Override public Element modifyElement(Element element) throws Exception { for (String attributeName : attributeNames) { element.remove(element.attribute(attributeName)); } return element; } }); return this; }
From source file:com.webarch.common.io.xml.XMLDao.java
License:Apache License
/** * @param xPath/* w ww .ja va 2s .co m*/ * @param content * @param attributeName * @param overwriteAble */ @Override public XMLEditor modifyeAttributeContent(String xPath, final String content, final String attributeName, final boolean overwriteAble) { super.addModifier(xPath, new ElementModifier() { @Override public Element modifyElement(Element element) throws Exception { Attribute attribute = element.attribute(attributeName); StringBuffer contentText = new StringBuffer(); if (overwriteAble) { contentText.append(content); } else { contentText.append(attribute.getText()); contentText.append(content); } attribute.setText(contentText.toString()); return element; } }); return this; }
From source file:com.webarch.common.io.xml.XMLDao.java
License:Apache License
public XMLEditor replaceAttributeContent(final String xPath, final String content, final String replaceContent, final String attributeName) { super.addModifier(xPath, new ElementModifier() { @Override/* w ww. j av a2s. c om*/ public Element modifyElement(Element element) throws Exception { Attribute attribute = element.attribute(attributeName); String tempContent = attribute.getText(); tempContent = tempContent.replace(content, replaceContent); attribute.setText(tempContent); return element; } }); return this; }
From source file:com.webarch.common.io.xml.XMLDao.java
License:Apache License
/** * @param xPath/*w ww . j a v a 2s . co m*/ * @param attributes key ?? value * @param overwriteAble */ public XMLEditor modifyeAttributesContent(String xPath, final Map<String, String> attributes, final boolean overwriteAble) { super.addModifier(xPath, new ElementModifier() { @Override public Element modifyElement(Element element) throws Exception { Set<String> attributeNames = attributes.keySet(); for (String attributeName : attributeNames) { final Attribute attribute = element.attribute(attributeName); final String content = attributes.get(attributeName); StringBuffer contentText = new StringBuffer(); if (overwriteAble) { contentText.append(content); } else { contentText.append(attribute.getText()); contentText.append(content); } attribute.setText(contentText.toString()); } return element; } }); return this; }
From source file:com.webarch.common.io.xml.XMLDao.java
License:Apache License
/** * ?xml attribute//from w ww . j a v a 2 s .co m * * @return * @throws org.dom4j.DocumentException */ public Set<String> parserAttribute(Element rootElement, String xpath, String attributeName) throws DocumentException { Set<String> attributeSet = new HashSet<String>(); List elements = rootElement.selectNodes(xpath); for (Object attributeObject : elements) { if (attributeObject instanceof Element) { Element element = (Element) attributeObject; String attributeText = element.attribute(attributeName).getText(); if (StringUtils.isNotEmpty(attributeText)) { attributeSet.add(attributeText); } } } return attributeSet; }
From source file:com.wedian.site.common.utils.SettingUtils.java
License:Open Source License
/** * /* ww w. j a v a2 s . com*/ * * @param setting * */ public static void set(Setting setting) { try { File shopxxXmlFile = new ClassPathResource(CommonAttributes.SITE_XML_PATH).getFile(); Document document = new SAXReader().read(shopxxXmlFile); List<Element> elements = document.selectNodes("/site/setting"); for (Element element : elements) { try { String name = element.attributeValue("name"); String value = beanUtils.getProperty(setting, name); Attribute attribute = element.attribute("value"); attribute.setValue(value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } FileOutputStream fileOutputStream = null; XMLWriter xmlWriter = null; try { OutputFormat outputFormat = OutputFormat.createPrettyPrint(); outputFormat.setEncoding("UTF-8"); outputFormat.setIndent(true); outputFormat.setIndent(" "); outputFormat.setNewlines(true); fileOutputStream = new FileOutputStream(shopxxXmlFile); xmlWriter = new XMLWriter(fileOutputStream, outputFormat); xmlWriter.write(document); } catch (Exception e) { e.printStackTrace(); } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException e) { } } IOUtils.closeQuietly(fileOutputStream); } Ehcache cache = cacheManager.getEhcache(Setting.CACHE_NAME); cache.put(new net.sf.ehcache.Element(Setting.CACHE_KEY, setting)); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.xebia.mojo.dashboard.reports.html.CloverDashboardReport.java
License:Apache License
private void changeImageSrc(MavenProject subProject, Node node) throws MojoExecutionException { List list = xmlUtil.findNodes(node, ".//img"); for (int i = 0; i < list.size(); i++) { Node aNode = (Node) list.get(i); if (aNode instanceof Element) { Element anElement = (Element) aNode; Node srcAtt = anElement.attribute("src"); srcAtt.setText(DashboardUtil.determineCompletePath(subProject) + "clover/" + srcAtt.getText()); }//w w w.ja va 2s . c om } }
From source file:com.xebia.mojo.dashboard.util.HtmlUtil.java
License:Apache License
/** * Removes an {@link Attribute} specified by the attribute name from an {@link Element}. * * @param element The {@link Element} from which to remove the {@link Attribute}. * @param attribute The name of the {@link Attribute} that is to be removed. */// w w w .j a v a2 s .c om public static final void removeAttribute(Element element, String attribute) { Attribute attr = element.attribute(attribute); if (attr != null) { element.remove(attr); } }