List of usage examples for org.dom4j Element attribute
Attribute attribute(QName qName);
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
private void doUpgrade(String url) { Document doc = credentials.get(url).doc; String path = "//child::*[text() = '" + TreeObject.CATEGORY_FOLDER //$NON-NLS-1$ + "' and count(@Universe) = 0 and count(@Url) = 0"//$NON-NLS-1$ + "]";//$NON-NLS-1$ List<Element> categorys = doc.selectNodes(path); for (Element elem : categorys) { Attribute attr = elem.attribute(URL); if (attr == null) { elem.addAttribute(URL, UnifyUrl(url)); }//from w w w . j av a 2 s. c om } saveDocument(url); }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
private void addAttributeToCategoryElem(TreeParent category, String attrName, String defaultAttrValue) { Element elem = locateCategoryElement(category); Attribute attr = elem.attribute(attrName); if (attr != null) { elem.remove(attr);//from w w w .ja v a 2 s .c om } elem.addAttribute(attrName, defaultAttrValue); }
From source file:com.amalto.workbench.utils.LocalTreeObjectRepository.java
License:Open Source License
public boolean getCategoryExpandState(TreeParent category) { Element elem = locateCategoryElement(category); if (elem != null) { return Boolean.valueOf(elem.attribute(EXPAND_NAME).getValue()); }/* w w w . jav a 2s.co m*/ return false; }
From source file:com.app.util.SettingUtils.java
License:Open Source License
/** * /* w ww .j av a 2 s. co m*/ * * @param setting * */ public static void set(Setting setting) { try { File appXmlFile = new ClassPathResource(CommonAttributes.APP_XML_PATH).getFile(); Document document = new SAXReader().read(appXmlFile); List<Element> elements = document.selectNodes("/app/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(appXmlFile); 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.arc.cdt.debug.seecode.core.launch.CMPDInfoFromVDKConfigReader.java
License:Open Source License
/** * Given a VDK configuration file, extract CMPD information suitable for creating a launch configuration. * @param vdkConfig the XML file to read from. * @return cmpd description/*from w ww .ja v a 2s. c om*/ * @throws VDKConfigException if an error occurs in reading the config file. */ @SuppressWarnings("unchecked") public static ICMPDInfo extractCMPDInfo(File vdkConfig, IProject project) throws VDKConfigException { try { SAXReader reader = new SAXReader(); Document doc = reader.read(vdkConfig); Element root = doc.getRootElement(); if (root == null || !root.getName().equalsIgnoreCase("CMPD")) { throw new DocumentException("Root element is not \"CMPD\" node"); } if (!"1".equals(root.attributeValue("version"))) { throw new DocumentException("VDK config file has unknown version: " + root.attribute("version")); } List<Element> processes = root.elements("PROCESS"); final List<ICMPDInfo.IProcess> pList = new ArrayList<ICMPDInfo.IProcess>(processes.size()); File workingDir = vdkConfig.getParentFile(); for (Element p : processes) { pList.add(formProcess(p, workingDir, project)); } List<Element> launches = root.elements("LAUNCH"); // should be just one final List<String> launchSwitches = new ArrayList<String>(); final List<String> startupCommands = new ArrayList<String>(); if (launches != null) { for (Element e : launches) { appendLaunchSwitches(launchSwitches, startupCommands, e); } } return new ICMPDInfo() { @Override public String[] getLaunchArgs() { return launchSwitches.toArray(new String[launchSwitches.size()]); } @Override public IProcess[] getProcesses() { return pList.toArray(new IProcess[pList.size()]); } @Override public String[] getStartupCommands() { return startupCommands.toArray(new String[startupCommands.size()]); } }; } catch (MalformedURLException e) { throw new VDKConfigException(e.getMessage(), e); } catch (DocumentException e) { throw new VDKConfigException(e.getMessage(), e); } }
From source file:com.beacon.wlsagent.xml.XmlWorker.java
public String[] getAttrValuesOfSingleNode(Document document, String xpath, String[] attrNameStrs) { Element domEle = (Element) document.selectSingleNode(xpath); log.info(document);/*from ww w . ja va2 s. c o m*/ int attrCount = attrNameStrs.length; String attrValues[] = new String[attrCount]; for (int i = 0; i < attrCount; i++) { attrValues[i] = domEle.attribute(attrNameStrs[i]).getText(); } return attrValues; }
From source file:com.beyondb.io.DBConfig.java
/** *??//from w ww.j a va2 s .com * @param path * @return */ public static DataSource readDBConfig(String path) { DataSource ds = null; try { SAXReader reader = new SAXReader(); File file = new File(path); if (file.exists()) { Document doc = reader.read(file); Element datasource = doc.getRootElement(); Element dbElement = datasource.element(Node_database); if (dbElement != null) { String id = dbElement.attribute(Attribute_id).getValue(); String username = dbElement.attribute(Attribute_username).getValue(); String password = dbElement.attribute(Attribute_password).getValue(); String virtualNode = dbElement.attribute(Attribute_virtualNode).getValue(); String url = dbElement.elementText(Attribute_jdbcurl); ds = new BydDataSource(url, username, password); ds.setVirtualNode(virtualNode); ds.setID(id); } } } catch (DocumentException ex) { Logger.getLogger(DBConfig.class.getName()).log(Level.SEVERE, "???", ex); } return ds; }
From source file:com.beyondb.io.DBConfig.java
/** *??/*from ww w . j av a2s . c o m*/ * @param path * @return */ public static ArrayList<DataSource> readDBConfig1(String path) { ArrayList<DataSource> dslist = new ArrayList<>(); try { SAXReader reader = new SAXReader(); File file = new File(path); if (file.exists()) { Document doc = reader.read(file); Element datasource = doc.getRootElement(); Iterator it = datasource.elementIterator(Node_database); while (it.hasNext()) { Element dbElement = (Element) it.next(); String id = dbElement.attribute(Attribute_id).getValue(); String username = dbElement.attribute(Attribute_username).getValue(); String password = dbElement.attribute(Attribute_password).getValue(); String virtualNode = dbElement.attribute(Attribute_virtualNode).getValue(); String url = dbElement.elementText(Attribute_jdbcurl); DataSource ds = new BydDataSource(url, username, password); ds.setVirtualNode(virtualNode); ds.setID(id); dslist.add(ds); } } } catch (DocumentException ex) { Logger.getLogger(DBConfig.class.getName()).log(Level.SEVERE, "???", ex); } return dslist; }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * ??//from w w w . j av a 2 s . c o m * * * * @param element * * @param name * ?? * @param optional * ?? * @return * * * * @throws XMLDocException * @throws BaseException */ public static String getAttribute(Element element, String name, boolean optional) throws BaseException { Attribute attr = element.attribute(name); if (attr == null && !optional) { throw new BaseException("UTIL-0001", "Attribute " + name + " of " + element.getName() + " expected."); } else if (attr != null) { return attr.getValue(); } else { return null; } }
From source file:com.blocks.framework.utils.date.XMLDom4jUtils.java
License:Open Source License
/** * //from w w w. ja v a 2 s .c o m * * * * * @param ele * Element * @param attributeName * String * @return Element */ public static Element removeAttribute(Element ele, String attributeName) { if (ele == null) { return null; } Attribute att = ele.attribute(attributeName); ele.remove(att); return ele; }