Refine search
public <T> T fromXmlPartial(InputStream inputStream, Class<T> o) throws Exception { Document document = new SAXBuilder().build(inputStream); Element element = document.getRootElement(); return classParser(element, o, configCache, new GoCipher(), registry, new ConfigReferenceElements()).parse(); }
/** * Create and initialize the SAX builder. * * @return the SAX builder instance. * @since 1.4.9 */ protected SAXBuilder createBuilder() { final SAXBuilder builder = new SAXBuilder(); builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); return builder; } }
try SAXBuilder builder = new SAXBuilder( false ); builder.setExpandEntities( false ); if ( ignoreDtd ) builder.setEntityResolver( new EntityResolver() r = builder.build( is ); throw new RuntimeException( "Error processing resource " + resource + ": " + e.getMessage(), e ); appendElement( r.getRootElement(), doc.getRootElement() ); Object source = path.selectSingleNode( r.getRootElement() ); if ( !( source instanceof Element ) )
private int getCurrentSchemaVersion(String content) { try { SAXBuilder builder = new SAXBuilder(); Document document = builder.build(new ByteArrayInputStream(content.getBytes())); Element root = document.getRootElement(); String currentVersion = root.getAttributeValue(schemaVersion) == null ? "0" : root.getAttributeValue(schemaVersion); return Integer.parseInt(currentVersion); } catch (Exception e) { throw bomb(e); } }
private Document parseXML(byte[] xml) throws Exception { SAXBuilder builder = new SAXBuilder(); InputStream stream = new ByteArrayInputStream(xml); return builder.build(stream); } }
public static void loadMacro(String folderPath) throws JDOMException, IOException{ File file = FileUtil.getFile(folderPath); // File file = new File(url.getFile()); if(!file.exists() || file.isFile()){ return; } folderPath = file.getPath(); String[] xmlFileNames = file.list(); for(String xmlFileName : xmlFileNames){ Document doc = new SAXBuilder().build(new File(folderPath,xmlFileName)); Element root = doc.getRootElement(); if(!"macros".equals(root.getName())){ continue; } for(Element macro : root.getChildren()){ new MacroObject(macro); } } }
public TableConfig readConfigXML(String fileLocation, FeatureType wantFeatureType, NetcdfDataset ds, Formatter errlog) throws IOException { org.jdom2.Document doc; try { SAXBuilder builder = new SAXBuilder(false); if (debugURL) System.out.println(" PointConfig URL = <" + fileLocation + ">"); doc = builder.build(fileLocation); } catch (JDOMException e) { throw new IOException(e.getMessage()); } if (debugXML) System.out.println(" SAXBuilder done"); if (showParsedXML) { XMLOutputter xmlOut = new XMLOutputter(); System.out.println("*** PointConfig/showParsedXML = \n" + xmlOut.outputString(doc) + "\n*******"); } Element configElem = doc.getRootElement(); String featureType = configElem.getAttributeValue("featureType"); Element tableElem = configElem.getChild("table"); TableConfig tc = parseTableConfig(ds, tableElem, null); tc.featureType = FeatureType.valueOf(featureType); return tc; }
private InputStream convert2XmlDecoder(InputStream is) throws IOException { org.jdom2.Document doc; try { SAXBuilder builder = new SAXBuilder(false); doc = builder.build(is); } catch (JDOMException e) { throw new IOException(e.getMessage()); } finally { if (is != null) is.close(); } if (debugConvert) { XMLOutputter xmlOut = new XMLOutputter(); System.out.println("***XMLStore.convert2XmlDecoder = \n" + xmlOut.outputString(doc) + "\n*******"); } Element root = doc.getRootElement(); org.jdom2.Document convertDoc = new Document(); Element convertRoot = new Element("java"); convertRoot.setAttribute("version", "1.4.1_01"); convertRoot.setAttribute("class", "java.beans.XMLDecoder"); convertDoc.setRootElement(convertRoot); add(root, convertRoot); XMLOutputter xmlOut = new XMLOutputter(); xmlOut.setFormat(Format.getPrettyFormat()); if (debugConvert) { System.out.printf("%n************************************%n"); System.out.println("***Convert2Version2 converted = \n" + xmlOut.outputString(convertDoc) + "\n*******"); } return new StringBufferInputStream(xmlOut.outputString(convertDoc)); }
/** * Converts the navigation.xml to the old format. */ private static byte[] convertToOldFormat(byte[] xml) throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new ByteArrayInputStream(xml)); Element rootElement = doc.getRootElement(); rootElement.setAttribute("href", rootElement.getName()); List<Element> children = rootElement.getChildren(); for (Element menu : children) { String id = menu.getAttributeValue("id"); menu.setName(id); menu.setAttribute("href", id); menu.removeAttribute("id"); } XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); ByteArrayOutputStream bout = new ByteArrayOutputStream(xml.length); out.output(doc, bout); return bout.toByteArray(); }
/** * Read NcML doc from an InputStream, and construct a NetcdfDataset. * * @param ins the InputStream containing the NcML document * @param cancelTask allow user to cancel the task; may be null * @return the resulting NetcdfDataset * @throws IOException on read error, or bad referencedDatasetUri URI */ static public NetcdfDataset readNcML(InputStream ins, CancelTask cancelTask) throws IOException { org.jdom2.Document doc; try { SAXBuilder builder = new SAXBuilder(); doc = builder.build(ins); } catch (JDOMException e) { throw new IOException(e.getMessage()); } if (debugXML) System.out.println(" SAXBuilder done"); if (showParsedXML) { XMLOutputter xmlOut = new XMLOutputter(); System.out.println("*** NetcdfDataset/showParsedXML = \n" + xmlOut.outputString(doc) + "\n*******"); } Element netcdfElem = doc.getRootElement(); NetcdfDataset ncd = readNcML(null, netcdfElem, cancelTask); if (debugOpen) System.out.println("***NcMLReader.readNcML (stream) result= \n" + ncd); return ncd; }
public GeniaPosParser(File xmlFile) throws IOException, JDOMException { this(); SAXBuilder builder = new SAXBuilder(); builder.setDTDHandler(null); root = builder.build(xmlFile).getRootElement(); articles = root.getChildren("article").iterator(); outputter = new XMLOutputter(); }
public static void main(String[] args) { try { SAXBuilder b = new SAXBuilder(true); // true -> validate // Create a JDOM document. Document doc = b.build(new File("people+dtd.xml")); // Create an output formatter, and have it write the doc. new XMLOutputter().output(doc, System.out); } catch (JDOMException jex) { System.out.print("PARSE ERROR: " + jex.getMessage()); } catch (Exception ex) { ex.printStackTrace(); } } }
try SAXBuilder builder = new SAXBuilder( false ); builder.setExpandEntities( false ); if ( ignoreDtd ) builder.setEntityResolver( new EntityResolver() r = builder.build( is ); throw new RuntimeException( "Error processing resource " + resource + ": " + e.getMessage(), e ); Element root = r.getRootElement(); for ( Iterator<Attribute> itr = root.getAttributes().iterator(); itr.hasNext(); ) Element mergedEl = doc.getRootElement(); Attribute mergedAtt = mergedEl.getAttribute( a.getName(), a.getNamespace() ); if ( mergedAtt == null ) mergedEl.setAttribute( a ); itr.remove(); doc.getRootElement().addContent( n );
static public void passTwo() throws IOException { org.jdom2.Document tdoc; try { SAXBuilder builder = new SAXBuilder(); tdoc = builder.build(trans1); org.jdom2.Document ndoc = new org.jdom2.Document(); Element nroot = new Element("ndoc"); ndoc.setRootElement(nroot); transform2(tdoc.getRootElement(), nroot); XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat()); Writer pw = new FileWriter(trans2); fmt.output(ndoc, pw); pw = new PrintWriter(System.out); fmt.output(ndoc, pw); } catch (JDOMException e) { throw new IOException(e.getMessage()); } }
public HashMap<String, String> parseInfoToGetUUID(String output, String queryURL, SAXBuilder builder) { HashMap<String, String> uidToUrlMap = new HashMap<>(); try { Document document = builder.build(new StringReader(output)); Element root = document.getRootElement(); List<Element> entries = root.getChildren("entry"); for (Element entry : entries) { uidToUrlMap.put(queryURL, entry.getChild("repository").getChild("uuid").getValue()); } } catch (Exception e) { throw new RuntimeException(e); } return uidToUrlMap; }
public void parse (String file) throws JDOMException, SQLException, HibernateException, ParseException, IOException, GLException, DocumentException { SAXBuilder builder = new SAXBuilder (true); builder.setEntityResolver (this); Document doc = builder.build (file); Element root = doc.getRootElement (); if (!"minigl".equals (root.getName ())) { throw new IllegalStateException ( "Invalid root element "+root.getName () ); } if (root.getChild ("create-schema") != null) createSchema (); try (DB db = new DB()) { Session sess = db.open(); createUsers(sess, root.getChildren("user").iterator()); createCurrencies(sess, root.getChildren("currency").iterator()); createCharts(sess, root.getChildren("chart-of-accounts").iterator()); createJournals(sess, root.getChildren("journal").iterator()); createTransactions(db, root.getChildren("transaction").iterator()); } }
/** * Parses XHTML text string. Adds a wrapping "root" element before parsing and returns this root element. * @param text XHTML text string (root element not needed) * @param xhtmlEntities If set to true, Resolving of XHtml entities in XHtml fragment is supported. * @return Root element with parsed xhtml content * @throws JDOMException Is thrown if the text could not be parsed as XHTML */ public static @NotNull Element parseText(@NotNull String text, boolean xhtmlEntities) throws JDOMException { // add root element String xhtmlString = (xhtmlEntities ? "<!DOCTYPE root [" + XHTML_ENTITY_DEF + "]>" : "") + "<root>" + text + "</root>"; try { SAXBuilder saxBuilder = new SAXBuilder(); if (xhtmlEntities) { saxBuilder.setEntityResolver(XHtmlEntityResolver.getInstance()); } Document doc = saxBuilder.build(new StringReader(xhtmlString)); return doc.getRootElement(); } catch (IOException ex) { throw new RuntimeException("Error parsing XHTML fragment.", ex); } }
@Test @Ignore("WMS not working") public void checkWMSDates() throws JDOMException, IOException { String endpoint = TestOnLocalServer.withHttpPath("/wms/cdmUnitTest/ncss/climatology/PF5_SST_Climatology_Monthly_1985_2001.nc?service=WMS&version=1.3.0&request=GetCapabilities"); byte[] result = TestOnLocalServer.getContent(endpoint, 200, ContentType.xml); Reader in = new StringReader( new String(result, CDM.utf8Charset)); SAXBuilder sb = new SAXBuilder(); Document doc = sb.build(in); if (show) { XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat()); fmt.output(doc, System.out); } XPath xPath = XPath.newInstance("//wms:Dimension"); xPath.addNamespace("wms", doc.getRootElement().getNamespaceURI()); Element dimNode = (Element) xPath.selectSingleNode(doc); //List<String> content = Arrays.asList(dimNode.getText().trim().split(",")); List<String> content = new ArrayList<>(); for (String d : Arrays.asList(dimNode.getText().trim().split(","))) { // System.out.printf("Date= %s%n", d); CalendarDate cd = CalendarDate.parseISOformat(null, d); content.add(cd.toString()); } assertEquals(expectedDatesAsDateTime, content); }
static public void passOne() throws IOException { org.jdom2.Document orgDoc; try { SAXBuilder builder = new SAXBuilder(); orgDoc = builder.build(orgXml); org.jdom2.Document tdoc = new org.jdom2.Document(); Element root = new Element("tdoc"); tdoc.setRootElement(root); transform(orgDoc.getRootElement(), root); /* XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat()); Writer pw = new FileWriter("C:/docs/bufr/wmo/Code-FlagTables-11-2007.trans.xml"); fmt.output(tdoc, pw); pw = new PrintWriter(System.out); fmt.output(tdoc, pw); // */ } catch (JDOMException e) { throw new IOException(e.getMessage()); } }
private static double[] readCalibration( final File source ) throws JDOMException, IOException { final SAXBuilder sb = new SAXBuilder(); final Document document = sb.build( source ); final Element root = document.getRootElement(); final double[] calibration = new double[ 3 ]; final Element settings = root.getChild( "Settings" ); final Element imageData = settings.getChild( "ImageData" ); calibration[ 0 ] = imageData.getAttribute( "pixelwidth" ).getDoubleValue(); calibration[ 1 ] = imageData.getAttribute( "pixelheight" ).getDoubleValue(); calibration[ 2 ] = imageData.getAttribute( "voxeldepth" ).getDoubleValue(); return calibration; }