List of usage examples for org.dom4j Element attributeIterator
Iterator<Attribute> attributeIterator();
From source file:fr.gouv.culture.vitam.utils.XmlDom.java
License:Open Source License
public final static void removeEmptyElement(Element root) { // look first at attribute if (root.attributeCount() > 0) { @SuppressWarnings("unchecked") Iterator<Attribute> attribs = root.attributeIterator(); while (attribs.hasNext()) { Attribute attribute = (Attribute) attribs.next(); removeEmptyAttribute(attribute); }/* www .j a va 2 s .co m*/ } @SuppressWarnings("unchecked") Iterator<Element> elements = root.elementIterator(); while (elements.hasNext()) { Element elt = (Element) elements.next(); // look at its descendant removeEmptyElement(elt); if (elt.attributeCount() > 0) { continue; } if (elt.hasContent()) { continue; } elt.detach(); } }
From source file:fr.gouv.vitam.xml.XmlDom4jTools.java
License:Open Source License
public final static void removeEmptyElement(Element root) { // look first at attribute if (root.attributeCount() > 0) { @SuppressWarnings("unchecked") Iterator<Attribute> attribs = root.attributeIterator(); List<Attribute> toremove = new ArrayList<>(); while (attribs.hasNext()) { Attribute attribute = (Attribute) attribs.next(); if (attribute.getValue().length() == 0) { toremove.add(attribute); }//www.ja v a2 s. com //removeEmptyAttribute(attribute); } for (Attribute attribute : toremove) { root.remove(attribute); } toremove.clear(); } @SuppressWarnings("unchecked") Iterator<Element> elements = root.elementIterator(); List<Element> toremove = new ArrayList<>(); while (elements.hasNext()) { Element elt = (Element) elements.next(); // look at its descendant removeEmptyElement(elt); if (elt.attributeCount() > 0) { continue; } if (elt.hasContent()) { continue; } toremove.add(elt); //elt.detach(); } for (Element element : toremove) { root.remove(element); } toremove.clear(); }
From source file:fr.mael.microrss.xml.opml.OPMLReader.java
License:Open Source License
private String getAttribute(String attributeName, Element element) { for (Iterator i = element.attributeIterator(); i.hasNext();) { Attribute attribute = (Attribute) i.next(); if (attributeName.equals(attribute.getName())) { return attribute.getValue(); }// w ww. j a v a 2s . c o m } return null; }
From source file:it.eng.spagobi.studio.chart.editors.model.chart.ChartModel.java
License:Mozilla Public License
/** Gets from actual template you are opening informations about series personalization * /*ww w. j av a 2 s . c o m*/ * @param chartSubType * @param thisDocument */ public void fillSeriesPersonalization() { logger.debug("Start recording and filling series personalization"); String upperCaseNameSl = getType().toUpperCase(); String upperCaseNamePl = upperCaseNameSl + "S"; seriesPersonalizationHashMap = new HashMap<String, SeriePersonalization>(); seriesOrderPersonalizationVector = new Vector<RGB>(); // SERIES ORDE COLOR Element orderColorsThis = (Element) thisDocument .selectSingleNode("//" + upperCaseNameSl + "/SERIES_ORDER_COLORS"); ChartEditorUtils.print("", orderColorsThis); if (orderColorsThis != null) { for (Iterator iterator = orderColorsThis.attributeIterator(); iterator.hasNext();) { DefaultAttribute att = (DefaultAttribute) iterator.next(); //String name=att.getName(); String value = null; if (att.getData() != null) { value = att.getData().toString(); // add seriePers if not present RGB rgb = null; try { rgb = ChartEditor.convertHexadecimalToRGB(value); } catch (Exception e) { continue; } seriesOrderPersonalizationVector.add(rgb); } // else{ // SeriePersonalization serPers = seriesPersonalizationHashMap.get(name); // serPers.setColor(ChartEditor.convertHexadecimalToRGB(value)); // } } } // COLOR Element colorsThis = (Element) thisDocument.selectSingleNode("//" + upperCaseNameSl + "/SERIES_COLORS"); ChartEditorUtils.print("", colorsThis); if (colorsThis != null) { for (Iterator iterator = colorsThis.attributeIterator(); iterator.hasNext();) { DefaultAttribute att = (DefaultAttribute) iterator.next(); String name = att.getName(); String value = null; if (att.getData() != null) { value = att.getData().toString(); // add seriePers if not present if (!seriesPersonalizationHashMap.containsKey(name)) { SeriePersonalization serPers = new SeriePersonalization(name); RGB rgb = null; try { rgb = ChartEditor.convertHexadecimalToRGB(value); } catch (Exception e) { rgb = new RGB(255, 0, 0); } serPers.setColor(rgb); seriesPersonalizationHashMap.put(name, serPers); } else { SeriePersonalization serPers = seriesPersonalizationHashMap.get(name); serPers.setColor(ChartEditor.convertHexadecimalToRGB(value)); } } } } // LABEL Element labelThis = (Element) thisDocument.selectSingleNode("//" + upperCaseNameSl + "/SERIES_LABELS"); ChartEditorUtils.print("", labelThis); if (labelThis != null) { for (Iterator iterator = labelThis.attributeIterator(); iterator.hasNext();) { DefaultAttribute att = (DefaultAttribute) iterator.next(); String name = att.getName(); String value = null; if (att.getData() != null) { value = att.getData().toString(); // add seriePers if not present if (!seriesPersonalizationHashMap.containsKey(name)) { SeriePersonalization serPers = new SeriePersonalization(name); serPers.setLabel(value); seriesPersonalizationHashMap.put(name, serPers); } else { SeriePersonalization serPers = seriesPersonalizationHashMap.get(name); serPers.setLabel(value); } } } } // DRAW Element drawThis = (Element) thisDocument.selectSingleNode("//" + upperCaseNameSl + "/SERIES_DRAW"); ChartEditorUtils.print("", labelThis); if (drawThis != null) { for (Iterator iterator = drawThis.attributeIterator(); iterator.hasNext();) { DefaultAttribute att = (DefaultAttribute) iterator.next(); String name = att.getName(); String value = null; if (att.getData() != null) { value = att.getData().toString(); // add seriePers if not present if (!seriesPersonalizationHashMap.containsKey(name)) { SeriePersonalization serPers = new SeriePersonalization(name); serPers.setDraw(value); seriesPersonalizationHashMap.put(name, serPers); } else { SeriePersonalization serPers = seriesPersonalizationHashMap.get(name); serPers.setDraw(value); } } } } // SCALES Element scaleThis = (Element) thisDocument.selectSingleNode("//" + upperCaseNameSl + "/SERIES_SCALES"); ChartEditorUtils.print("", scaleThis); if (scaleThis != null) { for (Iterator iterator = scaleThis.attributeIterator(); iterator.hasNext();) { DefaultAttribute att = (DefaultAttribute) iterator.next(); String name = att.getName(); String value = null; if (att.getData() != null) { value = att.getData().toString(); // add seriePers if not present if (!seriesPersonalizationHashMap.containsKey(name)) { SeriePersonalization serPers = new SeriePersonalization(name); serPers.setScale(Integer.valueOf(value).intValue()); seriesPersonalizationHashMap.put(name, serPers); } else { SeriePersonalization serPers = seriesPersonalizationHashMap.get(name); serPers.setScale(Integer.valueOf(value).intValue()); } } } } }
From source file:lineage2.gameserver.data.xml.parser.FishDataParser.java
License:Open Source License
/** * Method readData.// w w w. ja va 2 s. c o m * @param rootElement Element * @throws Exception */ @Override protected void readData(Element rootElement) throws Exception { for (Iterator<Element> iterator = rootElement.elementIterator(); iterator.hasNext();) { Element e = iterator.next(); if ("fish".equals(e.getName())) { MultiValueSet<String> map = new MultiValueSet<>(); for (Iterator<Attribute> attributeIterator = e.attributeIterator(); attributeIterator.hasNext();) { Attribute attribute = attributeIterator.next(); map.put(attribute.getName(), attribute.getValue()); } getHolder().addFish(new FishTemplate(map)); } else if ("lure".equals(e.getName())) { MultiValueSet<String> map = new MultiValueSet<>(); for (Iterator<Attribute> attributeIterator = e.attributeIterator(); attributeIterator.hasNext();) { Attribute attribute = attributeIterator.next(); map.put(attribute.getName(), attribute.getValue()); } Map<FishGroup, Integer> chances = new HashMap<>(); for (Iterator<Element> elementIterator = e.elementIterator(); elementIterator.hasNext();) { Element chanceElement = elementIterator.next(); chances.put(FishGroup.valueOf(chanceElement.attributeValue("type")), Integer.parseInt(chanceElement.attributeValue("value"))); } map.put("chances", chances); getHolder().addLure(new LureTemplate(map)); } else if ("distribution".equals(e.getName())) { int id = Integer.parseInt(e.attributeValue("id")); for (Iterator<Element> forLureIterator = e.elementIterator(); forLureIterator.hasNext();) { Element forLureElement = forLureIterator.next(); LureType lureType = LureType.valueOf(forLureElement.attributeValue("type")); Map<FishGroup, Integer> chances = new HashMap<>(); for (Iterator<Element> chanceIterator = forLureElement.elementIterator(); chanceIterator .hasNext();) { Element chanceElement = chanceIterator.next(); chances.put(FishGroup.valueOf(chanceElement.attributeValue("type")), Integer.parseInt(chanceElement.attributeValue("value"))); } getHolder().addDistribution(id, lureType, chances); } } } }
From source file:lineage2.gameserver.data.xml.parser.ResidenceParser.java
License:Open Source License
/** * Method readData./*from w ww. j ava 2 s . co m*/ * @param rootElement Element * @throws Exception */ @Override protected void readData(Element rootElement) throws Exception { String impl = rootElement.attributeValue("impl"); Class<?> clazz = null; StatsSet set = new StatsSet(); for (Iterator<Attribute> iterator = rootElement.attributeIterator(); iterator.hasNext();) { Attribute element = iterator.next(); set.set(element.getName(), element.getValue()); } Residence residence = null; try { clazz = Class.forName("lineage2.gameserver.model.entity.residence." + impl); Constructor<?> constructor = clazz.getConstructor(StatsSet.class); residence = (Residence) constructor.newInstance(set); getHolder().addResidence(residence); } catch (Exception e) { error("fail to init: " + getCurrentFileName(), e); return; } for (Iterator<Element> iterator = rootElement.elementIterator(); iterator.hasNext();) { Element element = iterator.next(); String nodeName = element.getName(); int level = element.attributeValue("level") == null ? 0 : Integer.valueOf(element.attributeValue("level")); int lease = (int) ((element.attributeValue("lease") == null ? 0 : Integer.valueOf(element.attributeValue("lease"))) * Config.RESIDENCE_LEASE_FUNC_MULTIPLIER); int npcId = element.attributeValue("npcId") == null ? 0 : Integer.valueOf(element.attributeValue("npcId")); int listId = element.attributeValue("listId") == null ? 0 : Integer.valueOf(element.attributeValue("listId")); ResidenceFunction function = null; if (nodeName.equalsIgnoreCase("teleport")) { function = checkAndGetFunction(residence, ResidenceFunction.TELEPORT); List<TeleportLocation> targets = new ArrayList<>(); for (Iterator<Element> it2 = element.elementIterator(); it2.hasNext();) { Element teleportElement = it2.next(); if ("target".equalsIgnoreCase(teleportElement.getName())) { int npcStringId = Integer.parseInt(teleportElement.attributeValue("name")); long price = Long.parseLong(teleportElement.attributeValue("price")); int itemId = teleportElement.attributeValue("item") == null ? ItemTemplate.ITEM_ID_ADENA : Integer.parseInt(teleportElement.attributeValue("item")); TeleportLocation loc = new TeleportLocation(itemId, price, npcStringId, 0); loc.set(Location.parseLoc(teleportElement.attributeValue("loc"))); targets.add(loc); } } function.addTeleports(level, targets.toArray(new TeleportLocation[targets.size()])); } else if (nodeName.equalsIgnoreCase("support")) { if ((level > 9) && !Config.ALT_CH_ALLOW_1H_BUFFS) { continue; } function = checkAndGetFunction(residence, ResidenceFunction.SUPPORT); function.addBuffs(level); } else if (nodeName.equalsIgnoreCase("item_create")) { function = checkAndGetFunction(residence, ResidenceFunction.ITEM_CREATE); function.addBuylist(level, new int[] { npcId, listId }); } else if (nodeName.equalsIgnoreCase("curtain")) { function = checkAndGetFunction(residence, ResidenceFunction.CURTAIN); } else if (nodeName.equalsIgnoreCase("platform")) { function = checkAndGetFunction(residence, ResidenceFunction.PLATFORM); } else if (nodeName.equalsIgnoreCase("restore_exp")) { function = checkAndGetFunction(residence, ResidenceFunction.RESTORE_EXP); } else if (nodeName.equalsIgnoreCase("restore_hp")) { function = checkAndGetFunction(residence, ResidenceFunction.RESTORE_HP); } else if (nodeName.equalsIgnoreCase("restore_mp")) { function = checkAndGetFunction(residence, ResidenceFunction.RESTORE_MP); } else if (nodeName.equalsIgnoreCase("skills")) { for (Iterator<Element> nextIterator = element.elementIterator(); nextIterator.hasNext();) { Element nextElement = nextIterator.next(); int id2 = Integer.parseInt(nextElement.attributeValue("id")); int level2 = Integer.parseInt(nextElement.attributeValue("level")); Skill skill = SkillTable.getInstance().getInfo(id2, level2); if (skill != null) { residence.addSkill(skill); } } } else if (nodeName.equalsIgnoreCase("banish_points")) { for (Iterator<Element> banishPointsIterator = element.elementIterator(); banishPointsIterator .hasNext();) { Location loc = Location.parse(banishPointsIterator.next()); residence.addBanishPoint(loc); } } else if (nodeName.equalsIgnoreCase("owner_restart_points")) { for (Iterator<Element> ownerRestartPointsIterator = element .elementIterator(); ownerRestartPointsIterator.hasNext();) { Location loc = Location.parse(ownerRestartPointsIterator.next()); residence.addOwnerRestartPoint(loc); } } else if (nodeName.equalsIgnoreCase("other_restart_points")) { for (Iterator<Element> otherRestartPointsIterator = element .elementIterator(); otherRestartPointsIterator.hasNext();) { Location loc = Location.parse(otherRestartPointsIterator.next()); residence.addOtherRestartPoint(loc); } } else if (nodeName.equalsIgnoreCase("chaos_restart_points")) { for (Iterator<Element> chaosRestartPointsIterator = element .elementIterator(); chaosRestartPointsIterator.hasNext();) { Location loc = Location.parse(chaosRestartPointsIterator.next()); residence.addChaosRestartPoint(loc); } } else if (nodeName.equalsIgnoreCase("related_fortresses")) { for (Iterator<Element> subElementIterator = element.elementIterator(); subElementIterator .hasNext();) { Element subElement = subElementIterator.next(); if (subElement.getName().equalsIgnoreCase("domain")) { ((Castle) residence).addRelatedFortress(Fortress.DOMAIN, Integer.parseInt(subElement.attributeValue("fortress"))); } else if (subElement.getName().equalsIgnoreCase("boundary")) { ((Castle) residence).addRelatedFortress(Fortress.BOUNDARY, Integer.parseInt(subElement.attributeValue("fortress"))); } } } else if (nodeName.equalsIgnoreCase("merchant_guards")) { for (Iterator<Element> subElementIterator = element.elementIterator(); subElementIterator .hasNext();) { Element subElement = subElementIterator.next(); int itemId = Integer.parseInt(subElement.attributeValue("item_id")); int npcId2 = Integer.parseInt(subElement.attributeValue("npc_id")); int maxGuard = Integer.parseInt(subElement.attributeValue("max")); IntSet intSet = new HashIntSet(3); String[] ssq = subElement.attributeValue("ssq").split(";"); for (String q : ssq) { if (q.equalsIgnoreCase("cabal_null")) { intSet.add(0); } } ((Castle) residence).addMerchantGuard(new MerchantGuard(itemId, npcId2, maxGuard, intSet)); } } if (function != null) { function.addLease(level, lease); } } }
From source file:lineage2.gameserver.data.xml.parser.StatParser.java
License:Open Source License
/** * Method parseTargetCondition./* w w w . j a v a 2 s . com*/ * @param element Element * @return Condition */ private Condition parseTargetCondition(Element element) { Condition cond = null; for (Iterator<Attribute> iterator = element.attributeIterator(); iterator.hasNext();) { Attribute attribute = iterator.next(); String name = attribute.getName(); String value = attribute.getValue(); if (name.equalsIgnoreCase("pvp")) { cond = joinAnd(cond, new ConditionTargetPlayable(Boolean.valueOf(value))); } } return cond; }
From source file:lineage2.gameserver.data.xml.parser.StatParser.java
License:Open Source License
/** * Method parseZoneCondition./*from ww w . j ava2s . co m*/ * @param element Element * @return Condition */ private Condition parseZoneCondition(Element element) { Condition cond = null; for (Iterator<Attribute> iterator = element.attributeIterator(); iterator.hasNext();) { Attribute attribute = iterator.next(); String name = attribute.getName(); String value = attribute.getValue(); if (name.equalsIgnoreCase("type")) { cond = joinAnd(cond, new ConditionZoneType(value)); } } return cond; }
From source file:lineage2.gameserver.data.xml.parser.StatParser.java
License:Open Source License
/** * Method parsePlayerCondition./* w w w . j ava2 s . c om*/ * @param element Element * @return Condition */ private Condition parsePlayerCondition(Element element) { Condition cond = null; for (Iterator<Attribute> iterator = element.attributeIterator(); iterator.hasNext();) { Attribute attribute = iterator.next(); String name = attribute.getName(); String value = attribute.getValue(); if (name.equalsIgnoreCase("residence")) { String[] st = value.split(";"); cond = joinAnd(cond, new ConditionPlayerResidence(Integer.parseInt(st[1]), ResidenceType.valueOf(st[0]))); } else if (name.equalsIgnoreCase("classId")) { cond = joinAnd(cond, new ConditionPlayerClassId(value.split(","))); } else if (name.equalsIgnoreCase("olympiad")) { cond = joinAnd(cond, new ConditionPlayerOlympiad(Boolean.valueOf(value))); } else if (name.equalsIgnoreCase("instance_zone")) { cond = joinAnd(cond, new ConditionPlayerInstanceZone(Integer.parseInt(value))); } else if (name.equalsIgnoreCase("race")) { cond = joinAnd(cond, new ConditionPlayerRace(value)); } else if (name.equalsIgnoreCase("damage")) { String[] st = value.split(";"); cond = joinAnd(cond, new ConditionPlayerMinMaxDamage(Double.parseDouble(st[0]), Double.parseDouble(st[1]))); } else if (name.equalsIgnoreCase("castleLight")) { cond = joinAnd(cond, new ConditionCastleLight()); } else if (name.equalsIgnoreCase("castleLightClanLeader")) { cond = joinAnd(cond, new ConditionCastleLightClanLeader()); } else if (name.equalsIgnoreCase("castleDark")) { cond = joinAnd(cond, new ConditionCastleDark()); } else if (name.equalsIgnoreCase("castleDarkClanLeader")) { cond = joinAnd(cond, new ConditionCastleDarkClanLeader()); } } return cond; }
From source file:lineage2.gameserver.data.xml.parser.StatParser.java
License:Open Source License
/** * Method parseUsingCondition./*from w ww . ja v a 2 s . c om*/ * @param element Element * @return Condition */ private Condition parseUsingCondition(Element element) { Condition cond = null; for (Iterator<Attribute> iterator = element.attributeIterator(); iterator.hasNext();) { Attribute attribute = iterator.next(); String name = attribute.getName(); String value = attribute.getValue(); if (name.equalsIgnoreCase("slotitem")) { StringTokenizer st = new StringTokenizer(value, ";"); int id = Integer.parseInt(st.nextToken().trim()); int slot = Integer.parseInt(st.nextToken().trim()); int enchant = 0; if (st.hasMoreTokens()) { enchant = Integer.parseInt(st.nextToken().trim()); } cond = joinAnd(cond, new ConditionSlotItemId(slot, id, enchant)); } else if (name.equalsIgnoreCase("kind") || name.equalsIgnoreCase("weapon")) { long mask = 0; StringTokenizer st = new StringTokenizer(value, ","); tokens: while (st.hasMoreTokens()) { String item = st.nextToken().trim(); for (WeaponTemplate.WeaponType wt : WeaponTemplate.WeaponType.VALUES) { if (wt.toString().equalsIgnoreCase(item)) { mask |= wt.mask(); continue tokens; } } for (ArmorTemplate.ArmorType at : ArmorTemplate.ArmorType.VALUES) { if (at.toString().equalsIgnoreCase(item)) { mask |= at.mask(); continue tokens; } } error("Invalid item kind: \"" + item + "\" in " + getCurrentFileName()); } if (mask != 0) { cond = joinAnd(cond, new ConditionUsingItemType(mask)); } } else if (name.equalsIgnoreCase("skill")) { cond = joinAnd(cond, new ConditionUsingSkill(Integer.parseInt(value))); } } return cond; }