List of usage examples for org.dom4j Namespace get
public static Namespace get(String prefix, String uri)
From source file:com.cladonia.xml.XElement.java
License:Open Source License
/** * Constructs a default element with an initial type. * * @param name the unmutable name./*from w ww. jav a 2s.co m*/ */ public XElement(String name, String namespace, String prefix) { this(new QName(name, Namespace.get(prefix, namespace)), true); }
From source file:com.cladonia.xml.XElement.java
License:Open Source License
/** * Constructs a default element with an initial type. * * @param name the unmutable name./*from w w w . j a v a2s. c om*/ * @param name the unmutable namespace. * @param parsed the element has been parsed from text. */ public XElement(String name, String namespace, String prefix, boolean parsed) { this(new QName(name, Namespace.get(prefix, namespace)), parsed); }
From source file:org.apache.poi.openxml4j.opc.internal.ContentTypeManager.java
License:Apache License
/** * Save the contents type part./*w ww .j a v a 2 s . c o m*/ * * @param outStream * The output stream use to save the XML content of the content * types part. * @return <b>true</b> if the operation success, else <b>false</b>. */ public boolean save(OutputStream outStream) { Document xmlOutDoc = DocumentHelper.createDocument(); // Building namespace Namespace dfNs = Namespace.get("", TYPES_NAMESPACE_URI); Element typesElem = xmlOutDoc.addElement(new QName(TYPES_TAG_NAME, dfNs)); // Adding default types for (Entry<String, String> entry : defaultContentType.entrySet()) { appendDefaultType(typesElem, entry); } // Adding specific types if any exist if (overrideContentType != null) { for (Entry<PackagePartName, String> entry : overrideContentType.entrySet()) { appendSpecificTypes(typesElem, entry); } } xmlOutDoc.normalize(); // Save content in the specified output stream return this.saveImpl(xmlOutDoc, outStream); }
From source file:org.apache.poi.openxml4j.opc.internal.marshallers.ZipPartMarshaller.java
License:Apache License
/** * Save relationships into the part.// www .j a v a 2 s . com * * @param rels * The relationships collection to marshall. * @param relPartName * Part name of the relationship part to marshall. * @param zos * Zip output stream in which to save the XML content of the * relationships serialization. */ public static boolean marshallRelationshipPart(PackageRelationshipCollection rels, PackagePartName relPartName, ZipOutputStream zos) { // Building xml Document xmlOutDoc = DocumentHelper.createDocument(); // make something like <Relationships // xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> Namespace dfNs = Namespace.get("", PackageNamespaces.RELATIONSHIPS); Element root = xmlOutDoc.addElement(new QName(PackageRelationship.RELATIONSHIPS_TAG_NAME, dfNs)); // <Relationship // TargetMode="External" // Id="rIdx" // Target="http://www.custom.com/images/pic1.jpg" // Type="http://www.custom.com/external-resource"/> URI sourcePartURI = PackagingURIHelper.getSourcePartUriFromRelationshipPartUri(relPartName.getURI()); for (PackageRelationship rel : rels) { // the relationship element Element relElem = root.addElement(PackageRelationship.RELATIONSHIP_TAG_NAME); // the relationship ID relElem.addAttribute(PackageRelationship.ID_ATTRIBUTE_NAME, rel.getId()); // the relationship Type relElem.addAttribute(PackageRelationship.TYPE_ATTRIBUTE_NAME, rel.getRelationshipType()); // the relationship Target String targetValue; URI uri = rel.getTargetURI(); if (rel.getTargetMode() == TargetMode.EXTERNAL) { // Save the target as-is - we don't need to validate it, // alter it etc targetValue = uri.toString(); // add TargetMode attribute (as it is external link external) relElem.addAttribute(PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME, "External"); } else { URI targetURI = rel.getTargetURI(); targetValue = PackagingURIHelper.relativizeURI(sourcePartURI, targetURI, true).toString(); } relElem.addAttribute(PackageRelationship.TARGET_ATTRIBUTE_NAME, targetValue); } xmlOutDoc.normalize(); // String schemaFilename = Configuration.getPathForXmlSchema()+ // File.separator + "opc-relationships.xsd"; // Save part in zip ZipEntry ctEntry = new ZipEntry( ZipHelper.getZipURIFromOPCName(relPartName.getURI().toASCIIString()).getPath()); try { zos.putNextEntry(ctEntry); if (!StreamHelper.saveXmlInStream(xmlOutDoc, zos)) { return false; } zos.closeEntry(); } catch (IOException e) { logger.log(POILogger.ERROR, "Cannot create zip entry " + relPartName, e); return false; } return true; // success }
From source file:org.firesoa.common.jxpath.model.dom4j.Dom4JNodePointer.java
License:Open Source License
/** * ??nameattribute// w w w.j av a 2 s. co m */ public NodePointer createAttribute(JXPathContext context, QName name) { if (!(node instanceof Element)) { return super.createAttribute(context, name); } Element element = (Element) node; String prefix = name.getPrefix(); if (prefix != null) { String nsUri = null; NamespaceResolver nsr = getNamespaceResolver(); if (nsr != null) { nsUri = nsr.getNamespaceURI(prefix); } if (nsUri == null) { throw new JXPathException("Unknown namespace prefix: " + prefix); } Namespace dom4jNs = Namespace.get(prefix, nsUri); org.dom4j.QName attributeName = new org.dom4j.QName(name.getName(), dom4jNs); Attribute attr = element.attribute(attributeName); if (attr == null) { element.addAttribute(attributeName, ""); } } else { Attribute attr = element.attribute(name.getName()); if (attr == null) { element.addAttribute(name.getName(), ""); } } NodeIterator it = attributeIterator(name); it.setPosition(1); return it.getNodePointer(); }
From source file:org.makumba.devel.MDDRelationVisualiser.java
License:Open Source License
public static void main(String[] args) throws IOException { DataDefinitionProvider ddp = DataDefinitionProvider.getInstance(); Vector<String> mdds; if (args.length > 0) { mdds = ddp.getDataDefinitionsInAbsoluteLocation(args[0]); } else {/* w w w. jav a2 s .c o m*/ mdds = ddp.getDataDefinitionsInDefaultLocations(); } File tmp = new File("/tmp/graph.ml"); // File.createTempFile("graph_", ".ml"); Document d = DocumentHelper.createDocument(); Element graphml_tag = d.addElement("graphml"); Element root = graphml_tag.addElement("graph"); root.addAttribute("edgedefault", "directed"); Namespace ns = Namespace.get("", "http://graphml.graphdrawing.org/xmlns"); d.getRootElement().add(ns); Element incoming = root.addElement("key"); incoming.addAttribute("id", "name"); incoming.addAttribute("for", "node"); incoming.addAttribute("attr.name", "name"); incoming.addAttribute("attr.type", "string"); for (String mdd : mdds) { try { processMDD(root, ddp.getDataDefinition(mdd)); } catch (DataDefinitionParseError e) { System.out.println("Skipping broken MDD " + mdd); } } XMLWriter serializer = new XMLWriter(new FileWriter(tmp), new OutputFormat("", false)); serializer.write(d); serializer.close(); Graph graph = null; try { graph = new GraphMLReader().readGraph(tmp.getAbsoluteFile()); } catch (DataIOException e) { e.printStackTrace(); System.err.println("Error loading graph. Exiting..."); System.exit(1); } int minEdges = 3; for (int i = graph.getNodeCount() - 1; i >= 0; i--) { Node node = graph.getNode(i); System.out.println(node + ", " + node.getOutDegree()); if (node.getOutDegree() < minEdges) { graph.removeNode(node); } } // add the graph to the visualization as the data group "graph" // nodes and edges are accessible as "graph.nodes" and "graph.edges" Visualization m_vis = new Visualization(); m_vis.add("graph", graph); m_vis.setInteractive(treeNodes, null, false); // draw the "name" label for NodeItems LabelRenderer m_nodeRenderer = new LabelRenderer("name"); m_nodeRenderer.setRenderType(AbstractShapeRenderer.RENDER_TYPE_FILL); m_nodeRenderer.setHorizontalAlignment(Constants.CENTER); m_nodeRenderer.setRoundedCorner(8, 8); // round the corners EdgeRenderer m_edgeRenderer = new EdgeRenderer(); m_edgeRenderer.setDefaultLineWidth(1.0); // create a new default renderer factory // return our name label renderer as the default for all non-EdgeItems // includes straight line edges for EdgeItems by default final DefaultRendererFactory rf = new DefaultRendererFactory(m_nodeRenderer); rf.add(new InGroupPredicate(treeEdges), m_edgeRenderer); m_vis.setRendererFactory(rf); // use black for node text ColorAction text = new ColorAction(treeNodes, VisualItem.TEXTCOLOR, ColorLib.gray(0)); // use light grey for edges ColorAction edges = new ColorAction(treeEdges, VisualItem.STROKECOLOR, ColorLib.gray(200)); // create an action list containing all color assignments ActionList color = new ActionList(); // color.add(fill); color.add(text); color.add(edges); // create the tree layout action Layout graphLayout = new SquarifiedTreeMapLayout("graph"); m_vis.putAction("circleLayout", graphLayout); // create an action list with an animated layout // the INFINITY parameter tells the action list to run indefinitely ActionList layout = new ActionList(Activity.DEFAULT_STEP_TIME * 500); Layout l = new ForceDirectedLayout("graph"); layout.add(l); layout.add(new RepaintAction()); // add the actions to the visualization m_vis.putAction("color", color); m_vis.putAction("layout", layout); // create a new Display that pull from our Visualization Display display = new Display(m_vis); display.setSize(1200, 800); // set display size display.addControlListener(new DragControl()); // drag items around display.addControlListener(new PanControl()); // pan with background left-drag display.addControlListener(new ZoomControl()); // zoom with vertical right-drag // create a new window to hold the visualization JFrame frame = new JFrame("MDD analysis"); // ensure application exits when window is closed frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(display); frame.pack(); // layout components in window frame.setVisible(true); // show the window m_vis.run("color"); // assign the colors m_vis.run("layout"); // start up the animated layout }
From source file:org.onosproject.xmpp.core.stream.XmppStreamOpen.java
License:Apache License
@Override public String toXml() { StringWriter out = new StringWriter(); XMLWriter writer = new XMLWriter(out, OutputFormat.createCompactFormat()); try {//from w ww . j a va 2s.co m out.write("<"); writer.write(element.getQualifiedName()); for (Attribute attr : (List<Attribute>) element.attributes()) { writer.write(attr); } writer.write(Namespace.get(this.element.getNamespacePrefix(), this.element.getNamespaceURI())); writer.write(Namespace.get("jabber:client")); out.write(">"); } catch (IOException ex) { log.info("Error writing XML", ex); } return out.toString(); }
From source file:org.opencms.webdav.CmsWebdavServlet.java
License:Open Source License
/** * Adds an xml element to the given parent and sets the appropriate namespace and * prefix.<p>/*from ww w .ja v a 2 s . co m*/ * * @param parent the parent node to add the element * @param name the name of the new element * * @return the created element with the given name which was added to the given parent */ public static Element addElement(Element parent, String name) { return parent.addElement(new QName(name, Namespace.get("D", DEFAULT_NAMESPACE))); }
From source file:org.opencms.webdav.CmsWebdavServlet.java
License:Open Source License
/** * Process a PROPFIND WebDAV request for the specified resource.<p> * //from w w w . ja v a 2 s . co m * @param req the servlet request we are processing * @param resp the servlet response we are creating * * @throws IOException if an input/output error occurs */ protected void doPropfind(HttpServletRequest req, HttpServletResponse resp) throws IOException { String path = getRelativePath(req); if (!m_listings) { // Get allowed methods StringBuffer methodsAllowed = determineMethodsAllowed(getRelativePath(req)); resp.addHeader(HEADER_ALLOW, methodsAllowed.toString()); resp.setStatus(CmsWebdavStatus.SC_METHOD_NOT_ALLOWED); return; } // Properties which are to be displayed. List<String> properties = new Vector<String>(); // Propfind depth int depth = CmsRepositoryLockInfo.DEPTH_INFINITY_VALUE; // Propfind type int type = FIND_ALL_PROP; String depthStr = req.getHeader(HEADER_DEPTH); if (depthStr == null) { depth = CmsRepositoryLockInfo.DEPTH_INFINITY_VALUE; } else { if (depthStr.equals("0")) { depth = 0; } else if (depthStr.equals("1")) { depth = 1; } else if (depthStr.equalsIgnoreCase(DEPTH_INFINITY)) { depth = CmsRepositoryLockInfo.DEPTH_INFINITY_VALUE; } } Element propNode = null; try { SAXReader saxReader = new SAXReader(); Document document = saxReader.read(req.getInputStream()); // Get the root element of the document Element rootElement = document.getRootElement(); @SuppressWarnings("unchecked") Iterator<Element> iter = rootElement.elementIterator(); while (iter.hasNext()) { Element currentElem = iter.next(); switch (currentElem.getNodeType()) { case Node.TEXT_NODE: break; case Node.ELEMENT_NODE: if (currentElem.getName().endsWith("prop")) { type = FIND_BY_PROPERTY; propNode = currentElem; } if (currentElem.getName().endsWith("propname")) { type = FIND_PROPERTY_NAMES; } if (currentElem.getName().endsWith("allprop")) { type = FIND_ALL_PROP; } break; default: break; } } } catch (Exception e) { // Most likely there was no content : we use the defaults. } if (propNode != null) { if (type == FIND_BY_PROPERTY) { @SuppressWarnings("unchecked") Iterator<Element> iter = propNode.elementIterator(); while (iter.hasNext()) { Element currentElem = iter.next(); switch (currentElem.getNodeType()) { case Node.TEXT_NODE: break; case Node.ELEMENT_NODE: String nodeName = currentElem.getName(); String propertyName = null; if (nodeName.indexOf(':') != -1) { propertyName = nodeName.substring(nodeName.indexOf(':') + 1); } else { propertyName = nodeName; } // href is a live property which is handled differently properties.add(propertyName); break; default: break; } } } } boolean exists = m_session.exists(path); if (!exists) { resp.setStatus(CmsWebdavStatus.SC_NOT_FOUND); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_ITEM_NOT_FOUND_1, path)); } return; } I_CmsRepositoryItem item = null; try { item = m_session.getItem(path); } catch (CmsException e) { resp.setStatus(CmsWebdavStatus.SC_NOT_FOUND); return; } resp.setStatus(CmsWebdavStatus.SC_MULTI_STATUS); resp.setContentType("text/xml; charset=UTF-8"); // Create multistatus object Document doc = DocumentHelper.createDocument(); Element multiStatusElem = doc.addElement(new QName(TAG_MULTISTATUS, Namespace.get("D", DEFAULT_NAMESPACE))); if (depth == 0) { parseProperties(req, multiStatusElem, item, type, properties); } else { // The stack always contains the object of the current level Stack<I_CmsRepositoryItem> stack = new Stack<I_CmsRepositoryItem>(); stack.push(item); // Stack of the objects one level below Stack<I_CmsRepositoryItem> stackBelow = new Stack<I_CmsRepositoryItem>(); while ((!stack.isEmpty()) && (depth >= 0)) { I_CmsRepositoryItem currentItem = stack.pop(); parseProperties(req, multiStatusElem, currentItem, type, properties); if ((currentItem.isCollection()) && (depth > 0)) { try { List<I_CmsRepositoryItem> list = m_session.list(currentItem.getName()); Iterator<I_CmsRepositoryItem> iter = list.iterator(); while (iter.hasNext()) { I_CmsRepositoryItem element = iter.next(); stackBelow.push(element); } } catch (CmsException e) { resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); if (LOG.isErrorEnabled()) { LOG.error(Messages.get().getBundle().key(Messages.LOG_LIST_ITEMS_ERROR_1, currentItem.getName()), e); } return; } } if (stack.isEmpty()) { depth--; stack = stackBelow; stackBelow = new Stack<I_CmsRepositoryItem>(); } } } Writer writer = resp.getWriter(); doc.write(writer); writer.close(); }
From source file:org.openxml4j.opc.internal.marshallers.ZipPartMarshaller.java
License:Apache License
/** * Save relationships into the part.//from w w w . java 2 s . c o m * * @param rels * The relationships collection to marshall. * @param relPartURI * Part name of the relationship part to marshall. * @param zos * Zip output stream in which to save the XML content of the * relationships serialization. */ public static boolean marshallRelationshipPart(PackageRelationshipCollection rels, PackagePartName relPartName, ZipOutputStream zos) { // Building xml Document xmlOutDoc = DocumentHelper.createDocument(); // make something like <Relationships // xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> Namespace dfNs = Namespace.get("", PackageNamespaces.RELATIONSHIPS); Element root = xmlOutDoc.addElement(new QName(PackageRelationship.RELATIONSHIPS_TAG_NAME, dfNs)); // <Relationship // TargetMode="External" // Id="rIdx" // Target="http://www.custom.com/images/pic1.jpg" // Type="http://www.custom.com/external-resource"/> URI sourcePartURI = PackagingURIHelper.getSourcePartUriFromRelationshipPartUri(relPartName.getURI()); for (PackageRelationship rel : rels) { // L'lment de la relation Element relElem = root.addElement(PackageRelationship.RELATIONSHIP_TAG_NAME); // L'attribut ID relElem.addAttribute(PackageRelationship.ID_ATTRIBUTE_NAME, rel.getId()); // L'attribut Type relElem.addAttribute(PackageRelationship.TYPE_ATTRIBUTE_NAME, rel.getRelationshipType()); // L'attribut Target String targetValue; URI uri = rel.getTargetURI(); if (rel.getTargetMode() == TargetMode.EXTERNAL) { // Save the target as-is - we don't need to validate it, // alter it etc try { targetValue = URLEncoder.encode(uri.toString(), "UTF-8"); } catch (UnsupportedEncodingException e) { targetValue = uri.toString(); } // add TargetMode attribut (as it is external link external) relElem.addAttribute(PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME, "External"); } else { targetValue = PackagingURIHelper.relativizeURI(sourcePartURI, rel.getTargetURI()).getPath(); } relElem.addAttribute(PackageRelationship.TARGET_ATTRIBUTE_NAME, targetValue); } xmlOutDoc.normalize(); // String schemaFilename = Configuration.getPathForXmlSchema()+ // File.separator + "opc-relationships.xsd"; // Save part in zip ZipEntry ctEntry = new ZipEntry( ZipHelper.getZipURIFromOPCName(relPartName.getURI().toASCIIString()).getPath()); try { // Cration de l'entre dans le fichier ZIP zos.putNextEntry(ctEntry); if (!StreamHelper.saveXmlInStream(xmlOutDoc, zos)) { return false; } zos.closeEntry(); } catch (IOException e) { logger.error("Cannot create zip entry " + relPartName, e); return false; } return true; // success }