List of usage examples for org.jdom2 Element getChildren
public List<Element> getChildren(final String cname)
List
of all the child elements nested directly (one level deep) within this element with the given local name and belonging to no namespace, returned as Element
objects. From source file:EvaluateNeurode.java
License:Apache License
public synchronized double sumInput(Element node) throws JDOMException { List SynIns = node.getChildren("SYNAPSE"); double bias = java.lang.Double.parseDouble(node.getAttributeValue("BIAS")); double sumInputs = 0 + bias; for (Iterator itSI = SynIns.iterator(); itSI.hasNext();) { Element SynapseI = (Element) itSI.next(); double weight = java.lang.Double.parseDouble(SynapseI.getAttributeValue("WEIGHT")); String OrgNodeID = SynapseI.getAttributeValue("ORG_NEURODE"); Element OrgNode = (Element) XPath.selectSingleNode(Erudite_gui.NNetMap, "/NNETWORK/SUBNET/LAYER/NEURODE[@N_ID='" + OrgNodeID + "']"); int activeTF = java.lang.Integer.parseInt(OrgNode.getAttributeValue("ACTIVE")); if (activeTF == 1) { double value = java.lang.Double.parseDouble(OrgNode.getAttributeValue("ACTIVITY")); sumInputs += weight * value; } else if (activeTF == -1) { int TFcheck = java.lang.Integer.parseInt(OrgNode.getAttributeValue("ACTIVE")); while (TFcheck != 1) { TFcheck = java.lang.Integer.parseInt(OrgNode.getAttributeValue("ACTIVE")); }/*w w w .jav a 2 s. c o m*/ double value = java.lang.Double.parseDouble(OrgNode.getAttributeValue("ACTIVITY")); sumInputs += weight * value; } else if (activeTF == 0) { sumInputs += 0; } } return sumInputs; }
From source file:VraagServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //Bestandslocatie van de XML file. Later als parameter meegeven String xmlUrl = "file:///H:/NetBeansProjects/WebApplication1/GMFM.xml"; PrintWriter out = new PrintWriter(response.getOutputStream()); //Maakt HTML pagina aan out.println("<html>"); out.println("<head><title>Formulier</title></head>"); out.println("<body>"); try {//from w ww . jav a 2 s . c om //Maakt een URL aan die naar het XML document wijst. En een builder die vervolgens een document opbouwt. URL theDoc = new URL(xmlUrl); SAXBuilder builder = new SAXBuilder(); Document document = builder.build(theDoc); // Geeft het root element (Formulier) Element root = document.getRootElement(); /* Maakt een lijst aan waarin alle XML staat die tussen <uitleg> </uitleg> staat. De lijst wordt vervolgens geitereerd totdat alle elementen uit de uitleg zijn geweest en in de html staan.*/ List uitleg = root.getChildren("UITLEG"); Iterator uitlegItr = uitleg.iterator(); while (uitlegItr.hasNext()) { Object u = uitlegItr.next(); Element beschrijving = (Element) u; out.println(beschrijving.getChildText("BESCHRIJVING")); } /* Maakt een lijst aan waarin alle XML staat die tussen <regel> </regel> staat. De lijst wordt vervolgens geitereerd totdat alle elementen uit de regel zijn geweest.*/ List vragen = root.getChildren("REGEL"); Iterator itr = vragen.iterator(); //Er wordt net zolang doorgegaan totdat de laatste vraag is bereikt. Alle vragen worden in een tabel gestopt. out.println("<table border =1>"); out.println("<form >"); while (itr.hasNext()) { Object o = itr.next(); Element vraag = (Element) o; /*Hieronder worden de verschillende invoermogelijkheden opgeslagen dus bijvoorbeeld 4 checkbox buttons naast elkaar. Een variabele met NT erachter betekent dat deze een extra knop heeft voor niet getest. VALUES NOG TOEVOEGEN AAN VARIABELEN Uitbreiden indien nodig!!*/ StringBuffer row = new StringBuffer("<tr>"); // /*De vraag wordt opgehaald en in de eerste kolom van de tabel gezet. Vervolgens wordt het antwoord opgehaald en wordt gekeken waarmee dit antwoord overeen komt. Dit bepaald vervolgens hoeveel checkbox buttons/tekstvakken er gemaakt worden of dat er gewoon tekst afgedrukt wordt. Uitbreiden als nodig!!! */ row.append("<td>" + vraag.getChildText("VRAAG") + "</td>"); String antwoord = vraag.getChildText("INVOERMOGELIJKHEID"); if (antwoord.equals("driecheckbox")) { row.append("<td>" + "<input type=\"checkbox\" name=\"driecheckbox\" value=\"0\">" + "<input type=\"checkbox\" name=\"driecheckbox\" value=\"0\">" + "<input type=\"checkbox\" name=\"driecheckbox\" value=\"0\">"); } else if (antwoord.equals("viercheckboxNT")) { row.append("<td>" + "<input type=\"checkbox\" name=\"viercheckboxNT\" value=\"0\" id=\"0\">" + "<input type=\"checkbox\"name=\"viercheckboxNT\"value=\"1\"id=\"1\">" + "<input type=\"checkbox\"name=\"viercheckboxNT\"value=\"2\"id=\"2\">" + "<input type=\"checkbox\"name=\"viercheckboxNT\"value=\"3\"id=\"3\">" + "<input type=\"checkbox\"name=\"viercheckboxNT\"value=\"\"id=\"4\">" + "</td>"); } else if (antwoord.equals("vijfcheckbox")) { row.append("<td>" + "<input type=\"checkbox\" name=\"vijfcheckbox\" value=\"0\">" + "<input type=\"checkbox\"name=\"vijfcheckbox\"value=\"1\">" + "<input type=\"checkbox\"name=\"vijfcheckbox\"value=\"2\">" + "<input type=\"checkbox\"name=\"vijfcheckbox\"value=\"3\">" + "<input type=\"checkbox\"name=\"vijfcheckbox\"value=\"4\">"); } else if (antwoord.equals("tekstvak")) { row.append("<td>" + "<INPUT TYPE=\"text\" NAME=\"tekstvak\" SIZE=\"13\" MAXLENGTH=\"20\">"); } else { row.append("<td>" + antwoord); } //Hier wordt de regel uitgeprint in de html out.println(row.toString()); } //Sluiten van tabel en html out.println("</table>"); out.println("<input type=\"submit\" value=\"Formulier verzenden\">"); String[] results = request.getParameterValues("viercheckboxNT"); for (int i = 0; i < results.length; i++) { out.println(results[i]); } out.println("</form>"); out.println("</body></html>"); } catch (MalformedURLException e) { e.printStackTrace(); } catch (JDOMException e) { e.printStackTrace(); } finally { out.close(); } }
From source file:agendavital.modelo.data.InicializarBD.java
public static void cargarXMLS() throws JDOMException, IOException, SQLException, ConexionBDIncorrecta { SAXBuilder builder = new SAXBuilder(); File xmlFolder = new File("Noticias"); File[] xmlFile = xmlFolder.listFiles(); System.out.println("LONGITUD " + xmlFile.length); for (int i = 0; i < xmlFile.length; i++) { Document document = (Document) builder.build(xmlFile[i]); Element rootNode = document.getRootElement(); List list = rootNode.getChildren("Noticia"); for (Object list1 : list) { Element noticia = (Element) list1; List noticiaCampos = noticia.getChildren(); String titulo = noticia.getChildTextTrim("titulo"); String fecha = noticia.getChildTextTrim("fecha"); String link = noticia.getChildTextTrim("link"); String categorias = noticia.getChildTextTrim("categoria"); String cuerpo = noticia.getChildTextTrim("cuerpo"); List tags = noticia.getChildren("tag"); ArrayList<String> etiquetas = new ArrayList<>(); for (Object tags1 : tags) { Element tag = (Element) tags1; etiquetas.add(tag.getTextTrim()); }//from w w w.j a v a 2s.c om Noticia.Insert(titulo, link, fecha, categorias, cuerpo, etiquetas); } } }
From source file:app.simulation.Importer.java
License:MIT License
public void importXML() throws Exception { File file = new File(path); if (!file.exists()) throw new FileNotFoundException(path); if (!getFileFormat().equalsIgnoreCase("xml")) throw new InvalidFileFormatException(getFileFormat()); SAXBuilder saxBuilder = new SAXBuilder(); Document document = saxBuilder.build(file); Element root = document.getRootElement(); Element configuration = root.getChild("configuration"); if (configuration != null) { String delayText = configuration.getChildText("delay"); if (delayText == null) throw new AttributeNotFoundException("delay"); String iterationsText = configuration.getChildText("iterations"); if (iterationsText == null) throw new AttributeNotFoundException("iterations"); String agentsText = configuration.getChildText("agents"); if (agentsText == null) throw new AttributeNotFoundException("agents"); String latticeSizeText = configuration.getChildText("latticeSize"); if (latticeSizeText == null) throw new AttributeNotFoundException("latticeSize"); String descriptionText = configuration.getChildText("description"); if (descriptionText == null) throw new AttributeNotFoundException("description"); int delay = Integer.parseInt(delayText); int iterations = Integer.parseInt(iterationsText); int agents = Integer.parseInt(agentsText); int latticeSize = Integer.parseInt(latticeSizeText); this.configuration = new Configuration(delay, iterations, agents, latticeSize, descriptionText); }//from w ww .jav a2s. c o m Element initialCell = root.getChild("initialCell"); if (initialCell != null) { String xText = initialCell.getChildText("x"); if (xText == null) throw new AttributeNotFoundException("x"); String yText = initialCell.getChildText("y"); if (yText == null) throw new AttributeNotFoundException("y"); String zText = initialCell.getChildText("z"); if (zText == null) throw new AttributeNotFoundException("z"); String stateText = initialCell.getChildText("state"); if (stateText == null) throw new AttributeNotFoundException("state"); Element colorElement = initialCell.getChild("color"); if (colorElement == null) throw new AttributeNotFoundException("color"); String rText = colorElement.getChildText("r"); if (rText == null) throw new AttributeNotFoundException("r"); String gText = colorElement.getChildText("g"); if (gText == null) throw new AttributeNotFoundException("g"); String bText = colorElement.getChildText("b"); if (bText == null) throw new AttributeNotFoundException("b"); int x = Integer.parseInt(xText); int y = Integer.parseInt(yText); int z = Integer.parseInt(zText); int state = Integer.parseInt(stateText); Color color = new Color(Integer.parseInt(rText), Integer.parseInt(gText), Integer.parseInt(bText)); this.initialCell = new Cell(x, y, z, state, color); } Element tagRules = root.getChild("rules"); rules = new ArrayList<Rule>(); if (tagRules != null) { List<Element> elementRules = tagRules.getChildren("rule"); if (elementRules.size() > 0) { for (Element rule : elementRules) { String neighbourhood = rule.getChildText("neighbourhood"); if (neighbourhood == null) throw new AttributeNotFoundException("neighbourhood"); String stateText = rule.getChildText("state"); if (stateText == null) throw new AttributeNotFoundException("state"); Element colorElement = rule.getChild("color"); if (colorElement == null) throw new AttributeNotFoundException("color"); String rText = colorElement.getChildText("r"); if (rText == null) throw new AttributeNotFoundException("r"); String gText = colorElement.getChildText("g"); if (gText == null) throw new AttributeNotFoundException("g"); String bText = colorElement.getChildText("b"); if (bText == null) throw new AttributeNotFoundException("b"); int state = Integer.parseInt(stateText); Color color = new Color(Integer.parseInt(rText), Integer.parseInt(gText), Integer.parseInt(bText)); rules.add(new Rule(neighbourhood, state, color)); } } } }
From source file:arquivo.Arquivo.java
protected List buscaInterna(Element root, boolean completa, String nome, String nomeE) { List<Element> retorna = new LinkedList<>(); List<Element> empregados = root.getChildren(nomeE); for (Element empregado : empregados) { if (completa) { if (empregado.getAttributeValue("nome").equals(nome)) retorna.add(empregado);/*ww w . ja va 2s. c om*/ } else { if (empregado.getAttributeValue("nome").contains(nome)) retorna.add(empregado); } } return retorna; }
From source file:arquivo.ArquivoFilme.java
public boolean confirnaSesao(int numeroSala, int horaI, int mimI, int horaF, int mimF) { SAXBuilder builder = new SAXBuilder(); try {/*from ww w . j a va 2 s . c o m*/ Document doc = builder.build(arquivo); Element root = (Element) doc.getRootElement(); List<Element> filme = root.getChildren("filme"); for (int i = 0; i < filme.size(); i++) { List<Element> salas = filme.get(i).getChildren("sala"); for (int j = 0; j < salas.size(); j++) { if (salas.get(j).getAttribute("numeroSala").equals("" + numeroSala)) { List<Element> secoes = salas.get(j).getChildren("secao"); for (int d = 0; d < secoes.size(); d++) { int horaEF = Integer.parseInt(secoes.get(d).getAttributeValue("horaF")); int mimEF = Integer.parseInt(secoes.get(d).getAttributeValue("mimF")); if (horaI >= horaEF && mimI > mimEF + 15) { return true; } int horaIF = Integer.parseInt(secoes.get(d).getAttributeValue("horaI")); int mimIF = Integer.parseInt(secoes.get(d).getAttributeValue("mimI")); if (horaF <= horaIF && mimF < mimIF + 15) { return true; } } } } } } catch (Exception e) { } return false; }
From source file:arquivo.ArquivoFilme.java
public List buscaSesao(Element filme, int numeroSala, int horaI, int mimI) { List<Element> buscado = new LinkedList<>(); List<Element> salas = filme.getChildren("sala"); for (int i = 0; i < salas.size(); i++) { if (salas.get(i).getAttribute("numeroSala").equals("" + numeroSala)) { List<Element> secoes = salas.get(i).getChildren("secao"); for (int j = 0; j < secoes.size(); j++) { if (secoes.get(j).getAttributeValue("horaI").equals("" + horaI) && secoes.get(j).getAttributeValue("mimI").equals("" + mimI)) { buscado.add(secoes.get(j)); }/*from ww w . j a v a 2 s . c o m*/ } } } return buscado; }
From source file:at.newmedialab.lmf.search.services.cores.SolrCoreServiceImpl.java
License:Apache License
/** * Create/update the solrconfig.xml file for the given core according to the core configuration. * * @param engine the solr core configuration *///w w w. jav a 2s .co m private void createSolrConfigXml(SolrCoreConfiguration engine) throws MarmottaException { File configTemplate = new File(getCoreDirectory(engine.getName()), "conf" + File.separator + "solrconfig-template.xml"); File configFile = new File(getCoreDirectory(engine.getName()), "conf" + File.separator + "solrconfig.xml"); try { SAXBuilder parser = new SAXBuilder(XMLReaders.NONVALIDATING); Document solrConfig = parser.build(configTemplate); FileOutputStream out = new FileOutputStream(configFile); // Configure suggestion service: add fields to suggestion handler Program<Value> program = engine.getProgram(); for (Element handler : solrConfig.getRootElement().getChildren("requestHandler")) { if (handler.getAttribute("class").getValue().equals(SuggestionRequestHandler.class.getName())) { for (Element lst : handler.getChildren("lst")) { if (lst.getAttribute("name").getValue().equals("defaults")) { //set suggestion fields for (FieldMapping<?, Value> fieldMapping : program.getFields()) { String fieldName = fieldMapping.getFieldName(); final Map<String, String> fieldConfig = fieldMapping.getFieldConfig(); if (fieldConfig != null && fieldConfig.keySet().contains(SOLR_SUGGESTION_FIELD_OPTION)) { String suggestionType = fieldConfig.get(SOLR_SUGGESTION_FIELD_OPTION); if (suggestionType.equals("facet")) { Element field_elem = new Element("str"); field_elem.setAttribute("name", SuggestionRequestParams.SUGGESTION_FIELD); field_elem.setText(fieldName); lst.addContent(field_elem); } else { log.error("suggestionType " + suggestionType + " not supported"); } } } } } } } XMLOutputter xo = new XMLOutputter(Format.getPrettyFormat().setIndent(" ")); xo.output(solrConfig, out); out.close(); } catch (JDOMException e) { throw new MarmottaException("parse error while parsing SOLR schema template file " + configTemplate, e); } catch (IOException e) { throw new MarmottaException("I/O error while parsing SOLR schema template file " + configTemplate, e); } }
From source file:BL.Servlets.AddNode.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from ww w . ja v a 2 s .c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet AddUser</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet AddUser at " + request.getContextPath() + "</h1>"); String NodeType = "residentialProperties"; Boolean isFound = false; try { String note_id = keyin("Please Enter note id you need to search: "); SAXBuilder saxBuilder = new SAXBuilder(); String xmlFile = "src\\database.xml"; Document xmlDoc = saxBuilder.build(new File(xmlFile)); Element rootElement = xmlDoc.getRootElement(); // List<Element> ListNodeType = rootElement.getChildren(NodeType); // List<Element> lstNotes = rootElement.getChildren(); for (int i = 0; i < lstNotes.size(); i++) { Element note = (Element) lstNotes.get(i); String n_id = note.getAttributeValue("id"); System.out.println("Note id: " + n_id); if (note_id.equalsIgnoreCase(n_id)) { isFound = true; String name = note.getChildText("name"); String value = note.getAttributeValue("value"); System.out.println( "We found a note with id " + note_id + "; name: " + name + "Value: " + value); break; } } if (!isFound) { System.out.println("Sorry, we don't find out any note with id: " + note_id); } System.out.println("Finished search!"); } catch (Exception e) { // TODO: handle exception } out.println("</body>"); out.println("</html>"); } finally { out.close(); } }
From source file:br.com.sicoob.cro.cop.util.JobXMLLoader.java
/** * Le o XML e cria o objeto de Step.//from w w w. ja v a2 s . co m * * @param rootNode Nodo princiapl * @throws Exception para algum erro. */ private void loadSteps(Element rootNode) throws Exception { List steps = rootNode.getChildren(STEP); List<Step> jobSteps = new ArrayList(); for (Object obj : steps) { Element stepNode = (Element) obj; StepParameters stepParameters = parseParameters(); Element taskletNode = stepNode.getChild(TASKLET); Element chunkNode = stepNode.getChild(CHUNK); if (Validation.notNull(taskletNode)) { Step step = new Step(getTasklet(taskletNode), Step.Type.TASKLET, stepParameters); step.setId(stepNode.getAttributeValue(ID)); getListener(stepNode, step); jobSteps.add(step); } else if (Validation.notNull(chunkNode)) { Step step = new Step(getReader(chunkNode), getProcessor(chunkNode), getWriter(chunkNode), Step.Type.CHUNK, stepParameters, getCommitInterval(chunkNode)); step.setId(stepNode.getAttributeValue(ID)); getListener(stepNode, step); jobSteps.add(step); } } this.job.setSteps(jobSteps); }