/** * Creates a new element with the supplied (local) name and namespace. If * the provided namespace is null, the element will have no namespace. * * @param name local name of the element * @param namespace namespace for the element * @throws IllegalNameException if the given name is illegal as an element * name */ public Element(final String name, final Namespace namespace) { super(CType.Element); setName(name); setNamespace(namespace); }
/** * @param name The name of the element. * @return {@link Element} * @see org.jdom2.Element#setName(java.lang.String) */ public Element setName( String name ) { return element.setName( name ); }
/** * Sets element name - should not be used for HtmlElement-derived classes! * @param value Element name * @return Self reference * @deprecated Deprecated */ @Override @Deprecated public final org.jdom2.Element setName(String value) { return super.setName(value); }
private void addMetadataFiles(final String internalPath, final MetadataElement destElem) throws IOException { String[] metaFiles = productDir.list(internalPath); for (String file : metaFiles) { if (file.endsWith(".xml")) { try { final File metaFile = getFile(internalPath + "/" + file); final Document xmlDoc = XMLSupport.LoadXML(metaFile.getAbsolutePath()); final Element metaFileElement = xmlDoc.getRootElement(); if (metaFileElement.getName().equals("lut")) { metaFileElement.setName(file.substring(0, file.lastIndexOf(".xml"))); } AbstractMetadataIO.AddXMLMetadata(metaFileElement, destElem); } catch (IOException e) { SystemUtils.LOG.severe("Unable to read metadata " + file); } } } }
private Element cloneRelatedItem(Element relatedItem) { Element mods = relatedItem.clone(); mods.setName("mods"); mods.removeAttribute("type"); mods.removeAttribute("href", MCRConstants.XLINK_NAMESPACE); mods.removeAttribute("type", MCRConstants.XLINK_NAMESPACE); mods.removeChildren("part", MCRConstants.MODS_NAMESPACE); return mods; }
/** * Merges the publication data returned by the data source with the existing data */ void mergeResultWith(Element existingData) { if (existingData.getName().equals("relatedItem")) { // resolved is always mods:mods, transform to mods:relatedItem to be mergeable result.setName("relatedItem"); result.setAttribute(existingData.getAttribute("type").clone()); } MCRMerger a = MCRMergerFactory.buildFrom(existingData); MCRMerger b = MCRMergerFactory.buildFrom(result); a.mergeFrom(b); }
/** * Converts the navigation.xml to the old format. */ private static byte[] convertToOldFormat(byte[] xml) throws JDOMException, IOException { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new ByteArrayInputStream(xml)); Element rootElement = doc.getRootElement(); rootElement.setAttribute("href", rootElement.getName()); List<Element> children = rootElement.getChildren(); for (Element menu : children) { String id = menu.getAttributeValue("id"); menu.setName(id); menu.setAttribute("href", id); menu.removeAttribute("id"); } XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); ByteArrayOutputStream bout = new ByteArrayOutputStream(xml.length); out.output(doc, bout); return bout.toByteArray(); }
private Element writeCoordTransform(CoverageTransform ct) { Element ctElem = new Element("coordTransform"); ctElem.setAttribute("name", ct.getName()); ctElem.setAttribute("transformType", ct.isHoriz() ? "Projection" : "Vertical"); for (Attribute param : ct.getAttributes()) { Element pElem = ncmlWriter.makeAttributeElement(param); pElem.setName("parameter"); ctElem.addContent(pElem); } return ctElem; }
public Element makeNetcdfElement(NetcdfFile ncFile, String location) { Element rootElem = makeGroupElement(ncFile.getRootGroup()); // rootElem isn't just like any other group element; we must undo some of the changes made to it in writeGroup(). rootElem.setName("netcdf"); // Was "group". rootElem.removeAttribute("name"); // This attribute is not defined on the root "netcdf" element. rootElem.addNamespaceDeclaration(namespace); if (null == location) location = ncFile.getLocation(); if (null != location) { rootElem.setAttribute("location", URLnaming.canonicalizeWrite(location)); } if (null != ncFile.getId()) rootElem.setAttribute("id", ncFile.getId()); if (null != ncFile.getTitle()) rootElem.setAttribute("title", ncFile.getTitle()); return rootElem; }
@Test public void testInstantiateThrowsNullPointerException3() throws Throwable { String[] args = new String[0]; Q2 q2 = new Q2(args); Element element = new Element("testQFactoryName", "testQFactoryUri"); element.setAttribute(new Attribute("testQFactoryName", "testQFactoryValue", 0)); Element e = (Element) element.clone(); QFactory qFactory = new QFactory(new ObjectName("testQFactoryParam1", "testQFactoryParam2", "testQFactoryParam3"), q2); e.setName("testQFactoryName"); String[] args2 = new String[2]; args2[0] = "stat"; args2[1] = "undeplying:"; Q2 server = new Q2(args2); try { qFactory.instantiate(server, e); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("ex.getMessage()", ex.getMessage()); assertTrue("qFactory.classMapping.getKeys().hasMoreElements()", qFactory.classMapping .getKeys().hasMoreElements()); assertSame("qFactory.q2", q2, qFactory.q2); assertEquals("e.getName()", "testQFactoryName", e.getName()); assertSame("server.getCommandLineArgs()", args2, server.getCommandLineArgs()); } }