Example usage for org.jdom2 Element getChild

List of usage examples for org.jdom2 Element getChild

Introduction

In this page you can find the example usage for org.jdom2 Element getChild.

Prototype

public Element getChild(final String cname) 

Source Link

Document

This returns the first child element within this element with the given local name and belonging to no namespace.

Usage

From source file:de.openVJJ.basic.Plugable.java

License:Open Source License

/**
 * for restoring from saved configuration
 * @param element XML Element//from w w w .ja v  a 2 s  .  c o m
 */
public void setConfig(Element element) {
    Element guiPositionElement = element.getChild(ELEMENT_NAME_GUI_POSITION);
    if (guiPositionElement != null) {
        Rectangle guiPosition = getGuiPosition();
        String val = guiPositionElement.getAttributeValue("x");
        if (val != null) {
            guiPosition.x = Integer.parseInt(val);
        }
        val = guiPositionElement.getAttributeValue("y");
        if (val != null) {
            guiPosition.y = Integer.parseInt(val);
        }
        val = guiPositionElement.getAttributeValue("height");
        if (val != null) {
            guiPosition.height = Integer.parseInt(val);
        }
        val = guiPositionElement.getAttributeValue("width");
        if (val != null) {
            guiPosition.width = Integer.parseInt(val);
        }
    }
}

From source file:de.openVJJ.basic.ProjectConf.java

License:Open Source License

public static void load(String fileName) {

    try {/*  w w w  . j  a v  a 2  s. c om*/
        Document document = new SAXBuilder().build(fileName);
        Element rootElement = document.getRootElement();
        if (rootElement.getName() != ROOT_ELEMET_NAME) {
            System.err.println("is not an Open-VJJ 2 Project");
            return;
        }
        //         Element gpuElement = rootElement.getChild(GPU_ELEMENT_NAME);
        //         if(gpuElement != null){
        //            Attribute gpuActiv = gpuElement.getAttribute(GPU_ACTIV_ATTRIBUTE_NAME);
        //            if(gpuActiv != null){
        //               useGPU = gpuActiv.getBooleanValue();
        //            }
        //         }
        Element baseModuleElement = rootElement.getChild(ELEMET_NAME_BASE_MODULE);
        baseModule = new Module();
        baseModule.setBaseModule(true);
        baseModule.setConfig(baseModuleElement);
        if (projectFrame != null) {
            projectFrame.dispose();
        }
        openFrame();
    } catch (JDOMException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:de.openVJJ.InputComponents.java

License:Open Source License

public static void load(String fileName) {
    try {//from w w  w .j av  a 2  s  .  c o  m
        Document document = new SAXBuilder().build(fileName);
        Element rootElement = document.getRootElement();
        if (rootElement.getName() != ROOT_ELEMET_NAME) {
            System.err.println("is notan Open-VJJ Project");
            return;
        }
        Element gpuElement = rootElement.getChild(GPU_ELEMENT_NAME);
        if (gpuElement != null) {
            Attribute gpuActiv = gpuElement.getAttribute(GPU_ACTIV_ATTRIBUTE_NAME);
            if (gpuActiv != null) {
                useGPU = gpuActiv.getBooleanValue();
            }
        }
        removeAll();
        Element components = rootElement.getChild(COMPONENTS_ELEMENT_NAME);
        List<Element> elements = components.getChildren(COMPONENT_ELEMENT_NAME);
        for (Element rootComponente : elements) {
            addComponent((ImagePublisher) loadComponent(rootComponente));
        }
    } catch (JDOMException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:de.openVJJ.InputComponents.java

License:Open Source License

private static VJJComponent loadComponent(Element element) {
    String className = element.getAttribute(CLASS_NAME_ATTRIBUTE_NAME).getValue();
    try {/*w  ww.j a  va  2s . c  o  m*/
        Class<?> c = Class.forName(className);
        Object classInstance = c.newInstance();
        if (VJJComponent.class.isInstance(classInstance)) {
            VJJComponent vjjComponent = (VJJComponent) classInstance;
            Element componentSetup = element.getChild(COMPONENT_SETUP_ELEMENT_NAME);
            if (componentSetup != null) {
                vjjComponent.setConfig(componentSetup);
            }
            if (ImagePublisher.class.isInstance(vjjComponent)) {
                ImagePublisher imagePublisher = (ImagePublisher) classInstance;
                Element components = element.getChild(COMPONENTS_ELEMENT_NAME);
                if (components != null) {
                    List<Element> elements = components.getChildren(COMPONENT_ELEMENT_NAME);
                    for (Element subComponentElement : elements) {
                        ImageListener imageListener = (ImageListener) loadComponent(subComponentElement);
                        if (imageListener == null) {
                            continue;
                        }
                        addComponent(imageListener, imagePublisher);
                    }
                }
            }
            return vjjComponent;
        }
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InstantiationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:de.openVJJ.plugins.LineFromSorbel2DIntArray.java

License:Open Source License

/**
 * for restoring from saved configuration
 * @param element XML Element//from w w w.j ava2 s  . c  om
 */
public void setConfig(Element element) {
    Element myConfigElement = element.getChild(ELEMENT_NAME_LineFromSorbel2DIntArray_CONFIG);
    if (myConfigElement != null) {
        String val = myConfigElement.getAttributeValue("directionx");
        if (val != null) {
            xDirection = Boolean.parseBoolean(val);
        }
        val = myConfigElement.getAttributeValue("lineLimit");
        if (val != null) {
            lineLimit = Integer.parseInt(val);
        }
        val = myConfigElement.getAttributeValue("histery");
        if (val != null) {
            histery = Integer.parseInt(val);
        }
        val = myConfigElement.getAttributeValue("minLength");
        if (val != null) {
            minLength = Integer.parseInt(val);
        }
    }
    super.setConfig(element);
}

From source file:de.openVJJ.plugins.PixelLineToVectors.java

License:Open Source License

/**
 * for restoring from saved configuration
 * @param element XML Element//  w ww  .  j  a  va2s. c  o m
 */
public void setConfig(Element element) {
    Element myConfigElement = element.getChild(ELEMENT_NAME_PixelLineToVectors_CONFIG);
    if (myConfigElement != null) {
        String val = myConfigElement.getAttributeValue("horizontal");
        if (val != null) {
            horizontal = Boolean.parseBoolean(val);
        }
    }
    super.setConfig(element);
}

From source file:de.openVJJ.plugins.PointsToLineOfBestFit.java

License:Open Source License

/**
 * for restoring from saved configuration
 * @param element XML Element//from w w w  .j av a2 s . c  o m
 */
public void setConfig(Element element) {
    Element myConfigElement = element.getChild(ELEMENT_NAME_PointsToLineOfBestFit_CONFIG);
    if (myConfigElement != null) {
        String val = myConfigElement.getAttributeValue("directionx");
        if (val != null) {
            xDirection = Boolean.parseBoolean(val);
        }
        val = myConfigElement.getAttributeValue("minLength");
        if (val != null) {
            minLength = Integer.parseInt(val);
        }
    }
    super.setConfig(element);
}

From source file:de.openVJJ.plugins.XuggleWebCam.java

License:Open Source License

/**
 * for restoring from saved configuration
 * @param element XML Element/*from   w w  w. j a  v a  2s. com*/
 */
public void setConfig(Element element) {
    Element myConfigElement = element.getChild(ELEMENT_NAME_XuggleWebCam_CONFIG);
    if (myConfigElement != null) {
        String val = myConfigElement.getAttributeValue("driverName");
        if (val != null) {
            driverName = val;
        }
        val = myConfigElement.getAttributeValue("deviceName");
        if (val != null) {
            deviceName = val;
        }
        val = myConfigElement.getAttributeValue("framerateLimit");
        if (val != null) {
            framerateLimit = Integer.parseInt(val);
        }
    }
    super.setConfig(element);
}

From source file:de.rallye.api.LandingPage.java

License:Open Source License

private void replaceKgRooms(Document doc, String groupsCode) {
    List<Element> days = doc.getRootElement().getChild("days").getChildren("day");
    for (Element day : days) {
        String dateStr = formatDate(day.getChildText("heading"));

        List<Element> events = day.getChild("events").getChildren("event");
        for (Element event : events) {
            if (event.getChildText("type").equals("kleingruppe")) {

                String locCode = event.getChildText("location");
                RoomCode code = roomCodeMap.get(locCode);
                if (code == null)
                    continue;

                String room = "Kleingruppe";
                if (groupsCode != null) {
                    char ch = groupsCode.charAt(code.digit);
                    int groupIdx = Character.getNumericValue(ch);

                    room = code.rooms.get(groupIdx);
                }/*from   ww w.  j  a  va  2s .c o  m*/

                event.getChild("location").removeContent();
                event.getChild("location").addContent(room);
            }
        }
    }
}

From source file:de.rallye.api.LandingPage.java

License:Open Source License

@GET
@Produces("text/calendar")
@Path("timetable/{groupsCode}.ics")
@Template(name = "/calendar")
public List<Event> getCalendar(@PathParam("groupsCode") String groupsCode) throws JDOMException, IOException {
    try {//from   w ww  .jav  a  2  s.  c o  m
        String year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));

        Document doc = new SAXBuilder()
                .build(StadtRallye.class.getResourceAsStream("timetable/stundenplan.xml"));
        replaceKgRooms(doc, groupsCode);

        List<Event> result = new ArrayList<>();

        List<Element> days = doc.getRootElement().getChild("days").getChildren("day");
        for (Element day : days) {
            String dateStr = formatDate(day.getChildText("heading"));

            List<Element> events = day.getChild("events").getChildren("event");
            for (int i = 0; i < events.size(); i++) {
                Element event = events.get(i);

                if (event.getChildText("type").equals("spacer"))
                    continue;

                Time startT = Time.fromString(event.getChildText("starttime"));
                String start = startT.toString();

                Time endT = new Time(20, 200);
                if (i < events.size() - 1) {
                    Element next = events.get(i + 1);
                    String endStr = next.getChildText("starttime");
                    endT = Time.fromString(endStr);

                    endT = endT.subtractMinutes(10);
                } else {
                    float dur = Float.parseFloat(event.getChildText("duration")) * 55;
                    endT = startT.addMinutes((int) dur);
                }

                String title = event.getChildText("title");
                String titleR = title.replace("&amp;", "&");

                Event e = new Event(year + dateStr + "T" + start + "00",
                        year + dateStr + "T" + endT.toString() + "00", titleR, event.getChildText("location"));
                result.add(e);
            }
        }

        return result;
    } catch (RuntimeException e) {
        e.printStackTrace();
    }
    return null;
}