List of usage examples for org.dom4j Element elements
List<Element> elements(QName qName);
From source file:com.apicloud.commons.model.Feature.java
License:Open Source License
public static List<Feature> loadXml2(File file) { if (!file.exists()) { return new ArrayList<Feature>(); }/*from w w w . j a va2s . co m*/ Document document = null; try { document = XMLUtil.loadXmlFile(file); } catch (DocumentException e) { e.printStackTrace(); return null; } Element rootElement = document.getRootElement(); List<Element> featureElementList = rootElement.elements("feature"); return parseFeature2(featureElementList); }
From source file:com.apicloud.commons.model.Feature.java
License:Open Source License
public static List<Feature> loadXml3(File file) { if (!file.exists()) { return new ArrayList<Feature>(); }//from w w w . j a v a 2s . c o m Document document = null; try { document = XMLUtil.loadXmlFile(file); } catch (DocumentException e) { e.printStackTrace(); return null; } Element rootElement = document.getRootElement(); List<Element> featureElementList = rootElement.elements("feature"); return parseFeature3(featureElementList); }
From source file:com.apicloud.commons.model.Feature.java
License:Open Source License
private static List<Feature> parseFeature2(List<Element> featureElementList) { List<Feature> features = new ArrayList<Feature>(); for (Element pref : featureElementList) { Feature feature = new Feature(); String name = pref.attributeValue("name"); String desc = pref.attributeValue("desc"); String isAndroid = pref.attributeValue("isAndroid"); String isIos = pref.attributeValue("isIOS"); String type = pref.attributeValue("type"); feature.setName(name);/*from w w w. j a v a 2 s .c om*/ feature.setDesc(desc); feature.setAndroid(Boolean.parseBoolean(isAndroid)); feature.setIos(Boolean.parseBoolean(isIos)); feature.setType(type); List<Element> paramsLists = pref.elements("param"); for (Element pelement : paramsLists) { Param param = new Param(); String pname = pelement.attributeValue("name"); String pvalue = pelement.attributeValue("value"); param.setName(pname); param.setValue(pvalue); feature.addParams(param); } features.add(feature); } return features; }
From source file:com.apicloud.commons.model.Feature.java
License:Open Source License
private static List<Feature> parseFeature3(List<Element> featureElementList) { List<Feature> features = new ArrayList<Feature>(); for (Element pref : featureElementList) { Feature feature = new Feature(); String name = pref.attributeValue("name"); feature.setName(name);/*w ww .ja va2 s. co m*/ List<Element> paramsLists = pref.elements("param"); for (Element pelement : paramsLists) { Param param = new Param(); String pname = pelement.attributeValue("name"); String pvalue = pelement.attributeValue("value"); param.setName(pname); param.setValue(pvalue); feature.addParams(param); } features.add(feature); } return features; }
From source file:com.appdynamics.monitors.hbase.HBaseMonitor.java
License:Apache License
private void getCredentials(final Map<String, String> args) { credentials = new ArrayList<Credential>(); Credential cred = new Credential(); cred.dbname = args.get("dbname"); cred.host = args.get("host"); cred.port = args.get("port"); cred.username = args.get("user"); cred.password = args.get("pass"); if (!isNotEmpty(cred.dbname)) { cred.dbname = "DB 1"; }//from w ww. ja v a2 s. c o m credentials.add(cred); String xmlPath = args.get("properties-path"); if (isNotEmpty(xmlPath)) { try { SAXReader reader = new SAXReader(); Document doc = reader.read(xmlPath); Element root = doc.getRootElement(); for (Element credElem : (List<Element>) root.elements("credentials")) { cred = new Credential(); cred.dbname = credElem.elementText("dbname"); cred.host = credElem.elementText("host"); cred.port = credElem.elementText("port"); cred.username = credElem.elementText("user"); cred.password = credElem.elementText("pass"); if (isNotEmpty(cred.host) && isNotEmpty(cred.port)) { if (!isNotEmpty(cred.dbname)) { cred.dbname = "DB " + (credentials.size() + 1); } credentials.add(cred); } } } catch (DocumentException e) { logger.error("Cannot read '" + xmlPath + "'. Monitor is running without additional credentials"); } } }
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 ww w . java 2 s . co m*/ * @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.arc.cdt.debug.seecode.core.launch.CMPDInfoFromVDKConfigReader.java
License:Open Source License
@SuppressWarnings("unchecked") private static void appendLaunchSwitches(List<String> switchList, List<String> startupCommands, Element launch) { List<Element> switches = launch.elements("SWITCH"); for (Element e : switches) { String data = e.getTextTrim(); if (data.startsWith("-multifiles=")) { // Do nothing } else if (data.equals("-OKN")) { // Do nothing } else if (data.startsWith("-cmd=")) { startupCommands.add(data.substring(5)); } else//from www.j a va 2s . c om switchList.add(data); } }
From source file:com.arc.cdt.debug.seecode.core.launch.CMPDInfoFromVDKConfigReader.java
License:Open Source License
@SuppressWarnings("unchecked") private static ICMPDInfo.IProcess formProcess(Element e, File workingDir, final IProject project) throws DocumentException { List<Element> switches = e.elements("SWITCH"); final String name = e.attributeValue("name"); final List<String> args = new ArrayList<String>(switches.size()); ProcessIdList plist = null;/*from w w w. j a v a2 s. com*/ boolean exeArgsPending = false; final List<String> exeCommand = new ArrayList<String>(); for (Element s : switches) { String arg = s.getTextTrim(); if (arg.startsWith("-pset=")) { try { plist = ProcessIdList.create(arg.substring(6)); } catch (NumberFormatException x) { throw new DocumentException("Bogus -pset value: " + arg.substring(6) + ": " + x.getMessage()); } } else if (arg.startsWith("-psetname=")) { // Do nothing; process name already known } else if (arg.equals("--") && exeCommand.size() == 1) { exeArgsPending = true; } else if (arg.startsWith("-") && !exeArgsPending) { args.add(arg); } else if (exeCommand.size() > 0 && !exeArgsPending) { throw new DocumentException("Multiple exe path specified: " + exeCommand.get(0) + " and " + arg); } else exeCommand.add(arg); } if (exeCommand.size() == 0) { throw new DocumentException("exe path missing for process " + name); } if (!new File(exeCommand.get(0)).isAbsolute() && workingDir != null) { String file = new File(workingDir, exeCommand.get(0)).toString(); exeCommand.set(0, file.replaceAll("\\\\", "/")); } if (new File(exeCommand.get(0)).isAbsolute() && project != null) { // Make absolute paths relative to project if possible. IPath exePath = new Path(exeCommand.get(0)); IPath projectPath = project.getLocation(); if (projectPath.isPrefixOf(exePath)) { exePath = exePath.setDevice(null).removeFirstSegments(projectPath.segmentCount()); exeCommand.set(0, exePath.toString()); } } List<Element> props = e.elements("property"); final Map<String, String> properties = new HashMap<String, String>(); if (props != null) { for (Element p : props) { String key = p.attributeValue("name"); String value = p.attributeValue("value"); if (key != null && value != null && key.length() > 0) { properties.put(key, value); } } } final ProcessIdList plistCopy = plist; return new ICMPDInfo.IProcess() { @Override public String[] getCommand() { return exeCommand.toArray(new String[exeCommand.size()]); } @Override public int getInstanceCount() { return plistCopy.getCount(); } @Override public ProcessIdList getIDList() { return plistCopy; } @Override public String getProcessName() { return name; } @Override public IProject getProject() { return project; } @Override public String[] getSwahiliArgs() { return args.toArray(new String[args.size()]); } @Override public Map<String, String> getGuihiliProperties() { return properties; } }; }
From source file:com.arc.intro.CompilerSamplesProvider.java
License:Open Source License
private String getProjectDescription(Element cat, File projectFile) { List<Element> projects = Cast.toType(cat.elements(PROJECT_TAG)); String projectName = projectFile.getName(); for (Element projectElement : projects) { if (projectName.equals(projectElement.attributeValue(NAME_ATTR, null))) { return projectElement.getTextTrim(); }//from w w w . ja v a 2 s .c om } File readmeFile = new File(projectFile, "README.txt"); if (readmeFile.exists()) { try { FileReader reader = new FileReader(readmeFile); BufferedReader input = new BufferedReader(reader); StringBuilder buf = new StringBuilder(); String line = input.readLine(); while (line != null) { buf.append(line); buf.append("\n"); line = input.readLine(); } return buf.toString(); } catch (IOException e) { //couldn't read the "README.txt" file. } } return ""; }
From source file:com.aricojf.util.ConfigParser.java
/** * ??/* www.java 2s .c o m*/ * ?String "/?/?" * ep: "config/conn/user" * @return */ public static String parseConfigParmByPath(String configFilePath, String nodes) { value = ""; FileInputStream fs = null; File file = new File(configFilePath); if (file.exists()) { file = null; try { fs = new FileInputStream(configFilePath); SAXReader reader = new SAXReader(); org.dom4j.Document document = reader.read(fs); org.dom4j.Element element = document.getRootElement(); String[] nod = nodes.trim().split(FILE_SEPARATOR); for (int i = 1; i < nod.length; i++) { List<Element> elements = element.elements(nod[i]); /** * ??????? * ??xml????? */ for (Element ele : elements) { element = ele; value = ele.getText(); break; } } } catch (Exception e) { e.printStackTrace(); } finally { closeConn(fs); } } return null == value ? "" : value; }