List of usage examples for org.jdom2.input SAXBuilder SAXBuilder
public SAXBuilder()
From source file:io.smartspaces.domain.support.JdomActivityDescriptionReader.java
License:Apache License
@Override public ActivityDescription readDescription(InputStream activityDescriptionStream) { try {/*from www. j a v a 2s . co m*/ SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(activityDescriptionStream); Element rootElement = doc.getRootElement(); ActivityDescription description = new ActivityDescription(); List<String> errors = new ArrayList<>(); getMainData(description, rootElement, errors); getMetadata(description, rootElement, errors); getDependencies(description, rootElement, errors); return description; } catch (Exception e) { throw new SmartSpacesException("Unable to read activity descriptiuon", e); } }
From source file:io.smartspaces.master.server.services.internal.support.JdomMasterDomainModelImporter.java
License:Apache License
/** * Parse the description./*w ww. j av a 2 s .c om*/ * * @param description * the model description * * @return the root element of the parse * * @throws SmartSpacesException * if there was an error reading the description */ private Element readDescription(String description) throws SmartSpacesException { try { StringReader reader = new StringReader(description); SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(reader); return doc.getRootElement(); } catch (Exception e) { throw new SmartSpacesException("Unable to read master domain model description", e); } }
From source file:io.smartspaces.workbench.project.jdom.JdomReader.java
License:Apache License
/** * Get the root element for a given input file. * * @param inputFile/*from w w w . j a v a 2s. com*/ * input project file * * @return top-level element */ Element getRootElement(File inputFile) { Document doc; try { SAXBuilder builder = new SAXBuilder(); builder.setJDOMFactory(new LocatedJDOMFactory()); builder.setFeature(XML_PARSER_FEATURE_XINCLUDE, true); builder.setEntityResolver(new MyEntityResolver()); doc = builder.build(inputFile); } catch (Exception e) { throw new SmartSpacesException( String.format("Exception while processing %s", inputFile.getAbsolutePath()), e); } return doc.getRootElement(); }
From source file:io.wcm.handler.richtext.util.RichTextUtil.java
License:Apache License
/** * 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 *//* w w w . j a v a 2 s .co m*/ public static Element parseText(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); } }
From source file:io.wcm.maven.plugins.contentpackage.unpacker.ContentUnpacker.java
License:Apache License
private void writeXmlWithExcludes(InputStream inputStream, OutputStream outputStream) throws IOException, JDOMException { SAXBuilder saxBuilder = new SAXBuilder(); Document doc = saxBuilder.build(inputStream); applyXmlExcludes(doc.getRootElement(), ""); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat().setLineSeparator(LineSeparator.UNIX)); outputter.setXMLOutputProcessor(new OneAttributePerLineXmlProcessor()); outputter.output(doc, outputStream); outputStream.flush();// w ww . j av a2 s .c o m }
From source file:io.wcm.maven.plugins.i18n.readers.XmlI18nReader.java
License:Apache License
@Override public Map<String, String> read(File sourceFile) throws IOException { try {// ww w . j av a 2 s .com SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(sourceFile); Map<String, String> map = new HashMap<String, String>(); parseXml(doc.getRootElement(), map, ""); return map; } catch (JDOMException ex) { throw new IOException("Unable to read XML from " + sourceFile.getAbsolutePath(), ex); } }
From source file:isjexecact.AppSettings.java
/** * Carrega os valores do arquivo de configurao para AppSeting ambiente. */*from w w w . j ava2 s. c o m*/ * @throws org.jdom2.JDOMException * @throws java.io.IOException */ public void loadDefaultSetings() throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); //Document doc = builder.build("c:/TMPGED/teste.xml"); Document doc = builder.build(appFileName); Element xmllei = doc.getRootElement(); List<Element> lista = xmllei.getChildren(); for (Element e : lista) { setValue(e.getAttributeValue("id"), e.getChildText("valor")); // System.out.println("Chave: "+ e.getAttributeValue("id")); // System.out.println("Valor: " + e.getChildText("valor")); } }
From source file:it.cnr.ilc.clavius.controller.ProofReaderController.java
public void loadLetter() { String token, lemma, morpho, sentence = ""; res.clear();//from w w w . j a va 2 s. c o m InputStream currLetterStream = null; SAXBuilder builder = new SAXBuilder(); setCurrSentence(""); setDis(true); try { currLetterStream = new FileInputStream( HandleConstants.getWorkDir() + "Letter" + HandleConstants.getLetterRif() + "_anOUT.xml"); Document document = (Document) builder.build(currLetterStream); getDocumentTei().setAnalysis(document); Element rootNode = document.getRootElement(); List sentenceList = rootNode.getChildren("sentence"); setCurrLetterSize(sentenceList.size()); Element sentenceNode = (Element) sentenceList.get(0); setCurrSentenceNumber(0); List tokenList = sentenceNode.getChildren("token"); for (int i = 0; i < tokenList.size(); i++) { Element tokenNode = (Element) tokenList.get(i); token = tokenNode.getAttributeValue("form"); lemma = tokenNode.getAttributeValue("lemma"); morpho = tokenNode.getAttributeValue("morphoCode"); sentence = sentence + " " + token; setMorphoElement(token, lemma, morpho); } setCurrSentence(sentence); setCountsentence("1/" + getCurrLetterSize()); } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } finally { try { currLetterStream.close(); } catch (IOException ioe) { System.out.println(ioe.getMessage()); } } }
From source file:it.cnr.ilc.clavius.manager.TranscriptionManager.java
@PostConstruct public void init() { builder = new SAXBuilder(); teiDoc = new HierarchicalTeiDocument(); MapTemplates = initTemplates(); }
From source file:it.intecs.pisa.openCatalogue.openSearch.OpenSearchHandler.java
License:Open Source License
private ArrayList prepareDataForVelocity(SaxonDocument solrResponse) throws XPathFactoryConfigurationException, XPathException, XPathExpressionException, IOException, SAXException, JDOMException, DocumentException { ArrayList metadataList = new ArrayList(); SAXBuilder builder;/* w w w.j a v a2 s . c o m*/ //Loop on the solrResponse and load the metadata in the repository int results = Integer.parseInt((String) solrResponse.evaluatePath(XPATH_COUNT_DOC, XPathConstants.STRING)); String id = ""; String original_polygon = ""; String cdata_field = ""; for (int i = 1; i <= results; i++) { Map metadata = new HashMap(); id = (String) solrResponse.evaluatePath(XPATH_IDENTIFIER.replace("$$", String.valueOf(i)), XPathConstants.STRING); original_polygon = (String) solrResponse.evaluatePath(XPATH_POLYGON.replace("$$", String.valueOf(i)), XPathConstants.STRING); builder = new SAXBuilder(); // builder.setJDOMFactory( (JDOMFactory)new AnakiaJDOMFactory()); cdata_field = (String) solrResponse.evaluatePath(XPATH_METADATA.replace("$$", String.valueOf(i)), XPathConstants.STRING); HashMap<String, String> urls = Prefs.getURLBase(); if (null != urls && !urls.isEmpty()) { for (String stringKey : urls.keySet()) { cdata_field = cdata_field.replace(stringKey, (String) urls.get(stringKey)); //System.out.println("stringKey=" +stringKey +" --> value="+(String) urls.get(stringKey)); } } /* * String urls = Prefs.getBrowseURLBase(); if (null != urls && * !urls.equals("")) { // replace the string in the metadata * cdata_field = cdata_field.replace(BROWSE_URL_KEY, urls); } */ SAXReader reader = new SAXReader(); org.dom4j.Document root = reader.read(new StringReader(cdata_field)); // XmlTool x = new XmlTool(root); // x.find("//*[local-name() = 'ProductInformation']//*[local-name() = 'ServiceReference']/@*[local-name() = 'href']"); // x.find("//*[local-name() = 'ProductInformation']/*[local-name() = 'fileName']/*[local-name() = 'ServiceReference']/@*[local-name() = 'href']"); /* * some example on how to use the xpath XmlTool x = new * XmlTool(root); x.find("//*[local-name() = * 'ServiceReference']/@*[local-name() = 'href']"); * x.find("//*[local-name() = 'orbitType']/text()"); * x.find("//*[local-name() = 'sensorType']/text()"); * x.find("//*[local-name() = 'orbitType']/text()").isEmpty(); * x.find("//*[local-name() = 'sensorType']/text()").isEmpty(); */ metadata.put(XML_TOOL, new XmlTool(root)); metadata.put(METADATA_STRING, cdata_field.trim()); metadata.put(METADATA_DOCUMENT, root); metadata.put(IDENTIFIER, id); metadata.put(POLYGON, original_polygon); // load the metadata and add it to the array metadataList.add(metadata); } return metadataList; }