List of usage examples for org.dom4j Element attributeValue
String attributeValue(QName qName);
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);// www.java 2s .co m 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 . j a v a2 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.app.util.SettingUtils.java
License:Open Source License
/** * ?//from ww w .jav a 2 s . c om * * @return */ public static Setting get() { Ehcache cache = cacheManager.getEhcache(Setting.CACHE_NAME); net.sf.ehcache.Element cacheElement = cache.get(Setting.CACHE_KEY); Setting setting; if (cacheElement != null) { setting = (Setting) cacheElement.getObjectValue(); } else { setting = new 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) { String name = element.attributeValue("name"); String value = element.attributeValue("value"); try { beanUtils.setProperty(setting, name, value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } cache.put(new net.sf.ehcache.Element(Setting.CACHE_KEY, setting)); } return setting; }
From source file:com.app.util.SettingUtils.java
License:Open Source License
/** * //from ww w . j av a 2 s. com * * @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.apporiented.hermesftp.usermanager.impl.XmlFileReader.java
License:Open Source License
@SuppressWarnings("unchecked") private void processUserData(Document doc, UserManagerData umd) { Element usersElement = (Element) doc.selectSingleNode(XPATH_USERS); String defaultDir = usersElement.attributeValue(ATTR_DEFAULT_DIR); List<Element> userElements = usersElement.selectNodes(ELEM_USER); for (Element userElement : userElements) { String uid = userElement.attributeValue(ATTR_UID); String fullName = userElement.attributeValue(ATTR_FULLNAME); String password = userElement.attributeValue(ATTR_PASSWORD); String adminrole = userElement.attributeValue(ATTR_ADMINROLE); String dir = userElement.attributeValue(ATTR_DIR); if (dir == null || dir.length() == 0) { dir = defaultDir;/* www .j ava 2 s. co m*/ } UserData userData = new UserData(); userData.setFullName(fullName); userData.setUid(uid); userData.setPassword(password); userData.setAdminRole(Boolean.valueOf(adminrole)); userData.setDir(dir); List<Element> groupRefElements = userElement.selectNodes(ELEM_GROUP_REF); for (Element element : groupRefElements) { String groupRefName = element.attributeValue(ATTR_NAME); if (groupRefName != null) { userData.addGroupName(groupRefName.trim()); } } umd.getUserData().add(userData); } }
From source file:com.apporiented.hermesftp.usermanager.impl.XmlFileReader.java
License:Open Source License
@SuppressWarnings("unchecked") private void processGroupData(Document doc, UserManagerData umd) { List<Element> groupElements = doc.selectNodes(XPATH_GROUPS); for (Element groupElement : groupElements) { String name = groupElement.attributeValue(ATTR_NAME); GroupData groupData = new GroupData(); groupData.setName(name);//from w ww. j a va 2 s.c om List<Element> limitElements = groupElement.selectNodes(XPATH_LIMITS); for (Element limitElement : limitElements) { String limitName = limitElement.attributeValue(ATTR_NAME); String limitValue = limitElement.attributeValue(ATTR_VALUE); if (limitName != null && limitValue != null) { Long limitLong = new Long(limitValue); groupData.getLimits().put(limitName, limitLong); } } List<Element> permissionElements = groupElement.selectNodes(XPATH_PERMISSIONS); for (Element permissionElement : permissionElements) { String path = permissionElement.attributeValue(ATTR_PATH); /* value attribute is supported for backward compatibility */ String value = permissionElement.attributeValue(ATTR_VALUE); String flag = permissionElement.attributeValue(ATTR_FLAG); int permissionValue = getPermissionValue(value, flag); PermissionData pd = new PermissionData(); pd.setPermission(permissionValue); pd.setTemplate(path); groupData.getPermissions().add(pd); } umd.getGroupData().addGroup(groupData); } }
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// w w w . ja v a 2 s.c o 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 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;// w ww . j a va 2 s. c o m 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.cdt.debug.seecode.options.Condition.java
License:Open Source License
static Condition parse(Element e) { String name = e.getName().toLowerCase(); if (name.equals("equals") || name.equals("notequals")) { String propName = e.attributeValue("property"); String option = e.attributeValue("option"); String value = e.attributeValue("value"); if (value == null) throw new IllegalStateException("Value in SetIf condition is missing"); if (propName != null) { if (option != null) throw new IllegalStateException("Can't specify properyt and option in same SetIf condition"); return PropertyEquals(propName, value, name.charAt(0) == 'n'); }//www. j av a2 s. co m if (option == null) throw new IllegalStateException("Missing property or option in setIf \"equals\" condition"); return OptionEquals(option, value, name.charAt(0) == 'n'); } if (name.equals("and") || name.equals("or")) { @SuppressWarnings("unchecked") List<Element> kids = e.elements(); if (kids.size() < 2) throw new IllegalStateException("And/Or node in SetIf condition must have 2 or more kids"); Condition cond = parse(kids.get(0)); for (int i = 1; i < kids.size(); i++) { Condition cond2 = parse(kids.get(i)); if (name.charAt(0) == 'a') cond = And(cond, cond2); else cond = Or(cond, cond2); } return cond; } if (name.equals("not")) { @SuppressWarnings("unchecked") List<Element> kids = e.elements(); if (kids.size() != 1) throw new IllegalStateException("Not node in SetIf condition must have 2 or more kids"); Condition cond = parse(kids.get(0)); return Not(cond); } throw new IllegalStateException("Unknown SetIf condition node: " + name); }
From source file:com.arc.cdt.debug.seecode.options.SeeCodeOptionsAugmenter.java
License:Open Source License
private void handleSetIf(Element e) { // <setIf property=... value=...> conditions </setIf> String property = e.attributeValue("property"); String value = e.attributeValue("value"); if (property == null || property.length() == 0) throw new IllegalStateException("Missing property in setIf"); if (value == null) throw new IllegalStateException("Value is null in setIf"); @SuppressWarnings("unchecked") List<Element> kids = e.elements(); if (kids.size() != 1) { throw new IllegalStateException("setIf must have one and only one child element"); }/*from www.jav a2s . c o m*/ Condition cond = Condition.parse(kids.get(0)); mSetIfList.add(new SetIf(property, value, cond)); }