org.jdom.Namespace Java Examples
The following examples show how to use
org.jdom.Namespace.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JDOMNamespaceContext.java From cxf with Apache License 2.0 | 6 votes |
static void rawGetPrefixes(Element element, String namespaceURI, List<String> prefixes) { if (element.getNamespaceURI().equals(namespaceURI)) { prefixes.add(element.getNamespacePrefix()); } List<?> namespaces = element.getAdditionalNamespaces(); for (Iterator<?> itr = namespaces.iterator(); itr.hasNext();) { Namespace ns = (Namespace)itr.next(); if (ns.getURI().equals(namespaceURI)) { prefixes.add(ns.getPrefix()); } } if (element.getParentElement() != null) { rawGetPrefixes(element.getParentElement(), namespaceURI, prefixes); } }
Example #2
Source File: LtiParser.java From sakai with Educational Community License v2.0 | 6 votes |
public void parseContent(DefaultHandler the_handler, CartridgeLoader the_cartridge, Element the_resource, boolean isProtected) throws ParseException { try { //ok, so we're looking at a discussion topic here... Element blti = getXML(the_cartridge, ((Element)the_resource.getChildren(FILE, the_handler.getNs().cc_ns()).get(0)).getAttributeValue(HREF)); log.info("blti="+blti); Namespace topicNs = the_handler.getNs().blti_ns(); the_handler.startLti(blti.getChildText(TITLE, topicNs), blti.getChild(TEXT, topicNs).getAttributeValue(TEXTTYPE), blti.getChildText(TEXT, topicNs), isProtected); the_handler.setLtiXml(blti); the_handler.endLti(); } catch (IOException e) { throw new ParseException(e); } }
Example #3
Source File: SCORM12_DocumentHandler.java From olat with Apache License 2.0 | 6 votes |
protected static boolean canHandle(final Document doc) throws DocumentHandlerException { // The first thing we do is to see if there is a root Namespace in the Document final Namespace nameSpace = XMLUtils.getDocumentNamespace(doc); // No Namespace, sorry we don't know what it is! if (nameSpace == null || nameSpace.equals(Namespace.NO_NAMESPACE)) { throw new DocumentHandlerException("No Namespace in Document so cannot determine what it is!"); } // Does it have the correct root Namespace? if (SUPPORTED_NAMESPACES.containsKey(nameSpace) == false) { return false; } // Now find out if it is a SCORM Document and if so whether we support it // We'll search all elements for the ADL Namespace final Namespace nsSCORM = getSCORM_Namespace(doc); if (nsSCORM == null) { return false; } // Do we support this version of SCORM? return SUPPORTED_SCORM_NAMESPACES.containsKey(nsSCORM); }
Example #4
Source File: SCORM12_DocumentHandler.java From olat with Apache License 2.0 | 6 votes |
protected static boolean canHandle(final Document doc) throws DocumentHandlerException { // The first thing we do is to see if there is a root Namespace in the Document final Namespace nameSpace = XMLUtils.getDocumentNamespace(doc); // No Namespace, sorry we don't know what it is! if (nameSpace == null || nameSpace.equals(Namespace.NO_NAMESPACE)) { throw new DocumentHandlerException("No Namespace in Document so cannot determine what it is!"); } // Does it have the correct root Namespace? if (SUPPORTED_NAMESPACES.containsKey(nameSpace) == false) { return false; } // Now find out if it is a SCORM Document and if so whether we support it // We'll search all elements for the ADL Namespace final Namespace nsSCORM = getSCORM_Namespace(doc); if (nsSCORM == null) { return false; } // Do we support this version of SCORM? return SUPPORTED_SCORM_NAMESPACES.containsKey(nsSCORM); }
Example #5
Source File: NATO4676Decoder.java From geowave with Apache License 2.0 | 6 votes |
private List<ObjectClassification> readObjectClassifications( final Element element, final Namespace xmlns) { final List<ObjectClassification> objClassList = new ArrayList<>(); final List<Element> children = element.getChildren(); final Iterator<Element> childIter = children.iterator(); while (childIter.hasNext()) { final Element child = childIter.next(); final String childName = child.getName(); final String childValue = child.getValue(); if ("classification".equals(childName)) { final ObjectClassification classification = ObjectClassification.fromString(childValue); if (classification != null) { objClassList.add(classification); } } } return objClassList; }
Example #6
Source File: WebLinkParser.java From sakai with Educational Community License v2.0 | 6 votes |
public void parseContent(DefaultHandler the_handler, CartridgeLoader the_cartridge, Element the_resource, boolean isProtected) throws ParseException { try { //ok, so we're looking at a web link here... Element link = getXML(the_cartridge, ((Element)the_resource.getChildren(FILE, the_handler.getNs().cc_ns()).get(0)).getAttributeValue(HREF)); Namespace linkNs = the_handler.getNs().link_ns(); Element urlElement = link.getChild(URL, linkNs); the_handler.startWebLink(link.getChildText(TITLE, linkNs), urlElement.getAttributeValue(HREF), urlElement.getAttributeValue(TARGET), urlElement.getAttributeValue(WINDOW_FEATURES), isProtected); the_handler.setWebLinkXml(link); the_handler.endWebLink(); } catch (IOException e) { throw new ParseException(e); } }
Example #7
Source File: NATO4676Decoder.java From geowave with Apache License 2.0 | 6 votes |
private TrackMessage readTrackMessage(final Element element, final Namespace xmlns) { final TrackMessage msg = new TrackMessage(); msg.setUuid(UUID.randomUUID()); final List<Element> children = element.getChildren(); final Iterator<Element> childIter = children.iterator(); while (childIter.hasNext()) { final Element child = childIter.next(); final String childName = child.getName(); final String childValue = child.getValue(); if ("stanagVersion".equals(childName)) { msg.setFormatVersion(childValue); } else if ("messageSecurity".equals(childName)) { msg.setSecurity(readSecurity(child, xmlns)); } else if ("msgCreatedTime".equals(childName)) { msg.setMessageTime(DateStringToLong(childValue)); } else if ("senderId".equals(childName)) { msg.setSenderID(readIDdata(child, xmlns)); } else if ("tracks".equals(childName)) { msg.addTrackEvent(readTrackEvent(child, xmlns)); } } return msg; }
Example #8
Source File: NATO4676Decoder.java From geowave with Apache License 2.0 | 6 votes |
private IDdata readIDdata(final Element element, final Namespace xmlns) { final IDdata id = new IDdata(); final List<Element> children = element.getChildren(); final Iterator<Element> childIter = children.iterator(); while (childIter.hasNext()) { final Element child = childIter.next(); final String childName = child.getName(); final String childValue = child.getValue(); if ("stationID".equals(childName)) { id.setStationId(childValue); } else if ("nationality".equals(childName)) { id.setNationality(childValue); } } return id; }
Example #9
Source File: WebLinkParser.java From sakai with Educational Community License v2.0 | 6 votes |
public void parseContent(DefaultHandler the_handler, CartridgeLoader the_cartridge, Element the_resource, boolean isProtected) throws ParseException { try { //ok, so we're looking at a web link here... Element link = getXML(the_cartridge, ((Element)the_resource.getChildren(FILE, the_handler.getNs().cc_ns()).get(0)).getAttributeValue(HREF)); Namespace linkNs = the_handler.getNs().link_ns(); Element urlElement = link.getChild(URL, linkNs); the_handler.startWebLink(link.getChildText(TITLE, linkNs), urlElement.getAttributeValue(HREF), urlElement.getAttributeValue(TARGET), urlElement.getAttributeValue(WINDOW_FEATURES), isProtected); the_handler.setWebLinkXml(link); the_handler.endWebLink(); } catch (IOException e) { throw new ParseException(e); } }
Example #10
Source File: AnnotationSchema.java From gate-core with GNU Lesser General Public License v3.0 | 6 votes |
/** This method creates an AnnotationSchema object fom an org.jdom.Element * @param anElement is an XSchema element element */ private void createAnnotationSchemaObject(org.jdom.Element anElement, Namespace namespace){ // Get the value of the name attribute. If this attribute doesn't exists // then it will receive a default one. annotationName = anElement.getAttributeValue("name"); if (annotationName == null) annotationName = "UnknownElement"; // See if this element has a complexType element inside it org.jdom.Element complexTypeElement = anElement.getChild("complexType", namespace); if (complexTypeElement != null){ List<?> complexTypeCildrenList = complexTypeElement.getChildren("attribute", namespace); Iterator<?> complexTypeCildrenIterator = complexTypeCildrenList.iterator(); if (complexTypeCildrenIterator.hasNext()) featureSchemaSet = new LinkedHashSet<FeatureSchema>(); while (complexTypeCildrenIterator.hasNext()) { org.jdom.Element childElement = (org.jdom.Element) complexTypeCildrenIterator.next(); createAndAddFeatureSchemaObject(childElement, namespace); }// end while }// end if }
Example #11
Source File: NATO4676Decoder.java From geowave with Apache License 2.0 | 6 votes |
private TrackIdentity readTrackIdentity(final Element element, final Namespace xmlns) { final TrackIdentity trackIdentity = new TrackIdentity(); final List<Element> children = element.getChildren(); final Iterator<Element> childIter = children.iterator(); while (childIter.hasNext()) { final Element child = childIter.next(); final String childName = child.getName(); final String childValue = child.getValue(); if ("identity".equals(childName)) { try { trackIdentity.identity = Identity.valueOf(childValue); } catch (final IllegalArgumentException iae) { LOGGER.warn("Unable to set identity", iae); trackIdentity.identity = null; } } // TODO: Track Identity } return trackIdentity; }
Example #12
Source File: NATO4676Decoder.java From geowave with Apache License 2.0 | 6 votes |
private MissionFrame readFrame(final Element element, final Namespace xmlns) { final MissionFrame frame = new MissionFrame(); final List<Element> children = element.getChildren(); final Iterator<Element> childIter = children.iterator(); while (childIter.hasNext()) { final Element child = childIter.next(); final String childName = child.getName(); final String childValue = child.getValue(); if ("frameNumber".equals(childName)) { frame.setFrameNumber(Integer.parseInt(childValue)); } else if ("frameTimestamp".equals(childName)) { frame.setFrameTime(DateStringToLong(childValue)); } else if ("frameCoverageArea".equals(childName)) { frame.setCoverageArea(readCoverageArea(child, xmlns)); } } return frame; }
Example #13
Source File: JDOMNamespaceContext.java From cxf with Apache License 2.0 | 6 votes |
public static String rawGetPrefix(Element element, String namespaceURI) { if (element.getNamespaceURI().equals(namespaceURI)) { return element.getNamespacePrefix(); } List<?> namespaces = element.getAdditionalNamespaces(); for (Iterator<?> itr = namespaces.iterator(); itr.hasNext();) { Namespace ns = (Namespace)itr.next(); if (ns.getURI().equals(namespaceURI)) { return ns.getPrefix(); } } if (element.getParentElement() != null) { return rawGetPrefix(element.getParentElement(), namespaceURI); } return null; }
Example #14
Source File: PodcastService.java From subsonic with GNU General Public License v3.0 | 5 votes |
private String getITunesAttribute(Element element, String childName, String attributeName) { for (Namespace ns : ITUNES_NAMESPACES) { Element elem = element.getChild(childName, ns); if (elem != null) { return StringUtils.trimToNull(elem.getAttributeValue(attributeName)); } } return null; }
Example #15
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 5 votes |
public static List<Element> getChildrenIgnoreNamespace( final Element parentEl, final String childName, final Namespace[] namespaces, final boolean tryLowerCase) { List<?> el = parentEl.getChildren(childName); if ((el == null) || el.isEmpty()) { for (final Namespace ns : namespaces) { el = parentEl.getChildren(childName, ns); if ((el != null) && (!el.isEmpty())) { break; } } } if ((el == null) && tryLowerCase) { el = getChildrenIgnoreNamespace( parentEl, childName.toLowerCase(Locale.ENGLISH), namespaces, false); } if (el == null) { return new ArrayList<>(); } final List<Element> elementList = new ArrayList<>(); for (final Object element : el) { elementList.add((Element) element); } return elementList; }
Example #16
Source File: JDOMNodePointer.java From commons-jxpath with Apache License 2.0 | 5 votes |
/** * Find the nearest occurrence of the specified attribute * on the specified and enclosing elements. * @param n current node * @param attrName attribute name * @param ns Namespace * @return attribute value */ protected static String findEnclosingAttribute(Object n, String attrName, Namespace ns) { while (n != null) { if (n instanceof Element) { Element e = (Element) n; String attr = e.getAttributeValue(attrName, ns); if (attr != null && !attr.equals("")) { return attr; } } n = nodeParent(n); } return null; }
Example #17
Source File: JDOMStreamWriter.java From cxf with Apache License 2.0 | 5 votes |
public void writeNamespace(String prefix, String namespace) throws XMLStreamException { Namespace decNS = currentNode.getNamespace(prefix); if (decNS == null || !decNS.getURI().equals(namespace)) { currentNode.addNamespaceDeclaration(Namespace.getNamespace(prefix, namespace)); } }
Example #18
Source File: SchemaParser.java From uyuni with GNU General Public License v2.0 | 5 votes |
/** * <p> * This will create a new <code>SchemaParser</code>, given * the URL of the schema to parse. * </p> * * @param schemaURLIn the <code>URL</code> of the schema to parse. * @throws IOException when parsing errors occur. */ public SchemaParser(URL schemaURLIn) throws IOException { this.schemaURL = schemaURLIn; constraints = new LinkedHashMap<String, Constraint>(); schemaNamespace = Namespace.getNamespace(SCHEMA_NAMESPACE_URI); // Parse the schema and prepare constraints parseSchema(); }
Example #19
Source File: DiscussionParser.java From sakai with Educational Community License v2.0 | 5 votes |
public void parseContent(DefaultHandler the_handler, CartridgeLoader the_cartridge, Element the_resource, boolean isProtected) throws ParseException { // none of this is used if (false) { try { //ok, so we're looking at a discussion topic here... Element discussion = getXML(the_cartridge, ((Element)the_resource.getChildren(FILE, the_handler.getNs().cc_ns()).get(0)).getAttributeValue(HREF)); Namespace topicNs = the_handler.getNs().topic_ns(); the_handler.startDiscussion(discussion.getChildText(TITLE, topicNs), discussion.getChild(TEXT, topicNs).getAttributeValue(TEXTTYPE), discussion.getChildText(TEXT, topicNs), isProtected); the_handler.setDiscussionXml(discussion); //discussion may have attachments XPath path = XPath.newInstance(ATTACHMENT_QUERY); if (!topicNs.equals(Namespace.NO_NAMESPACE)) path.addNamespace(topicNs); for (Iterator iter=path.selectNodes(discussion).iterator(); iter.hasNext();) { the_handler.addAttachment(((Element)iter.next()).getAttributeValue(HREF)); } the_handler.endDiscussion(); } catch (IOException e) { throw new ParseException(e); } catch (JDOMException je) { throw new ParseException(je); } } }
Example #20
Source File: PmdProfileImporter.java From sonar-p3c-pmd with MIT License | 5 votes |
protected PmdRuleset parsePmdRuleset(Reader pmdConfigurationFile, ValidationMessages messages) { try { SAXBuilder parser = new SAXBuilder(); Document dom = parser.build(pmdConfigurationFile); Element eltResultset = dom.getRootElement(); Namespace namespace = eltResultset.getNamespace(); PmdRuleset pmdResultset = new PmdRuleset(); for (Element eltRule : getChildren(eltResultset, "rule", namespace)) { PmdRule pmdRule = new PmdRule(eltRule.getAttributeValue("ref")); pmdRule.setClazz(eltRule.getAttributeValue("class")); pmdRule.setName(eltRule.getAttributeValue("name")); pmdRule.setMessage(eltRule.getAttributeValue("message")); parsePmdPriority(eltRule, pmdRule, namespace); parsePmdProperties(eltRule, pmdRule, namespace); pmdResultset.addRule(pmdRule); } return pmdResultset; } catch (Exception e) { String errorMessage = "The PMD configuration file is not valid"; messages.addErrorText(errorMessage + " : " + e.getMessage()); LOG.error(errorMessage, e); return new PmdRuleset(); } }
Example #21
Source File: PodcastService.java From subsonic with GNU General Public License v3.0 | 5 votes |
private String getITunesElement(Element element, String childName) { for (Namespace ns : ITUNES_NAMESPACES) { String value = element.getChildTextTrim(childName, ns); if (value != null) { return value; } } return null; }
Example #22
Source File: SCORM12_DocumentHandler.java From olat with Apache License 2.0 | 5 votes |
/** * @param doc * @return The SCORM Namespace if this doc a SCORM Document - we look for the ADL Namespaces or null if not found in the Document */ protected static Namespace getSCORM_Namespace(final Document doc) { // We'll search all elements for the ADL Namespace boolean found = XMLUtils.containsNamespace(doc, ADLCP_NAMESPACE_12); if (found) { return ADLCP_NAMESPACE_12; } found = XMLUtils.containsNamespace(doc, ADLCP_NAMESPACE_13); if (found) { return ADLCP_NAMESPACE_13; } return null; }
Example #23
Source File: NATO4676Decoder.java From geowave with Apache License 2.0 | 5 votes |
private Area readCoverageArea(final Element element, final Namespace xmlns) { final Area area = new Area(); final List<Element> children = element.getChildren(); final Iterator<Element> childIter = children.iterator(); while (childIter.hasNext()) { final Element child = childIter.next(); final String childName = child.getName(); final String childValue = child.getValue(); if ("areaBoundaryPoints".equals(childName)) { final GeodeticPosition pos = readGeodeticPosition(child, xmlns); area.getPoints().add(pos); } } return area; }
Example #24
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 5 votes |
public static String getStringValIgnoreNamespace( final Element parentEl, final String childName, final Namespace[] namespaces, final boolean tryLowerCase) { final Element el = getChildIgnoreNamespace(parentEl, childName, namespaces, tryLowerCase); if (el != null) { return el.getTextTrim(); } else { return null; } }
Example #25
Source File: ImmutableSameTypeAttributeList.java From consulo with Apache License 2.0 | 5 votes |
Attribute get(String name, Namespace namespace) { if (!myNs.equals(namespace)) return null; for (int i = 0; i < myNameValues.length; i+=2) { String aname = myNameValues[i]; if (aname.equals(name)) { return get(i/2); } } return null; }
Example #26
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 5 votes |
public static Long getLongVal(final Element e, final String childText, final Namespace ns) { try { return Long.valueOf(e.getChildText(childText, ns)); } catch (final NumberFormatException ex) { LOGGER.error("Unable to get value", ex); return null; } }
Example #27
Source File: JDOMUtils.java From geowave with Apache License 2.0 | 5 votes |
@SuppressFBWarnings( value = "NP_BOOLEAN_RETURN_NULL", justification = "its known that it can return null") public static Boolean getBoolValIgnoreNamespace( final Element rootEl, final String tagName, final Namespace[] namespaces, final boolean tryLowerCase) { final String str = getStringValIgnoreNamespace(rootEl, tagName, namespaces, tryLowerCase); if (str != null) { Integer val = null; try { val = Integer.parseInt(str); } catch (final NumberFormatException e) { LOGGER.error("Unable to parse", e); } if (val != null) { if (val == 0) { return false; } else { return true; } } } return null; }
Example #28
Source File: NATO4676Decoder.java From geowave with Apache License 2.0 | 5 votes |
private TrackClassification readTrackClassification( final Element element, final Namespace xmlns) { final TrackClassification trackClassification = new TrackClassification(); final List<Element> children = element.getChildren(); final Iterator<Element> childIter = children.iterator(); while (childIter.hasNext()) { final Element child = childIter.next(); final String childName = child.getName(); final String childValue = child.getValue(); if ("trackItemUUID".equals(childName)) { try { trackClassification.setUuid(UUID.fromString(childValue)); } catch (final IllegalArgumentException iae) { LOGGER.warn("Unable to set uuid", iae); trackClassification.setUuid(null); } } else if ("trackItemSecurity".equals(childName)) { trackClassification.setSecurity(readSecurity(child, xmlns)); } else if ("trackItemTime".equals(childName)) { trackClassification.setTime(DateStringToLong(childValue)); } else if ("trackItemSource".equals(childName)) { trackClassification.setSource(childValue); } else if ("classification".equals(childName)) { trackClassification.classification = ObjectClassification.fromString(childValue); } else if ("classificationCredibility".equals(childName)) { trackClassification.credibility = readClassificationCredibility(child, xmlns); } else if ("numObjects".equals(childName)) { trackClassification.setNumObjects(Integer.parseInt(child.getText())); } } return trackClassification; }
Example #29
Source File: JDOMStreamReader.java From cxf with Apache License 2.0 | 5 votes |
private void setupNamespaces(Element element) { namespaceContext.setElement(element); if (prefix2decNs != null) { namespaceStack.push(prefix2decNs); } prefix2decNs = new HashMap<>(); namespaces.clear(); for (Iterator<?> itr = element.getAdditionalNamespaces().iterator(); itr.hasNext();) { declare((Namespace)itr.next()); } Namespace ns = element.getNamespace(); if (shouldDeclare(ns)) { declare(ns); } for (Iterator<?> itr = element.getAttributes().iterator(); itr.hasNext();) { ns = ((Attribute)itr.next()).getNamespace(); if (shouldDeclare(ns)) { declare(ns); } } }
Example #30
Source File: SchemaParser.java From spacewalk with GNU General Public License v2.0 | 5 votes |
/** * <p> * This will create a new <code>SchemaParser</code>, given * the URL of the schema to parse. * </p> * * @param schemaURLIn the <code>URL</code> of the schema to parse. * @throws IOException when parsing errors occur. */ public SchemaParser(URL schemaURLIn) throws IOException { this.schemaURL = schemaURLIn; constraints = new LinkedHashMap<String, Constraint>(); schemaNamespace = Namespace.getNamespace(SCHEMA_NAMESPACE_URI); // Parse the schema and prepare constraints parseSchema(); }