List of usage examples for org.jdom2 Document Document
public Document(List<? extends Content> content)
Document
, with the supplied list of content, and a DocType
declaration only if the content contains a DocType instance. From source file:msi.gama.doc.util.UnifyDoc.java
License:Open Source License
private static Document mergeFiles(final HashMap<String, File> hmFilesPackages) { try {//from w w w. jav a2 s. c o m 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:negocio.Metodos.java
public Document inicializarDocumento() { Document doc = new Document(new Element("raiz")); Element totales = new Element("totales"); totales.addContent(new Element("enStock").setText("")); totales.addContent(new Element("vendidos").setText("")); totales.addContent(new Element("alquilados").setText("")); totales.addContent(new Element("TotalFacturado").setText("")); doc.getRootElement().addContent(totales); doc.getRootElement().addContent(new Element("franquicias")); return doc;// w ww . java 2 s. co m }
From source file:neon.common.resources.loaders.CreatureLoader.java
License:Open Source License
@Override public void save(Resource resource) throws IOException { RCreature rc = RCreature.class.cast(resource); Element creature = new Element("creature"); creature.setAttribute("id", rc.id); creature.setAttribute("name", rc.name); creature.setAttribute("speed", Integer.toString(rc.speed)); Element graphics = new Element("graphics"); graphics.setAttribute("char", Character.toString(rc.glyph)); graphics.setAttribute("color", GraphicsUtils.getColorString(rc.color)); creature.addContent(graphics);//from ww w . j av a 2 s. co m Element stats = new Element("stats"); stats.setAttribute("str", Integer.toString(rc.strength)); stats.setAttribute("con", Integer.toString(rc.constitution)); stats.setAttribute("dex", Integer.toString(rc.dexterity)); stats.setAttribute("int", Integer.toString(rc.intelligence)); stats.setAttribute("wis", Integer.toString(rc.wisdom)); stats.setAttribute("cha", Integer.toString(rc.charisma)); creature.addContent(stats); files.saveFile(new Document(creature), translator, namespace, resource.id + ".xml"); }
From source file:neon.common.resources.loaders.ItemLoader.java
License:Open Source License
@Override public void save(Resource resource) throws IOException { RItem ri = RItem.class.cast(resource); Element item = new Element("item"); item.setAttribute("id", ri.id); item.setAttribute("name", ri.name); files.saveFile(new Document(item), translator, namespace, resource.id + ".xml"); }
From source file:neon.common.resources.loaders.ModuleLoader.java
License:Open Source License
@Override public void save(Resource resource) throws IOException { RModule module = RModule.class.cast(resource); Element root = new Element("module"); root.setAttribute("id", module.id); Element title = new Element("title"); title.setText(module.title);//w ww. j ava 2 s.c o m root.addContent(title); Element start = new Element("start"); start.setAttribute("map", module.map); start.setAttribute("x", Integer.toString(module.x)); start.setAttribute("y", Integer.toString(module.y)); root.addContent(start); if (!module.intro.isEmpty()) { Element intro = new Element("intro"); intro.setText(module.intro); root.addContent("intro"); } Element playable = new Element("playable"); root.addContent(playable); for (String species : module.getPlayableSpecies()) { Element id = new Element("id"); id.setText(species); playable.addContent(id); } Element parents = new Element("parents"); root.addContent(parents); for (String parent : module.getParentModules()) { Element id = new Element("id"); id.setText(parent); parents.addContent(id); } files.saveFile(new Document(root), translator, resource.id + ".xml"); }
From source file:neon.common.resources.loaders.TerrainLoader.java
License:Open Source License
@Override public void save(Resource resource) throws IOException { RTerrain terrain = RTerrain.class.cast(resource); Element root = new Element("terrain"); root.setAttribute("id", terrain.id); root.setAttribute("name", terrain.name); Element graphics = new Element("graphics"); graphics.setAttribute("text", Character.toString(terrain.glyph)); graphics.setAttribute("color", GraphicsUtils.getColorString(terrain.color)); root.addContent(graphics);// w w w. j a va 2 s . c om for (Modifier modifier : terrain.getModifiers()) { Element mod = new Element("modifier"); mod.setText(modifier.toString()); root.addContent(mod); } files.saveFile(new Document(root), translator, namespace, resource.id + ".xml"); }
From source file:neon.editor.ModFiler.java
License:Open Source License
public void save() { XMLBuilder builder = new XMLBuilder(store); RMod active = store.getActive();// www .ja va2s.c o m saveFile(new Document(store.getActive().getMainElement()), "main.xml"); saveFile(new Document(store.getActive().getCCElement()), "cc.xml"); saveFile(builder.getResourceDoc(Editor.resources.getResources(RItem.class), "items", active), "objects", "items.xml"); saveFile(builder.getListDoc(Editor.resources.getResources(RFaction.class), "factions", active), "factions.xml"); saveFile(builder.getListDoc(Editor.resources.getResources(RRecipe.class), "recipes", active), "objects", "alchemy.xml"); saveFile(builder.getEventsDoc(), "events.xml"); saveFile(builder.getListDoc(Editor.resources.getResources(RPerson.class), "people", active), "objects", "npc.xml"); saveFile(builder.getResourceDoc(Editor.resources.getResources(RCreature.class), "monsters", active), "objects", "monsters.xml"); saveFile(builder.getResourceDoc(Editor.resources.getResources(RSpell.class), "spells", active), "spells.xml"); saveFile(builder.getListDoc(Editor.resources.getResources(RTerrain.class), "terrain", active), "terrain.xml"); saveFile(builder.getListDoc(Editor.resources.getResources(RCraft.class), "items", active), "objects", "crafting.xml"); saveFile(builder.getListDoc(Editor.resources.getResources(RSign.class), "signs", active), "signs.xml"); saveFile(builder.getListDoc(Editor.resources.getResources(RTattoo.class), "tattoos", active), "tattoos.xml"); saveFile(builder.getListDoc(Editor.resources.getResources(RZoneTheme.class), "themes", active), "themes", "zones.xml"); saveFile(builder.getListDoc(Editor.resources.getResources(RDungeonTheme.class), "themes", active), "themes", "dungeons.xml"); saveFile(builder.getListDoc(Editor.resources.getResources(RRegionTheme.class), "themes", active), "themes", "regions.xml"); saveMaps(); saveQuests(); saveScripts(); }
From source file:neon.editor.ModFiler.java
License:Open Source License
private void saveQuests() { for (String name : files.listFiles(store.getActive().getPath()[0], "quests")) { String quest = name.substring(name.lastIndexOf(File.separator) + 1, name.length() - 4); // -4 voor ".xml" if (Editor.resources.getResource(quest, "quest") == null) { files.delete(name);/* w w w. j a v a2 s . co m*/ } } for (RQuest quest : Editor.resources.getResources(RQuest.class)) { saveFile(new Document(quest.toElement()), "quests", quest.id + ".xml"); } }
From source file:neon.editor.resource.MapLoader.java
License:Open Source License
@Override public void save(Resource resource) throws IOException { RMap map = RMap.class.cast(resource); Element root = new Element("map"); root.setAttribute("id", map.id); root.setAttribute("name", map.name); root.setAttribute("uid", Short.toString(map.uid)); root.setAttribute("module", map.module); Element size = new Element("size"); size.setAttribute("width", Integer.toString(map.getWidth())); size.setAttribute("height", Integer.toString(map.getHeight())); root.addContent(size);/*from ww w.ja v a2 s .co m*/ Element terrain = new Element("terrain"); root.addContent(terrain); Map<Rectangle, String> leaves = map.getTerrain().getElements(); for (Entry<Rectangle, String> entry : leaves.entrySet()) { if (entry.getValue() != null) { Element region = new Element("region"); region.setAttribute("x", Integer.toString(entry.getKey().x)); region.setAttribute("y", Integer.toString(entry.getKey().y)); region.setAttribute("w", Integer.toString(entry.getKey().width)); region.setAttribute("h", Integer.toString(entry.getKey().height)); region.setAttribute("id", entry.getValue()); terrain.addContent(region); } } Element elevation = new Element("elevation"); root.addContent(elevation); Element entities = new Element("entities"); for (REntity entity : map.getEntities()) { System.out.println(entity); Element element = new Element(entity.getType()); element.setAttribute("uid", Long.toString(entity.uid)); element.setAttribute("id", entity.getID()); element.setAttribute("x", Integer.toString(entity.shape.getX())); element.setAttribute("y", Integer.toString(entity.shape.getY())); entities.addContent(element); } root.addContent(entities); files.saveFile(new Document(root), translator, namespace, resource.id + ".xml"); }
From source file:neon.editor.SVGExporter.java
License:Open Source License
public static void exportToSVG(ZoneTreeNode node, FileSystem files, DataStore store) { if (node != null) { Namespace ns = Namespace.getNamespace("http://www.w3.org/2000/svg"); Element svg = new Element("svg", ns); Document doc = new Document(svg); doc.setDocType(new DocType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd")); svg.setAttribute("width", "100%"); svg.setAttribute("height", "100%"); svg.setAttribute("version", "1.1"); ArrayList<Renderable> regions = new ArrayList<Renderable>(node.getZone().getScene().getElements()); Collections.sort(regions, new ZComparator()); for (Renderable i : regions) { if (i instanceof IRegion) { IRegion ri = (IRegion) i; Element region = new Element("rect", ns); region.setAttribute("x", Integer.toString(ri.x)); region.setAttribute("y", Integer.toString(ri.y)); region.setAttribute("width", Integer.toString(ri.width)); region.setAttribute("height", Integer.toString(ri.height)); int red = ColorFactory.getColor(ri.resource.color).getRed(); int green = ColorFactory.getColor(ri.resource.color).getGreen(); int blue = ColorFactory.getColor(ri.resource.color).getBlue(); region.setAttribute("style", "fill:rgb(" + red + "," + green + "," + blue + ")"); svg.addContent(region);// w ww .ja va 2 s . co m } } files.saveFile(doc, new XMLTranslator(), store.getActive().getPath()[0], "shots", node.getZone().map.id + ".svg"); } }