Example usage for org.dom4j Attribute getValue

List of usage examples for org.dom4j Attribute getValue

Introduction

In this page you can find the example usage for org.dom4j Attribute getValue.

Prototype

String getValue();

Source Link

Document

Returns the value of the attribute.

Usage

From source file:job.tot.xml.DOM4JConfiguration.java

License:Apache License

/**
 * Loads and initializes from the XML file.
 *
 * @param element The element to start processing from.  Callers
 * should supply the root element of the document.
 * @param hierarchy//from  w w w  .ja v a2 s .  c  o m
 */
private void initProperties(Element element, StringBuffer hierarchy) {
    for (Iterator it = element.elementIterator(); it.hasNext();) {
        StringBuffer subhierarchy = new StringBuffer(hierarchy.toString());
        Element child = (Element) it.next();
        String nodeName = child.getName();
        String nodeValue = child.getTextTrim();
        subhierarchy.append(nodeName);
        if (nodeValue.length() > 0) {
            super.addProperty(subhierarchy.toString(), nodeValue);
        }

        // Add attributes as x.y{ATTRIB_START_MARKER}att{ATTRIB_END_MARKER}
        List attributes = child.attributes();
        for (int j = 0, k = attributes.size(); j < k; j++) {
            Attribute a = (Attribute) attributes.get(j);
            String attName = subhierarchy.toString() + '[' + ATTRIB_MARKER + a.getName() + ']';
            String attValue = a.getValue();
            super.addProperty(attName, attValue);
        }
        StringBuffer buf = new StringBuffer(subhierarchy.toString());
        initProperties(child, buf.append('.'));
    }
}

From source file:lineage2.gameserver.data.xml.parser.FishDataParser.java

License:Open Source License

/**
 * Method readData.//from w w  w . j  ava2s  . c om
 * @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 w  w.  java  2s  . 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.RestartPointParser.java

License:Open Source License

/**
 * Method readData.//  ww  w.  j a v  a 2 s  .  com
 * @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.StatParser.java

License:Open Source License

/**
 * Method parseTargetCondition.//from  www  . j  a v  a 2 s. c o m
 * @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.// ww w.j a  v a  2 s.  com
 * @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.//from   ww w.j a va 2s .  c  o m
 * @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  ww w  .j  a va2s.  co  m*/
 * @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;
}

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  . ja  va  2s  . com
        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 {/*  ww  w .  j  a  v a 2s .com*/
        return MesquiteInteger.fromString(childcountAttribute.getValue()) > 0;
    } catch (Exception e) {
        return false;
    }
}