List of usage examples for org.jdom2 Namespace NO_NAMESPACE
Namespace NO_NAMESPACE
To view the source code for org.jdom2 Namespace NO_NAMESPACE.
Click Source Link
Namespace
for when not in a namespace From source file:es.upm.dit.xsdinferencer.generation.generatorimpl.schemageneration.XMLSchemaDocumentGenerator.java
License:Apache License
/** * Method that generates the namespace declarations which will be appended to the root of the generated XSD files. * @param namespaceURIToPrefixMappings solved namespace URI-to-prefix mappings * @param xsdNamespace namespace of XSD// ww w.j a v a 2s . c o m * @return a list of {@link Namespace} JDOM2 object that describe the solved mappings and includes the declaration of the * XSD namespace used by the generated XSD itself. */ private List<Namespace> getNamespaceDeclarations(Map<String, String> namespaceURIToPrefixMappings, Namespace xsdNamespace) { List<Namespace> namespaceDeclarations = new ArrayList<>(namespaceURIToPrefixMappings.size() + 1); namespaceDeclarations.add(xsdNamespace); for (String namespaceURI : ImmutableSortedSet.copyOf(namespaceURIToPrefixMappings.keySet())) { String namespacePrefix = namespaceURIToPrefixMappings.get(namespaceURI).replace(":", ""); if (namespaceURI.equals("")) { namespaceDeclarations.add(Namespace.NO_NAMESPACE); } else if (namespacePrefix.equals("")) { namespaceDeclarations.add(Namespace.getNamespace(namespaceURI)); } else { namespaceDeclarations.add(Namespace.getNamespace(namespacePrefix, namespaceURI)); } } return namespaceDeclarations; }
From source file:io.smartspaces.workbench.project.jdom.JdomProjectReader.java
License:Apache License
/** * Process an element and return a new project. * * @param projectElement/*from w w w. j a va 2 s .co m*/ * element to process * * @return project representing the element */ Project makeProjectFromElement(Element projectElement) { Namespace projectNamespace = projectElement.getNamespace(); if (!PROJECT_ELEMENT_NAME_PROJECT.equals(projectElement.getName())) { throw new SimpleSmartSpacesException("Invalid project root element name " + projectElement.getName()); } // When an xi:include statement is used, the included elements do not pick // up the default namespace. if (!Namespace.NO_NAMESPACE.equals(projectNamespace)) { getLog().info(String.format("Applying default namespace '%s' to project element tree", projectNamespace.getURI())); applyDefaultNamespaceRecursively(projectElement, projectNamespace, true); } String projectType = getProjectType(projectElement); Project project = getWorkbench().getProjectTypeRegistry().newProject(projectType); project.setPlatform(getProjectPlatform(projectElement)); processPrototypeChain(project, projectNamespace, projectElement); configureProjectFromElement(project, projectNamespace, projectElement); if (project.getSmartSpacesVersionRange() == null) { getLog().warn("Did not specify a range of needed Smart Spaces versions. Setting default to " + SMARTSPACES_VERSION_RANGE_DEFAULT); project.setSmartSpacesVersionRange(SMARTSPACES_VERSION_RANGE_DEFAULT); } if (failure) { throw new SimpleSmartSpacesException("Project specification had errors"); } return project; }
From source file:io.smartspaces.workbench.project.jdom.JdomProjectReader.java
License:Apache License
/** * Recursively apply a default namespace to an element tree. This will log * instances that are changed at the root of a tree (but not elements * underneath that root).//from w w w. ja v a 2s . c om * * @param element * target root element * @param namespace * namespace to apply as default * @param shouldLog * {@code true} if logging should be applied to any matches */ void applyDefaultNamespaceRecursively(Element element, Namespace namespace, boolean shouldLog) { if (Namespace.NO_NAMESPACE.equals(element.getNamespace())) { if (shouldLog) { getLog().info( String.format("Applying default namespace to element tree root '%s'", element.getName())); shouldLog = false; } element.setNamespace(namespace); } for (Element child : element.getChildren()) { applyDefaultNamespaceRecursively(child, namespace, shouldLog); } }
From source file:net.exclaimindustries.paste.braket.server.TeamDownloader.java
License:Open Source License
public static Team parseTeam(Document document) throws MalformedURLException { // Parse out the details Element rootNode = document.getRootElement(); // I need the espn namespace List<Namespace> namespaceList = rootNode.getNamespacesInScope(); Namespace ns = Namespace.NO_NAMESPACE; for (Namespace namespace : namespaceList) { if (namespace.getPrefix() == "espn") { ns = namespace;/*from ww w.j a va 2 s . c o m*/ break; } } // Find the "item" element that has the right stuff in it Element channel = rootNode.getChild("channel"); List<Element> items = channel.getChildren("item"); Element teamElement = null; for (Element item : items) { if (item.getChild("teamAbbrev", ns) != null) { teamElement = item.clone(); break; } } if (teamElement == null) { // Couldn't find any info about the team, so skip it. return null; } // Make sure that the given ID matches the ID in the team (else this // is not a real team) Long teamId = Long.valueOf(teamElement.getChildText("teamId", ns)); Team team = new Team(); team.setId(teamId); String abbreviation = digOutCDATA(teamElement, "teamAbbrev", ns); String displayName = digOutCDATA(teamElement, "teamDisplayName", ns); String location = digOutCDATA(teamElement, "teamLocation", ns); String nickname = digOutCDATA(teamElement, "teamNickname", ns); String teamNameString = teamElement.getChildText("teamName", ns); String teamColorString = "#" + teamElement.getChildText("teamColor", ns); String teamLogoUrl = teamElement.getChildText("teamLogo", ns); TeamName teamName = new TeamName(location, teamNameString, displayName, nickname, abbreviation); team.setName(teamName); try { if (teamColorString != null) { RGBAColor color = RGBAColor.fromCSSString(teamColorString); team.setColor(color); } } catch (Exception e) { // TODO Is this okay? } // Save the image name (should be the same as the downloaded version) URL url = new URL(teamLogoUrl); File file = new File(url.getPath()); String teamLogoName = file.getName(); team.setPicture(teamLogoName); return team; }
From source file:org.mycore.common.xml.MCRNodeBuilder.java
License:Open Source License
@SuppressWarnings("unchecked") private Object buildNameStep(NameStep nameStep, String value, Parent parent) throws JaxenException { String name = nameStep.getLocalName(); String prefix = nameStep.getPrefix(); Namespace ns = prefix.isEmpty() ? Namespace.NO_NAMESPACE : MCRConstants.getStandardNamespace(prefix); if (nameStep.getAxis() == Axis.CHILD) { if (parent instanceof Document) return buildPredicates(nameStep.getPredicates(), ((Document) parent).getRootElement()); else/*w ww . j a v a 2 s. com*/ return buildPredicates(nameStep.getPredicates(), buildElement(ns, name, value, (Element) parent)); } else if (nameStep.getAxis() == Axis.ATTRIBUTE) { return buildAttribute(ns, name, value, (Element) parent); } else { if (LOGGER.isDebugEnabled()) LOGGER.debug("ignoring axis, can not be built: " + nameStep.getAxis() + " " + (prefix.isEmpty() ? "" : prefix + ":") + name); return null; } }
From source file:org.mycore.frontend.editor.MCREditorSubmission.java
License:Open Source License
private String getNamespacePrefix(Namespace ns) { if (ns == null || ns.equals(Namespace.NO_NAMESPACE)) { return ""; }/*from www . j av a 2 s . co m*/ for (String key : nsMap.keySet()) { if (ns.equals(nsMap.get(key))) { return key + ":"; } } String msg = "Namespace " + ns.getURI() + " used in editor source input, but not declared in editor definition. Using: " + ns.getPrefix(); LOGGER.warn(msg); return ns.getPrefix() + ":"; }
From source file:org.mycore.frontend.editor.MCREditorSubmission.java
License:Open Source License
private void buildTargetXML() { Element root;//from w w w .ja v a 2 s. c om if (variables.size() > 0) { root = buildElement(((MCREditorVariable) variables.get(0)).getPathElements()[0]); } else { root = buildElement(rootName.replace("/", "")); } for (Object variable : variables) { MCREditorVariable var = (MCREditorVariable) variable; Element parent = root; String[] elements = var.getPathElements(); for (int j = 1; j < elements.length; j++) { String name = elements[j]; if (name.endsWith("]")) { int pos = name.lastIndexOf("["); name = name.substring(0, pos) + "_XXX_" + name.substring(pos + 1, name.length() - 1); } Namespace ns = getNamespace(name); if (!ns.equals(Namespace.NO_NAMESPACE)) { name = name.substring(name.indexOf(":") + 1); } Element child = parent.getChild(name, ns); if (child == null) { child = new Element(name, ns); parent.addContent(child); } parent = child; } Object node; if (!var.isAttribute()) { parent.addContent(var.getValue()); node = parent; } else { LOGGER.debug("Setting attribute " + var.getPath() + " = " + var.getValue()); setAttribute(parent, var.getAttributeName(), var.getValue()); node = parent.getAttribute(var.getAttributeName()); } FileItem file = parms == null ? null : parms.getFileItem(var.getPath()); if (file != null) { file2node.put(file, node); node2file.put(node, file); } } renameRepeatedElements(root); xml = new Document(root); }
From source file:org.mycore.frontend.editor.MCREditorSubmission.java
License:Open Source License
/** * Extracts namespace prefix from the given name (the part before the ":") * and resolves it to the namespace registered in the editor definition. *//* ww w. j a v a 2 s. co m*/ private Namespace getNamespace(String name) { int pos1 = name.indexOf(":"); int pos2 = name.indexOf(ATTR_SEP); if (pos1 == -1 || pos1 > pos2 && pos2 >= 0) { return Namespace.NO_NAMESPACE; } String prefix = name.substring(0, pos1); if (!nsMap.containsKey(prefix)) { String msg = "Namespace prefix " + prefix + " is used in editor variable, but not defined"; throw new MCRConfigurationException(msg); } return nsMap.get(prefix); }
From source file:org.mycore.frontend.editor.MCREditorSubmission.java
License:Open Source License
/** * Builds a new XML element for data output. The name may contain a * namespace prefix, which is resolved to a namespace then. *//*w w w . j av a 2 s . c o m*/ private Element buildElement(String name) { Namespace ns = getNamespace(name); if (!ns.equals(Namespace.NO_NAMESPACE)) { name = name.substring(name.indexOf(":") + 1); } return new Element(name, ns); }
From source file:org.mycore.frontend.editor.MCREditorSubmission.java
License:Open Source License
/** * Sets attribute value of the given parent element. The name may contain a * namespace prefix, which is resolved to a namespace then. *//* www .j av a 2 s. c o m*/ private void setAttribute(Element parent, String name, String value) { Namespace ns = getNamespace(name); if (!ns.equals(Namespace.NO_NAMESPACE)) { name = name.substring(name.indexOf(":") + 1); } parent.setAttribute(name, value, ns); }