List of usage examples for org.jdom2.input SAXBuilder SAXBuilder
public SAXBuilder()
From source file:it.intecs.pisa.openCatalogue.openSearch.OpenSearchHandler.java
License:Open Source License
private ArrayList prepareDataForVelocity(String id) throws XPathFactoryConfigurationException, XPathException, XPathExpressionException, IOException, SAXException, JDOMException { ArrayList metadataList = new ArrayList(); SAXBuilder builder;//ww w . ja va 2 s .c o m org.jdom2.Document root = null; Map metadata = new HashMap(); builder = new SAXBuilder(); root = builder.build(this.repository.getAbsolutePath() + "/" + id + ".xml"); metadata.put(METADATA_DOCUMENT, root); metadata.put(IDENTIFIER, id); // load the metadata and add it to the array metadataList.add(metadata); return metadataList; }
From source file:it.intecs.pisa.openCatalogue.solr.ingester.Ingester.java
@Override public void setConfiguration(AbstractFilesystem configDirectory) throws SAXException, IOException, SaxonApiException, Exception { super.setConfiguration(configDirectory); configDocument = new SaxonDocument(configDirectory.get(configuration).getInputStream()); sensorType = (!"".equals((String) configDocument .evaluatePath(XPATH_SENSOR_TYPE + SLASH + TAG_INDEX_FIELD_NAME, XPathConstants.STRING)) ? (DOLLAR + (String) configDocument.evaluatePath( XPATH_SENSOR_TYPE + SLASH + TAG_INDEX_FIELD_NAME, XPathConstants.STRING)) : (String) configDocument.evaluatePath(XPATH_SENSOR_TYPE + SLASH + TAG_DEFAULT_VALUE, XPathConstants.STRING)); dateTimeFormat = !"" .equals((String) configDocument.evaluatePath(XPATH_DATE_TIME_FORMAT, XPathConstants.STRING)) ? ((String) configDocument.evaluatePath(XPATH_DATE_TIME_FORMAT, XPathConstants.STRING)) : DEFAULT_DATE_TIME_FORMAT; elements_separator = (String) configDocument.evaluatePath(XPATH_SEPARATOR, XPathConstants.STRING); SAXBuilder saxBuilder = new SAXBuilder(); org.jdom2.Document doc = saxBuilder.build(configDirectory.get(configuration).getInputStream()); Element rootElement = doc.getRootElement(); defaultMap = new HashMap(); generateDefaultMap(rootElement, defaultMap); }
From source file:it.intecs.pisa.openCatalogue.solr.ingester.Ingester.java
protected org.jdom2.Document generateMetadata(Map metadataMap, String key, HashMap<String, String> queryHeaders) throws IOException, SaxonApiException, XPathFactoryConfigurationException, JDOMException { //debug// w w w.ja v a2 s. c om /* List<String> keys = new ArrayList<String>(metadataMap.keySet()); Collections.sort(keys); for (String keyString: keys) { System.out.println(keyString + ": " + metadataMap.get(keyString)); }*/ //debug VelocityContext context = new VelocityContext(); context.put(VELOCITY_DATE, new DateTool()); context.put(VELOCITY_METADATA_LIST, metadataMap); context.put("coordinates", new CoordinatesUtil()); context.put(VELOCITY_PERIOD_START, this.period_start); context.put(VELOCITY_PERIOD_END, this.period_end); context.put("KEY", key); if (queryHeaders != null) { context.put("queryValues", queryHeaders); } StringWriter swOut = new StringWriter(); String sType = sensorType.startsWith(DOLLAR) ? ((String) metadataMap.get(sensorType.substring(1))) : sensorType; getTemplate(sType).merge(context, swOut); SAXBuilder builder; builder = new SAXBuilder(); org.jdom2.Document metadata = builder.build(new ByteArrayInputStream(swOut.toString().getBytes())); //SaxonDocument metadata = new SaxonDocument(swOut.toString()); swOut.close(); return metadata; }
From source file:it.intecs.pisa.openCatalogue.solr.ingester.OEMIngester.java
@Override protected Document[] parse(AbstractFilesystem indexFile, HashMap<String, String> queryHeaders) { try {//from w ww .j a v a 2 s.c om SAXBuilder builder = new SAXBuilder(); Document document = builder.build(indexFile.getInputStream()); return new Document[] { document }; } catch (Exception e) { return new Document[0]; } }
From source file:it.isislab.floasys.core.security.users.UserAccountXMLParser.java
License:Open Source License
public List<UserAccount> parse(InputStream is) throws CannotParseException { try {//from w ww.j a va 2s . co m Document doc = new SAXBuilder().build(is); Element rootNode = doc.getRootElement(); List<Element> elUsers = rootNode.getChildren(EL_USERACCOUNT); for (Element elUser : elUsers) { UserAccount userAccount = new UserAccount(); List<Element> children = elUser.getChildren(); for (Element child : children) { String childName = child.getName(); if (childName.equals(EL_USERNAME)) { } else if (childName.equals(EL_PASSWORD)) { } else if (childName.equals(EL_ACTIVATIONCODE)) { } else if (childName.equals(EL_ACTIVATED)) { } } //EndFor. } } catch (Exception e) { throw new CannotParseException(e); } return null; }
From source file:it.isislab.floasys.core.security.users.UserAccountXMLParser.java
License:Open Source License
/** * Write another account to the XML file. * @param is/*from w w w . j a v a 2s . c om*/ * @param os * @param account * @throws CannotParseException */ public void write(InputStream is, OutputStream os, UserAccount account) throws CannotParseException { try { //Read the existing file. Document doc = new SAXBuilder().build(is); Element rootNode = doc.getRootElement(); //Create a new user element. Element elAccount = new Element(EL_USERACCOUNT); Element elUsername = new Element(EL_USERNAME); Element elPassword = new Element(EL_PASSWORD); Element elActivationCode = new Element(EL_ACTIVATIONCODE); Element elActivated = new Element(EL_ACTIVATED); elAccount.addContent(elUsername); elAccount.addContent(elPassword); elAccount.addContent(elActivationCode); elAccount.addContent(elActivated); //Add the account to the root element. rootNode.addContent(elAccount); //Set the root for document. doc.setContent(rootNode); //Write the file content. XMLOutputter outputter = new XMLOutputter(); outputter.setFormat(Format.getPrettyFormat()); outputter.output(doc, os); } catch (Exception ex) { throw new CannotParseException(ex); } }
From source file:javaapplication1.LeerXml.java
public void cargarXml() { //Se crea un SAXBuilder para poder parsear el archivo SAXBuilder builder = new SAXBuilder(); File xmlFile = new File("archivo.xml"); try {//from w w w. j a va 2 s .com //Se crea el documento a traves del archivo Document document = (Document) builder.build(xmlFile); //Se obtiene la raiz 'tables' Element rootNode = document.getRootElement(); //Se obtiene la lista de hijos de la raiz 'tables' List list = rootNode.getChildren("dimension"); List list_dobles = rootNode.getChildren("dobles"); List list_triples = rootNode.getChildren("triples"); List list_diccionario = rootNode.getChildren("diccionario"); //Se recorre la lista de hijos de 'tables' for (int i = 0; i < list.size(); i++) { //Se obtiene el elemento 'tabla' Element tabla = (Element) list.get(i); System.out.println("Dimension: " + tabla.getText()); dimension = Integer.parseInt(tabla.getText()); m = new Matriz(dimension, dimension); } for (int i = 0; i < list_dobles.size(); i++) { //Se obtiene el elemento 'tabla' Element tabla = (Element) list_dobles.get(i); //Se obtiene el atributo 'nombre' que esta en el tag 'tabla' //String nombreTabla = tabla.getAttributeValue("nombre"); //System.out.println("Tabla: " + nombreTabla); //Se obtiene la lista de hijos del tag 'tabla' List lista_campos = tabla.getChildren(); //System.out.println("\tNombre\t\tTipo\t\tValor"); //Se recorre la lista de campos for (int j = 0; j < lista_campos.size(); j++) { //Se obtiene el elemento 'campo' Element campo = (Element) lista_campos.get(j); //Se obtienen los valores que estan entre los tags '<campo></campo>' //Se obtiene el valor que esta entre los tags '<nombre></nombre>' String x = campo.getChildTextTrim("x"); //Se obtiene el valor que esta entre los tags '<tipo></tipo>' String y = campo.getChildTextTrim("y"); m.item(Integer.parseInt(x) - 1, Integer.parseInt(y) - 1).datos = 2; System.out.println("Puntos Dobles en la posicion X:" + x + " Y: " + y); } } for (int i = 0; i < list_triples.size(); i++) { //Se obtiene el elemento 'tabla' Element tabla = (Element) list_triples.get(i); //Se obtiene el atributo 'nombre' que esta en el tag 'tabla' //String nombreTabla = tabla.getAttributeValue("nombre"); //System.out.println("Tabla: " + nombreTabla); //Se obtiene la lista de hijos del tag 'tabla' List lista_campos = tabla.getChildren(); //System.out.println("\tNombre\t\tTipo\t\tValor"); //Se recorre la lista de campos for (int j = 0; j < lista_campos.size(); j++) { //Se obtiene el elemento 'campo' Element campo = (Element) lista_campos.get(j); //Se obtienen los valores que estan entre los tags '<campo></campo>' //Se obtiene el valor que esta entre los tags '<nombre></nombre>' String x = campo.getChildTextTrim("x"); //Se obtiene el valor que esta entre los tags '<tipo></tipo>' String y = campo.getChildTextTrim("y"); m.item(Integer.parseInt(x) - 1, Integer.parseInt(y) - 1).datos = 3; System.out.println("Puntos Triples en la posicion X:" + x + " Y: " + y); } } for (int i = 0; i < list_diccionario.size(); i++) { //Se obtiene el elemento 'tabla' Element tabla = (Element) list_diccionario.get(i); //Se obtiene el atributo 'nombre' que esta en el tag 'tabla' //String nombreTabla = tabla.getAttributeValue("nombre"); //System.out.println("Tabla: " + nombreTabla); //Se obtiene la lista de hijos del tag 'tabla' List lista_campos = tabla.getChildren(); //System.out.println("\tNombre\t\tTipo\t\tValor"); //Se recorre la lista de campos for (int j = 0; j < lista_campos.size(); j++) { //Se obtiene el elemento 'campo' Element campo = (Element) lista_campos.get(j); System.out.println("Palabra: " + campo.getText() + " tamano lista " + diccionario.getsize()); diccionario.insertarAlFinal(campo.getText()); } } } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } }
From source file:javaapplication5.JavaApplication5.java
public static Boolean checkRemitente(String from) throws JDOMException, IOException { boolean resultado = false; //Se crea un SAXBuilder para poder parsear el archivo SAXBuilder builder = new SAXBuilder(); //Traigo el XML de remitentes validos File xmlFile = new File( "C:\\Users\\Matias\\Documents\\NetBeansProjects\\Repo\\JavaApplication5\\src\\javaapplication5\\remitentes.xml"); //Se crea el documento a traves del archivo Document document = (Document) builder.build(xmlFile); //Se obtiene la raiz 'remitentes' Element rootNode = document.getRootElement(); //Se obtiene la lista de hijos de la raiz 'remitentes' List list = rootNode.getChildren(); //Se recorre la lista de hijos de 'remitentes' for (int i = 0; i < list.size(); i++) { //por cada remitente Element remitente = (Element) list.get(i); String rem = remitente.getText(); //si el remitente q me vino del mail esta en el XML pone en true la variable resultado if (from.equals(rem)) { resultado = true;//from ww w .j a v a 2 s .c o m return (resultado); } } return resultado; }
From source file:jcodecollector.io.PackageManager.java
License:Apache License
public static ArrayList<Snippet> readPackage(File file) { ArrayList<Snippet> array = new ArrayList<Snippet>(); Element root = null;// w w w . j av a 2s . co m try { SAXBuilder builder = new SAXBuilder(); root = builder.build(file).getRootElement(); } catch (Exception ex) { return null; } @SuppressWarnings("unchecked") Iterator<Element> iterator = root.getChildren("snippet").iterator(); while (iterator.hasNext()) { Element e = iterator.next(); String category = e.getChildTextTrim("category"); String name = e.getChildTextTrim("name"); String syntax = e.getChildTextTrim("syntax"); String code = e.getChildTextTrim("code"); String comment = e.getChildTextTrim("comment"); @SuppressWarnings("unchecked") List<Element> tagElements = e.getChildren("tag"); String[] tags = new String[tagElements.size()]; for (int i = 0; i < tags.length; i++) { tags[i] = tagElements.get(i).getTextTrim(); } Snippet snippet = new Snippet(-1, category, name, tags, code, comment, syntax, false); array.add(snippet); } return array; }
From source file:jcodecollector.io.XMLManagerOldVersion.java
License:Apache License
@SuppressWarnings("unchecked") public static ArrayList<Snippet> readPackage(File file) { Element root_xml = null;/*w w w.ja v a2s . co m*/ try { SAXBuilder builder = new SAXBuilder(); root_xml = builder.build(file).getRootElement(); } catch (Exception ex) { ex.printStackTrace(); return null; } ArrayList<Snippet> array = new ArrayList<Snippet>(); Iterator<Element> iterator = root_xml.getChildren("snippet").iterator(); while (iterator.hasNext()) { Element element = iterator.next(); String category = element.getChildTextTrim("category"); String name = element.getChildTextTrim("name"); String syntax = element.getChildTextTrim("syntax"); String code = element.getChildTextTrim("code"); String comment = element.getChildTextTrim("comment"); List<Element> tags_xml = element.getChildren("tag"); String[] tags = new String[tags_xml.size()]; for (int i = 0; i < tags.length; i++) { tags[i] = tags_xml.get(i).getTextTrim(); } boolean locked = Boolean.parseBoolean(element.getChildTextTrim("locked")); Snippet snippet = new Snippet(-1, category, name, tags, code, comment, syntax, locked); array.add(snippet); } return array; }