Example usage for org.jdom2 Attribute getValue

List of usage examples for org.jdom2 Attribute getValue

Introduction

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

Prototype

public String getValue() 

Source Link

Document

This will return the actual textual value of this Attribute.

Usage

From source file:tradingapp.TradeTimer.java

public static void LoadSpecialTradingDays() {
    logger.fine("Loading special days!");
    specialTradingDays.clear();/*www. java  2s . co m*/
    try {
        File inputFile = new File(FilePaths.specialTradingDaysPathFile);
        SAXBuilder saxBuilder = new SAXBuilder();
        Document document = saxBuilder.build(inputFile);

        Element rootElement = document.getRootElement();
        List<Element> dayElements = rootElement.getChildren();

        for (Element dayElement : dayElements) {
            TradingDay day = new TradingDay();
            Attribute attribute = dayElement.getAttribute("date");
            if (attribute != null) {
                String dateStr = attribute.getValue();
                day.date = LocalDate.parse(dateStr);
            } else {
                logger.severe("Failed to load special trading day from " + inputFile.getAbsolutePath());
                continue;
            }

            attribute = dayElement.getAttribute("closeTime");
            if (attribute != null) {
                String timeStr = attribute.getValue();
                day.closingTime = LocalTime.parse(timeStr);
            } else {
                day.closingTime = null;
            }

            specialTradingDays.add(day);
        }

        logger.fine("Special days loaded: " + specialTradingDays.size());
    } catch (JDOMException e) {
        e.printStackTrace();
        logger.severe("Error in loading special days from XML: JDOMException.\r\n" + e);
    } catch (IOException ioe) {
        ioe.printStackTrace();
        logger.severe("Error in loading special days from XML: IOException.\r\n" + ioe);
    }
}

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;//  ww w .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:unidue.ub.statistics.resolver.JOPResolver.java

/**
 * Queries the JOP brief xml service to get the total status of electronic availability, and adds that state
 * to the ElectronicData element. In case total access is given by combining multiple licenses with state '3' 
 * (partially licensed), only the brief response contains the information that the combined license covers
 * the complete journal, if so. //from   w w w.ja  v  a 2 s .c om
 */
private void addElectronicDataTotalState(Element fullXML, String query)
        throws SAXException, IOException, JDOMException {
    Element briefData = getJOPDataFromRemoteServer(query, jopBriefURL);
    XPathExpression<Attribute> xPath = XPathFactory.instance().compile(xpathToElectronicDataState,
            Filters.attribute());
    Attribute state = xPath.evaluateFirst(briefData);
    LOGGER.debug("electronic availability total state from brief xml response is " + state.getValue());
    Element electronicData = XPathFactory.instance().compile(xpathToElectronicDataFull, Filters.element())
            .evaluateFirst(fullXML);
    state.detach();
    electronicData.setAttribute(state);
}

From source file:us.xwhite.dvd.endpoint.RentalEndpoint.java

License:Apache License

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "RentalRequest")
public void handleHolidayRequest(@RequestPayload Element rentalRequest) throws Exception {
    this.storeId.evaluateFirst(rentalRequest).getLongValue();
    List<Attribute> filmTitleAttributes = this.filmTitles.evaluate(rentalRequest);
    List<String> filmTitles = new ArrayList<>();
    for (Attribute attr : filmTitleAttributes) {
        filmTitles.add(attr.getValue());
    }/*from  w w  w  .  j av a 2 s .c  o  m*/

    this.rentalService.rentMovies(this.storeId.evaluateFirst(rentalRequest).getLongValue(), filmTitles);
}

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.DocNode.java

License:Apache License

private String getTemplateAttribute(String attributeName, String defaultValue) {
    Attribute attribute = template.getAttribute(attributeName);
    return attribute == null ? defaultValue : attribute.getValue();
}

From source file:xml.JDOMConverter.java

License:Apache License

/**.
 * Handles the case where the object in filter is an attribute
 * @param a the filtered attribute//from ww w.  j a  v  a2 s  .  com
 * @throws JSONException
 */
private void handleAttribute(final Attribute a) throws JSONException {
    tree.get(current).put(a.getName(), a.getValue());
}