List of usage examples for org.dom4j Element attribute
Attribute attribute(QName qName);
From source file:hello.SampleSimpleApplication.java
License:Apache License
private void addAutoTile(Document domFromStream) { DOMElement autoTileElement1 = (DOMElement) domFromStream .selectSingleNode("/html/body//div[@id='page1-div']"); Element autoTileElement = autoTileElement1; if (autoTileElement != null) { autoTileElement.attribute("id").setValue("auto_tile_" + autoTileNr); changeImgUrl(autoTileElement);//w w w.j av a 2 s . co m addBreadcrumbBefore(autoTileElement1); cleanSymbols(autoTileElement); Element detach = (Element) autoTileElement.detach(); autoDocBody.add(detach); } else { //audi Element autoTileElementFromStream = (Element) domFromStream .selectSingleNode("/html/body/div/table//td[div/h2]"); changeImgUrl(autoTileElementFromStream); /* Element autoTileNameElement = (Element) autoTileElement2.selectSingleNode("div/h2"); autoTileNameElement.setText(autoTileName); * */ /* * */ List<Element> breadcrumOld = autoTileElementFromStream.selectNodes("div/h3"); for (Element element : breadcrumOld) { element.detach(); } autoTileElement = autoDocBody.addElement("div"); autoTileElement.addAttribute("id", "auto_tile_" + autoTileNr); addBreadcrumb(autoTileElement); cleanSymbols(autoTileElementFromStream); for (Iterator iterator = autoTileElementFromStream.elementIterator(); iterator.hasNext();) { Element element = (Element) iterator.next(); autoTileElement.add(element.detach()); } } /* neccesary * */ }
From source file:hello.W2j.java
License:Apache License
private void readNextAutoIndexList(String autoTileHref) { DOMDocument autoTileContextDom = null; try {/* w w w .j av a 2 s.c om*/ Document autoTileDom = getDomFromStream(autoTileHref); String indexHrefAdd = ((Attribute) autoTileDom.selectSingleNode("/html/body//iframe/@src")).getValue(); String hrefContent = autoTileHref + "" + indexHrefAdd; autoTileContextDom = getDomFromStream(hrefContent); } catch (Exception e) { List<Map<String, Object>> workIndexList = initIndexList(autoData); Map<String, Object> workContentItem = workIndexList.get(workIndexList.size() - 1); HashMap<String, Object> contextItem = new HashMap<String, Object>(); contextItem.put("text", "BAD PAGE"); contextItem.put("error", e.getMessage()); contextItem.put("url", autoTileHref); workIndexList.add(contextItem); logger.error(e.getMessage()); nextAutoTileElement = null; return; } if (autoTileContextDom == null) return; List<DOMElement> myPagePosition = (List<DOMElement>) autoTileContextDom .selectNodes("/html/body/div/p[@style and not(a)]"); if (myPagePosition.size() == 0) {//bad link auto tile page not exist logger.debug(nextAutoTileElement.asXML()); nextAutoTileElement = (DOMElement) nextAutoTileElement.getNextSibling(); logger.debug(nextAutoTileElement.asXML()); return; } Map<String, Object> contextItem = null; for (Element element : myPagePosition) { String text = element.getText(); String style = element.attribute("style").getValue(); String level = style.split(";")[0].split("padding-left:")[1].split("pt")[0]; int levelInt = Integer.parseInt(level) / 10; if (levelInt < 0 && !autoData.containsKey("autoName")) { autoData.put("autoName", text); } else if (levelInt >= 0) { int indexOfcurrent = text.indexOf(">>"); if (indexOfcurrent == 0) { levelInt = levelInt + 1; text = text.replace(">>", "").replace("<<", "").trim(); logger.debug(autoTileAllIndexNr + "/" + levelInt + " -- " + text); // logger.debug(autoTileIndexNr+"/"+autoTileAllIndexNr+"/"+levelInt+" -- "+text); } contextItem = new HashMap<String, Object>(); contextItem.put("text", text); Map<String, Object> workContentItem = autoData; List<Map<String, Object>> workIndexList = initIndexList(workContentItem); for (int i = 0; i < levelInt; i++) { if (workIndexList.size() == 0)//not skip level break; workContentItem = workIndexList.get(workIndexList.size() - 1); workIndexList = initIndexList(workContentItem); } workIndexList.add(contextItem); } } DOMElement lastElement = myPagePosition.get(myPagePosition.size() - 1); contextItem.put("url", autoTileHref); nextAutoTileElement = (DOMElement) lastElement.getNextSibling(); // nextAutoTileElement = getLastIndexElement(nextAutoTileElement); autoTileAllIndexNr++; }
From source file:info.jtrac.domain.Field.java
License:Apache License
public Field(Element e) { setName(e.attributeValue(NAME));//from w ww . j av a2s . co m label = e.attributeValue(LABEL); if (e.attribute(OPTIONAL) != null && e.attributeValue(OPTIONAL).equals(TRUE)) { optional = true; } for (Object o : e.elements(OPTION)) { addOption((Element) o); } }
From source file:javaapplication3.DataXmlWorker.java
private void setXmlData(ShortBuffer mem_data) { SAXReader reader = new SAXReader(); File f = new File(file_name_from_unit_); if (!f.exists()) { System.out.println("no data file " + file_name_from_unit_); }/*from www .j a va2s . com*/ try { Document document = reader.read(f); Element root = document.getRootElement().element("map"); // iterate through child elements of root for (Iterator i = root.elementIterator(); i.hasNext();) { Element element = (Element) i.next(); //System.out.println("addr[ " + element.attributeValue("addr") + "] = " + element.attributeValue("value")); int mem_adr = Integer.parseInt(element.attributeValue("addr")) - mem_shift_; //System.out.println("mem_adr = " + mem_adr); if (mem_adr < mem_data.limit()) { int data = mem_data.get(mem_adr); if (data < 0) data += 65536; //System.out.println("in put attr to xml int = " + data); element.attribute("value").setValue(Integer.toString(data)); } } // XMLWriter writer = new XMLWriter( new FileWriter( "output.xml" )); XMLWriter writer = new XMLWriter(new FileWriter(file_name_from_unit_)); writer.write(document); writer.close(); } catch (DocumentException ex) { System.out.println("Exeption: " + ex.getMessage()); Logger.getLogger(DataXmlWorker.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { System.out.println("Exeption: " + ex.getMessage()); Logger.getLogger(DataXmlWorker.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:job.tot.xml.DOM4JConfiguration.java
License:Apache License
private void clearXmlProperty(String name) { String[] nodes = StringUtils.split(name, NODE_DELIMITER); String attName = null;/*from w w w . j a v a 2 s . c o m*/ Element element = document.getRootElement(); for (int i = 0; i < nodes.length; i++) { String eName = nodes[i]; int index = eName.indexOf(ATTRIB_START_MARKER); if (index > -1) { attName = eName.substring(index + ATTRIB_START_MARKER.length(), eName.length() - 1); eName = eName.substring(0, index); } element = element.element(eName); if (element == null) { return; } } if (attName == null) { element.remove(element.element(nodes[nodes.length - 1])); } else { element.remove(element.attribute(attName)); } }
From source file:lineage2.gameserver.data.xml.parser.RestartPointParser.java
License:Open Source License
/** * Method readData.//from www . jav a 2 s .c o m * @param rootElement Element * @throws Exception */ @Override protected void readData(Element rootElement) throws Exception { List<Pair<Territory, Map<Race, String>>> restartArea = new ArrayList<>(); Map<String, RestartPoint> restartPoint = new HashMap<>(); for (Iterator<Element> iterator = rootElement.elementIterator(); iterator.hasNext();) { Element listElement = iterator.next(); if ("restart_area".equals(listElement.getName())) { Territory territory = null; Map<Race, String> restarts = new HashMap<>(); for (Iterator<Element> i = listElement.elementIterator(); i.hasNext();) { Element n = i.next(); if ("region".equalsIgnoreCase(n.getName())) { Rectangle shape; Attribute map = n.attribute("map"); String s = map.getValue(); String val[] = s.split("_"); int rx = Integer.parseInt(val[0]); int ry = Integer.parseInt(val[1]); int x1 = World.MAP_MIN_X + ((rx - Config.GEO_X_FIRST) << 15); int y1 = World.MAP_MIN_Y + ((ry - Config.GEO_Y_FIRST) << 15); int x2 = (x1 + (1 << 15)) - 1; int y2 = (y1 + (1 << 15)) - 1; shape = new Rectangle(x1, y1, x2, y2); shape.setZmin(World.MAP_MIN_Z); shape.setZmax(World.MAP_MAX_Z); if (territory == null) { territory = new Territory(); } territory.add(shape); } else if ("polygon".equalsIgnoreCase(n.getName())) { Polygon shape = ZoneParser.parsePolygon(n); if (!shape.validate()) { error("RestartPointParser: invalid territory data : " + shape + "!"); } if (territory == null) { territory = new Territory(); } territory.add(shape); } else if ("restart".equalsIgnoreCase(n.getName())) { Race race = Race.valueOf(n.attributeValue("race")); String locName = n.attributeValue("loc"); restarts.put(race, locName); } } if (territory == null) { throw new RuntimeException("RestartPointParser: empty territory!"); } if (restarts.isEmpty()) { throw new RuntimeException("RestartPointParser: restarts not defined!"); } restartArea.add(new ImmutablePair<>(territory, restarts)); } else if ("restart_loc".equals(listElement.getName())) { String name = listElement.attributeValue("name"); int bbs = Integer.parseInt(listElement.attributeValue("bbs", "0")); int msgId = Integer.parseInt(listElement.attributeValue("msg_id", "0")); List<Location> restartPoints = new ArrayList<>(); List<Location> PKrestartPoints = new ArrayList<>(); for (Iterator<Element> i = listElement.elementIterator(); i.hasNext();) { Element n = i.next(); if ("restart_point".equals(n.getName())) { for (Iterator<Element> ii = n.elementIterator(); ii.hasNext();) { Element d = ii.next(); if ("coords".equalsIgnoreCase(d.getName())) { Location loc = Location.parseLoc(d.attribute("loc").getValue()); restartPoints.add(loc); } } } else if ("PKrestart_point".equals(n.getName())) { for (Iterator<Element> ii = n.elementIterator(); ii.hasNext();) { Element d = ii.next(); if ("coords".equalsIgnoreCase(d.getName())) { Location loc = Location.parseLoc(d.attribute("loc").getValue()); PKrestartPoints.add(loc); } } } } if (restartPoints.isEmpty()) { throw new RuntimeException( "RestartPointParser: restart_points not defined for restart_loc : " + name + "!"); } if (PKrestartPoints.isEmpty()) { PKrestartPoints = restartPoints; } RestartPoint rp = new RestartPoint(name, bbs, msgId, restartPoints, PKrestartPoints); restartPoint.put(name, rp); } } for (Pair<Territory, Map<Race, String>> ra : restartArea) { Map<Race, RestartPoint> restarts = new HashMap<>(); for (Map.Entry<Race, String> e : ra.getValue().entrySet()) { RestartPoint rp = restartPoint.get(e.getValue()); if (rp == null) { throw new RuntimeException("RestartPointParser: restart_loc not found : " + e.getValue() + "!"); } restarts.put(e.getKey(), rp); getHolder().addRegionData(new RestartArea(ra.getKey(), restarts)); } } }
From source file:lineage2.gameserver.data.xml.parser.ZoneParser.java
License:Open Source License
/** * Method readData.// ww w. j a va 2 s .co m * @param rootElement Element * @throws Exception */ @Override protected void readData(Element rootElement) throws Exception { for (Iterator<Element> iterator = rootElement.elementIterator(); iterator.hasNext();) { StatsSet zoneDat = new StatsSet(); Element zoneElement = iterator.next(); if ("zone".equals(zoneElement.getName())) { zoneDat.set("name", zoneElement.attribute("name").getValue()); zoneDat.set("type", zoneElement.attribute("type").getValue()); Territory territory = null; boolean isShape; for (Iterator<Element> i = zoneElement.elementIterator(); i.hasNext();) { Element n = i.next(); if ("set".equals(n.getName())) { zoneDat.set(n.attributeValue("name"), n.attributeValue("val")); } else if ("restart_point".equals(n.getName())) { List<Location> restartPoints = new ArrayList<>(); for (Iterator<?> ii = n.elementIterator(); ii.hasNext();) { Element d = (Element) ii.next(); if ("coords".equalsIgnoreCase(d.getName())) { Location loc = Location.parseLoc(d.attribute("loc").getValue()); restartPoints.add(loc); } } zoneDat.set("restart_points", restartPoints); } else if ("PKrestart_point".equals(n.getName())) { List<Location> PKrestartPoints = new ArrayList<>(); for (Iterator<?> ii = n.elementIterator(); ii.hasNext();) { Element d = (Element) ii.next(); if ("coords".equalsIgnoreCase(d.getName())) { Location loc = Location.parseLoc(d.attribute("loc").getValue()); PKrestartPoints.add(loc); } } zoneDat.set("PKrestart_points", PKrestartPoints); } else if ((isShape = "rectangle".equalsIgnoreCase(n.getName())) || "banned_rectangle".equalsIgnoreCase(n.getName())) { Shape shape = parseRectangle(n); if (territory == null) { territory = new Territory(); zoneDat.set("territory", territory); } if (isShape) { territory.add(shape); } else { territory.addBanned(shape); } } else if ((isShape = "circle".equalsIgnoreCase(n.getName())) || "banned_cicrcle".equalsIgnoreCase(n.getName())) { Shape shape = parseCircle(n); if (territory == null) { territory = new Territory(); zoneDat.set("territory", territory); } if (isShape) { territory.add(shape); } else { territory.addBanned(shape); } } else if ((isShape = "polygon".equalsIgnoreCase(n.getName())) || "banned_polygon".equalsIgnoreCase(n.getName())) { Polygon shape = parsePolygon(n); if (!shape.validate()) { error("ZoneParser: invalid territory data : " + shape + ", zone: " + zoneDat.getString("name") + "!"); } if (territory == null) { territory = new Territory(); zoneDat.set("territory", territory); } if (isShape) { territory.add(shape); } else { territory.addBanned(shape); } } } if ((territory == null) || territory.getTerritories().isEmpty()) { error("Empty territory for zone: " + zoneDat.get("name")); } ZoneTemplate template = new ZoneTemplate(zoneDat); getHolder().addTemplate(template); } } }
From source file:lineage2.gameserver.data.xml.parser.ZoneParser.java
License:Open Source License
/** * Method parseCircle.// w ww . j av a2 s. co m * @param shape Element * @return Circle * @throws Exception */ private static Circle parseCircle(Element shape) throws Exception { Circle circle; String[] coord = shape.attribute("loc").getValue().split("[\\s,;]+"); if (coord.length < 5) { circle = new Circle(Integer.parseInt(coord[0]), Integer.parseInt(coord[1]), Integer.parseInt(coord[2])) .setZmin(World.MAP_MIN_Z).setZmax(World.MAP_MAX_Z); } else { circle = new Circle(Integer.parseInt(coord[0]), Integer.parseInt(coord[1]), Integer.parseInt(coord[2])) .setZmin(Integer.parseInt(coord[3])).setZmax(Integer.parseInt(coord[4])); } return circle; }
From source file:mesquite.tol.lib.ToLUtil.java
License:Open Source License
public static boolean isLeaf(Element element) { if (!isNode(element)) return false; Attribute leafAttribute = element.attribute("LEAF"); try {/*from w w w.j a va2 s . c o m*/ return leafAttribute.getValue().equals("1"); } catch (Exception e) { return false; } }
From source file:mesquite.tol.lib.ToLUtil.java
License:Open Source License
public static boolean hasChildren(Element element) { if (!isNode(element)) return false; Attribute childcountAttribute = element.attribute("CHILDCOUNT"); try {/*from w w w. jav a2 s . c o m*/ return MesquiteInteger.fromString(childcountAttribute.getValue()) > 0; } catch (Exception e) { return false; } }