List of usage examples for org.jdom2 Document getRootElement
public Element getRootElement()
Element
for this Document
From source file:com.jamfsoftware.jss.healthcheck.HealthCheckUtility.java
License:Open Source License
private void startMonitor() { Scanner scanner = new Scanner(System.in); ConfigurationController con = new ConfigurationController(); while (!con.canGetFile()) { if (!(con.attemptAutoDiscover())) { System.out.println(/* w w w . j a v a 2 s .c o m*/ "Path to Config.xml not found. Please type the full path below or type 'exit' to close the program. "); String path = scanner.next(); if (path.equals("exit")) { System.exit(0); } else { prefs.put("config_xml_path", path); } } } String xmlPath = prefs.get("config_xml_path", "Path to file '/Users/user/desktop/config.xml'"); SAXBuilder builder = new SAXBuilder(); File xmlFile = new File(xmlPath); try { Document document = builder.build(xmlFile); Element root = document.getRootElement(); HealthCheck hc = new HealthCheck(); int mobile_device_length = hc.checkAPILength(root.getChild("jss_url").getValue(), root.getChild("jss_username").getValue(), root.getChild("jss_password").getValue(), "mobiledevicecommands"); int computer_length = hc.checkAPILength(root.getChild("jss_url").getValue(), root.getChild("jss_username").getValue(), root.getChild("jss_password").getValue(), "computercommands"); writeLogEntry(mobile_device_length, computer_length); } catch (Exception e) { LOGGER.error("Config XML file damaged. Unable to run monitor.", e); } }
From source file:com.khodev.oradiff.io.XmlSchemaReader.java
License:Open Source License
@Override public Schema get() { Schema schema = new Schema(); try {//w w w .j av a 2 s . com SAXBuilder sxb = new SAXBuilder(); org.jdom2.Document document = sxb.build(new File(filename)); Element database = document.getRootElement(); schema.setDbTables(getTables(database)); schema.setDbPackages(getPackages(database)); schema.setDbFunctions(getFunctions(database)); schema.setDbProcedures(getProcedures(database)); schema.setDbViews(getViews(database)); schema.setDbSequences(getSequences(database)); schema.setDbTriggers(getTriggers(database)); } catch (Exception e) { e.printStackTrace(); } return schema; }
From source file:com.kixeye.kixmpp.KixmppWebSocketCodec.java
License:Apache License
@Override protected void decode(ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception { WebSocketFrame frame = (WebSocketFrame) msg; ByteBuf content = frame.retain().content(); String frameString = content.toString(StandardCharsets.UTF_8); if (logger.isDebugEnabled()) { logger.debug("Received: [{}]", frameString); }// w ww. j av a 2 s. c o m if (frameString.startsWith("<?xml")) { frameString = frameString.replaceFirst("<\\?xml.*?\\?>", ""); } if (frameString.startsWith("<stream:stream")) { out.add(new KixmppStreamStart(null, true)); } else if (frameString.startsWith("</stream:stream")) { out.add(new KixmppStreamEnd()); } else { SAXBuilder saxBuilder = new SAXBuilder(readerFactory); Document document = saxBuilder.build(new ByteBufInputStream(content)); Element element = document.getRootElement(); out.add(element); } }
From source file:com.marklogic.client.example.handle.JDOMHandleExample.java
License:Apache License
public static void runShortcut(ExampleProperties props) throws JDOMException, IOException { String filename = "flipper.xml"; // register the handle from the extra library DatabaseClientFactory.getHandleRegistry().register(JDOMHandle.newFactory()); // create the client DatabaseClient client = DatabaseClientFactory.newClient(props.host, props.port, props.writerUser, props.writerPassword, props.authType); // create a manager for documents of any format XMLDocumentManager docMgr = client.newXMLDocumentManager(); // read the example file InputStream docStream = Util.openStream("data" + File.separator + filename); if (docStream == null) throw new IOException("Could not read document example"); // create an identifier for the document String docId = "/example/" + filename; // parse the example file with JDOM Document writeDocument = new SAXBuilder(XMLReaders.NONVALIDATING) .build(new InputStreamReader(docStream, "UTF-8")); // write the document docMgr.writeAs(docId, writeDocument); // ... at some other time ... // read the document content Document readDocument = docMgr.readAs(docId, Document.class); String rootName = readDocument.getRootElement().getName(); // delete the document docMgr.delete(docId);//from w w w . j a v a 2s .com System.out.println("(Shortcut) Wrote and read /example/" + filename + " content with the <" + rootName + "/> root element using JDOM"); // release the client client.release(); }
From source file:com.marklogic.client.example.handle.JDOMHandleExample.java
License:Apache License
public static void runStrongTyped(ExampleProperties props) throws JDOMException, IOException { String filename = "flipper.xml"; // create the client DatabaseClient client = DatabaseClientFactory.newClient(props.host, props.port, props.writerUser, props.writerPassword, props.authType); // create a manager for documents of any format XMLDocumentManager docMgr = client.newXMLDocumentManager(); // read the example file InputStream docStream = Util.openStream("data" + File.separator + filename); if (docStream == null) throw new IOException("Could not read document example"); // create an identifier for the document String docId = "/example/" + filename; // create a handle for the document JDOMHandle writeHandle = new JDOMHandle(); // parse the example file with JDOM Document writeDocument = writeHandle.getBuilder().build(new InputStreamReader(docStream, "UTF-8")); writeHandle.set(writeDocument);//from w ww.j a v a 2 s . c o m // write the document docMgr.write(docId, writeHandle); // ... at some other time ... // create a handle to receive the document content JDOMHandle readHandle = new JDOMHandle(); // read the document content docMgr.read(docId, readHandle); // access the document content Document readDocument = readHandle.get(); String rootName = readDocument.getRootElement().getName(); // delete the document docMgr.delete(docId); System.out.println("(Strong Typed) Wrote and read /example/" + filename + " content with the <" + rootName + "/> root element using JDOM"); // release the client client.release(); }
From source file:com.mercurypay.ws.sdk.MercuryResponse.java
License:Open Source License
public MercuryResponse(String responseXml) throws Exception { // PosLog.debug(getClass(),responseXml); SAXBuilder jdomBuilder = new SAXBuilder(); Document document = jdomBuilder.build(new StringReader(responseXml)); responseRoot = document.getRootElement(); cmdStatus = responseRoot.getChild("CmdResponse").getChildText("CmdStatus"); //$NON-NLS-1$ //$NON-NLS-2$ }
From source file:com.move.in.nantes.cars.ParkingParser.java
private static List<Parking> parseXml() { List<Parking> listPakings = new ArrayList<Parking>(); try {/*from w ww.j a v a2 s . c om*/ SAXBuilder saxb = new SAXBuilder(); File file = new File("WEB-INF/json/Parking.xml"); Document doc = saxb.build(file); Element root = doc.getRootElement(); List<Element> locations = root.getChildren("data").get(0).getChildren("element"); for (int i = 0; i < locations.size(); i++) { Element elem = locations.get(i); if (elem.getChildText("CATEGORIE").equalsIgnoreCase("1001")) { String name = elem.getChild("geo").getChildText("name"); Coordinates coordinates = getCoordinates(elem.getChildText("_l")); String postalCode = elem.getChildText("CODE_POSTAL"); String city = elem.getChildText("COMMUNE"); String address = elem.getChildText("ADRESSE"); listPakings.add(new Parking(name, coordinates, postalCode, city, address)); } } } catch (JDOMException ex) { Logger.getLogger(ParkingParser.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ParkingParser.class.getName()).log(Level.SEVERE, null, ex); } return listPakings; }
From source file:com.musala.cron.RefreshDbTask.java
License:Apache License
@Scheduled(fixedRate = 300000) @Transactional//ww w. j a v a2 s .c o m public void printMe() { logger.info("Cron task is started"); for (Site rssFeedSite : siteService.findAll()) { logger.info("--------------> Reading information for site: " + rssFeedSite.getRssLink()); SAXBuilder builder = new SAXBuilder(); Document doc = null; try { doc = builder.build(new URL(rssFeedSite.getRssLink())); if (rssFeedSite.getLastVisitDateTag() != null) { Element root = doc.getRootElement(); ElementFilter filter = new ElementFilter(rssFeedSite.getLastVisitDateTag()); String currentLastVisitedDate = null; for (Element c : root.getDescendants(filter)) { currentLastVisitedDate = c.getTextNormalize(); } if (currentLastVisitedDate != null && currentLastVisitedDate.equals(rssFeedSite.getLastVisitDate())) { logger.info("--------------> Rss {} is not changed", rssFeedSite.getRssLink()); } else { logger.info("--------------> Rss {} is changed", rssFeedSite.getRssLink()); rssFeedSite.setLastVisitDate(currentLastVisitedDate); subject.processRss(rssFeedSite); } } } catch (JDOMException | IOException e) { logger.warn("Error occurred during reading of rss", e); } } }
From source file:com.novell.ldapchai.impl.edir.NmasResponseSet.java
License:Open Source License
static List<Challenge> parseNmasPolicyXML(final String str, final Locale locale) throws IOException, JDOMException { final List<Challenge> returnList = new ArrayList<Challenge>(); final Reader xmlreader = new StringReader(str); final SAXBuilder builder = new SAXBuilder(); final Document doc = builder.build(xmlreader); final boolean required = doc.getRootElement().getName().equals("RequiredQuestions"); for (Iterator qIter = doc.getDescendants(new ElementFilter("Question")); qIter.hasNext();) { final Element loopQ = (Element) qIter.next(); final int maxLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MaxLength"), 255); final int minLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MinLength"), 1); final String challengeText = readDisplayString(loopQ, locale); final Challenge challenge = new ChaiChallenge(required, challengeText, minLength, maxLength, true, 0, false);/*from w w w. j av a 2s . c o m*/ returnList.add(challenge); } for (Iterator iter = doc.getDescendants(new ElementFilter("UserDefined")); iter.hasNext();) { final Element loopQ = (Element) iter.next(); final int maxLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MaxLength"), 255); final int minLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MinLength"), 1); final Challenge challenge = new ChaiChallenge(required, null, minLength, maxLength, false, 0, false); returnList.add(challenge); } return returnList; }
From source file:com.novell.ldapchai.impl.edir.NmasResponseSet.java
License:Open Source License
static ChallengeSet parseNmasUserResponseXML(final String str) throws IOException, JDOMException, ChaiValidationException { final List<Challenge> returnList = new ArrayList<Challenge>(); final Reader xmlreader = new StringReader(str); final SAXBuilder builder = new SAXBuilder(); final Document doc = builder.build(xmlreader); final Element rootElement = doc.getRootElement(); final int minRandom = StringHelper.convertStrToInt(rootElement.getAttributeValue("RandomQuestions"), 0); final String guidValue; {// w ww . j a v a2s . c om final Attribute guidAttribute = rootElement.getAttribute("GUID"); guidValue = guidAttribute == null ? null : guidAttribute.getValue(); } for (Iterator iter = doc.getDescendants(new ElementFilter("Challenge")); iter.hasNext();) { final Element loopQ = (Element) iter.next(); final int maxLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MaxLength"), 255); final int minLength = StringHelper.convertStrToInt(loopQ.getAttributeValue("MinLength"), 2); final String defineStrValue = loopQ.getAttributeValue("Define"); final boolean adminDefined = defineStrValue.equalsIgnoreCase("Admin"); final String typeStrValue = loopQ.getAttributeValue("Type"); final boolean required = typeStrValue.equalsIgnoreCase("Required"); final String challengeText = loopQ.getText(); final Challenge challenge = new ChaiChallenge(required, challengeText, minLength, maxLength, adminDefined, 0, false); returnList.add(challenge); } return new ChaiChallengeSet(returnList, minRandom, null, guidValue); }