Example usage for org.jdom2 Document getRootElement

List of usage examples for org.jdom2 Document getRootElement

Introduction

In this page you can find the example usage for org.jdom2 Document getRootElement.

Prototype

public Element getRootElement() 

Source Link

Document

This will return the root Element for this Document

Usage

From source file:de.intranda.goobi.plugins.sru.SRUHelper.java

License:Open Source License

public static Element getRecordWithoutSruHeader(Document document) {
    Element root = document.getRootElement();
    // <srw:records>
    Element srw_records = root.getChild("records", SRW);
    // <srw:record>
    if (srw_records == null) {
        return null;
    }/*from  w  w  w  .  j a va  2  s.c o  m*/
    List<Element> srw_recordList = srw_records.getChildren("record", SRW);

    // <srw:recordData>
    if (srw_recordList == null || srw_recordList.isEmpty()) {
        return null;
    }
    Element recordData = srw_recordList.get(0).getChild("recordData", SRW);

    Element record = recordData.getChild("record", MARC);
    return record;
}

From source file:de.knewcleus.openradar.gui.flightplan.FlightPlanExchangeManager.java

License:Open Source License

private void loadUpdatesFromServer() {
    // collect the active contacts in range
    StringBuilder callSignList = new StringBuilder();
    for (GuiRadarContact contact : radarContactController.getContactListCopy()) {
        // we must send all because server releases contacts that are out of range
        if (callSignList.length() > 0) {
            callSignList.append(",");
        }/*from   w  w w  .  j  a v  a2 s .  c  om*/
        callSignList.append(contact.getCallSign().trim());
    }
    log.trace("Flightplan: " + data.getCallSign() + " Going to request updates for: " + callSignList);
    // send the list to the server to request updated flightplans

    //        if (callSignList.length() > 0) {

    try {
        StringBuilder result = new StringBuilder();
        String line = null;
        URL url;
        if (initial) {
            url = new URL(baseUrl + "/getAllFlightplans");
            initial = false;
        } else {
            url = new URL(baseUrl + "/getFlightplans");
        }

        String frequency = "000.00";
        if (!master.getRadioManager().getModels().isEmpty()) {
            frequency = master.getRadioManager().getModels().get("COM0").getSelectedItem().getFrequency();
        }

        String parameters = "user=" + URLEncoder.encode(data.getFpServerUser(), "UTF-8") + "&password="
                + URLEncoder.encode(data.getFpServerPassword(), "UTF-8") + "&username="
                + URLEncoder.encode("John Doe", "UTF-8") // todo
                + "&atc=" + URLEncoder.encode(data.getCallSign(), "UTF-8") + "&airport="
                + URLEncoder.encode(data.getAirportCode(), "UTF-8") + "&lon="
                + Double.toString(data.getAirportPosition().getX()) + "&lat="
                + Double.toString(data.getAirportPosition().getY()) + "&frequency=" + frequency
                + "&xmlVersion=1.0" + "&contacts=" + URLEncoder.encode(callSignList.toString(), "UTF-8");

        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setRequestMethod("POST");
        con.setDoInput(true);
        con.setDoOutput(true);
        con.setUseCaches(false);
        con.setRequestProperty("Accept-Charset", "UTF-8");
        con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
        con.setRequestProperty("User-Agent", "OpenRadar");
        DataOutputStream dos = new DataOutputStream(con.getOutputStream());
        dos.write(parameters.getBytes("UTF-8"));
        dos.flush();
        dos.close();

        // parse response

        int responseCode = con.getResponseCode();
        if (responseCode == 200) {
            BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
            line = reader.readLine();
            while (line != null) {
                result.append(line).append("\n");
                line = reader.readLine();
            }
            reader.close();

            try {
                Document document = new SAXBuilder().build(new StringReader(result.toString().trim()));
                // String version = document.getRootElement().getAttributeValue("version");

                Element eAtcsInRange = document.getRootElement().getChild("atcsInRange");
                if (eAtcsInRange != null) {
                    List<FpAtc> activeAtcs = FpXml_1_0.parseAtcs(eAtcsInRange);
                    master.getRadarContactManager().setActiveAtcs(activeAtcs);
                }

                List<Element> eFlightPlans = document.getRootElement().getChildren("flightplan");
                for (Element eFp : eFlightPlans) {
                    String callsign = FpXml_1_0.getCallSign(eFp);
                    GuiRadarContact c = radarContactController.getContactFor(callsign);
                    if (c != null) {
                        radarContactController.updateFlightPlan(c, FpXml_1_0.parseXml(data, c, eFp));
                    }
                    log.info("Got FP update for: " + callsign);
                }
                connectedToServer = true;
            } catch (IOException e) {
                log.error("Error while parsing flightplan!", e);
            }

        } else {
            log.warn("Flightplan: " + data.getCallSign()
                    + " Failed to retrieve flightplan updates! (got response code " + responseCode + " from "
                    + url.toString() + ")...");
            connectedToServer = false;
        }
    } catch (ConnectException e) {
        log.error("Problem to connect to fpserver: " + e.getMessage());
    } catch (Exception e) {
        log.error("Problem to parse updated flightplans!", e);
    }
    //   } // callsignlist.length>0
}

From source file:de.knewcleus.openradar.gui.flightplan.lenny64.Lenny64XmlParser.java

License:Open Source License

public static List<FlightPlanData> parse(AirportData data, GuiRadarContact contact, Document document) {
    List<FlightPlanData> result = new ArrayList<FlightPlanData>();

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    String today = sdf.format(new Date());

    SimpleDateFormat xmlTimeFormat = new SimpleDateFormat("HH:mm:ss");
    SimpleDateFormat shortTimeFormat = new SimpleDateFormat("HH:mm");

    List<Element> eFlightPlans = document.getRootElement().getChildren("flightplan");
    if (eFlightPlans != null) {
        for (Element eFp : eFlightPlans) {
            String flightplanId = eFp.getChildText("flightplanId");
            String callsign = eFp.getChildText("callsign");
            String flightNumber = eFp.getChildText("flightNumber");
            String airportFrom = eFp.getChildText("airportFrom");
            String airportTo = eFp.getChildText("airportTo");
            String alternateDestination = eFp.getChildText("alternateDestination");
            String cruiseAltitude = eFp.getChildText("cruiseAltitude");
            String trueAirspeed = eFp.getChildText("trueAirspeed");
            String dateDeparture = eFp.getChildText("dateDeparture");
            String dateArrival = eFp.getChildText("dateArrival");
            String departureTime = eFp.getChildText("departureTime");
            String arrivalTime = eFp.getChildText("arrivalTime");
            String aircraft = eFp.getChildText("aircraft");
            String soulsOnBoard = eFp.getChildText("soulsOnBoard");
            String fuelTime = eFp.getChildText("fuelTime");
            String pilotName = eFp.getChildText("pilotName");
            String waypoints = eFp.getChildText("waypoints");
            String category = eFp.getChildText("category");
            //                String comments = eFp.getChildText("comments");
            //                StringBuilder messages = new StringBuilder();
            //                List<Element> eComments = document.getRootElement().getChild("comments").getChildren("comment");
            //                for (Element eComment : eComments) {
            //                    String user = eComment.getChildText("user");
            //                    String message = eComment.getChildText("message");
            //                    messages.append(user).append(": ").append(message).append("; ");
            //                }
            String status = eFp.getChildText("status");
            status = status.equals("") ? FlightPlanData.FlightPlanStatus.ACTIVE.toString()
                    : status.replaceAll("filled", "FILED");
            //                String additionalInformation = eFp.getChildText("additionalInformation");
            //                String lastUpdated = eFp.getChildText("lastUpdated");

            if ((status.equalsIgnoreCase(FlightPlanData.FlightPlanStatus.ACTIVE.toString())
                    || status.equalsIgnoreCase(FlightPlanData.FlightPlanStatus.FILED.toString()))
                    /*(airportFrom.equals(data.getAirportCode()) || airportTo.equals(data.getAirportCode()) ) */
                    && (dateDeparture.equals(today) || dateArrival.equals(today))) {
                // check for departure date
                try {
                    FlightPlanData fpd = contact.getFlightPlan().copy(); // creates a copy of the existing record
                    // now merge the data we have got and which we do not already know
                    fpd.setFlightPlanId(flightplanId);
                    fpd.setAircraft(aircraft);
                    fpd.setAlternativeDestinationAirports(alternateDestination);
                    // callsign is already known
                    cruiseAltitude = cruiseAltitude.equals("FL") ? "" : cruiseAltitude;
                    fpd.setCruisingAltitude(cruiseAltitude);
                    departureTime = shortTimeFormat.format(xmlTimeFormat.parse(departureTime));
                    fpd.setDeparture(departureTime); // todo
                    fpd.setDepartureAirport(airportFrom);
                    fpd.setDestinationAirport(airportTo);
                    arrivalTime = shortTimeFormat.format(xmlTimeFormat.parse(arrivalTime));
                    //fpd.setEstimatedFlightTime(estimatedFlightTime); // todo
                    fpd.setEstimatedFuelTime(fuelTime);
                    fpd.setFlightCode(flightNumber);
                    fpd.setFpStatus(status);
                    fpd.setPilotName(pilotName);
                    // fpd.setRemarks(messages.toString());
                    fpd.setRoute(waypoints);
                    if (null != soulsOnBoard && !"".equals(soulsOnBoard)) {
                        fpd.setSoulsOnBoard(Integer.parseInt(soulsOnBoard));
                    }// ww w  .j av  a2 s .co m
                    trueAirspeed = trueAirspeed.equals("TAS") ? "" : trueAirspeed;
                    fpd.setTrueAirspeed(trueAirspeed);
                    fpd.setType(category);
                    result.add(fpd);
                } catch (Exception e) {
                    log.error("Error while parsing flightplan #" + flightNumber + " for " + callsign, e);
                }
            } else {
                log.trace("Skipping flightplan, it is for another airport: #" + flightNumber + " from:"
                        + airportFrom + " to:" + airportTo);
            }
        }
    }

    return result;
}

From source file:de.knewcleus.openradar.view.groundnet.GroundnetReader.java

License:Open Source License

private void readGroundnetXml() {

    SAXBuilder builder = new SAXBuilder();
    InputStream xmlInputStream = null;

    try {/*from  ww w .  j  a  v a  2s . c o  m*/
        xmlInputStream = getZipArchiveFileInputStream("data/airports.zip", airportCode);

        Document document = (Document) builder.build(xmlInputStream);
        Element rootNode = document.getRootElement();

        // read parking list
        List<Element> list = rootNode.getChild("parkingList").getChildren("Parking");
        for (Element p : list) {
            String index = p.getAttributeValue("index");
            String type = p.getAttributeValue("type");
            String name = p.getAttributeValue("name");
            String number = p.getAttributeValue("number");
            String lat = p.getAttributeValue("lat");
            String lon = p.getAttributeValue("lon");
            String heading = p.getAttributeValue("heading");
            String radius = p.getAttributeValue("radius");
            String airlineCodes = p.getAttributeValue("airlineCodes");
            ParkPos pos = new ParkPos(index, type, name, number, lat, lon, heading, radius, airlineCodes);
            parkPosList.add(pos);
            mapTaxiPoints.put(index, pos);
        }

        // read nodes
        list = rootNode.getChild("TaxiNodes").getChildren("node");
        for (Element p : list) {
            String index = p.getAttributeValue("index");
            String lat = p.getAttributeValue("lat");
            String lon = p.getAttributeValue("lon");
            boolean isOnRunway = !"0".equals(p.getAttributeValue("isOnRunway"));
            String holdPointType = p.getAttributeValue("holdPointType");
            TaxiPoint point = new TaxiPoint(index, lat, lon, isOnRunway, holdPointType);
            mapTaxiPoints.put(index, point);
        }
        // read segments
        list = rootNode.getChild("TaxiWaySegments").getChildren("arc");
        for (Element a : list) {
            String beginPoint = a.getAttributeValue("begin");
            String endPoint = a.getAttributeValue("end");
            boolean isPushBackRoute = !"0".equals(a.getAttributeValue("isPushBackRoute"));
            String name = a.getAttributeValue("name");
            TaxiWaySegment seg = new TaxiWaySegment(name, mapTaxiPoints.get(beginPoint),
                    mapTaxiPoints.get(endPoint), isPushBackRoute);
            taxiwaySegmentList.add(seg);
        }

    } catch (Exception e) {
        log.error(e.getMessage());
    } finally {
        if (xmlInputStream != null) {
            try {
                xmlInputStream.close();
                zipArchive.close();
            } catch (IOException e) {
            }
        }
    }
}

From source file:de.knewcleus.openradar.view.stdroutes.StdRouteReader.java

License:Open Source License

private void readRouteXml() {

    SAXBuilder builder = new SAXBuilder();
    InputStream xmlInputStream = null;

    File dir = new File("data/routes/" + data.getAirportCode());
    if (!dir.exists() || !dir.isDirectory()) {
        return;/*from  w w  w. j a v a2  s  . c om*/
    }

    List<File> files = new ArrayList<File>(Arrays.asList(dir.listFiles()));

    data.getNavaidDB().clearAddPoints();

    while (files.size() > 0) {
        File file = files.remove(0);
        try {
            if (!file.getName().endsWith(".xml"))
                continue;
            // todo read all files
            xmlInputStream = new FileInputStream(file);

            Document document = (Document) builder.build(xmlInputStream);
            Element rootNode = document.getRootElement();

            //                String orFilename = "data/routes/" + data.getAirportCode() + "/" + file.getName().substring(0, file.getName().indexOf(".xml")) + ".or.xml";
            if ("ProceduresDB".equalsIgnoreCase(rootNode.getName())) {// && !(new File(orFilename).exists())) {
                // if converted file does not exist, convert it now.
                // deactivated for now convertProcedureDbFile(orFilename, rootNode);
            } else {
                // read or file
                List<Element> list = rootNode.getChildren("addPoint");
                for (Element eAddPoint : list) {
                    String code = eAddPoint.getAttributeValue("code");
                    String sPoint = eAddPoint.getAttributeValue("point");
                    try {
                        Point2D point = StdRoute.getPoint(data, mapViewAdapter, sPoint, null);
                        data.getNavaidDB().addPoint(code, point);
                    } catch (Exception e) {
                        log.error("Problem to parse file " + file.getAbsolutePath() + ", addPoint: " + code
                                + ": " + sPoint + ", Error:" + e.getMessage());
                    }
                }
                List<Element> includeList = rootNode.getChildren("include");
                for (Element eInclude : includeList) {
                    String fileName = eInclude.getAttributeValue("file");
                    files.add(new File(file.getAbsolutePath().substring(0,
                            file.getAbsolutePath().lastIndexOf(File.separator) + 1) + fileName));
                }
                // routes
                list = rootNode.getChildren("route");
                for (Element eRoute : list) {
                    String name = eRoute.getAttributeValue("name");
                    String displayMode = eRoute.getAttributeValue("displayMode");
                    String zoomMin = eRoute.getAttributeValue("zoomMin");
                    String zoomMax = eRoute.getAttributeValue("zoomMax");
                    String stroke = eRoute.getAttributeValue("stroke");
                    String lineWidth = eRoute.getAttributeValue("lineWidth");
                    String color = eRoute.getAttributeValue("color");
                    List<Element> sublist = eRoute.getChildren();
                    AStdRouteElement previous = null;
                    StdRoute route = new StdRoute(data, mapViewAdapter, name, displayMode, zoomMin, zoomMax,
                            stroke, lineWidth, color);
                    for (Element element : sublist) {
                        try {
                            if (element.getName().equalsIgnoreCase("activeLandingRunways")) {
                                route.setActiveLandingRunways(element.getText());
                            } else if (element.getName().equalsIgnoreCase("activeStartRunways")) {
                                route.setActiveStartingRunways(element.getText());
                            } else if (element.getName().equalsIgnoreCase("navaids")) {
                                color = element.getAttributeValue("color");
                                route.setNavaids(element.getText(), color);
                            } else if (element.getName().equalsIgnoreCase("include")) {
                                String routeName = element.getAttributeValue("routeName");
                                route.includeRoute(stdRoutes, routeName);
                            } else if (element.getName().equalsIgnoreCase("line")) {
                                String start = element.getAttributeValue("start");
                                String end = element.getAttributeValue("end");
                                String angle = element.getAttributeValue("angle");
                                String length = element.getAttributeValue("length");
                                String startOffset = element.getAttributeValue("startOffset");
                                String endOffset = element.getAttributeValue("endOffset");
                                stroke = element.getAttributeValue("stroke");
                                lineWidth = element.getAttributeValue("lineWidth");
                                String arrows = element.getAttributeValue("arrows");
                                color = element.getAttributeValue("color");
                                String text = element.getAttributeValue("text");
                                StdRouteLine line = new StdRouteLine(route, mapViewAdapter, previous, start,
                                        end, angle, length, startOffset, endOffset, stroke, lineWidth, arrows,
                                        color, text);
                                previous = line;
                                route.addElement(line);
                            } else if (element.getName().equalsIgnoreCase("bow")) {
                                String center = element.getAttributeValue("center");
                                String radius = element.getAttributeValue("radius");
                                String startAngle = element.getAttributeValue("startAngle");
                                String extentAngle = element.getAttributeValue("extentAngle");
                                stroke = element.getAttributeValue("stroke");
                                lineWidth = element.getAttributeValue("lineWidth");
                                String arrows = element.getAttributeValue("arrows");
                                color = element.getAttributeValue("color");
                                String text = element.getAttributeValue("text");
                                StdRouteBow bow = new StdRouteBow(route, mapViewAdapter, previous, center,
                                        radius, startAngle, extentAngle, stroke, lineWidth, color, arrows,
                                        text);
                                previous = bow;
                                route.addElement(bow);
                            } else if (element.getName().equalsIgnoreCase("curve")) {
                                String start = element.getAttributeValue("start");
                                String end = element.getAttributeValue("end");
                                String controlPoint = element.getAttributeValue("controlPoint");
                                stroke = element.getAttributeValue("stroke");
                                lineWidth = element.getAttributeValue("lineWidth");
                                String arrows = element.getAttributeValue("arrows");
                                color = element.getAttributeValue("color");
                                StdRouteCurve bow = new StdRouteCurve(route, mapViewAdapter, previous, start,
                                        end, controlPoint, stroke, lineWidth, color, arrows);
                                previous = bow;
                                route.addElement(bow);
                            } else if (element.getName().equalsIgnoreCase("intercept")) {
                                String start = element.getAttributeValue("start");
                                String startOffset = element.getAttributeValue("startOffset");
                                String startHeading = element.getAttributeValue("startHeading");
                                String startTurn = element.getAttributeValue("startTurn");
                                String radius = element.getAttributeValue("radius");
                                String speed = element.getAttributeValue("speed");
                                String end = element.getAttributeValue("end");
                                String radial = element.getAttributeValue("radial");
                                String endHeading = element.getAttributeValue("endHeading");
                                String direction = element.getAttributeValue("direction");
                                String endOffset = element.getAttributeValue("endOffset");
                                String text = element.getAttributeValue("text");
                                stroke = element.getAttributeValue("stroke");
                                lineWidth = element.getAttributeValue("lineWidth");
                                String arrows = element.getAttributeValue("arrows");
                                color = element.getAttributeValue("color");
                                StdRouteIntercept intercept = new StdRouteIntercept(route, mapViewAdapter,
                                        previous, start, startOffset, startHeading, startTurn, radius, speed,
                                        end, radial, endHeading, direction, endOffset, stroke, lineWidth,
                                        arrows, color, text);
                                previous = intercept;
                                route.addElement(intercept);
                            } else if (element.getName().equalsIgnoreCase("loop")) {
                                String navpoint = element.getAttributeValue("navpoint");
                                String inboundHeading = element.getAttributeValue("inboundHeading");
                                String length = element.getAttributeValue("length");
                                String width = element.getAttributeValue("width");
                                String right = element.getAttributeValue("right");
                                String arrows = element.getAttributeValue("arrows");
                                String minHeight = element.getAttributeValue("minHeight");
                                String maxHeight = element.getAttributeValue("maxHeight");
                                String misapHeight = element.getAttributeValue("misapHeight");
                                stroke = element.getAttributeValue("stroke");
                                lineWidth = element.getAttributeValue("lineWidth");
                                color = element.getAttributeValue("color");
                                StdRouteLoop ellipse = new StdRouteLoop(route, mapViewAdapter, previous,
                                        navpoint, inboundHeading, length, width, right, arrows, minHeight,
                                        maxHeight, misapHeight, stroke, lineWidth, color);
                                previous = ellipse;
                                route.addElement(ellipse);
                            } else if (element.getName().equalsIgnoreCase("multiPointLine")) {
                                String close = element.getAttributeValue("close");
                                stroke = element.getAttributeValue("stroke");
                                lineWidth = element.getAttributeValue("lineWidth");
                                color = element.getAttributeValue("color");
                                List<String> points = new ArrayList<String>();
                                List<Element> pointList = element.getChildren("point");
                                for (Element ePoint : pointList) {
                                    points.add(ePoint.getTextTrim());
                                }
                                StdRouteMultipointLine line = new StdRouteMultipointLine(route, mapViewAdapter,
                                        previous, points, close, stroke, lineWidth, color);
                                previous = line;
                                route.addElement(line);
                            } else if (element.getName().equalsIgnoreCase("text")) {
                                String position = element.getAttributeValue("position");
                                String angle = element.getAttributeValue("angle");
                                String alignHeading = element.getAttributeValue("alignHeading");
                                String font = element.getAttributeValue("font");
                                String fontSize = element.getAttributeValue("fontSize");
                                color = element.getAttributeValue("color");
                                boolean clickable = "true".equals(element.getAttributeValue("clickable"));
                                String sText = element.getAttributeValue("text");
                                StdRouteText text = new StdRouteText(route, mapViewAdapter, previous, position,
                                        angle, alignHeading, font, fontSize, color, clickable, sText);
                                previous = text;
                                route.addElement(text);
                            } else if (element.getName().equalsIgnoreCase("screenText")) {
                                String position = element.getAttributeValue("screenPos");
                                String angle = element.getAttributeValue("angle");
                                String font = element.getAttributeValue("font");
                                String fontSize = element.getAttributeValue("fontSize");
                                color = element.getAttributeValue("color");
                                String sText = element.getAttributeValue("text");
                                StdRouteScreenText text = new StdRouteScreenText(route, mapViewAdapter,
                                        previous, position, angle, font, fontSize, color, sText);
                                previous = text;
                                route.addElement(text);
                            } else if (element.getName().equalsIgnoreCase("minAlt")) {
                                String position = element.getAttributeValue("position");
                                String value = element.getAttributeValue("value");
                                String font = element.getAttributeValue("font");
                                String fontSize = element.getAttributeValue("fontSize");
                                color = element.getAttributeValue("color");
                                StdRouteMinAltitude minAlt = new StdRouteMinAltitude(route, mapViewAdapter,
                                        previous, position, value, font, fontSize, color);
                                previous = minAlt;
                                route.addElement(minAlt);
                            }

                        } catch (Exception e) {
                            log.error("Problem to parse file " + file.getAbsolutePath() + ", Route: "
                                    + route.getName() + ", Error:" + e.getMessage(), e);
                            break;
                        }
                    }
                    stdRoutes.add(route);
                }
            }

        } catch (Exception e) {
            log.error("Problem to parse file " + file.getAbsolutePath() + ", Error:" + e.getMessage());

        } finally {
            if (xmlInputStream != null) {
                try {
                    xmlInputStream.close();
                } catch (IOException e) {
                }
            }
        }
    }
    data.getNavaidDB().setStdRoutes(stdRoutes);
}

From source file:de.knowwe.visualization.dot.DOTRenderer.java

License:Open Source License

/**
 * Adds the target-tag to every URL in the svg-file
 *
 * @created 01.08.2012//from   w  w  w  . jav a2  s.c  o m
 */
private static void augmentSVG(File svg) throws IOException {
    Log.finest("Starting to augment SVG: " + svg.getAbsolutePath());
    try {
        // check if svg file is closed, otherwise wait timeout second
        long start = System.currentTimeMillis();
        while (!Utils.isFileClosed(svg)) {
            if ((System.currentTimeMillis() - start) > TIMEOUT) {
                Log.warning("Exceded timeout while waiting for SVG file to be closed.");
                return;
            }
        }

        Document doc = SAXBuilderSingleton.getInstance().build(svg);
        Element root = doc.getRootElement();
        if (root == null)
            return;

        findAndAugmentElements(root);

        XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
        xmlOutputter.output(doc, new FileWriter(svg));
        Log.finest("Finished augmenting SVG: " + svg.getAbsolutePath());
    } catch (JDOMException e) {
        Log.warning("Exception while augmenting SVG " + svg.getAbsolutePath(), e);
    }
}

From source file:de.nava.informa.parsers.FeedParser.java

License:Open Source License

private static synchronized ChannelIF parse(ChannelBuilderIF cBuilder, Document doc) throws ParseException {

    if (cBuilder == null) {
        throw new RuntimeException("Without builder no channel can " + "be created.");
    }/*from ww w  .ja  va 2s  .  c  o  m*/
    LOGGER.debug("start parsing.");
    // Get the root element (must be rss)
    Element root = doc.getRootElement();
    String rootElement = root.getName().toLowerCase();
    // Decide which parser to use
    if (rootElement.startsWith("rss")) {
        String rssVersion = root.getAttribute("version").getValue();
        if (rssVersion.contains("0.91")) {
            LOGGER.info("Channel uses RSS root element (Version 0.91).");
            return RSS_0_91_Parser.getInstance().parse(cBuilder, root);
        } else if (rssVersion.contains("0.92")) {
            LOGGER.info("Channel uses RSS root element (Version 0.92).");
            // logger.warn("RSS 0.92 not fully supported yet, fall back to 0.91.");
            // TODO: support RSS 0.92 when aware of all subtle differences.
            return RSS_0_91_Parser.getInstance().parse(cBuilder, root);
        } else if (rootElement.contains("0.93")) {
            LOGGER.info("Channel uses RSS root element (Version 0.93).");
            LOGGER.warn("RSS 0.93 not fully supported yet, fall back to 0.91.");
            // TODO: support RSS 0.93 when aware of all subtle differences.
        } else if (rootElement.contains("0.94")) {
            LOGGER.info("Channel uses RSS root element (Version 0.94).");
            LOGGER.warn("RSS 0.94 not fully supported yet, will use RSS 2.0");
            // TODO: support RSS 0.94 when aware of all subtle differences.
            return RSS_2_0_Parser.getInstance().parse(cBuilder, root);
        } else if (rssVersion.contains("2.0") || rssVersion.equals("2")) {
            LOGGER.info("Channel uses RSS root element (Version 2.0).");
            return RSS_2_0_Parser.getInstance().parse(cBuilder, root);
        } else {
            throw new UnsupportedFormatException("Unsupported RSS version [" + rssVersion + "].");
        }
    } else if (rootElement.contains("rdf")) {
        return RSS_1_0_Parser.getInstance().parse(cBuilder, root);
    } else if (rootElement.contains("feed")) {
        Attribute versionAttr = root.getAttribute("version");
        Namespace namespace = ParserUtils.getDefaultNS(root);
        if (versionAttr != null) {
            String feedVersion = versionAttr.getValue();
            if (feedVersion.contains("0.1") || feedVersion.contains("0.2")) {
                LOGGER.info("Channel uses feed root element (Version " + feedVersion + ").");
                LOGGER.warn("This atom version is not really supported yet, assume Atom 0.3 format");
                return Atom_0_3_Parser.getInstance().parse(cBuilder, root);
            } else if (feedVersion.contains("0.3")) {
                LOGGER.info("Channel uses feed root element (Version 0.3).");
                return Atom_0_3_Parser.getInstance().parse(cBuilder, root);
            }
        } else if (namespace != null && namespace.getURI() != null) {
            if (!namespace.getURI().equals("http://www.w3.org/2005/Atom")) {
                LOGGER.warn("Channel uses unknown namespace in feed root element, assume Atom 1.0 format.");
            } else {
                LOGGER.info("Channel uses feed root element (Atom 1.0 format).");
            }
            return Atom_1_0_Parser.getInstance().parse(cBuilder, root);
        }
    }

    // did not match anything
    throw new UnsupportedFormatException("Unsupported root element [" + rootElement + "].");
}

From source file:de.nava.informa.parsers.OPMLParser.java

License:Open Source License

private static synchronized Collection<FeedIF> parse(Document doc) throws ParseException {

    logger.debug("start parsing.");
    // Get the root element (must be opml)
    Element root = doc.getRootElement();
    String rootElement = root.getName().toLowerCase();
    String opmlVersion;/*from   www.j  a  va2s . c  o  m*/

    // Decide which parser to use
    if (rootElement.startsWith("opml")) {
        Attribute attrOpmlVersion = root.getAttribute("version");

        // there is no version information set
        if (attrOpmlVersion == null) {
            // there seems to be no opml version set, so we'll try to parse it with 1.1..
            // TODO is it worth to implement also a opml 1.0 parser? are there markable differences between opml 1.1 and 1.0?
            logger.info(
                    "Collection uses OPML root element (no version information available), trying to parse with 1.1 anyway.");
            return OPML_1_1_Parser.parse(root);
        } else {
            // version information seems to be set, so go get it
            opmlVersion = attrOpmlVersion.getValue();
        }

        // version information is set
        if (opmlVersion.contains("1.1")) {
            // OPML 1.1 version information is set, so we'll parse it with 1.1!
            logger.info("Collection uses OPML root element (Version 1.1).");
            return OPML_1_1_Parser.parse(root);
        } else if (opmlVersion.contains("1.0")) {
            // TODO is it worth to implement also a opml 1.0 parser? are there markable differences between opml 1.1 and 1.0?
            // OPML 1.0 version information is set, we'll try to parse it using 1.1 anyway..
            logger.info("Collection uses OPML root element (Version 1.0), trying to parse with 1.1 anyway.");
            return OPML_1_1_Parser.parse(root);
        } else {
            // since it is neither a 1.0 nor 1.1 opml feed we maybe cannot handle it, so it's better to throw some exception..
            throw new UnsupportedFormatException(
                    MessageFormat.format("Unsupported OPML version information [{0}].", opmlVersion));
        }
    }

    // did not match anything
    throw new UnsupportedFormatException(
            MessageFormat.format("Unsupported OPML root element [{0}].", rootElement));
}

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

License:Open Source License

public static void load(String fileName) {

    try {// w w w. j a  va 2s  .  co m
        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 www .  j  a  v a 2s . c om*/
        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();
    }
}