List of usage examples for org.jdom2.input SAXBuilder SAXBuilder
public SAXBuilder()
From source file:com.rhythm.louie.server.LouieProperties.java
License:Apache License
private static void loadInternals() throws JDOMException, IOException { Document internals;// w w w. j a va 2 s. c om SAXBuilder docBuilder = new SAXBuilder(); URL xmlURL = LouieProperties.class.getResource("/config/louie-internal.xml"); internals = docBuilder.build(xmlURL); Element louie = internals.getRootElement(); //Load internal defaults into Server Element serverDef = louie.getChild("server_defaults"); Server.setDefaultHost(serverDef.getChildText(HOST)); Server.setDefaultGateway(serverDef.getChildText(GATEWAY)); Server.setDefaultDisplay(serverDef.getChildText(DISPLAY)); Server.setDefaultIP(serverDef.getChildText(IP)); Server.setDefaultTimezone(serverDef.getChildText(TIMEZONE)); Server.setDefaultLocation(serverDef.getChildText(LOCATION)); Server.setDefaultPort(Integer.parseInt(serverDef.getChildText(PORT))); Server.setDefaultSecure(Boolean.parseBoolean(serverDef.getChildText(SECURE))); //Load internal defaults into ServiceProperties Element serviceDef = louie.getChild("service_defaults"); ServiceProperties.setDefaultCaching(Boolean.parseBoolean(serviceDef.getChildText(CACHING))); ServiceProperties.setDefaultEnable(Boolean.parseBoolean(serviceDef.getChildText(ENABLE))); ServiceProperties.setDefaultReadOnly(Boolean.parseBoolean(serviceDef.getChildText(READ_ONLY))); //Load internal services into ServiceProperties Element coreServices = louie.getChild("core_services"); processServices(coreServices, true); Element schedDef = louie.getChild("scheduler_defaults"); TaskSchedulerProperties.setThreadPoolSize(Integer.parseInt(schedDef.getChildText(POOL_SIZE))); Element accessDef = louie.getChild("group_defaults"); AccessManager.loadGroups(accessDef); }
From source file:com.rometools.propono.atom.client.ClientAtomService.java
License:Open Source License
private Document getAtomServiceDocument() throws ProponoException { GetMethod method = null;/*from w w w .j av a 2 s .co m*/ final int code = -1; try { httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); // TODO: make connection timeout configurable httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000); method = new GetMethod(uri); authStrategy.addAuthentication(httpClient, method); httpClient.executeMethod(method); final SAXBuilder builder = new SAXBuilder(); final String doc = method.getResponseBodyAsString(); LOG.debug(doc); return builder.build(method.getResponseBodyAsStream()); } catch (final Throwable t) { final String msg = "ERROR retrieving Atom Service Document, code: " + code; LOG.debug(msg, t); throw new ProponoException(msg, t); } finally { if (method != null) { method.releaseConnection(); } } }
From source file:com.rometools.propono.atom.client.ClientCategories.java
License:Apache License
public void fetchContents() throws ProponoException { final GetMethod method = new GetMethod(getHrefResolved()); clientCollection.addAuthentication(method); try {//from w w w .ja v a 2 s . c o m clientCollection.getHttpClient().executeMethod(method); if (method.getStatusCode() != 200) { throw new ProponoException("ERROR HTTP status code=" + method.getStatusCode()); } final SAXBuilder builder = new SAXBuilder(); final Document catsDoc = builder.build(new InputStreamReader(method.getResponseBodyAsStream())); parseCategoriesElement(catsDoc.getRootElement()); } catch (final IOException ioe) { throw new ProponoException("ERROR: reading out-of-line categories", ioe); } catch (final JDOMException jde) { throw new ProponoException("ERROR: parsing out-of-line categories", jde); } finally { method.releaseConnection(); } }
From source file:com.rometools.propono.atom.client.EntryIterator.java
License:Open Source License
private void getNextEntries() throws ProponoException { if (nextURI == null) { return;/* w ww.ja va 2 s . c o m*/ } final GetMethod colGet = new GetMethod(collection.getHrefResolved(nextURI)); collection.addAuthentication(colGet); try { collection.getHttpClient().executeMethod(colGet); final SAXBuilder builder = new SAXBuilder(); final Document doc = builder.build(colGet.getResponseBodyAsStream()); final WireFeedInput feedInput = new WireFeedInput(); col = (Feed) feedInput.build(doc); } catch (final Exception e) { throw new ProponoException("ERROR: fetching or parsing next entries, HTTP code: " + (colGet != null ? colGet.getStatusCode() : -1), e); } finally { colGet.releaseConnection(); } members = col.getEntries().iterator(); col.getEntries().size(); nextURI = null; final List<Link> altLinks = col.getOtherLinks(); if (altLinks != null) { for (final Link link : altLinks) { if ("next".equals(link.getRel())) { nextURI = link.getHref(); } } } }
From source file:com.rometools.rome.io.impl.Atom03Generator.java
License:Open Source License
protected void fillContentElement(final Element contentElement, final Content content) throws FeedException { final String type = content.getType(); if (type != null) { final Attribute typeAttribute = new Attribute("type", type); contentElement.setAttribute(typeAttribute); }//from w w w . j a va2 s. com final String mode = content.getMode(); if (mode != null) { final Attribute modeAttribute = new Attribute("mode", mode.toString()); contentElement.setAttribute(modeAttribute); } final String value = content.getValue(); if (value != null) { if (mode == null || mode.equals(Content.ESCAPED)) { contentElement.addContent(value); } else if (mode.equals(Content.BASE64)) { contentElement.addContent(Base64.encode(value)); } else if (mode.equals(Content.XML)) { final StringBuffer tmpDocString = new StringBuffer("<tmpdoc>"); tmpDocString.append(value); tmpDocString.append("</tmpdoc>"); final StringReader tmpDocReader = new StringReader(tmpDocString.toString()); Document tmpDoc; try { final SAXBuilder saxBuilder = new SAXBuilder(); tmpDoc = saxBuilder.build(tmpDocReader); } catch (final Exception ex) { throw new FeedException("Invalid XML", ex); } final List<org.jdom2.Content> children = tmpDoc.getRootElement().removeContent(); contentElement.addContent(children); } } }
From source file:com.rometools.rome.io.impl.Atom10Generator.java
License:Open Source License
protected void fillContentElement(final Element contentElement, final Content content) throws FeedException { final String type = content.getType(); String atomType = type;//from w w w . j a v a2s . co m if (type != null) { // Fix for issue #39 "Atom 1.0 Text Types Not Set Correctly" // we're not sure who set this value, so ensure Atom types are used if ("text/plain".equals(type)) { atomType = Content.TEXT; } else if ("text/html".equals(type)) { atomType = Content.HTML; } else if ("application/xhtml+xml".equals(type)) { atomType = Content.XHTML; } final Attribute typeAttribute = new Attribute("type", atomType); contentElement.setAttribute(typeAttribute); } final String href = content.getSrc(); if (href != null) { final Attribute srcAttribute = new Attribute("src", href); contentElement.setAttribute(srcAttribute); } final String value = content.getValue(); if (value != null) { if (atomType != null && (atomType.equals(Content.XHTML) || atomType.indexOf("/xml") != -1 || atomType.indexOf("+xml") != -1)) { final StringBuffer tmpDocString = new StringBuffer("<tmpdoc>"); tmpDocString.append(value); tmpDocString.append("</tmpdoc>"); final StringReader tmpDocReader = new StringReader(tmpDocString.toString()); Document tmpDoc; try { final SAXBuilder saxBuilder = new SAXBuilder(); tmpDoc = saxBuilder.build(tmpDocReader); } catch (final Exception ex) { throw new FeedException("Invalid XML", ex); } final List<org.jdom2.Content> children = tmpDoc.getRootElement().removeContent(); contentElement.addContent(children); } else { // must be type html, text or some other non-XML format // JDOM will escape property for XML contentElement.addContent(value); } } }
From source file:com.rometools.rome.io.impl.Atom10Parser.java
License:Open Source License
/** * Parse entry from reader./*from w w w . j av a 2 s . c o m*/ */ public static Entry parseEntry(final Reader rd, final String baseURI, final Locale locale) throws JDOMException, IOException, IllegalArgumentException, FeedException { // Parse entry into JDOM tree final SAXBuilder builder = new SAXBuilder(); final Document entryDoc = builder.build(rd); final Element fetchedEntryElement = entryDoc.getRootElement(); fetchedEntryElement.detach(); // Put entry into a JDOM document with 'feed' root so that Rome can // handle it final Feed feed = new Feed(); feed.setFeedType("atom_1.0"); final WireFeedOutput wireFeedOutput = new WireFeedOutput(); final Document feedDoc = wireFeedOutput.outputJDom(feed); feedDoc.getRootElement().addContent(fetchedEntryElement); if (baseURI != null) { feedDoc.getRootElement().setAttribute("base", baseURI, Namespace.XML_NAMESPACE); } final WireFeedInput input = new WireFeedInput(false, locale); final Feed parsedFeed = (Feed) input.build(feedDoc); return parsedFeed.getEntries().get(0); }
From source file:com.seleniumtests.util.squashta.TaScriptGenerator.java
License:Apache License
/** * Search for tests in TestNG files//from w w w. ja va 2 s.c o m * @param path * @param application * @return */ public List<SquashTaTestDef> parseTestNgXml() { // look for feature file into data folder File dir = Paths.get(srcPath, "data", application, "testng").toFile(); if (!dir.exists()) { return new ArrayList<>(); } File[] testngFiles = dir.listFiles((d, filename) -> filename.endsWith(".xml")); List<SquashTaTestDef> testDefs = new ArrayList<>(); for (File testngFile : testngFiles) { Document doc; SAXBuilder sxb = new SAXBuilder(); sxb.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); try { doc = sxb.build(testngFile); } catch (Exception e) { logger.error(String.format("Fichier %s illisible: %s", testngFile, e.getMessage())); return testDefs; } Element suite = doc.getRootElement(); if (!"suite".equalsIgnoreCase(suite.getName())) { continue; } for (Element test : suite.getChildren("test")) { readTestTag(test, testDefs, testngFile); } } return testDefs; }
From source file:com.speedment.codgen.example.uml.Generate.java
License:Open Source License
public static void main(String... params) { final Generator gen = new JavaGenerator(new JavaTransformFactory(), new UMLTransformFactory()); final URL umlPath = Generate.class.getResource(PATH + "ExampleUML.cdg"); try {/*from www . java 2 s . com*/ final SAXBuilder jdomBuilder = new SAXBuilder(); final Document doc = jdomBuilder.build(umlPath); final Element classDiagram = doc.getRootElement(); //gen.metaOn(classDiagram.getChild("ClassDiagramRelations").getChildren() System.out.println(gen.metaOn(classDiagram.getChild("ClassDiagramComponents").getChildren(), File.class) .map(Meta::getResult).flatMap(gen::metaOn).map(Meta::getResult) .collect(joining("\n----------------------------------\n"))); } catch (JDOMException ex) { Logger.getLogger(Generate.class.getName()).log(Level.SEVERE, "Failed to parse XML structure.", ex); } catch (IOException ex) { Logger.getLogger(Generate.class.getName()).log(Level.SEVERE, "Could not load file '" + umlPath.toExternalForm() + "'.", ex); } }
From source file:com.sun.syndication.io.impl.Atom03Generator.java
License:Open Source License
protected void fillContentElement(Element contentElement, Content content) throws FeedException { if (content.getType() != null) { Attribute typeAttribute = new Attribute("type", content.getType()); contentElement.setAttribute(typeAttribute); }/*w w w . j a v a 2s. com*/ String mode = content.getMode(); if (mode != null) { Attribute modeAttribute = new Attribute("mode", content.getMode().toString()); contentElement.setAttribute(modeAttribute); } if (content.getValue() != null) { if (mode == null || mode.equals(Content.ESCAPED)) { contentElement.addContent(content.getValue()); } else if (mode.equals(Content.BASE64)) { contentElement.addContent(Base64.encode(content.getValue())); } else if (mode.equals(Content.XML)) { StringBuffer tmpDocString = new StringBuffer("<tmpdoc>"); tmpDocString.append(content.getValue()); tmpDocString.append("</tmpdoc>"); StringReader tmpDocReader = new StringReader(tmpDocString.toString()); Document tmpDoc; try { SAXBuilder saxBuilder = new SAXBuilder(); tmpDoc = saxBuilder.build(tmpDocReader); } catch (Exception ex) { throw new FeedException("Invalid XML", ex); } List children = tmpDoc.getRootElement().removeContent(); contentElement.addContent(children); } } }