List of usage examples for org.jdom2 Element setNamespace
public Element setNamespace(Namespace namespace)
From source file:com.ardor3d.extension.model.collada.jdom.ColladaDOMUtil.java
License:Open Source License
/** * Strips the namespace from all nodes in a tree. * // ww w . ja v a2s . com * @param rootElement * Root of strip operation */ public void stripNamespace(final Element rootElement) { rootElement.setNamespace(null); @SuppressWarnings("unchecked") final List<Element> children = rootElement.getChildren(); final Iterator<Element> i = children.iterator(); while (i.hasNext()) { final Element child = i.next(); stripNamespace(child); } }
From source file:com.cybernostics.jsp2thymeleaf.api.elements.CopyElementConverter.java
protected Optional<Element> createElement(JspElementContext node, JSPElementNodeConverter context) { final Element element = new Element(newNameForElement(node)); element.removeNamespaceDeclaration(element.getNamespace()); element.setNamespace(newNamespaceForElement(node)); return Optional.of(element); }
From source file:com.cybernostics.jsp2thymeleaf.JSP2Thymeleaf.java
private List<Content> rootContentFor(JspTree jspTree) { List<Content> contents = new ArrayList<>(); if (showBanner) { contents.add(new Comment("Created with JSP2Thymeleaf")); contents.add(new Text(NEWLINE)); }/*from ww w. j a va2 s.c om*/ contents.addAll(contentFor(jspTree, this)); final Optional<Content> foundHtmlElement = contents.stream().filter(JSP2Thymeleaf::isHtmlElement) .findFirst(); if (foundHtmlElement.isPresent()) { final Element htmlElement = (Element) foundHtmlElement.get(); contents.remove(htmlElement); trimTrailingWhitespace(contents); htmlElement.addContent(contents); htmlElement.setNamespace(xmlns); ActiveNamespaces.get().forEach(ns -> htmlElement.addNamespaceDeclaration(ns)); return Arrays.asList(new DocType("html", THYMELEAF_DTD), htmlElement); } else { Element thFragment = createFragmentDef(contents); return Arrays.asList(new DocType("html", THYMELEAF_DTD), thFragment); } }
From source file:com.globalsight.dispatcher.bo.JobTask.java
License:Apache License
private void setNamespace(Element p_element, Namespace p_namespace) { p_element.setNamespace(p_namespace); for (Element child : p_element.getChildren()) { setNamespace(child, p_namespace); }/*from ww w. j a va 2 s . c o m*/ }
From source file:com.init.octo.schema.XSDSchema.java
License:Open Source License
public Document getDocument() { if (targetNamespace != null) { Element e = buildDocument.getRootElement(); Namespace ns = Namespace.getNamespace("tns", targetNamespace); e.setNamespace(ns); buildDocument.setBaseURI(targetNamespace); }//from w ww. ja va2 s .c om return (buildDocument); }
From source file:com.kixeye.kixmpp.KixmppWebSocketCodec.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception { WebSocketFrame frame = null;/*ww w . j a v a 2s .c o m*/ if (msg instanceof Element) { Element element = (Element) msg; if (element.getNamespace() == null || element.getNamespace() == Namespace.NO_NAMESPACE) { if ("stream".equals(element.getNamespacePrefix())) { element.setNamespace(Namespace.getNamespace("http://etherx.jabber.org/streams")); } else { element.setNamespace(Namespace.getNamespace("jabber:client")); IteratorIterable<Content> descendants = element.getDescendants(); while (descendants.hasNext()) { Content content = descendants.next(); if (content instanceof Element) { Element descendantElement = (Element) content; if (descendantElement.getNamespace() == null || descendantElement.getNamespace() == Namespace.NO_NAMESPACE) { descendantElement.setNamespace(element.getNamespace()); } } } } } ByteBuf binaryData = ctx.alloc().buffer(); new XMLOutputter().output((Element) msg, new ByteBufOutputStream(binaryData)); frame = new TextWebSocketFrame(binaryData); } else if (msg instanceof KixmppStreamStart) { KixmppStreamStart streamStart = (KixmppStreamStart) msg; StringWriter writer = new StringWriter(); if (streamStart.doesIncludeXmlHeader()) { writer.append("<?xml version='1.0' encoding='UTF-8'?>"); } writer.append("<stream:stream "); if (streamStart.getId() != null) { writer.append(String.format("id=\"%s\" ", streamStart.getId())); } if (streamStart.getFrom() != null) { writer.append(String.format("from=\"%s\" ", streamStart.getFrom().getFullJid())); } if (streamStart.getTo() != null) { writer.append(String.format("to=\"%s\" ", streamStart.getTo())); } writer.append( "version=\"1.0\" xmlns=\"jabber:client\" xmlns:stream=\"http://etherx.jabber.org/streams\">"); frame = new TextWebSocketFrame(writer.toString()); } else if (msg instanceof KixmppStreamEnd) { frame = new TextWebSocketFrame("</stream:stream>"); } else if (msg instanceof String) { frame = new TextWebSocketFrame((String) msg); } else if (msg instanceof ByteBuf) { frame = new TextWebSocketFrame((ByteBuf) msg); } if (frame != null) { if (logger.isDebugEnabled()) { logger.debug("Sending: [{}]", frame.content().toString(StandardCharsets.UTF_8)); } out.add(frame); } }
From source file:com.rometools.rome.io.impl.Atom03Parser.java
License:Open Source License
private Content parseContent(final Element e) { String value = null;// w w w. j a v a2s . c o m String type = getAttributeValue(e, "type"); if (type == null) { type = "text/plain"; } String mode = getAttributeValue(e, "mode"); if (mode == null) { mode = Content.XML; // default to xml content } if (mode.equals(Content.ESCAPED)) { // do nothing XML Parser took care of this value = e.getText(); } else if (mode.equals(Content.BASE64)) { value = Base64.decode(e.getText()); } else if (mode.equals(Content.XML)) { final XMLOutputter outputter = new XMLOutputter(); final List<org.jdom2.Content> contents = e.getContent(); for (final org.jdom2.Content content : contents) { if (content instanceof Element) { final Element element = (Element) content; if (element.getNamespace().equals(getAtomNamespace())) { element.setNamespace(Namespace.NO_NAMESPACE); } } } value = outputter.outputString(contents); } final Content content = new Content(); content.setType(type); content.setMode(mode); content.setValue(value); return content; }
From source file:com.rometools.rome.io.impl.Atom10Parser.java
License:Open Source License
private String parseTextConstructToString(final Element e) { String type = getAttributeValue(e, "type"); if (type == null) { type = Content.TEXT;// w w w . j a v a2 s . c o m } String value = null; if (type.equals(Content.XHTML) || type.indexOf("/xml") != -1 || type.indexOf("+xml") != -1) { // XHTML content needs special handling final XMLOutputter outputter = new XMLOutputter(); final List<org.jdom2.Content> contents = e.getContent(); for (final org.jdom2.Content content : contents) { if (content instanceof Element) { final Element element = (Element) content; if (element.getNamespace().equals(getAtomNamespace())) { element.setNamespace(Namespace.NO_NAMESPACE); } } } value = outputter.outputString(contents); } else { // Everything else comes in verbatim value = e.getText(); } return value; }
From source file:Contabilidad.CodeBase64.java
public void limpia(String ruta) { try {/*from www . j a v a2 s. c o 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: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 {/* w w w.j a va 2 s. c om*/ child.setNamespace(element.getNamespace()); } propagateNamespace(child); } }