Example usage for org.dom4j Element elementIterator

List of usage examples for org.dom4j Element elementIterator

Introduction

In this page you can find the example usage for org.dom4j Element elementIterator.

Prototype

Iterator<Element> elementIterator(QName qName);

Source Link

Document

Returns an iterator over the elements contained in this element which match the given fully qualified name.

Usage

From source file:galign.helpers.tmx.Tu.java

License:Apache License

protected void init(Element p_root) {
    clearTuvs();/*from   w w  w. j  a v  a 2  s .c o m*/

    m_tuid = p_root.attributeValue("tuid");
    m_srclang = p_root.attributeValue("srclang");
    m_datatype = p_root.attributeValue("datatype");

    for (Iterator i = p_root.elementIterator("prop"); i.hasNext();) {
        Element item = (Element) i.next();
        m_props.add(item);
    }

    for (Iterator i = p_root.elementIterator("tuv"); i.hasNext();) {
        Element item = (Element) i.next();
        Tuv tuv = new Tuv(item);

        addTuv(tuv);
    }
}

From source file:imageviewer.tools.annotation.LIDCAnnotationReader.java

License:Open Source License

public void readFile(File f, ArrayList<? extends Image> images) {

    SeriesAnnotation sa = new SeriesAnnotation();

    try {/*from w  ww  . j a  v a  2  s .c om*/
        SAXReader saxReader = new SAXReader();
        Document doc = saxReader.read(f);
        Element root = doc.getRootElement();
        Iterator responseHeaderIter = root.elementIterator("ResponseHeader");
        String seriesUID = "";
        String studyUID = "";
        while (responseHeaderIter.hasNext()) {
            Element responseHeader = (Element) responseHeaderIter.next();
            sa.setUID(responseHeader.elementText("SeriesInstanceUid"));
            //sa.setUID(responseHeader.elementText("StudyInstanceUID"));
        }
        Iterator readingSessionIter = root.elementIterator("readingSession");
        while (readingSessionIter.hasNext()) {
            Element readingSessionElem = (Element) readingSessionIter.next();
            Iterator unblindedIter = readingSessionElem.elementIterator("unblindedReadNodule");
            while (unblindedIter.hasNext()) {
                Element unblindedElem = (Element) unblindedIter.next();
                Iterator roiIter = unblindedElem.elementIterator("roi");
                while (roiIter.hasNext()) {
                    Element roi = (Element) roiIter.next();
                    String imageUID = roi.elementText("imageSOP_UID");
                    String inclusion = roi.elementText("inclusion");
                    ImageAnnotation imageA = new ImageAnnotation(imageUID);
                    imageA.setNodule(true);
                    if (inclusion.equalsIgnoreCase(("true"))) {
                        imageA.setInclusion(true);
                    } else {
                        imageA.setInclusion(false);
                    }
                    Iterator edgeMapIter = roi.elementIterator("edgeMap");
                    while (edgeMapIter.hasNext()) {
                        Element edgeMapElem = (Element) edgeMapIter.next();
                        String x = edgeMapElem.elementText("xCoord");
                        String y = edgeMapElem.elementText("yCoord");
                        // System.out.println("[debug] nodule adding for " + imageUID + ": " + x + "," + y);
                        imageA.addPoint(Integer.valueOf(x), Integer.valueOf(y));
                    }
                    sa.addAnnotation(imageA);
                }
            }
            Iterator nonNoduleIter = readingSessionElem.elementIterator("nonNodule");
            while (nonNoduleIter.hasNext()) {
                Element nonNoduleElem = (Element) nonNoduleIter.next();
                String imageUID = nonNoduleElem.elementText("imageSOP_UID");
                ImageAnnotation imageA = new ImageAnnotation(imageUID);
                imageA.setNodule(false);
                Iterator locusIter = nonNoduleElem.elementIterator("locus");
                while (locusIter.hasNext()) {
                    Element locusElem = (Element) locusIter.next();
                    String x = locusElem.elementText("xCoord");
                    String y = locusElem.elementText("yCoord");
                    // System.out.println("[debug] nonNodule adding for " + imageUID + ": " + x + "," + y);
                    imageA.addPoint(Integer.valueOf(x), Integer.valueOf(y));
                }
                sa.addAnnotation(imageA);
            }
        }
    } catch (Exception exc) {
        exc.printStackTrace();
    }

    // Given the series annotation, create the appropriate data layers
    // per annotation

    for (int loop = 0, n = sa.numAnnotations(); loop < n; loop++) {
        ImageAnnotation ia = sa.getAnnotation(loop);
        String annotationUID = ia.getUID();
        for (Iterator i = images.iterator(); i.hasNext();) {
            Image img = (Image) i.next();
            String imageUID = (String) img.getProperties().get("SOPInstanceUID");
            if ((imageUID != null) && (imageUID.equals(annotationUID))) {
                ShapeDataLayer sdl = (ShapeDataLayer) img.findDataLayer(DataLayer.SHAPE);
                if (sdl == null) {
                    sdl = new ShapeDataLayer();
                    img.addDataLayer(sdl);
                }
                Polygon polygon = new Polygon();
                for (int j = 0, m = ia.numPoints(); j < m; j++) {
                    Point pt = ia.getPoint(j);
                    polygon.addPoint(pt.x, pt.y);
                }
                StylizedShape ss = new StylizedShape(polygon, null, 1.0f, 0.75f);
                // ss.setFilled(isFilled);
                ss.setStrokeColor(STROKE_COLOR);
                ss.setFillColor(FILL_COLOR);
                ss.setFillAlphaComposite(0.5f);
                sdl.addShape(ss);
            }
        }
    }
}

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

License:Open Source License

@Override
protected void readData(Element rootElement) throws Exception {
    for (Iterator<?> iterator = rootElement.elementIterator("config"); iterator.hasNext();) {
        Element element = (Element) iterator.next();
        Config.BEAUTY_SHOP_COIN_ITEM_ID = Integer.parseInt(element.attributeValue("coin_item_id"));
    }/*from   w ww.  jav a2s .  c om*/

    for (Iterator<?> iterator = rootElement.elementIterator("set"); iterator.hasNext();) {
        Element element = (Element) iterator.next();
        int setId = Integer.parseInt(element.attributeValue("id"));
        TIntObjectHashMap<BeautyShopHairStyle> hairStyles = new TIntObjectHashMap<>();
        TIntObjectHashMap<BeautyShopFace> faces = new TIntObjectHashMap<>();

        for (Iterator<?> subIterator = element.elementIterator("hair"); subIterator.hasNext();) {
            Element subElement = (Element) subIterator.next();
            int id = Integer.parseInt(subElement.attributeValue("id"));
            long adena = Long.parseLong(subElement.attributeValue("adena"));
            long coins = Long.parseLong(subElement.attributeValue("coins"));
            long resetPrice = Long.parseLong(subElement.attributeValue("reset_price"));
            TIntObjectHashMap<BeautyShopHairColor> colors = new TIntObjectHashMap<>();

            for (Iterator<?> colorIterator = subElement.elementIterator("color"); colorIterator.hasNext();) {
                Element colorElement = (Element) colorIterator.next();
                int cId = Integer.parseInt(colorElement.attributeValue("id"));
                long cAdena = Long.parseLong(colorElement.attributeValue("adena"));
                long cCoins = Long.parseLong(colorElement.attributeValue("coins"));
                colors.put(cId, new BeautyShopHairColor(cId, cAdena, cCoins));
            }

            if (colors.isEmpty()) {
                colors.put(101, new BeautyShopHairColor(101, 0L, 0L));
            }

            hairStyles.put(id, new BeautyShopHairStyle(id, adena, coins, resetPrice, colors));
        }

        for (Iterator<?> subIterator = element.elementIterator("face"); subIterator.hasNext();) {
            Element subElement = (Element) subIterator.next();
            int id = Integer.parseInt(subElement.attributeValue("id"));
            long adena = Long.parseLong(subElement.attributeValue("adena"));
            long coins = Long.parseLong(subElement.attributeValue("coins"));
            long resetPrice = Long.parseLong(subElement.attributeValue("reset_price"));
            faces.put(id, new BeautyShopFace(id, adena, coins, resetPrice));
        }

        getHolder().addSet(new BeautyShopSet(setId, hairStyles, faces));
    }
}

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

License:Open Source License

@Override
protected void readData(Element rootElement) throws Exception {
    for (Iterator<Element> iterator = rootElement.elementIterator("appearance_stone"); iterator.hasNext();) {
        Element stoneElement = iterator.next();
        int itemId = Integer.parseInt(stoneElement.attributeValue("id"));
        String[] targetTypesStr = stoneElement.attributeValue("target_type").split(",");
        AppearanceStone.ShapeTargetType[] targetTypes = new AppearanceStone.ShapeTargetType[targetTypesStr.length];

        for (int i = 0; i < targetTypesStr.length; i++) {
            targetTypes[i] = AppearanceStone.ShapeTargetType.valueOf(targetTypesStr[i].toUpperCase());
        }/*from   w w  w .j a  v a 2 s.co  m*/

        AppearanceStone.ShapeType type = AppearanceStone.ShapeType
                .valueOf(stoneElement.attributeValue("shifting_type").toUpperCase());
        String[] gradesStr = stoneElement.attributeValue("grade") == null ? new String[0]
                : stoneElement.attributeValue("grade").split(",");
        ItemTemplate.Grade[] grades = new ItemTemplate.Grade[gradesStr.length];

        for (int i = 0; i < gradesStr.length; i++) {
            grades[i] = ItemTemplate.Grade.valueOf(gradesStr[i].toUpperCase());
        }

        long cost = stoneElement.attributeValue("cost") == null ? 0L
                : Long.parseLong(stoneElement.attributeValue("cost"));
        int extractItemId = stoneElement.attributeValue("extract_id") == null ? 0
                : Integer.parseInt(stoneElement.attributeValue("extract_id"));
        String[] itemTypesStr = stoneElement.attributeValue("item_type") == null ? new String[0]
                : stoneElement.attributeValue("item_type").split(",");
        ExItemType[] itemTypes = new ExItemType[itemTypesStr.length];

        for (int i = 0; i < itemTypesStr.length; i++) {
            itemTypes[i] = ExItemType.valueOf(itemTypesStr[i].toUpperCase());
        }

        getHolder().addAppearanceStone(
                new AppearanceStone(itemId, targetTypes, type, grades, cost, extractItemId, itemTypes));
    }
}

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

License:Open Source License

/**
 * Method readData./*from   w w  w  .j  a  v  a 2  s  .c o m*/
 * @param rootElement Element
 * @throws Exception
 */
@Override
@SuppressWarnings("unchecked")
protected void readData(Element rootElement) throws Exception {
    for (Iterator<?> iterator = rootElement.elementIterator("event"); iterator.hasNext();) {
        Element eventElement = (Element) iterator.next();
        int id = Integer.parseInt(eventElement.attributeValue("id"));
        String name = eventElement.attributeValue("name");
        String impl = eventElement.attributeValue("impl");
        EventType type = EventType.valueOf(eventElement.attributeValue("type"));
        Class<GlobalEvent> eventClass = null;

        try {
            eventClass = (Class<GlobalEvent>) Class
                    .forName("lineage2.gameserver.model.entity.events.impl." + impl + "Event");
        } catch (ClassNotFoundException e) {
            info("Not found impl class: " + impl + "; File: " + getCurrentFileName());
            continue;
        }

        Constructor<GlobalEvent> constructor = eventClass.getConstructor(MultiValueSet.class);
        MultiValueSet<String> set = new MultiValueSet<>();
        set.set("id", id);
        set.set("name", name);

        for (Iterator<?> parameterIterator = eventElement.elementIterator("parameter"); parameterIterator
                .hasNext();) {
            Element parameterElement = (Element) parameterIterator.next();
            set.set(parameterElement.attributeValue("name"), parameterElement.attributeValue("value"));
        }

        GlobalEvent event = constructor.newInstance(set);
        event.addOnStartActions(parseActions(eventElement.element("on_start"), Integer.MAX_VALUE));
        event.addOnStopActions(parseActions(eventElement.element("on_stop"), Integer.MAX_VALUE));
        event.addOnInitActions(parseActions(eventElement.element("on_init"), Integer.MAX_VALUE));
        Element onTime = eventElement.element("on_time");

        if (onTime != null) {
            for (Iterator<?> onTimeIterator = onTime.elementIterator("on"); onTimeIterator.hasNext();) {
                Element on = (Element) onTimeIterator.next();
                int time = Integer.parseInt(on.attributeValue("time"));
                List<EventAction> actions = parseActions(on, time);
                event.addOnTimeActions(time, actions);
            }
        }

        for (Iterator<?> objectIterator = eventElement.elementIterator("objects"); objectIterator.hasNext();) {
            Element objectElement = (Element) objectIterator.next();
            String objectsName = objectElement.attributeValue("name");
            List<Serializable> objects = parseObjects(objectElement);
            event.addObjects(objectsName, objects);
        }

        getHolder().addEvent(type, event);
    }
}

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

License:Open Source License

/**
 * Method readData.//  ww w .ja  va2 s.  c  o m
 * @param rootElement Element
 */
@Override
protected void readData(Element rootElement) {
    for (Iterator<Element> iterator = rootElement.elementIterator("pet"); iterator.hasNext();) {
        Element pet = iterator.next();
        StatsSet set = new StatsSet();
        set.set("id", pet.attributeValue("id"));
        set.set("index", pet.attributeValue("index"));

        for (Iterator<Element> i1 = pet.elementIterator(); i1.hasNext();) {
            Element element = i1.next();

            if (element.getName().equals("set")) {
                set.set(element.attributeValue("name"), element.attributeValue("val"));
            } else if (element.getName().equals("stats")) {
                for (Iterator<Element> itr = element.elementIterator("stat"); itr.hasNext();) {
                    Element stat = itr.next();
                    set.set("level", stat.attributeValue("level"));

                    for (Iterator<Element> it = stat.elementIterator("set"); it.hasNext();) {
                        Element e = it.next();
                        set.set(e.attributeValue("name"), e.attributeValue("val"));
                    }
                }
            }
        }

        getHolder().addPetData(set);
    }
}

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

License:Open Source License

/**
 * Method readData./*from ww w .j  a va2s.  c  o m*/
 * @param rootElement Element
 * @throws Exception
 */
@Override
protected void readData(Element rootElement) throws Exception {
    for (Iterator<Element> iterator = rootElement.elementIterator("certification_skill_tree"); iterator
            .hasNext();) {
        getHolder().addAllCertificationLearns(parseSkillLearn(iterator.next()));
    }

    for (Iterator<Element> iterator = rootElement
            .elementIterator("dualclass_certification_skill_tree"); iterator.hasNext();) {
        getHolder().addAllDualCertificationLearns(parseSkillLearn(iterator.next()));
    }

    for (Iterator<Element> iterator = rootElement.elementIterator("sub_unit_skill_tree"); iterator.hasNext();) {
        getHolder().addAllSubUnitLearns(parseSkillLearn(iterator.next()));
    }

    for (Iterator<Element> iterator = rootElement.elementIterator("pledge_skill_tree"); iterator.hasNext();) {
        getHolder().addAllPledgeLearns(parseSkillLearn(iterator.next()));
    }

    for (Iterator<Element> iterator = rootElement.elementIterator("collection_skill_tree"); iterator
            .hasNext();) {
        getHolder().addAllCollectionLearns(parseSkillLearn(iterator.next()));
    }

    for (Iterator<Element> iterator = rootElement.elementIterator("fishing_skill_tree"); iterator.hasNext();) {
        Element nxt = iterator.next();

        for (Iterator<Element> classIterator = nxt.elementIterator("race"); classIterator.hasNext();) {
            Element classElement = classIterator.next();
            int race = Integer.parseInt(classElement.attributeValue("id"));
            List<SkillLearn> learns = parseSkillLearn(classElement);
            getHolder().addAllFishingLearns(race, learns);
        }
    }

    for (Iterator<Element> iterator = rootElement.elementIterator("transfer_skill_tree"); iterator.hasNext();) {
        Element nxt = iterator.next();

        for (Iterator<Element> classIterator = nxt.elementIterator("class"); classIterator.hasNext();) {
            Element classElement = classIterator.next();
            int classId = Integer.parseInt(classElement.attributeValue("id"));
            List<SkillLearn> learns = parseSkillLearn(classElement);
            getHolder().addAllTransferLearns(classId, learns);
        }
    }

    for (Iterator<Element> iterator = rootElement.elementIterator("normal_skill_tree"); iterator.hasNext();) {
        HashMap<Integer, List<SkillLearn>> map = new HashMap<>();
        Element nxt = iterator.next();

        for (Iterator<Element> classIterator = nxt.elementIterator("class"); classIterator.hasNext();) {
            Element classElement = classIterator.next();
            int classId = Integer.parseInt(classElement.attributeValue("id"));
            List<SkillLearn> learns = parseSkillLearn(classElement);
            map.put(classId, learns);
        }

        getHolder().addAllNormalSkillLearns(map);
    }

    for (Iterator<Element> iterator = rootElement.elementIterator("transformation_skill_tree"); iterator
            .hasNext();) {
        Element nxt = iterator.next();

        for (Iterator<Element> classIterator = nxt.elementIterator("race"); classIterator.hasNext();) {
            Element classElement = classIterator.next();
            int race = Integer.parseInt(classElement.attributeValue("id"));
            List<SkillLearn> learns = parseSkillLearn(classElement);
            getHolder().addAllTransformationLearns(race, learns);
        }
    }

    for (Iterator<Element> iterator = rootElement.elementIterator("awakening_keep_skill_tree"); iterator
            .hasNext();) {
        HashMap<Integer, HashMap<Integer, List<Integer>>> map = new HashMap<>();
        Element nxt = iterator.next();

        for (Iterator<Element> awakenClassIterator = nxt.elementIterator("awakenClass"); awakenClassIterator
                .hasNext();) {
            Element awakenClass = awakenClassIterator.next();
            int awakenClassId = Integer.parseInt(awakenClass.attributeValue("id"));
            HashMap<Integer, List<Integer>> transferClassList = new HashMap<>();

            for (Iterator<Element> fromClassIterator = awakenClass
                    .elementIterator("fromClass"); fromClassIterator.hasNext();) {
                Element fromClass = fromClassIterator.next();
                int fromClassId = Integer.parseInt(fromClass.attributeValue("id"));
                List<Integer> keepSkill = parseKeepSkill(fromClass);
                transferClassList.put(fromClassId, keepSkill);
            }

            map.put(awakenClassId, transferClassList);
        }

        getHolder().addSkillsToMaintain(map);
    }
}

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

License:Open Source License

/**
 * Method parseSkillLearn./*from w w w.j  av a2 s  .c  o m*/
 * @param tree Element
 * @return List<SkillLearn>
 */
private List<SkillLearn> parseSkillLearn(Element tree) {
    List<SkillLearn> skillLearns = new ArrayList<>();

    for (Iterator<Element> iterator = tree.elementIterator("skill"); iterator.hasNext();) {
        Element element = iterator.next();
        int id = Integer.parseInt(element.attributeValue("id"));
        int level = Integer.parseInt(element.attributeValue("level"));
        int cost = element.attributeValue("cost") == null ? 0
                : Integer.parseInt(element.attributeValue("cost"));
        int min_level = Integer.parseInt(element.attributeValue("min_level"));
        int item_id = element.attributeValue("item_id") == null ? 0
                : Integer.parseInt(element.attributeValue("item_id"));
        long item_count = element.attributeValue("item_count") == null ? 1
                : Long.parseLong(element.attributeValue("item_count"));
        boolean clicked = (element.attributeValue("clicked") != null)
                && Boolean.parseBoolean(element.attributeValue("clicked"));
        boolean deprecated = (element.attributeValue("deprecated") != null)
                && Boolean.parseBoolean(element.attributeValue("deprecated"));
        Race race = element.attributeValue("race") == null ? null
                : Race.valueOf(element.attributeValue("race"));
        skillLearns.add(new SkillLearn(id, level, min_level, cost, item_id, item_count, clicked, deprecated,
                race, new HashMap<Integer, Long>(), new ArrayList<Integer>()));
    }

    return skillLearns;
}

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

License:Open Source License

/**
 * Method parseRemoveSkill/*from  ww w  . j  a  va  2  s.co m*/
 * @param tree Element
 * @return List<Integer>
 */
private List<Integer> parseKeepSkill(Element tree) {
    List<Integer> skillRemove = new ArrayList<>();

    for (Iterator<Element> iterator = tree.elementIterator("keepSkill"); iterator.hasNext();) {
        Element element = iterator.next();
        int id = Integer.parseInt(element.attributeValue("id"));
        skillRemove.add(id);
    }

    return skillRemove;
}

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

License:Open Source License

/**
 * Method readData./*from www.  j ava  2 s  . c om*/
 * @param rootElement Element
 * @throws Exception
 */
@Override
protected void readData(Element rootElement) throws Exception {
    for (Iterator<?> iterator = rootElement.elementIterator("crystal"); iterator.hasNext();) {
        Element element = (Element) iterator.next();
        int itemId = Integer.parseInt(element.attributeValue("item_id"));
        int level = Integer.parseInt(element.attributeValue("level"));
        int nextItemId = Integer.parseInt(element.attributeValue("next_item_id"));
        int cursedNextItemId = element.attributeValue("cursed_next_item_id") == null ? 0
                : Integer.parseInt(element.attributeValue("cursed_next_item_id"));
        getHolder().addCrystal(new SoulCrystal(itemId, level, nextItemId, cursedNextItemId));
    }
}