List of usage examples for org.jdom2 Element getTextTrim
public String getTextTrim()
From source file:gov.nasa.jpl.mudrod.main.MudrodEngine.java
License:Apache License
/** * Load the configuration provided at <a href= * "https://github.com/mudrod/mudrod/blob/master/core/src/main/resources/config.xml">config.xml</a>. * * @return a populated {@link java.util.Properties} object. *///from w w w .ja va2 s .co m public Properties loadConfig() { SAXBuilder saxBuilder = new SAXBuilder(); InputStream configStream = locateConfig(); Document document; try { document = saxBuilder.build(configStream); Element rootNode = document.getRootElement(); List<Element> paraList = rootNode.getChildren("para"); for (int i = 0; i < paraList.size(); i++) { Element paraNode = paraList.get(i); String attributeName = paraNode.getAttributeValue("name"); if (MudrodConstants.SVM_SGD_MODEL.equals(attributeName)) { props.put(attributeName, decompressSVMWithSGDModel(paraNode.getTextTrim())); } else { props.put(attributeName, paraNode.getTextTrim()); } } } catch (JDOMException | IOException e) { LOG.error("Exception whilst retrieving or processing XML contained within 'config.xml'!", e); } return getConfig(); }
From source file:io.smartspaces.master.server.services.internal.support.JdomMasterDomainModelImporter.java
License:Apache License
/** * Get an individual named script.//from w w w. j a v a2 s . com * * @param scriptElement * the script XML element * @param automationRepository * repository for automation entities */ private void getNamedScript(Element scriptElement, AutomationRepository automationRepository) { String id = scriptElement.getAttributeValue(ATTRIBUTE_NAME_ID); NamedScript script = automationRepository.newNamedScript(); String name = scriptElement.getChildTextTrim(ELEMENT_NAME_NAME); String description = scriptElement.getChildTextTrim(ELEMENT_NAME_DESCRIPTION); String language = scriptElement.getChildTextTrim(ELEMENT_NAME_NAMED_SCRIPT_LANGUAGE); String content = scriptElement.getChildTextTrim(ELEMENT_NAME_NAMED_SCRIPT_CONTENT); script.setName(name); script.setDescription(description); script.setLanguage(language); script.setContent(content); Element scheduleElement = scriptElement.getChild(ELEMENT_NAME_NAMED_SCRIPT_SCHEDULE); if (scheduleElement != null) { script.setSchedule(scheduleElement.getTextTrim()); script.setScheduled(VALUE_TRUE.equalsIgnoreCase( scheduleElement.getAttributeValue(ATTRIBUTE_NAME_NAMED_SCRIPT_SCHEDULE_SCHEDULED))); } Map<String, Object> metadata = getMetadata(scriptElement.getChild(ELEMENT_NAME_METADATA)); if (metadata != null) { script.setMetadata(metadata); } automationRepository.saveNamedScript(script); }
From source file:io.smartspaces.workbench.project.jdom.JdomProjectGroupTemplateSpecificationReader.java
License:Apache License
/** * Add the given element to the spec./*ww w .ja v a 2s. c o m*/ * * @param spec * specification to configure * @param namespace * XML namespace for elements * @param child * child element to add */ private void addElementToSpec(GroupProjectTemplateSpecification spec, Namespace namespace, Element child) { String name = child.getName(); try { if (JdomProjectReader.PROJECT_GROUP_ELEMENT_NAME.equals(name)) { addProjects(spec, child); } else if (JdomPrototypeProcessor.GROUP_ELEMENT_NAME.equals(name)) { addPrototypes(spec, child); } else if (JdomProjectReader.PROJECT_ELEMENT_NAME_NAME.equals(name)) { spec.setName(child.getTextTrim()); } else if (JdomProjectReader.PROJECT_ELEMENT_NAME_DESCRIPTION.equals(name)) { spec.setDescription(child.getTextTrim()); } else if (JdomReader.PROJECT_ELEMENT_NAME_TEMPLATES.equals(name)) { // This is really a prototype chain for the entire group project, but we // need to control when it is processed, // so instead snarf the attribute from the templates element when it is // processed. processPrototypeChain(spec, namespace, child); spec.addExtraConstituents(getContainerConstituents(namespace, child, null)); } else if (JdomProjectReader.PROJECT_ELEMENT_NAME_VERSION.equals(name)) { spec.setVersion(Version.parseVersion(child.getTextTrim())); } else { throw new SimpleSmartSpacesException("Unrecognized element name: " + name); } } catch (Exception e) { throw new SimpleSmartSpacesException("While processing projectGroup element: " + name, e); } }
From source file:it.intecs.pisa.openCatalogue.solr.ingester.Ingester.java
private static void generateMap2(org.dom4j.Element el, Map map) { String value = el.getTextTrim(); String currentPath = getXPath(el); Iterator a = null;//from ww w.j a v a2 s .c o m Iterator i = el.elementIterator(); a = el.attributeIterator(); while (a.hasNext()) { org.dom4j.Attribute attr = (org.dom4j.Attribute) a.next(); String aval = attr.getValue(); String apath = currentPath + "_" + attr.getName(); //System.out.println("PATH:" + apath + " --- " + aval); map.put(apath, aval); } if (!i.hasNext() && value != null) { // System.out.println("PATH:" + currentPath); map.put(currentPath, value); } else { while (i.hasNext()) { generateMap2((org.dom4j.Element) i.next(), map); } } }
From source file:it.intecs.pisa.openCatalogue.solr.ingester.Ingester.java
protected static void generateDefaultMap(Element el, Map map) { String key = ""; List<Element> listEmpElement = el.getChildren(); if (el.getName().equals("indexFieldName")) { key = el.getTextTrim(); // System.out.println("key:" + key); map.put(key, ""); } else {//from ww w.jav a2 s.co m for (Element empElement : listEmpElement) { generateDefaultMap(empElement, map); } } }
From source file:LectorXml.CargarXML.java
public void cargarDiccionario(String ruta) { //se cra un SAXBuilder para poder parsear el archivo SAXBuilder builder = new SAXBuilder(); File ArchivoXml = new File(ruta); try {//ww w. jav a 2 s .c o m //se crea el docuemento a traves del archio Document documento = (Document) builder.build(ArchivoXml); //se obtiene la raiz scrabble Element raiz = documento.getRootElement(); //se obtiene la lista de hijos de la raiz List list = raiz.getChildren("diccionario"); //si lista tiene un elemento lo obtiene if (list.size() == 1) { //se obtiene el elemento diccionario Element diccionario = (Element) list.get(0); // se obtiene los elementos de diccionario qe son palabras List list_palabras = diccionario.getChildren(); for (int x = 0; x < list_palabras.size(); x++) { Element palabra = (Element) list_palabras.get(x); System.out.println("" + palabra.getTextTrim()); } } else if (list.size() == 0) { JOptionPane.showMessageDialog(null, "No existe ninguna dimension del tablero"); } else { JOptionPane.showMessageDialog(null, "Revise su archivo de entrada"); } } catch (IOException io) { JOptionPane.showMessageDialog(null, io.getMessage()); } catch (JDOMException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } }
From source file:mammothkiosk.Bone.java
/** * Constructor that takes a JDOM element as an argument. Parses the data from * bones.xml found in the element, then parses its specific id.xml file for * further data./*from w ww . j a va 2s . com*/ * * @param boneRec The bone record to parse for information */ public Bone(Element boneRec) { // Retrieve info from boneRec (bones.xml file) Element temp; id = (temp = boneRec.getChild("uniqueid")) != null ? temp.getTextTrim() : null; year = (temp = boneRec.getChild("year")) != null ? temp.getTextTrim() : null; objectnum = (temp = boneRec.getChild("objectnum")) != null ? temp.getTextTrim() : null; part = (temp = boneRec.getChild("part")) != null ? temp.getTextTrim() : null; previous = (temp = boneRec.getChild("previous")) != null ? temp.getTextTrim() : null; taxon = (temp = boneRec.getChild("taxon")) != null ? temp.getTextTrim() : null; element = (temp = boneRec.getChild("element")) != null ? temp.getTextTrim() : null; subelement = (temp = boneRec.getChild("subelement")) != null ? temp.getTextTrim() : null; side = (temp = boneRec.getChild("side")) != null ? temp.getTextTrim() : null; portion = (temp = boneRec.getChild("portion")) != null ? temp.getTextTrim() : null; completeness = (temp = boneRec.getChild("completeness")) != null ? temp.getTextTrim() : null; expside = (temp = boneRec.getChild("expside")) != null ? temp.getTextTrim() : null; crack = (temp = boneRec.getChild("crack")) != null ? temp.getTextTrim() : null; articulate = (temp = boneRec.getChild("articulate")) != null ? temp.getTextTrim() : null; gender = (temp = boneRec.getChild("gender")) != null ? temp.getTextTrim() : null; remarks = (temp = boneRec.getChild("remarks")) != null ? temp.getTextTrim() : null; datefound = (temp = boneRec.getChild("datefound")) != null ? temp.getTextTrim() : null; foundby = (temp = boneRec.getChild("foundby")) != null ? temp.getTextTrim() : null; elevation = (temp = boneRec.getChild("elevation")) != null ? temp.getTextTrim() : null; updates = (temp = boneRec.getChild("updates")) != null ? temp.getTextTrim() : null; mappic = (temp = boneRec.getChild("mappic")) != null ? temp.getTextTrim() : null; fieldnotes = (temp = boneRec.getChild("fieldnotes")) != null ? temp.getTextTrim() : null; removed = (temp = boneRec.getChild("removed")) != null ? temp.getTextTrim() : null; removedby = (temp = boneRec.getChild("removedby")) != null ? temp.getTextTrim() : null; azimuth = (temp = boneRec.getChild("azimuth")) != null ? temp.getTextTrim() : null; incline = (temp = boneRec.getChild("incline")) != null ? temp.getTextTrim() : null; labrec = (temp = boneRec.getChild("labrec")) != null ? temp.getTextTrim() : null; objectid = (temp = boneRec.getChild("objectid")) != null ? temp.getTextTrim() : null; shapelength = (temp = boneRec.getChild("shapelength")) != null ? temp.getTextTrim() : null; min = null; max = null; polylines = null; boneImage = null; // Retrieve info for drawing bone from respective bone-shape file SAXBuilder saxBuild = new SAXBuilder(); Document doc; try { doc = saxBuild.build("../bonexml/" + id + ".xml"); Element rootElement = doc.getRootElement(); parseFile(rootElement); } catch (Exception ex) { System.out.println("Exception in Bone Constructor: " + ex.getMessage()); } }
From source file:middleware.Reserva.java
public static ArrayList<Reserva> ConsultarReservas() { //lista de reservaas ArrayList<Reserva> listaReservas = new ArrayList<Reserva>(); //Se crea un SAXBuilder para poder parsear el archivo SAXBuilder builder = new SAXBuilder(); //archivo que tiene las reservas File xmlFile = new File("reserva.xml"); try {//from w ww .j a v a2 s.c o m //Se crea el documento a traves del archivo Document document = (Document) builder.build(xmlFile); //Se obtiene la raiz 'reservas' Element rootNode = document.getRootElement(); //Se obtiene la lista de hijos de la raiz 'vuelo' List list = rootNode.getChildren("reserva"); //Se recorre la lista de hijos de 'disponibilidad' for (int i = 0; i < list.size(); i++) {//objeto de reservas Reserva objeto = new Reserva(); //Se obtiene el elemento 'vuelo' Element tabla = (Element) list.get(i); //Se obtiene el atributo 'id' que esta en el tag 'vuelo' String idVuelo = tabla.getAttributeValue("clave"); objeto.setReserva(idVuelo); //Se obtiene la lista de hijos del tag 'reserva' List lista_campos = tabla.getChildren(); //Se obtiene la lista de hijos del tag 'vuelo' Element tabla2 = (Element) lista_campos.get(0); List Lista_nombres = tabla2.getChildren(); //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); Element hijosCampo = (Element) Lista_nombres.get(j); //Se obtienen los valores que estan entre los tags //se guarda en el objeto los datos de la reserva String linea = campo.getAttributeValue("clave"); String lineaNombre = hijosCampo.getTextTrim(); if (campo.getName() == "vuelo") { //linea= campo.getAttributeValue("vuelo"); objeto.setVuelo(linea); } if (hijosCampo.getName() == "nombre") { objeto.setNombre(lineaNombre); } //System.out.println( "\t"+linea+"\t\t"); //listaVuelos.add(i,objeto); } //se agrega a la lista el objeto listaReservas.add(objeto); //System.out.println( "\"\t\t"); } //listaVuelos. add(objeto); } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } // se retorna la lista de las reservas return listaReservas; }
From source file:middleware.Vuelo.java
public static ArrayList<Vuelo> ConsultarVuelos() { ArrayList<Vuelo> listaVuelos = new ArrayList<Vuelo>(); //Se crea un SAXBuilder para poder parsear el archivo SAXBuilder builder = new SAXBuilder(); File xmlFile = new File("disponibilidad.xml"); try {//ww w . j a v a 2 s . c o m //Se crea el documento a traves del archivo Document document = (Document) builder.build(xmlFile); //Se obtiene la raiz 'disponibilidad' Element rootNode = document.getRootElement(); //Se obtiene la lista de hijos de la raiz 'vuelo' List list = rootNode.getChildren("vuelo"); //Se recorre la lista de hijos de 'disponibilidad' for (int i = 0; i < list.size(); i++) { Vuelo objeto = new Vuelo(); //Se obtiene el elemento 'vuelo' Element tabla = (Element) list.get(i); //Se obtiene el atributo 'id' que esta en el tag 'vuelo' String idVuelo = tabla.getAttributeValue("id"); objeto.setId(idVuelo); //Se obtiene la lista de hijos del tag 'vuelo' List lista_campos = tabla.getChildren(); //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 linea = campo.getTextTrim(); //dependiendo de la etiqueta que esta parada guarda en un atributo del objeto if (campo.getName() == "linea") { objeto.setLinea(linea); } if (campo.getName() == "origen") { objeto.setOrigen(linea); } if (campo.getName() == "destino") { objeto.setDestino(linea); } if (campo.getName() == "fecha") { objeto.setFecha(linea); } if (campo.getName() == "hora") { objeto.setHora(linea); } if (campo.getName() == "capacidad") { objeto.setCapacidad(linea); } if (campo.getName() == "precio") { objeto.setPrecio(linea); } //System.out.println( "\t"+linea+"\t\t"); } //se inserta el objeto de vuelos en la lista de vuelos listaVuelos.add(objeto); //System.out.println( ""); } //listaVuelos. add(objeto); } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } // se retorna la lista de vuelos return listaVuelos; }
From source file:neon.narrative.Resolver.java
License:Open Source License
private void addItem(Element var, List<String> strings) { Collection<RItem> items = Engine.getResources().getResources(RItem.class); if (var.getAttributeValue("type") != null) { for (RItem item : items) { if (item.type.name().equals(var.getAttributeValue("type"))) { strings.add("$" + var.getTextTrim() + "$"); strings.add(item.toString()); tracker.addObject(item.toString()); break; // uit de for loop halen }/* w w w . j ava 2 s . co m*/ } } else if (var.getAttributeValue("id") != null) { String[] things = var.getAttributeValue("id").split(","); String item = things[Dice.roll(1, things.length, -1)]; strings.add("$" + var.getTextTrim() + "$"); strings.add(item.toString()); tracker.addObject(item); } else { String item = items.toArray()[Dice.roll(1, items.size(), -1)].toString(); strings.add("$" + var.getTextTrim() + "$"); strings.add(item.toString()); tracker.addObject(item.toString()); } }