public List operate(Object node) { if (node instanceof Element) return Collections.singletonList(((Element) node).getQualifiedName()); else if (node instanceof Attribute) return Collections.singletonList(((Attribute) node).getQualifiedName()); // With 2.1 semantics it makes more sense to just return a null and let the core // throw an InvalidReferenceException and the template writer can use ?exists etcetera. (JR) return null; // throw new TemplateModelException("_qname can not be applied on " + node.getClass()); } }
public String getQualifiedName() { return element.getQualifiedName(); }
public List operate(Object node) { if (node instanceof Element) return Collections.singletonList(((Element) node).getQualifiedName()); else if (node instanceof Attribute) return Collections.singletonList(((Attribute) node).getQualifiedName()); // With 2.1 semantics it makes more sense to just return a null and let the core // throw an InvalidReferenceException and the template writer can use ?exists etcetera. (JR) return null; // throw new TemplateModelException("_qname can not be applied on " + node.getClass()); } }
public List operate(Object node) { if (node instanceof Element) return Collections.singletonList(((Element) node).getQualifiedName()); else if (node instanceof Attribute) return Collections.singletonList(((Attribute) node).getQualifiedName()); // With 2.1 semantics it makes more sense to just return a null and let the core // throw an InvalidReferenceException and the template writer can use ?exists etcetera. (JR) return null; // throw new TemplateModelException("_qname can not be applied on " + node.getClass()); } }
/** * This will create an <code>Exception</code> indicating * that the addition of the <code>{@link Element}</code> * to the <code>{@link Document}</code> is illegal. * * @param added <code>Element</code> that could not be added * @param reason cause of the problem */ IllegalAddException(Element added, String reason) { super(new StringBuffer() .append("The element \"") .append(added.getQualifiedName()) .append("\" could not be added as the root of the document: ") .append(reason) .toString()); }
/** * This will create an <code>Exception</code> indicating * that the addition of the <code>{@link Element}</code> * to parent is illegal. * * @param base <code>Element</code> that the child * couldn't be added to * @param added <code>Element</code> that could not be added * @param reason cause of the problem */ IllegalAddException(Element base, Element added, String reason) { super(new StringBuffer() .append("The element \"") .append(added.getQualifiedName()) .append("\" could not be added as a child of \"") .append(base.getQualifiedName()) .append("\": ") .append(reason) .toString()); }
/** * This will create an <code>Exception</code> indicating * that the addition of the <code>{@link Attribute}</code> * to the <code>{@link Element}</code> is illegal. * * @param base <code>Element</code> that <code>Attribute</code> * couldn't be added to * @param added <code>Attribute</code> that could not be added * @param reason cause of the problem */ IllegalAddException(Element base, Attribute added, String reason) { super(new StringBuffer() .append("The attribute \"") .append(added.getQualifiedName()) .append("\" could not be added to the element \"") .append(base.getQualifiedName()) .append("\": ") .append(reason) .toString()); }
/** * This will create an <code>Exception</code> indicating * that the addition of the <code>{@link ProcessingInstruction}</code> * to the <code>{@link Element}</code> is illegal. * * @param base <code>Element</code> that the * <code>ProcessingInstruction</code> couldn't be added to * @param added <code>ProcessingInstruction</code> that could not be added * @param reason cause of the problem */ IllegalAddException(Element base, ProcessingInstruction added, String reason) { super(new StringBuffer() .append("The PI \"") .append(added.getTarget()) .append("\" could not be added as content to \"") .append(base.getQualifiedName()) .append("\": ") .append(reason) .toString()); }
/** * This will create an <code>Exception</code> indicating * that the addition of the <code>{@link CDATA}</code> * * @param base <code>Element</code> that the <code>CDATA</code> * couldn't be added to * @param added <code>CDATA</code> that could not be added * @param reason cause of the problem */ IllegalAddException(Element base, CDATA added, String reason) { super(new StringBuffer() .append("The CDATA \"") .append(added.getText()) .append("\" could not be added as content to \"") .append(base.getQualifiedName()) .append("\": ") .append(reason) .toString()); }
/** * This will create an <code>Exception</code> indicating * that the addition of the <code>{@link EntityRef}</code> * to the <code>{@link Element}</code> is illegal. * * @param base <code>Element</code> that the <code>EntityRef</code> * couldn't be added to * @param added <code>EntityRef</code> reference that could not be added * @param reason cause of the problem */ IllegalAddException(Element base, EntityRef added, String reason) { super(new StringBuffer() .append("The entity reference\"") .append(added.getName()) .append("\" could not be added as content to \"") .append(base.getQualifiedName()) .append("\": ") .append(reason) .toString()); }
/** * This will create an <code>Exception</code> indicating * that the addition of the <code>{@link Comment}</code> * to the <code>{@link Element}</code> is illegal. * * @param base <code>Element</code> that the <code>Comment</code> * couldn't be added to * @param added <code>Comment</code> that could not be added * @param reason cause of the problem */ IllegalAddException(Element base, Comment added, String reason) { super(new StringBuffer() .append("The comment \"") .append(added.getText()) .append("\" could not be added as content to \"") .append(base.getQualifiedName()) .append("\": ") .append(reason) .toString()); }
/** * This will create an <code>Exception</code> indicating * that the addition of the <code>{@link Text}</code> * to the <code>{@link Element}</code> is illegal. * * @param base <code>Element</code> that the <code>Comment</code> * couldn't be added to * @param added <code>Text</code> that could not be added * @param reason cause of the problem */ IllegalAddException(Element base, Text added, String reason) { super(new StringBuffer() .append("The Text \"") .append(added.getText()) .append("\" could not be added as content to \"") .append(base.getQualifiedName()) .append("\": ") .append(reason) .toString()); }
/** * Get relative position of this among like-named siblings. * @return 1..n */ private int getRelativePositionByName() { if (node instanceof Element) { Object parent = ((Element) node).getParent(); if (!(parent instanceof Element)) { return 1; } List children = ((Element) parent).getContent(); int count = 0; String name = ((Element) node).getQualifiedName(); for (int i = 0; i < children.size(); i++) { Object child = children.get(i); if ((child instanceof Element) && ((Element) child).getQualifiedName().equals(name)) { count++; } if (child == node) { break; } } return count; } return 1; }
/** * <p> * This returns a <code>String</code> representation of the * <code>Element</code>, suitable for debugging. If the XML * representation of the <code>Element</code> is desired, * {@link org.jdom.output.XMLOutputter#outputString(Element)} * should be used. * </p> * * @return <code>String</code> - information about the * <code>Element</code> */ public String toString() { final StringBuffer stringForm = new StringBuffer(64) .append("[Element: <") .append(getQualifiedName()); final String nsuri = getNamespaceURI(); if (!"".equals(nsuri)) { stringForm .append(" [Namespace: ") .append(nsuri) .append("]"); } stringForm.append("/>]"); return stringForm.toString(); }
/** * <p> * This will invoke the <code>endElement</code> callback * in the <code>ContentHandler</code>. * </p> * * @param element <code>Element</code> used in callbacks. */ private void endElement(Element element) throws JDOMException { String namespaceURI = element.getNamespaceURI(); String localName = element.getName(); String rawName = element.getQualifiedName(); try { contentHandler.endElement(namespaceURI, localName, rawName); } catch (SAXException se) { throw new JDOMException("Exception in endElement", se); } }
/** * This will create an <code>Exception</code> indicating * that the addition of the <code>{@link Namespace}</code> * to the <code>{@link Element}</code> is illegal. * * @param base <code>Element</code> that the <code>Namespace</code> * couldn't be added to * @param added <code>Namespace</code> that could not be added * @param reason cause of the problem */ IllegalAddException(Element base, Namespace added, String reason) { super(new StringBuffer() .append("The namespace xmlns") .append((added.getPrefix() == null || added.getPrefix().equals("")) ? "=" : ":" + added.getPrefix() + "=") .append("\"") .append(added.getURI()) .append("\" could not be added as a namespace to \"") .append(base.getQualifiedName()) .append("\": ") .append(reason) .toString()); }
public List operate(Object node) { if (node instanceof Element) return Collections12.singletonList(((Element)node).getQualifiedName()); else if (node instanceof Attribute) return Collections12.singletonList(((Attribute)node).getQualifiedName()); // With 2.1 semantics it makes more sense to just return a null and let the core // throw an InvalidReferenceException and the template writer can use ?exists etcetera. (JR) return null; // throw new TemplateModelException("_qname can not be applied on " + node.getClass()); } }
@Test public void manifestMimetype() throws Exception { UCFPackage container = new UCFPackage(); container.setPackageMediaType(UCFPackage.MIME_WORKFLOW_BUNDLE); container.save(tmpFile); ZipFile zipFile = new ZipFile(tmpFile); ZipEntry manifestEntry = zipFile.getEntry("META-INF/manifest.xml"); InputStream manifestStream = zipFile.getInputStream(manifestEntry); //System.out.println(IOUtils.toString(manifestStream, "UTF-8")); /* <?xml version="1.0" encoding="UTF-8"?> <manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"> </manifest:manifest> */ Document doc = parseXml(manifestStream); assertEquals(MANIFEST_NS, doc.getRootElement().getNamespace()); assertEquals("manifest", doc.getRootElement().getNamespacePrefix()); assertEquals("manifest:manifest", doc.getRootElement().getQualifiedName()); assertNull(xpathSelectElement(doc.getRootElement(), "/manifest:manifest/*")); }
@Test public void manifestMimetype() throws Exception { UCFPackage container = new UCFPackage(); container.setPackageMediaType(UCFPackage.MIME_WORKFLOW_BUNDLE); container.save(tmpFile); ZipFile zipFile = new ZipFile(tmpFile); ZipEntry manifestEntry = zipFile.getEntry("META-INF/manifest.xml"); InputStream manifestStream = zipFile.getInputStream(manifestEntry); //System.out.println(IOUtils.toString(manifestStream, "UTF-8")); /* <?xml version="1.0" encoding="UTF-8"?> <manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"> </manifest:manifest> */ Document doc = parseXml(manifestStream); assertEquals(MANIFEST_NS, doc.getRootElement().getNamespace()); assertEquals("manifest", doc.getRootElement().getNamespacePrefix()); assertEquals("manifest:manifest", doc.getRootElement().getQualifiedName()); assertNull(xpathSelectElement(doc.getRootElement(), "/manifest:manifest/*")); }
assertEquals(MANIFEST_NS, doc.getRootElement().getNamespace()); assertEquals("manifest", doc.getRootElement().getNamespacePrefix()); assertEquals("manifest:manifest", doc.getRootElement().getQualifiedName()); assertXpathEquals("application/octet-stream", doc.getRootElement(), "/manifest:manifest/manifest:file-entry/@manifest:media-type"); assertXpathEquals("binary", doc.getRootElement(), "/manifest:manifest/manifest:file-entry/@manifest:full-path");