Example usage for org.jdom2 Element getAttribute

List of usage examples for org.jdom2 Element getAttribute

Introduction

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

Prototype

public Attribute getAttribute(final String attname) 

Source Link

Document

This returns the attribute for this element with the given name and within no namespace, or null if no such attribute exists.

Usage

From source file:TVShowTimelineMaker.util.XML.TopLevelXMLWriter.java

private static Show createShowFromDocument(Document inShowDocument) {
    Element rootElement = inShowDocument.getRootElement();
    Attribute namespaceAttribute = rootElement.getAttribute("namespace");
    Show newShow;/*from w ww.  j  ava  2 s. c o  m*/
    if (namespaceAttribute != null) {
        newShow = new Show(namespaceAttribute.getValue());
    } else {
        String baseURI = inShowDocument.getBaseURI();
        int beginIndex = baseURI.lastIndexOf('/');
        int endIndex = baseURI.lastIndexOf('.');
        if (beginIndex < 0) {
            beginIndex = 1;
        } else {
            beginIndex += 1;
        }
        if ((endIndex < 0) || (endIndex <= beginIndex)) {
            endIndex = baseURI.length();
        }
        baseURI = baseURI.substring(beginIndex, endIndex).replaceAll("%20", " ");
        if (baseURI != null) {
            newShow = new Show(baseURI);
        } else {
            newShow = new Show(defualtNameSpace);
        }
    }
    defualtNameSpace = newShow.getNameSpace();
    Timeline newTimeline = newShow.getTimeLine();
    Element EventsElement = rootElement.getChild("Events");
    //todo: make mutithreaded
    List<Event> collectedEvents = EventsElement.getChildren().parallelStream()
            .filter((Element curEventElement) -> XMLWriterImp.getXMLWriter(
                    MyLittePonyMaps.getEventClassForFriendlyString(curEventElement.getName())) != null)
            .map((Element curEventElement) -> {
                XMLWriter EventXMLWriter = XMLWriterImp.getXMLWriter(
                        MyLittePonyMaps.getEventClassForFriendlyString(curEventElement.getName()));
                return EventXMLWriter.readElements(curEventElement);
            }).filter((Object o) -> o instanceof Event).map((Object o) -> (Event) o)
            .collect(Collectors.toList());
    newTimeline.addEvents(collectedEvents);
    EventImp.addEventsToEventMap(collectedEvents);
    Element CharactersElement = rootElement.getChild("Characters");
    XMLWriter<NamedCharacter> NamedCharacterXMLWriter = XMLWriterImp.getXMLWriter(NamedCharacter.class);
    List<NamedCharacter> collectedCharacters = CharactersElement.getChildren().parallelStream()
            .map(NamedCharacterXMLWriter::readElements).collect(Collectors.toList());
    newShow.addCharacters(collectedCharacters);
    NamedCharacter.addCharactersIntoCharacterMap(collectedCharacters);
    Element EpisodesElement = rootElement.getChild("Episodes");
    XMLWriter<Episode> EpisodeXMLWriter = XMLWriterImp.getXMLWriter(Episode.class);
    //todo: make mutithreaded
    List<Episode> collectedEpisodes = EpisodesElement.getChildren().parallelStream()
            .map(EpisodeXMLWriter::readElements).collect(Collectors.toList());
    newShow.addEpisodes(collectedEpisodes);
    Element ConstraintsElement = rootElement.getChild("Constraints");
    //todo: make mutithreaded
    newTimeline.addTimeConstraints(ConstraintsElement.getChildren().parallelStream()
            .filter((Element curElement) -> XMLWriterImp.getXMLWriter(
                    MyLittePonyMaps.getConstraintClassForFriendlyString(curElement.getName())) != null)
            .map((Element curElement) -> {
                XMLWriter ConstraintXMLWriter = XMLWriterImp.getXMLWriter(
                        MyLittePonyMaps.getConstraintClassForFriendlyString(curElement.getName()));
                return (TimeConstraint) ConstraintXMLWriter.readElements(curElement);
            }).collect(Collectors.toList()));
    return newShow;
}

From source file:uk.ac.ox.oucs.vle.xcri.daisy.CourseSubUnit.java

License:Educational Community License

@Override
public void fromXml(Element element) throws InvalidElementException {
    super.fromXml(element);
    if (null != element.getAttribute("code")) {
        this.setCode(element.getAttributeValue("code"));
    }/*from w  w w  .j a  va  2  s.  c o  m*/
}

From source file:wasr.DocNode.java

License:Apache License

private static String getAttributeValue(Element element, String attributeName, String defaultValue) {
    Attribute attribute = element.getAttribute(attributeName);
    return attribute == null ? defaultValue : attribute.getValue();
}

From source file:wasr.FieldUI.java

License:Apache License

public static FieldUIWidget getFieldUIWidget(String nodeId, Element fieldElement) {
    String fieldId = fieldElement.getAttribute("id").getValue();
    String name = nodeId + '.' + fieldId;
    FieldUIWidget widget = widgetMap.get(name);
    if (widget == null) {
        String componentType = fieldElement.getAttribute("component") == null ? "JTextField"
                : fieldElement.getAttribute("component").getValue();
        widget = WidgetFactory.createWidget(componentType, nodeId, fieldId);

        if (widget == null) {
            widget = new JTextFieldUIWidget(nodeId, fieldId);
        }//w  w  w  .  j a va 2s  .com

        LOG.debug("Created and cached widget for " + nodeId + "." + fieldId);
        widgetMap.put(name, widget);
    }
    return widget;
}

From source file:whitehole.ObjectDB.java

License:Open Source License

public static void initialize() {
    fallback = true;/*from  ww w  . j  a  v  a 2s  .c o  m*/
    timestamp = 0;

    categories = new LinkedHashMap<>();
    objects = new LinkedHashMap<>();

    File odbfile = new File("objectdb.xml");
    if (!odbfile.exists())
        return;

    try {
        SAXBuilder sxb = new SAXBuilder();
        Document doc = sxb.build(odbfile);
        Element root = doc.getRootElement();
        timestamp = root.getAttribute("timestamp").getLongValue();

        List<Element> catelems = root.getChild("categories").getChildren("category");
        for (Element catelem : catelems)
            categories.put(catelem.getAttribute("id").getIntValue(), catelem.getText());

        List<Element> objelems = root.getChildren("object");
        for (Element objelem : objelems) {
            Object entry = new Object();
            entry.ID = objelem.getAttributeValue("id");

            entry.name = objelem.getChildText("name");

            Element flags = objelem.getChild("flags");
            entry.games = flags.getAttribute("games").getIntValue();

            entry.category = objelem.getChild("category").getAttribute("id").getIntValue();

            entry.preferredFile = objelem.getChild("preferredfile").getAttributeValue("name");
            entry.notes = objelem.getChildText("notes");

            entry.dataFiles = new ArrayList<>();
            String datafiles = objelem.getChildText("files");
            for (String datafile : datafiles.split("\n"))
                entry.dataFiles.add(datafile);

            List<Element> fields = objelem.getChildren("field");
            entry.fields = new HashMap<>(fields.size());
            for (Element field : fields) {
                Object.Field fielddata = new Object.Field();

                fielddata.ID = field.getAttribute("id").getIntValue();
                fielddata.type = field.getAttributeValue("type");
                fielddata.name = field.getAttributeValue("name");
                fielddata.values = field.getAttributeValue("values");
                fielddata.notes = field.getAttributeValue("notes");

                entry.fields.put(fielddata.ID, fielddata);
            }

            objects.put(entry.ID, entry);
        }
    } catch (Exception ex) {
        timestamp = 0;
        return;
    }

    fallback = false;
}