private static JSONObject recursive(Element parentElement) { List<Element> childElements = parentElement.elements(); JSONObject jsonObject = new JSONObject(); for (Element childElement : childElements) { String attributeValue = childElement.attributeValue(CLASS); if (LIST_CLASS_ATTRIBUTE.contains(attributeValue)) { List<Element> elements = childElement.elements(); JSONArray jsonArray = new JSONArray(); for (Element element : elements) { jsonArray.add(recursive(element)); } jsonObject.element(childElement.getName(), jsonArray); } else { if (!childElement.elements().isEmpty()) { JSONObject recursive = recursive(childElement); jsonObject.accumulate(childElement.getName(), recursive); } else { jsonObject.accumulate(childElement.getName(), childElement.getTextTrim()); } } } return jsonObject; }
public void testWithMultiMap() throws Exception { Map someMap = new HashMap(); someMap.put("M", "Male"); someMap.put("F", "Female"); this.bean.setSomeMap(someMap); this.tag.setPath("someMap"); this.tag.setItems("${sexes}"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getWriter().toString(); output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals(2, rootElement.elements().size()); Element selectElement = rootElement.element("select"); assertEquals("select", selectElement.getName()); assertEquals("someMap", selectElement.attribute("name").getValue()); List children = selectElement.elements(); assertEquals("Incorrect number of children", 2, children.size()); String hdivValue = this.confidentiality ? "1" : "M"; Element e = (Element) selectElement.selectSingleNode("option[@value = '" + hdivValue + "']"); assertEquals("M node not selected", "selected", e.attribute("selected").getValue()); hdivValue = this.confidentiality ? "2" : "F"; e = (Element) selectElement.selectSingleNode("option[@value = '" + hdivValue + "']"); assertEquals("F node not selected", "selected", e.attribute("selected").getValue()); }
private void processIQ(Element doc) { log.debug("processIQ()..."); IQ packet; try { packet = getIQ(doc); } catch (IllegalArgumentException e) { log.debug("Rejecting packet. JID malformed", e); IQ reply = new IQ(); if (!doc.elements().isEmpty()) { reply.setChildElement(((Element) doc.elements().get(0)).createCopy()); } reply.setID(doc.attributeValue("id")); reply.setTo(session.getAddress()); String to = doc.attributeValue("to"); if (to != null) { reply.getElement().addAttribute("from", to); } reply.setError(PacketError.Condition.jid_malformed); session.process(reply); return; } // if (packet.getID() == null) { // // IQ packets MUST have an 'id' attribute // StreamError error = new StreamError( // StreamError.Condition.invalid_xml); // session.deliverRawText(error.toXML()); // session.close(); // return; // } packet.setFrom(session.getAddress()); router.route(packet); session.incrementClientPacketCount(); }
public void testMultiWithEmptyCollection() throws Exception { this.bean.setSomeList(new ArrayList()); this.tag.setPath("someList"); this.tag.setItems("${countries}"); this.tag.setItemValue("isoCode"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getWriter().toString(); output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals(2, rootElement.elements().size()); Element selectElement = rootElement.element("select"); assertEquals("select", selectElement.getName()); assertEquals("someList", selectElement.attribute("name").getValue()); assertEquals("multiple", selectElement.attribute("multiple").getValue()); List children = selectElement.elements(); assertEquals("Incorrect number of children", 4, children.size()); Element inputElement = rootElement.element("input"); assertNotNull(inputElement); }
public static Map<String, ArrayList<CmisProperty>> getCmisRepositoryProperties( Element feedEntry) { Map<String, ArrayList<CmisProperty>> infoServerList = new HashMap<String, ArrayList<CmisProperty>>(); ArrayList<CmisProperty> propsList = new ArrayList<CmisProperty>(); ArrayList<CmisProperty> propsCapabilities = new ArrayList<CmisProperty>(); ArrayList<CmisProperty> propsACLCapabilities = new ArrayList<CmisProperty>(); Element objectElement = feedEntry.element(CMISRA_REPO_INFO); if (objectElement != null) { List<Element> properties = objectElement.elements(); for (Element property : properties) { if (CMIS_REPO_CAPABILITES.equals(property.getQName())) { List<Element> props = property.elements(); for (Element prop : props) { propsCapabilities.add( new CmisProperty( null, null, null, prop.getName().replace("capability", ""), prop.getText())); } } else if (CMIS_REPO_ACL_CAPABILITES.equals(property.getQName())) { /*List<Element> props = property.elements(); for (Element prop : props) { propsACLCapabilities.add(new CmisProperty(null, null, null, prop.getName().replace("cmis:", ""), prop.getText())); }*/ } else { propsList.add(new CmisProperty(null, null, null, property.getName(), property.getText())); } } infoServerList.put(Server.INFO_GENERAL, propsList); infoServerList.put(Server.INFO_CAPABILITIES, propsCapabilities); infoServerList.put(Server.INFO_ACL_CAPABILITIES, propsACLCapabilities); } return infoServerList; }
public void testWithIntegerArray() throws Exception { this.tag.setPath("someIntegerArray"); Integer[] array = new Integer[50]; for (int i = 0; i < array.length; i++) { array[i] = new Integer(i); } this.tag.setItems(array); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getWriter().toString(); output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals(2, rootElement.elements().size()); Element selectElement = rootElement.element("select"); assertEquals("select", selectElement.getName()); assertEquals("someIntegerArray", selectElement.attribute("name").getValue()); List children = selectElement.elements(); assertEquals("Incorrect number of children", array.length, children.size()); Element e = (Element) selectElement.selectSingleNode("option[text() = '12']"); assertEquals("'12' node not selected", "selected", e.attribute("selected").getValue()); e = (Element) selectElement.selectSingleNode("option[text() = '34']"); assertEquals("'34' node not selected", "selected", e.attribute("selected").getValue()); }
private void loadDbConf(String dbConfClassPath) { try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); InputStream confInput = loader.getResourceAsStream(dbConfClassPath); SAXReader reader = new SAXReader(); Document doc = reader.read(confInput); Element root = doc.getRootElement(); this.timeBetweenEvictionRunsMillis = Long.parseLong(root.elementText("timeBetweenEvictionRunsMillis")); this.maxActive = Integer.parseInt(root.elementText("maxActive")); this.maxIdle = Integer.parseInt(root.elementText("maxIdle")); this.maxWait = Integer.parseInt(root.elementText("maxWait")); this.testWhileIdle = Boolean.parseBoolean(root.elementText("maxActive")); Element masterEle = root.element("masters"); Map<String, DbInfo> masterDbInfoMap = this.parseDbInfo(masterEle.elements()); Element slavesEle = root.element("slaves"); Map<String, DbInfo> slaveDbInfoMap = this.parseDbInfo(slavesEle.elements()); this.checkMasterSlave(masterDbInfoMap, slaveDbInfoMap); this.masterDbInfoMap.putAll(masterDbInfoMap); this.slaveDbInfoMap.putAll(slaveDbInfoMap); } catch (Exception e) { throw new RuntimeException("loadDbConf failed !" + e.getMessage()); } }
public void testWithMultiList() throws Exception { List list = new ArrayList(); list.add(Country.COUNTRY_UK); list.add(Country.COUNTRY_AT); this.bean.setSomeList(list); this.tag.setPath("someList"); this.tag.setItems("${countries}"); this.tag.setItemValue("isoCode"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getWriter().toString(); output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals(2, rootElement.elements().size()); Element selectElement = rootElement.element("select"); assertEquals("select", selectElement.getName()); assertEquals("someList", selectElement.attribute("name").getValue()); List children = selectElement.elements(); assertEquals("Incorrect number of children", 4, children.size()); String hdivValue = this.confidentiality ? "3" : "UK"; Element e = (Element) selectElement.selectSingleNode("option[@value = '" + hdivValue + "']"); assertEquals("UK node not selected", "selected", e.attribute("selected").getValue()); hdivValue = this.confidentiality ? "1" : "AT"; e = (Element) selectElement.selectSingleNode("option[@value = '" + hdivValue + "']"); assertEquals("AT node not selected", "selected", e.attribute("selected").getValue()); }
public void testHiddenElementOmittedOnDisabled() throws Exception { this.tag.setPath("stringArray"); this.tag.setItems(new Object[] {"foo", "bar", "baz"}); this.tag.setDisabled("true"); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element rootElement = document.getRootElement(); assertEquals( "Both tag and hidden element rendered incorrectly", 3, rootElement.elements().size()); Element spanElement = (Element) document.getRootElement().elements().get(0); Element checkboxElement = (Element) spanElement.elements().get(0); assertEquals("input", checkboxElement.getName()); assertEquals("checkbox", checkboxElement.attribute("type").getValue()); assertEquals("stringArray", checkboxElement.attribute("name").getValue()); assertEquals("checked", checkboxElement.attribute("checked").getValue()); assertEquals("disabled", checkboxElement.attribute("disabled").getValue()); assertEquals("foo", checkboxElement.attribute("value").getValue()); }
/** * 获取 HotelGeo 节点的版本。三个节点:Districts CommericalLocations LandmarkLocations * * @param hotelGeoElement * @return */ public String getHotelGeoVersion(Element hotelGeoElement) { StringBuffer sb = new StringBuffer(""); if (null == hotelGeoElement) { return ""; } List<Element> hgElement = hotelGeoElement.elements(); // 包括 Districts CommericalLocations LandmarkLocations if (null != hgElement && hgElement.size() > 0) { for (int i = 0; i < hgElement.size(); i++) { Element elment = hgElement.get(i); if (null != elment && null != elment.elements()) { for (int j = 0; j < elment.elements().size(); j++) { Element node = (Element) elment.elements().get(j); if (null != node && null != node.attributes()) { for (int a = 0; a < node.attributes().size(); a++) { Attribute att = (Attribute) node.attributes().get(a); sb.append(att.getName()).append(att.getValue()); } } } } } } try { return MD5.encode(sb.toString()); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ""; }
@SuppressWarnings("unchecked") public static Properties getProperties(String persistenceFile, String persistenceUnit) { Properties properties = new Properties(); SAXReader reader = new SAXReader(); InputStream is = null; try { Document doc; is = XMLPersistenceUtil.class.getClassLoader().getResourceAsStream(persistenceFile); doc = reader.read(is); Element root = doc.getRootElement(); List<Element> elements = root.elements(); for (Element el : elements) { if (persistenceUnit.equals(el.attributeValue("name"))) { // this is the persistence unit specified, let's get all properties inside Element propsElement = el.element("properties"); List<Element> xmlProps = propsElement.elements("property"); for (Element prop : xmlProps) { properties.put(prop.attributeValue("name"), prop.attributeValue("value")); } } } } catch (DocumentException e) { _log.error("Failed to read file contents for " + persistenceFile, e); return null; } finally { if (is != null) try { is.close(); } catch (Exception e) { // do nothing } ; } return properties; }
private void verifyFileSystem(File teamsXmlFile, boolean nopublic) { assertTrue("teams.xml".equals(teamsXmlFile.getName())); numberOfTeamsXmls++; File teamsDir = teamsXmlFile.getParentFile(); File homeDir = teamsDir.getParentFile(); try { SAXReader reader = new SAXReader(); Document inDoc = reader.read(teamsXmlFile); Element root = inDoc.getRootElement(); assertTrue("teamManager".equals(root.getName())); List<Element> elements = (List<Element>) root.elements(); for (Element element : elements) { if ("team".equals(element.getName())) { List<Element> children = (List<Element>) element.elements(); File teamDir = null; for (Element child : children) { String childName = child.getName(); if ("name".equals(childName)) { // team must exist if ("public".equals(child.getText())) { if (nopublic) { assertTrue("Public team found", false); } teamDir = homeDir; } else { teamDir = new File(teamsDir, child.getText()); } assertTrue("Not exists " + teamDir.getAbsolutePath(), teamDir.exists()); assertTrue("Not a dir " + teamDir.getAbsolutePath(), teamDir.isDirectory()); } else if ("job".equals(childName)) { // we expect team name to be written before jobs assertNotNull(teamDir); Element idElement = child.element("id"); assertNotNull(idElement); String id = idElement.getText(); File jobDir = new File(new File(teamDir, "jobs"), id); assertTrue("Not exists " + jobDir.getAbsolutePath(), jobDir.exists()); assertTrue("Not exists " + jobDir.getAbsolutePath(), jobDir.isDirectory()); } } } } if (nopublic) { File jobsDir = new File(homeDir, "jobs"); if (jobsDir.exists() && jobsDir.isDirectory()) { for (File file : jobsDir.listFiles()) { if (file.isDirectory()) { assertTrue("Public job found at " + file.getAbsolutePath(), false); } } } } } catch (DocumentException ex) { Logger.getLogger(FindTest.class.getName()).log(Level.SEVERE, null, ex); } }
/** * 根据百度音乐返回的流解析出音乐信息 * * @param inputStream 输入流 * @return Music */ @SuppressWarnings("unchecked") private static Music parseMusicFromInputStream(InputStream inputStream) { Music music = null; try { // 通过SAX解析输入流 SAXReader reader = new SAXReader(); Document document = reader.read(inputStream); // 得到xml根元素 Element root = document.getRootElement(); // count表示搜索到的歌曲数 Element countElement = root.element(BaiduMusicUtil.ELEMENT_COUNT); String count = countElement.getText(); // 当搜索到的歌曲数大于0时 if (!"0".equals(count)) { // 普通音质 List<Element> urlList = root.elements(BaiduMusicUtil.ELEMENT_URL); // 高级音质 List<Element> durlList = root.elements(BaiduMusicUtil.ELEMENT_DURL); // 得到普通音质的url String urlEncode = urlList.get(0).element(BaiduMusicUtil.ELEMENT_ENCODE).getText(); String urlDecode = urlList.get(0).element(BaiduMusicUtil.ELEMENT_DECODE).getText(); // 普通音质url String url = urlEncode.substring(0, urlEncode.lastIndexOf("/") + 1) + urlDecode; if (-1 != urlDecode.lastIndexOf("&")) url = urlEncode.substring(0, urlEncode.lastIndexOf("/") + 1) + urlDecode.substring(0, urlDecode.lastIndexOf("&")); // 默认情况下,高音质的url = 低品质的url String durl = url; Element durlElement = durlList.get(0).element(BaiduMusicUtil.ELEMENT_ENCODE); // 如果结果中存在高音质的节点 if (null != durlElement) { String durlEncode = durlList.get(0).element(BaiduMusicUtil.ELEMENT_ENCODE).getText(); String durlDecode = durlList.get(0).element(BaiduMusicUtil.ELEMENT_DECODE).getText(); // 高级音质url durl = durlEncode.substring(0, durlEncode.lastIndexOf("/") + 1) + durlDecode; if (-1 != durlDecode.lastIndexOf("&")) durl = durlEncode.substring(0, durlEncode.lastIndexOf("/") + 1) + durlDecode.substring(0, durlDecode.lastIndexOf("&")); } music = new Music(); music.setMusicUrl(url); music.setHQMusicUrl(durl); } } catch (Exception e) { log.error("{}", e); } return music; }
public void testWithMultiValueWithFormatter() throws Exception { this.tag.setPath("stringArray"); this.tag.setItems(new Object[] {" foo", " bar", " baz"}); BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(this.bean, COMMAND_NAME); FormattingConversionService cs = new FormattingConversionService(); cs.addFormatterForFieldType( String.class, new Formatter<String>() { public String print(String object, Locale locale) { return object; } public String parse(String text, Locale locale) throws ParseException { return text.trim(); } }); bindingResult.initConversion(cs); getPageContext() .getRequest() .setAttribute(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, bindingResult); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element spanElement1 = (Element) document.getRootElement().elements().get(0); Element checkboxElement1 = (Element) spanElement1.elements().get(0); assertEquals("input", checkboxElement1.getName()); assertEquals("checkbox", checkboxElement1.attribute("type").getValue()); assertEquals("stringArray", checkboxElement1.attribute("name").getValue()); assertEquals("checked", checkboxElement1.attribute("checked").getValue()); assertEquals(" foo", checkboxElement1.attribute("value").getValue()); Element spanElement2 = (Element) document.getRootElement().elements().get(1); Element checkboxElement2 = (Element) spanElement2.elements().get(0); assertEquals("input", checkboxElement2.getName()); assertEquals("checkbox", checkboxElement2.attribute("type").getValue()); assertEquals("stringArray", checkboxElement2.attribute("name").getValue()); assertEquals("checked", checkboxElement2.attribute("checked").getValue()); assertEquals(" bar", checkboxElement2.attribute("value").getValue()); Element spanElement3 = (Element) document.getRootElement().elements().get(2); Element checkboxElement3 = (Element) spanElement3.elements().get(0); assertEquals("input", checkboxElement3.getName()); assertEquals("checkbox", checkboxElement3.attribute("type").getValue()); assertEquals("stringArray", checkboxElement3.attribute("name").getValue()); assertNull("not checked", checkboxElement3.attribute("checked")); assertEquals(" baz", checkboxElement3.attribute("value").getValue()); }
public State(Element e) { this.status = Integer.parseInt(e.attributeValue(STATUS)); for (Object o : e.elements(TRANSITION)) { Element t = (Element) o; transitions.add(new Integer(t.attributeValue(STATUS))); } for (Object o : e.elements(FIELD)) { Element f = (Element) o; String fieldName = f.attributeValue(NAME); fields.put(Field.convertToName(fieldName), new Integer(f.attributeValue(MASK))); } }
/** * 根据相对于父节点的子节点路径,查询子节点列表 * * @param parent 父节点 * @param childrenPath 子节点路径 * @return children 子节点列表 */ public static List children(Element parent, String childrenPath) { int slashLoc = childrenPath.lastIndexOf('/'); Element child = child(parent, childrenPath.substring(0, slashLoc)); if (child == null) return Collections.EMPTY_LIST; String childrenName = childrenPath.substring(slashLoc + 1); List children; if (childrenName.equals("*")) { children = child.elements(); } else { children = child.elements(childrenName); } return children; }
public void testWithMultiValueArrayAndDynamicAttributes() throws Exception { String dynamicAttribute1 = "attr1"; String dynamicAttribute2 = "attr2"; this.tag.setPath("stringArray"); this.tag.setItems(new Object[] {"foo", "bar", "baz"}); this.tag.setDynamicAttribute(null, dynamicAttribute1, dynamicAttribute1); this.tag.setDynamicAttribute(null, dynamicAttribute2, dynamicAttribute2); int result = this.tag.doStartTag(); assertEquals(Tag.SKIP_BODY, result); String output = getOutput(); // wrap the output so it is valid XML output = "<doc>" + output + "</doc>"; SAXReader reader = new SAXReader(); Document document = reader.read(new StringReader(output)); Element spanElement1 = (Element) document.getRootElement().elements().get(0); Element checkboxElement1 = (Element) spanElement1.elements().get(0); assertEquals("input", checkboxElement1.getName()); assertEquals("checkbox", checkboxElement1.attribute("type").getValue()); assertEquals("stringArray", checkboxElement1.attribute("name").getValue()); assertEquals("checked", checkboxElement1.attribute("checked").getValue()); assertEquals("foo", checkboxElement1.attribute("value").getValue()); assertEquals("foo", spanElement1.getStringValue()); assertEquals(dynamicAttribute1, checkboxElement1.attribute(dynamicAttribute1).getValue()); assertEquals(dynamicAttribute2, checkboxElement1.attribute(dynamicAttribute2).getValue()); Element spanElement2 = (Element) document.getRootElement().elements().get(1); Element checkboxElement2 = (Element) spanElement2.elements().get(0); assertEquals("input", checkboxElement2.getName()); assertEquals("checkbox", checkboxElement2.attribute("type").getValue()); assertEquals("stringArray", checkboxElement2.attribute("name").getValue()); assertEquals("checked", checkboxElement2.attribute("checked").getValue()); assertEquals("bar", checkboxElement2.attribute("value").getValue()); assertEquals("bar", spanElement2.getStringValue()); assertEquals(dynamicAttribute1, checkboxElement2.attribute(dynamicAttribute1).getValue()); assertEquals(dynamicAttribute2, checkboxElement2.attribute(dynamicAttribute2).getValue()); Element spanElement3 = (Element) document.getRootElement().elements().get(2); Element checkboxElement3 = (Element) spanElement3.elements().get(0); assertEquals("input", checkboxElement3.getName()); assertEquals("checkbox", checkboxElement3.attribute("type").getValue()); assertEquals("stringArray", checkboxElement3.attribute("name").getValue()); assertNull("not checked", checkboxElement3.attribute("checked")); assertEquals("baz", checkboxElement3.attribute("value").getValue()); assertEquals("baz", spanElement3.getStringValue()); assertEquals(dynamicAttribute1, checkboxElement3.attribute(dynamicAttribute1).getValue()); assertEquals(dynamicAttribute2, checkboxElement3.attribute(dynamicAttribute2).getValue()); }
private List<Method> parseMethods(List nodes, Node parent) { List<Method> methods = new ArrayList<Method>(nodes.size()); for (Element node : (List<Element>) nodes) { Method method = new Method(); method.setName(node.attributeValue("name")); method.setParent(parent); DocResult docResult = parseDoc(node, method); method.setReturntype(node.attributeValue("returntype")); method.setArgs(parseFields(node.elements("arg"), docResult, method)); method.setExs(parseFields(node.elements("ex"), docResult, method)); methods.add(method); } return methods; }
/** 使用Dom4j验证Jaxb所生成XML的正确性. */ private static void assertXmlByDom4j(String xml) { Document doc = null; try { doc = DocumentHelper.parseText(xml); } catch (DocumentException e) { fail(e.getMessage()); } Element user = doc.getRootElement(); assertThat(user.attribute("id").getValue()).isEqualTo("1"); Element interests = (Element) doc.selectSingleNode("//interests"); assertThat(interests.elements()).hasSize(2); assertThat(((Element) interests.elements().get(0)).getText()).isEqualTo("movie"); }
private List<Enum> parseEnums(Element el, Node parent) { if (el == null) { return Collections.EMPTY_LIST; } List<Element> nodes = el.elements(); List<Enum> enums = new ArrayList<Enum>(nodes.size()); for (Element node : nodes) { Enum e = new Enum(); e.setName(node.attributeValue("name")); e.setParent(parent); e.setFields(parseFields(node.elements("item"), parseDoc(node, e), e)); enums.add(e); } return enums; }
/* * 配置窗口参数 * * @param frame 配置文件的窗口配置元素 */ @SuppressWarnings("unchecked") public FrameConfig(Element frame){ this.width = Integer.parseInt(frame.attributeValue("width")); this.height = Integer.parseInt(frame.attributeValue("height")); this.padding = Integer.parseInt(frame.attributeValue("padding")); this.size = Integer.parseInt(frame.attributeValue("size")); this.up = Integer.parseInt(frame.attributeValue("up")); this.title = frame.attributeValue("title"); this.sizeRol = Integer.parseInt(frame.attributeValue("sizeRol")); this.loseIdx = Integer.parseInt(frame.attributeValue("loseIdx")); List<Element> bars = frame.elements("bars"); barConfig = new ArrayList<BarsConfig>(); for(Element bar : bars){ BarsConfig bc = new BarsConfig( bar.attributeValue("class"), Integer.parseInt(bar.attributeValue("x")), Integer.parseInt(bar.attributeValue("y")), Integer.parseInt(bar.attributeValue("w")), Integer.parseInt(bar.attributeValue("h")) ); barConfig.add(bc); }; this.btnConfig = new BtnConfig(frame.element("button")); }
/** * Sets the new list items based on the specified Element. The Element must contain a list of item * elements. * * @param listElement the element containing a list of items. * @param notify true if a provicy list modified event will be triggered. */ private void updateList(Element listElement, boolean notify) { // Reset the list of items of this list items = new ArrayList<PrivacyItem>(); List<Element> itemsElements = listElement.elements("item"); for (Element itemElement : itemsElements) { PrivacyItem newItem = new PrivacyItem(itemElement); items.add(newItem); // If the user's roster is required to evaluation whether a packet must be blocked // then ensure that the roster is available if (newItem.isRosterRequired()) { Roster roster = getRoster(); if (roster == null) { Log.warn("Privacy item removed since roster of user was not found: " + userJID.getNode()); items.remove(newItem); } } } // Sort items collections Collections.sort(items); if (notify) { // Trigger event that this list has been modified PrivacyListManager.getInstance().dispatchModifiedEvent(this); } }
private void buildRelaMap(Element centerNode) { String concept = centerNode.elementText("Label"); Element relaXML = ConceptEngine.getContent(concept, "关联词"); // <result db="中医药学语言系统" rela="被…使用">论利湿清热</result> String objectUri = ConceptEngine.skosPrefix + "#Concept"; List relas = relaXML.elements(); for (int i = 0; i < relas.size() && i < count; i++) { Element rela = (Element) relas.get(i); String content = rela.getText(); Element node = null; Boolean isNewNode = true; if (nodes.containsKey(content)) { Element e = (Element) nodes.get(content); if (e.elementText("TypeUri").equals(objectUri)) { isNewNode = false; node = e; } } if (isNewNode) { node = nodeArray.addElement("Node").addAttribute("id", nodeID++ + ""); node.addElement("Label").addText(content); node.addElement("TypeUri").addText(objectUri); node.addElement("Type").addText("事物"); nodes.put(content, node); } Element edge = edgeArray.addElement("Edge").addAttribute("id", edgeID++ + ""); edge.addElement("Label").addText(rela.attributeValue("rela")); edge.addElement("TypeUri").addText("rela"); edge.addElement("FromID").addText(centerNode.attributeValue("id")); edge.addElement("ToID").addText(node.attributeValue("id")); } }
public static Map<String, CmisProperty> getCmisPropertiesForEntry(Element feedEntry) { Map<String, CmisProperty> props = new HashMap<String, CmisProperty>(); Element objectElement = feedEntry.element(CMISRA_OBJECT); if (objectElement != null) { Element properitesElement = objectElement.element(CMIS_PROPERTIES); if (properitesElement != null) { List<Element> properties = properitesElement.elements(); for (Element property : properties) { final String id = property.attributeValue("propertyDefinitionId"); props.put( id, new CmisProperty( property.getName(), id, property.attributeValue("localName"), property.attributeValue("displayName"), property.elementText(CMIS_VALUE))); } } } return props; }
public void updateStatus(String message) { RequestReader reader = new RequestReader(message); Element root = reader.getRoot(); List<Element> resources = root.elements("Resource"); // 在线列表 List<String> onlineSns = new LinkedList<String>(); // 离线列表 List<String> offlineSns = new LinkedList<String>(); for (Element resource : resources) { if (TypeDefinition.STATUS_ONLINE.equals(resource.attributeValue("Status"))) { onlineSns.add(resource.attributeValue("SN")); } else { offlineSns.add(resource.attributeValue("SN")); } } // 获取所有的设备ID,key为SN, value为ID Map<String, Long> svDeviceMap = svDeviceManager.mapBySn(); Map<String, Long> tmDeviceMap = tmDeviceManager.mapBySn(); svDeviceMap.putAll(tmDeviceMap); if (onlineSns.size() > 0) { onlineManager.reportOnline(onlineSns, svDeviceMap); } if (offlineSns.size() > 0) { onlineManager.reportOffline(offlineSns); } }
/** * 获得指定元素下的某个子元素 * * @param element 指定元素 * @param idOrText id或者text的值 * @param type 根据id找?还是text? * @return 子元素 */ public static Element getElement(Element element, String idOrTextString, TiHuanType type) { Element re = null; List<?> list = element.elements(); for (Iterator<?> its = list.iterator(); its.hasNext(); ) { if (re != null) { break; } Element chileEle = (Element) its.next(); String ls = null; if (type == TiHuanType.ID) { ls = chileEle.attributeValue("tihuan"); } if (type == TiHuanType.TEXT) { ls = chileEle.getText(); } if (ls != null && ls.equals(idOrTextString)) { re = chileEle; } else { re = getElement(chileEle, idOrTextString, type); } } return re; }
@Override public void addInitDatas() { try { // 从类路径的根目录中读取指定的包含初始化数据的XML文件 Document document = new SAXReader() .read(Thread.currentThread().getContextClassLoader().getResourceAsStream(path)); // 文档根元素 Element root = document.getRootElement(); // 从文档根元素中提取出实体类所在的包名 String pkg = root.attributeValue("package"); // 得到根元素下面包含的所有的entity元素 List entityElements = root.elements("entity"); for (Iterator iterator = entityElements.iterator(); iterator.hasNext(); ) { Element entityElement = (Element) iterator.next(); addEntity(pkg, entityElement, null, null); } // 重建所有的ActionResource资源 ResourceService resourceService = (ResourceService) factory.getBean("resourceService"); resourceService.rebuildActionResources(); // initDao.addInitAdmin(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
/** * 根据参数给类赋值 * * @param object * @param type * @param field_name * @param element * @return */ private static Object newObjectByType( Object object, String type, String field_name, Element element) { try { if (type.endsWith("java.lang.String")) { // 处理String类型 PropertyUtils.setProperty(object, field_name, element.getText()); } else if (type.endsWith("java.lang.Integer")) { // 处理integer System.out.println(type.endsWith("java.lang.Integer")); PropertyUtils.setProperty(object, field_name, Integer.parseInt(element.getText())); } else if (type.endsWith("java.util.Set")) { Set set = new HashSet(); // 处理set List<Element> e_list = element.elements(); for (Iterator iterator = e_list.iterator(); iterator.hasNext(); ) { Element object2 = (Element) iterator.next(); generateBean(object2); set.add(generateBean(object2)); PropertyUtils.setProperty(object, field_name, set); } } else if (type.startsWith(domain_package)) { if (getBeanById(element) != null) { Class cls = Class.forName(domain_package_dot + element.getName()); PropertyUtils.setProperty( object, field_name.toLowerCase(), cls.cast(getBeanById(element))); } } } catch (Exception e) { log.error(domain_package_dot + element.getName() + "类不存在", e); } return object; }
@SuppressWarnings("unchecked") @Override protected void initial_internal(Element rootElement) { Element EventKeyElement = rootElement.element("EventKey"); if (EventKeyElement != null) { this.eventKey = EventKeyElement.getTextTrim(); } Element SendPicsInfoElement = rootElement.element("SendPicsInfo"); if (SendPicsInfoElement == null) { return; } Element CountElement = SendPicsInfoElement.element("Count"); if (CountElement != null) { this.count = (CountElement != null && CountElement.getTextTrim() != null && !CountElement.getTextTrim().equals("")) ? Integer.parseInt(CountElement.getTextTrim()) : 0; } Element PicListElement = SendPicsInfoElement.element("PicList"); if (PicListElement == null) { return; } List<Element> itemElements = PicListElement.elements("item"); if (itemElements != null && itemElements.size() > 0) { for (Element itemElement : itemElements) { Element PicMd5SumElement = itemElement.element("PicMd5Sum"); if (PicMd5SumElement != null) { this.addPicMd5Sum(PicMd5SumElement.getTextTrim()); } } } }
public void updateXMLbyId(String id, UpLoadFile pat) { String xmlStr = xml2String(); Document document = null; try { document = DocumentHelper.parseText(xmlStr); } catch (DocumentException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } Element rootElement = document.getRootElement(); String rootStrV = rootElement.getStringValue(); String rootStrT = rootElement.getText(); List<Element> elements = rootElement.elements("file"); for (Element ele : elements) { Element ide = ele.element("id"); if (id.equalsIgnoreCase(ide.getTextTrim())) { Element nameElement = ele.element("name"); Element crcElement = ele.element("crc"); Element urlElement = ele.element("url"); Element pathElement = ele.element("path"); Element isUpElement = ele.element("isUpFastFDS"); nameElement.setText(pat.getName()); crcElement.setText(pat.getCrc()); urlElement.setText(pat.getUrl()); pathElement.setText(pat.getPath()); isUpElement.setText(pat.getIsUpFastFDS()); } } writeXML(file, document); }