List of usage examples for org.jdom2 Element getName
public String getName()
From source file:mom.trd.opentheso.core.exports.privatesdatas.importxml.importxml.java
/** * cette funtion permet de ouvrir un fichier pour comence a faire une * injection de donnes. //from w ww. j a va 2 s . com * C'est seulement pour la creation de un nouvelle BDD. * la funtion generique est plus ba * @param con * @param archive * @throws ClassNotFoundException * @throws SQLException */ public void ouvreFichier(Connection con, File archive) throws ClassNotFoundException, SQLException { LanguageBean langueBean = new LanguageBean(); SAXBuilder builder = new SAXBuilder(); ArrayList<Table> toutTables = new ArrayList<>(); ArrayList<LineOfData> lineOfDatas = new ArrayList<>(); try { //on cre le document a partir du fichier que on a selection Document document = (Document) builder.build(archive); //Se obtiene la raiz 'tables' Element rootNode = document.getRootElement(); // ici on a toutes les tables (les enfants de la racine) List list = rootNode.getChildren("table"); // ici on fait le tour pour les enfants de 'tables' for (int i = 0; i < list.size(); i++) { // ici on a la premire table Element tabla = (Element) list.get(i); //ici on a le nom de la table String nombreTabla = tabla.getAttributeValue("nom"); // ici c'est la liste des lignes de la table List lista_campos = tabla.getChildren(); //ici on dcoupe la liste des lignes for (int j = 0; j < lista_campos.size(); j++) { //ici on a une ligne de la table Element campo = (Element) lista_campos.get(j); for (Element colonne : campo.getChildren()) { LineOfData lineOfData = new LineOfData(); lineOfData.setColomne(colonne.getName());// le nom de la colone lineOfData.setValue(colonne.getText());// le value que le correspond lineOfDatas.add(lineOfData); } insertLine(con, lineOfDatas, nombreTabla); lineOfDatas.clear(); } /// mettre jour la table dans la BDD } } catch (IOException | JDOMException io) { System.out.println("error"); } //FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("impBDD.info1"))); }
From source file:mom.trd.opentheso.core.exports.privatesdatas.importxml.importxml.java
/** * cette funtion permet de ouvrir un fichier pour comence a faire une * injection de donnes. /*from w w w . j av a 2 s . c om*/ * Cette funtion c'est la generique * @param ds * @param archive * @throws ClassNotFoundException * @throws SQLException */ public void ouvreFichier2(HikariDataSource ds, File archive) throws ClassNotFoundException, SQLException { LanguageBean langueBean = new LanguageBean(); SAXBuilder builder = new SAXBuilder(); ArrayList<Table> toutTables = new ArrayList<>(); ArrayList<LineOfData> lineOfDatas = new ArrayList<>(); try { //on cre le document a partir du fichier que on a selection Document document = (Document) builder.build(archive); //Se obtiene la raiz 'tables' Element rootNode = document.getRootElement(); // ici on a toutes les tables (les enfants de la racine) List list = rootNode.getChildren("table"); // ici on fait le tour pour les enfants de 'tables' for (int i = 0; i < list.size(); i++) { // ici on a la premire table Element tabla = (Element) list.get(i); //ici on a le nom de la table String nombreTabla = tabla.getAttributeValue("nom"); // ici c'est la liste des lignes de la table List lista_campos = tabla.getChildren(); //ici on dcoupe la liste des lignes for (int j = 0; j < lista_campos.size(); j++) { //ici on a une ligne de la table Element campo = (Element) lista_campos.get(j); for (Element colonne : campo.getChildren()) { LineOfData lineOfData = new LineOfData(); lineOfData.setColomne(colonne.getName()); lineOfData.setValue(colonne.getText()); lineOfDatas.add(lineOfData); } insertLine2(ds, lineOfDatas, nombreTabla); lineOfDatas.clear(); } /// mettre jour la table dans la BDD } } catch (IOException | JDOMException io) { System.out.println(io.toString()); } //FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("impBDD.info1"))); }
From source file:msi.gama.doc.util.UnifyDoc.java
License:Open Source License
private static Document mergeFiles(final HashMap<String, File> hmFilesPackages) { try {// w w w . j a v a 2s . com SAXBuilder builder = new SAXBuilder(); Document doc = null; doc = new Document(new Element(XMLElements.DOC)); for (String elt : tabEltXML) { doc.getRootElement().addContent(new Element(elt)); } for (Entry<String, File> fileDoc : hmFilesPackages.entrySet()) { Document docTemp = builder.build(fileDoc.getValue()); for (String catXML : tabEltXML) { if (docTemp.getRootElement().getChild(catXML) != null) { List<Element> existingElt = doc.getRootElement().getChild(catXML).getChildren(); for (Element e : docTemp.getRootElement().getChild(catXML).getChildren()) { // Do not add the projectName for every kinds of // categories // if (!Arrays.asList(tabCategoriesEltXML).contains(catXML)) { e.setAttribute("projectName", fileDoc.getKey()); // } // Test whether the element is already in the merged // doc boolean found = false; for (Element exElt : existingElt) { boolean equals = exElt.getName().equals(e.getName()); for (Attribute att : exElt.getAttributes()) { String valueExElt = exElt.getAttribute(att.getName()) != null ? exElt.getAttributeValue(att.getName()) : ""; String valueE = e.getAttribute(att.getName()) != null ? e.getAttributeValue(att.getName()) : ""; equals = equals && valueExElt.equals(valueE); } found = found || equals; } // Add if it is not already in the merged doc if (!found) { doc.getRootElement().getChild(catXML).addContent(e.clone()); } } } } } // Add an element for the generated types doc.getRootElement().getChild(XMLElements.OPERATORS_CATEGORIES) .addContent(new Element(XMLElements.CATEGORY).setAttribute(XMLElements.ATT_CAT_ID, new TypeConverter().getProperCategory("Types"))); return doc; } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:mymeteocal.boundary.ImportBean.java
/** * Given an XML document, updates the calendar with * the events in the document/*from w ww . j a va 2 s . com*/ * @param doc */ private void updateCalendarFromXML(Document doc) { // Element Calendar should be the root. Element root = doc.getRootElement(); if (!root.getName().equals("Calendar")) { throw new IllegalArgumentException("XML file not valid: " + "root element differs from Calendar."); } Element events = root.getChild("Events"); List eventsList = events.getChildren("Event"); for (Object event : eventsList) { try { createEventFromXML((Element) event); } catch (IllegalArgumentException ex) { FacesMessage message = new FacesMessage("WARNING! " + ex.getMessage()); FacesContext.getCurrentInstance().addMessage(null, message); } } }
From source file:neon.common.resources.loaders.ItemLoader.java
License:Open Source License
@Override public RItem load(String id) throws IOException { Element root = files.loadFile(translator, namespace, id + ".xml").getRootElement(); String name = root.getAttributeValue("name"); char glyph = root.getChild("graphics").getAttributeValue("char").charAt(0); Color color = Color.web(root.getChild("graphics").getAttributeValue("color")); RItem.Builder builder = new RItem.Builder(id, name).setGraphics(glyph, color); if (root.getAttribute("price") != null) { builder.setPrice(Integer.parseInt(root.getAttributeValue("price"))); }// ww w . j a va2s . c o m if (root.getAttribute("weight") != null) { builder.setWeight(Integer.parseInt(root.getAttributeValue("weight"))); } Element magic = root.getChild("magic"); if (magic != null) { Effect effect = Effect.valueOf(magic.getAttributeValue("effect").toUpperCase()); int magnitude = Integer.parseInt(magic.getAttributeValue("magnitude")); builder.setMagic(effect, magnitude); } switch (root.getName()) { case "armor": return createArmor(root, builder); case "clothing": return createClothing(root, builder); case "weapon": return createWeapon(root, builder); case "coin": return new RItem.Coin(builder); case "container": return new RItem.Container(builder); case "potion": return new RItem.Potion(builder); default: return builder.build(); } }
From source file:neon.editor.DataStore.java
License:Open Source License
private void loadMagic(RMod mod, String... path) { try {// w w w. j a v a 2 s .c o m Document doc = Editor.files.getFile(new XMLTranslator(), path); for (Element e : doc.getRootElement().getChildren()) { switch (e.getName()) { case "sign": Editor.resources.addResource(new RSign(e, mod.get("id")), "magic"); break; case "tattoo": Editor.resources.addResource(new RTattoo(e, mod.get("id")), "magic"); break; case "recipe": Editor.resources.addResource(new RRecipe(e, mod.get("id")), "magic"); break; case "list": Editor.resources.addResource(new LSpell(e, mod.get("id")), "magic"); break; case "power": Editor.resources.addResource(new RSpell.Power(e, mod.get("id")), "magic"); break; case "enchant": Editor.resources.addResource(new RSpell.Enchantment(e, mod.get("id")), "magic"); break; default: Editor.resources.addResource(new RSpell(e, mod.get("id")), "magic"); break; } } } catch (NullPointerException e) { } }
From source file:neon.editor.DataStore.java
License:Open Source License
private void loadCreatures(RMod mod, String... path) { try {//from ww w .j a v a2 s . c o m Document doc = Editor.files.getFile(new XMLTranslator(), path); for (Element e : doc.getRootElement().getChildren()) { switch (e.getName()) { case "list": Editor.resources.addResource(new LCreature(e, mod.get("id"))); break; case "npc": Editor.resources.addResource(new RPerson(e, mod.get("id"))); break; case "group": break; default: Editor.resources.addResource(new RCreature(e, mod.get("id"))); break; } } } catch (NullPointerException e) { e.printStackTrace(); } }
From source file:neon.editor.DataStore.java
License:Open Source License
private void loadItems(RMod mod, String... path) { try {// www . j a va 2 s. c o m Document doc = Editor.files.getFile(new XMLTranslator(), path); for (Element e : doc.getRootElement().getChildren()) { switch (e.getName()) { case "list": Editor.resources.addResource(new LItem(e, mod.get("id"))); break; case "book": case "scroll": Editor.resources.addResource(new RItem.Text(e, mod.get("id"))); break; case "armor": case "clothing": Editor.resources.addResource(new RClothing(e, mod.get("id"))); break; case "weapon": Editor.resources.addResource(new RWeapon(e, mod.get("id"))); break; case "craft": Editor.resources.addResource(new RCraft(e, mod.get("id"))); break; case "door": Editor.resources.addResource(new RItem.Door(e, mod.get("id"))); break; case "potion": Editor.resources.addResource(new RItem.Potion(e, mod.get("id"))); break; case "container": Editor.resources.addResource(new RItem.Container(e, mod.get("id"))); break; default: Editor.resources.addResource(new RItem(e, mod.get("id"))); break; } } } catch (NullPointerException e) { } }
From source file:neon.editor.DataStore.java
License:Open Source License
private void loadThemes(RMod mod, String... path) { try {/*from w ww . j a v a 2 s . c om*/ Document doc = Editor.files.getFile(new XMLTranslator(), path); for (Element e : doc.getRootElement().getChildren()) { switch (e.getName()) { case "dungeon": Editor.resources.addResource(new RDungeonTheme(e, mod.get("id")), "theme"); break; case "region": Editor.resources.addResource(new RRegionTheme(e, mod.get("id")), "theme"); break; case "zone": Editor.resources.addResource(new RZoneTheme(e, mod.get("id")), "theme"); break; } } } catch (NullPointerException e) { } }
From source file:neon.editor.editors.QuestEditor.java
License:Open Source License
protected void load() { nameField.setText(quest.name);//from w w w.ja va 2 s.c o m initialBox.setSelected(quest.initial); randomBox.setSelected(quest.repeat); freqField.setEnabled(quest.repeat); if (quest.repeat) { freqField.setValue(quest.frequency); } else { freqField.setValue(null); } if (quest.variables != null) { for (Element item : quest.variables.getChildren()) { String[] data = { item.getText(), item.getName(), item.getAttributeValue("id"), item.getAttributeValue("type") }; varModel.insertRow(0, data); } } for (String condition : quest.getConditions()) { String[] row = { condition }; conditionModel.addRow(row); } // for(Topic topic : quest.getTopics()) { // String[] data = {topic.getID(), topic.getCondition(), // topic.getAnswer(), topic.getAction()}; // dialogModel.insertRow(0, data); // } }