List of usage examples for org.jdom2.input SAXBuilder build
@Override public Document build(final String systemId) throws JDOMException, IOException
This builds a document from the supplied URI.
From source file:de.hbrs.oryx.yawl.converter.layout.YAWLLayoutConverter.java
License:Open Source License
private void initXMLReader() throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); Document document = builder.build(new StringReader(specificationString)); Element root = document.getRootElement(); layout = root.getChild("layout", root.getNamespace()); if (layout == null) layout = yawlLayoutArranger.arrangeLayout(root); yawlNamespace = layout.getNamespace(); setYAWLLocale(layout);//from ww w .j av a 2 s. com }
From source file:de.herm_detlef.java.application.io.Export.java
License:Apache License
private static void validateDocument(ByteArrayInputStream inputStream) throws JDOMException, IOException { assert schemafac != null; SAXBuilder builder = new SAXBuilder(schemafac); // XML validation against schema definition happens here: builder.build(inputStream); }
From source file:de.herm_detlef.java.application.io.Import.java
License:Apache License
private static Document createDocument(String filename) throws JDOMException, IOException { InputStream in = Import.class.getResourceAsStream(ApplicationConstants.XML_SCHEMA_DEFINITION); XMLReaderJDOMFactory schemafac = new XMLReaderXSDFactory(new StreamSource(in)); SAXBuilder builder = new SAXBuilder(schemafac); File xmlFile = new File(filename); return builder.build(xmlFile);// XML validation happens here }
From source file:de.huberlin.german.korpling.laudatioteitool.MergeTEI.java
License:Apache License
private void mergeMainCorpusHeader(Element root) throws SAXException, IOException, LaudatioException, JDOMException { // append global header File corpusHeaderDir = new File(inputDir, "CorpusHeader"); Preconditions.checkArgument(corpusHeaderDir.isDirectory()); File[] corpusHeaderFiles = corpusHeaderDir.listFiles(new FilenameFilter() { @Override//from w w w .j ava2s.c om public boolean accept(File dir, String name) { return name.endsWith(".xml"); } }); Preconditions.checkArgument(corpusHeaderFiles.length > 0); File headerFile = corpusHeaderFiles[0]; TEIValidator validator = corpusSchemeURL == null ? new TEICorpusValidator() : new FromURLValidator(corpusSchemeURL); if (validator.validate(headerFile)) { SAXBuilder sax = new SAXBuilder(); Document corpusDoc = sax.build(headerFile); // remove the pending text element corpusDoc.getRootElement().removeChild("text", null); // append to our new root root.addContent(corpusDoc.getRootElement().getChild("teiHeader", null).clone()); } else { System.err.println(validator.toString()); throw new LaudatioException("Corpus header is not valid"); } }
From source file:de.huberlin.german.korpling.laudatioteitool.MergeTEI.java
License:Apache License
private void mergeDocumentHeader(Element root) throws SAXException, JDOMException, IOException, LaudatioException { // append document headers File documentHeaderDir = new File(inputDir, "DocumentHeader"); Preconditions.checkArgument(documentHeaderDir.isDirectory()); File[] documentHeaderFiles = documentHeaderDir.listFiles(new FilenameFilter() { @Override//from www .ja v a2s . com public boolean accept(File dir, String name) { return name.endsWith(".xml"); } }); Preconditions.checkArgument(documentHeaderFiles.length > 0); SAXBuilder sax = new SAXBuilder(); TEIValidator validator = documentSchemeURL == null ? new TEIDocumentValidator() : new FromURLValidator(documentSchemeURL); for (File f : documentHeaderFiles) { if (validator.validate(f)) { Document documentDoc = sax.build(f); // remove the pending text element documentDoc.getRootElement().removeChild("text", null); // append to our new root root.addContent(documentDoc.getRootElement().getChild("teiHeader", null).clone()); } else { System.err.println(validator.toString()); throw new LaudatioException("A document header is not valid"); } } }
From source file:de.huberlin.german.korpling.laudatioteitool.MergeTEI.java
License:Apache License
private void mergePreparationHeader(Element root) throws SAXException, JDOMException, IOException, LaudatioException { // append preparation headers File preparationHeaderDir = new File(inputDir, "PreparationHeader"); Preconditions.checkState(preparationHeaderDir.isDirectory()); File[] preparationHeaderFiles = preparationHeaderDir.listFiles(new FilenameFilter() { @Override/*from www . j av a 2 s . c o m*/ public boolean accept(File dir, String name) { return name.endsWith(".xml"); } }); Preconditions.checkState(preparationHeaderFiles.length > 0); SAXBuilder sax = new SAXBuilder(); TEIValidator validator = preparationSchemeURL == null ? new TEIPreparationValidator() : new FromURLValidator(preparationSchemeURL); for (File f : preparationHeaderFiles) { if (validator.validate(f)) { Document preparation = sax.build(f); // remove the pending text element preparation.getRootElement().removeChild("text", null); // append to our new root root.addContent(preparation.getRootElement().getChild("teiHeader", null).clone()); } else { System.err.println(validator.toString()); throw new LaudatioException("A preparation header ist not valid."); } } }
From source file:de.huberlin.german.korpling.laudatioteitool.SplitTEI.java
License:Apache License
public void split() throws LaudatioException { if (!outputDirectory.isDirectory() && !outputDirectory.mkdirs()) { throw new LaudatioException(messages.getString("COULD NOT CREATE OUTPUT DIRECTORY.")); }// w w w. j a v a 2s. c om // check if input file exits if (!inputFile.isFile()) { throw new LaudatioException(messages.getString("INPUT FILE DOES NOT EXIST")); } // read in file SAXBuilder sax = new SAXBuilder(); try { Document doc = sax.build(inputFile); TEIValidator.Errors errors = new TEIValidator.Errors(); errors.putAll(extractMainCorpusHeader(doc)); errors.putAll(extractDocumentHeaders(doc)); errors.putAll(extractPreparationSteps(doc)); if (!errors.isEmpty()) { System.out.println(TEIValidator.formatParserExceptions(errors)); throw new LaudatioException("Source document was invalid"); } } catch (JDOMException ex) { throw new LaudatioException(ex.getLocalizedMessage()); } catch (SAXException ex) { throw new LaudatioException(TEIValidator.getSAXParserError(ex)); } catch (IOException ex) { throw new LaudatioException(ex.getLocalizedMessage()); } }
From source file:de.ing_poetter.binview.BinaryFormat.java
License:Open Source License
public static BinaryFormat loadFromFile(final File f) { final SAXBuilder builder = new SAXBuilder(); Document doc;/*w w w. j a v a 2s .c om*/ try { doc = builder.build(f); Element root = null; root = doc.getRootElement(); if (false == ROOT_ELEMENT_NAME.equalsIgnoreCase(root.getName())) { System.err.println("Format has invalid root Element of " + root.getName()); return null; } final BinaryFormat res = new BinaryFormat(); final List<Element> vars = root.getChildren(); for (int i = 0; i < vars.size(); i++) { final Element curVar = vars.get(i); final Variable v = VariableFactory.createVariableFrom(curVar); res.addVariable(v); } return res; } catch (final JDOMException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } return null; }
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 w w w . j a va2 s . 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 www .j av a 2 s. com*/ } 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); }