List of usage examples for org.jdom2 Namespace getNamespace
public static Namespace getNamespace(final String prefix, final String uri)
Namespace
for the supplied prefix and uri. From source file:com.thoughtworks.go.plugins.GoPluginManifest.java
License:Apache License
public Namespace getPluginNamespace() { return Namespace.getNamespace(getPluginNamespacePrefix(), getPluginNamespaceUri()); }
From source file:com.thoughtworks.go.util.ConfigUtil.java
License:Apache License
private Element child(Element e, ConfigTag tag) { return e.getChild(tag.value(), Namespace.getNamespace(tag.namespacePrefix(), tag.namespaceURI())); }
From source file:Contabilidad.CodeBase64.java
public void limpia(String ruta) { try {/*from w w w .ja v a 2 s . co m*/ org.jdom2.Document doc = new SAXBuilder().build(ruta); Element rootNode = doc.getRootElement(); List list = rootNode.getContent(); for (int i = 0; i < list.size(); i++) { Content elementos = (Content) list.get(i); if (elementos.getCType() == Content.CType.Element) { Element aux = (Element) elementos; if (aux.getName().compareToIgnoreCase("Addenda") == 0) { List list2 = aux.getContent(); for (int j = 0; j < list2.size(); j++) { Content elementos2 = (Content) list2.get(j); if (elementos2.getCType() == Content.CType.Element) { Element aux2 = (Element) elementos2; if (aux2.getName().compareToIgnoreCase("FactDocMX") == 0) { list2.remove(aux2); } if (aux2.getName().compareToIgnoreCase("ECFD") == 0) { Namespace NP = Namespace.getNamespace("", ""); aux2.setNamespace(NP); List list3 = aux2.getContent(); for (int k = 0; k < list3.size(); k++) { Content elementos3 = (Content) list3.get(k); if (elementos3.getCType() == Content.CType.Element) { Element aux3 = (Element) elementos3; aux3.setNamespace(NP); List list4 = aux3.getContent(); for (int l = 0; l < list4.size(); l++) { Content elementos4 = (Content) list4.get(l); if (elementos4.getCType() == Content.CType.Element) { Element aux4 = (Element) elementos4; aux4.setNamespace(NP); List list5 = aux4.getContent(); for (int m = 0; m < list5.size(); m++) { Content elementos5 = (Content) list5.get(m); if (elementos5.getCType() == Content.CType.Element) { Element aux5 = (Element) elementos5; aux5.setNamespace(NP); List list6 = aux5.getContent(); for (int n = 0; n < list6.size(); n++) { Content elementos6 = (Content) list6.get(n); if (elementos6 .getCType() == Content.CType.Element) { Element aux6 = (Element) elementos6; aux6.setNamespace(NP); List list7 = aux6.getContent(); for (int p = 0; p < list7.size(); p++) { Content elementos7 = (Content) list7.get(p); if (elementos7 .getCType() == Content.CType.Element) { Element aux7 = (Element) elementos7; aux7.setNamespace(NP); List list8 = aux7.getContent(); for (int q = 0; q < list8.size(); q++) { Content elementos8 = (Content) list8 .get(q); if (elementos8 .getCType() == Content.CType.Element) { Element aux8 = (Element) elementos8; aux8.setNamespace(NP); } } } } } } } } } } } } List atributos = aux2.getAttributes(); for (int a = 0; a < atributos.size(); a++) { Attribute at = (Attribute) atributos.get(a); if (at.getName().compareToIgnoreCase("schemaLocation") == 0) aux2.removeAttribute(at); } } } } } } } XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); try { outputter.output(doc, new FileOutputStream(ruta)); } catch (IOException e) { System.out.println(e); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Contabilidad.javaToXML.java
public void generaRaiz(TFactDocMX datos) { root = new Element("FactDocMX", PREFIX, PREFIX_URI); Namespace namespace = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); root.setAttribute("schemaLocation", COMPROBANTE_SCHEMA_XSD, namespace); root.addNamespaceDeclaration(namespace); root.addContent(new Element("Version", PREFIX, PREFIX_URI).setText(datos.getVersion().toString())); generaIdentificacion(datos.getIdentificacion()); generarCancelaciones(datos.getCancelaciones()); //Asignacion (Solo para algunas implementaciones in-house con cfdv2.) generarOrigen(datos.getOrigen());/* w w w.ja v a 2 s . c om*/ //generarProcesamiento(datos.getProcesamiento()); generarEmisor(datos.getEmisor()); generarReceptor(datos.getReceptor()); generarConceptos(datos.getConceptos()); generarTotales(datos.getTotales()); //Complementos //Divisas //Donatarias //Leyendas LeyendasFiscales //Nomina //PagoEnEspecie //Aerolineas //ValesDeDespensa //ConsumoDeCombustibles //EstadoDeCuentaCombustible //NotariosPublicos //VehiculoUsado generaComprobanteEx(datos.getComprobanteEx()); getXml().setRootElement(root); }
From source file:cz.pecina.retro.memory.Snapshot.java
License:Open Source License
/** * Writes a hardware shapshot to a file. * * @param file output file//w ww .j av a 2s .c om */ public void write(final File file) { log.fine("Writing snapshot to a file, file: " + file.getName()); final Element snapshot = new Element("snapshot"); final Namespace namespace = Namespace.getNamespace("xsi", XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI); snapshot.addNamespaceDeclaration(namespace); snapshot.setAttribute("noNamespaceSchemaLocation", Application.XSD_PREFIX + "snapshot-" + SNAPSHOT_XML_FILE_VERSION + ".xsd", namespace); snapshot.setAttribute("version", SNAPSHOT_XML_FILE_VERSION); hardware.marshal(snapshot); final Document doc = new Document(snapshot); try (final PrintWriter writer = new PrintWriter(file)) { new XMLOutputter(Format.getPrettyFormat()).output(doc, writer); } catch (final Exception exception) { log.fine("Error, writing failed, exception: " + exception.getMessage()); throw Application.createError(this, "XMLWrite"); } log.fine("Writing completed"); }
From source file:cz.pecina.retro.memory.XML.java
License:Open Source License
/** * Writes a memory range to a file, with wrap-around. * * @param file output file * @param startAddress starting address * @param number number of bytes * @param destinationAddress destination address */// w w w . j a v a 2s.c om public void write(final File file, final int startAddress, final int number, final int destinationAddress) { log.fine( String.format("Writing XML data to a file, file: %s, start address: %04x," + " number of bytes: %d", file.getName(), startAddress, number)); final Element tag = new Element("memory"); Snapshot.buildBlockElement(sourceMemory, tag, startAddress, number); final Namespace namespace = Namespace.getNamespace("xsi", XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI); tag.addNamespaceDeclaration(namespace); tag.setAttribute("noNamespaceSchemaLocation", Application.XSD_PREFIX + "memory-" + MEMORY_XML_FILE_VERSION + ".xsd", namespace); tag.setAttribute("version", MEMORY_XML_FILE_VERSION); tag.setAttribute("start", String.format("%04X", destinationAddress)); final Document doc = new Document(tag); try (final PrintWriter writer = new PrintWriter(file)) { new XMLOutputter(Format.getPrettyFormat()).output(doc, writer); } catch (final Exception exception) { log.fine("Error, writing failed, exception: " + exception.getMessage()); throw Application.createError(this, "XMLWrite"); } log.fine("Writing completed"); }
From source file:cz.pecina.retro.trec.XML.java
License:Open Source License
/** * Writes the tape to an XML file./*w w w .ja va 2 s . c o m*/ * * @param file output file */ public void write(final File file) { log.fine("Writing tape data to an XML file, file: " + file); final Element tag = new Element("tape"); final Namespace namespace = Namespace.getNamespace("xsi", XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI); tag.addNamespaceDeclaration(namespace); tag.setAttribute("noNamespaceSchemaLocation", Application.XSD_PREFIX + "tape-" + TAPE_XML_FILE_VERSION + ".xsd", namespace); tag.setAttribute("version", TAPE_XML_FILE_VERSION); tag.setAttribute("rate", String.valueOf(tapeRecorderInterface.tapeSampleRate)); tag.setAttribute("unit", "per sec"); try { long currPos = -1; for (long start : tape.navigableKeySet()) { final long duration = tape.get(start); log.finest(String.format("Fetched: (%d, %d)", start, duration)); if ((start > currPos) && (duration > 0)) { final Element pulse = new Element("pulse"); pulse.setAttribute("start", String.valueOf(start)); pulse.setAttribute("duration", String.valueOf(duration)); tag.addContent(pulse); log.finest(String.format("Write: (%d, %d)", start, duration)); currPos = start + duration; } } } catch (final Exception exception) { log.fine("Error, writing failed, exception: " + exception.getMessage()); throw Application.createError(this, "XMLWrite"); } final Document doc = new Document(tag); try (final PrintWriter writer = new PrintWriter(file)) { new XMLOutputter(Format.getPrettyFormat()).output(doc, writer); } catch (final Exception exception) { log.fine("Error, writing failed, exception: " + exception.getMessage()); throw Application.createError(this, "XMLWrite"); } log.fine("Writing completed"); }
From source file:de.dfki.iui.mmds.scxml.engine.impl.SCXMLEngineImpl.java
License:Apache License
private void propagateNamespace(Element element) { List children = element.getChildren(); for (Object o : children) { Element child = (Element) o; if (child.getName().equals("raise")) { child.setNamespace(Namespace.getNamespace("ca", "http://www.dfki.de/mmds/scxml/customaction")); } else {//from w w w . j a v a 2 s . c om child.setNamespace(element.getNamespace()); } propagateNamespace(child); } }
From source file:de.nava.informa.exporters.RSS_2_0_Exporter.java
License:Open Source License
public void write(ChannelIF channel) throws IOException { if (writer == null) { throw new RuntimeException("No writer has been initialized."); }// w ww.ja v a2s .c o m // create XML outputter with indent: 2 spaces, print new lines. Format format = Format.getPrettyFormat(); format.setEncoding(encoding); XMLOutputter outputter = new XMLOutputter(format); Namespace dcNs = Namespace.getNamespace("dc", NS_DC); Namespace syNs = Namespace.getNamespace("sy", NS_SY); Namespace adminNs = Namespace.getNamespace("admin", NS_ADMIN); //Namespace rdfNs = Namespace.getNamespace("rdf", NS_RDF); Element rootElem = new Element("rss"); rootElem.addNamespaceDeclaration(dcNs); rootElem.addNamespaceDeclaration(syNs); rootElem.addNamespaceDeclaration(adminNs); rootElem.setAttribute("version", RSS_VERSION); Element channelElem = new Element("channel"); // rootElem.setAttribute("version"); channelElem.addContent(new Element("title").setText(channel.getTitle())); if (channel.getSite() != null) { channelElem.addContent(new Element("link").setText(channel.getSite().toString())); } channelElem.addContent(new Element("description").setText(channel.getDescription())); if (channel.getLanguage() != null) { channelElem.addContent(new Element("language", dcNs).setText(channel.getLanguage())); } if (channel.getCopyright() != null) { channelElem.addContent(new Element("copyright", dcNs).setText(channel.getCopyright())); } if (channel.getPubDate() != null) { channelElem.addContent(new Element("pubDate").setText(ParserUtils.formatDate(channel.getPubDate()))); } if (channel.getCategories() != null) { Collection categories = channel.getCategories(); for (Object category : categories) { CategoryIF cat = (CategoryIF) category; channelElem = getCategoryElements(channelElem, cat, null); } } if (channel.getUpdateBase() != null) { channelElem.addContent(new Element("updateBase", syNs).setText(df.format(channel.getUpdateBase()))); } if (channel.getUpdatePeriod() != null) { // don't put out frequency without specifying period channelElem.addContent(new Element("updateFrequency", syNs) .setText((new Integer(channel.getUpdateFrequency())).toString())); channelElem.addContent(new Element("updatePeriod", syNs).setText(channel.getUpdatePeriod().toString())); } // export channel image if (channel.getImage() != null) { Element imgElem = new Element("image"); imgElem.addContent(new Element("title").setText(channel.getImage().getTitle())); imgElem.addContent(new Element("url").setText(channel.getImage().getLocation().toString())); imgElem.addContent(new Element("link").setText(channel.getImage().getLink().toString())); imgElem.addContent(new Element("height").setText("" + channel.getImage().getHeight())); imgElem.addContent(new Element("width").setText("" + channel.getImage().getWidth())); imgElem.addContent(new Element("description").setText(channel.getImage().getDescription())); channelElem.addContent(imgElem); } // TODO: add exporting textinput field // if (channel.getTextInput() != null) { // channelElem.addContent(channel.getTextInput().getElement()); // } Collection items = channel.getItems(); for (Object item : items) { channelElem.addContent(getItemElement((ItemIF) item)); } rootElem.addContent(channelElem); // --- Document doc = new Document(rootElem); outputter.output(doc, writer); // --- writer.close(); }
From source file:de.sixtyfourktec.mirrorhub.modules.NationalRailModule.java
License:Open Source License
private NationalRailModule() { /* Create the soap envelope document */ Document doc = new Document(); Namespace soap = Namespace.getNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/"); Namespace ldb = Namespace.getNamespace("ldb", "http://thalesgroup.com/RTTI/2014-02-20/ldb/"); Namespace typ = Namespace.getNamespace("typ", "http://thalesgroup.com/RTTI/2010-11-01/ldb/commontypes"); Element env = new Element("Envelope", soap); /* Header *///w w w .j ava 2 s. com env.addContent(new Element("Header", soap).addContent(new Element("AccessToken", typ) .addContent(new Element("TokenValue", typ).addContent(BuildConfig.NATIONALRAIL_API_KEY)))); /* Body */ Element dep_request = new Element("GetDepartureBoardRequest", ldb) .addContent(new Element("crs", ldb).addContent(BuildConfig.NATIONALRAIL_CRS)) .addContent(new Element("numRows", ldb).addContent("5")); if (!BuildConfig.NATIONALRAIL_FILTER_CRS.isEmpty()) { dep_request.addContent(new Element("filterCrs", ldb).addContent(BuildConfig.NATIONALRAIL_FILTER_CRS)) .addContent(new Element("filterType", ldb).addContent(BuildConfig.NATIONALRAIL_FILTER_TYPE)); } env.addContent(new Element("Body", soap).addContent(dep_request)); doc.setContent(env); String xml = new XMLOutputter(Format.getPrettyFormat()).outputString(doc); if (showXml) { Log.i(TAG, xml); } /* Create a static request object we can reuse */ RequestBody body = RequestBody.create(MediaType.parse("text/xml; charset=utf-8"), xml); request = new Request.Builder().url("https://lite.realtime.nationalrail.co.uk/OpenLDBWS/ldb6.asmx") .post(body).build(); }