Java Code Examples for org.jdom2.Namespace#equals()
The following examples show how to use
org.jdom2.Namespace#equals() .
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: MCRXPathBuilder.java From mycore with GNU General Public License v3.0 | 6 votes |
/** * Returns the namespace prefix for this element, followed by a ":", * or the empty string if no namespace prefix known. */ public static String getNamespacePrefix(Element element) { Namespace nsElement = element.getNamespace(); for (Namespace ns : MCRConstants.getStandardNamespaces()) { if (ns.equals(nsElement)) { return ns.getPrefix() + ":"; } } String prefix = nsElement.getPrefix(); if ((prefix != null) && !prefix.isEmpty()) { return prefix + ":"; } else { return ""; } }
Example 2
Source File: BaseWireFeedParser.java From rome with Apache License 2.0 | 6 votes |
protected List<Element> extractForeignMarkup(final Element e, final Extendable ext, final Namespace namespace) { final ArrayList<Element> foreignElements = new ArrayList<Element>(); for (final Element element : e.getChildren()) { if (!namespace.equals(element.getNamespace()) && ext.getModule(element.getNamespaceURI()) == null) { // if element not in the RSS namespace and elem was not handled by a module save it // as foreign markup but we can't detach it while we're iterating foreignElements.add(element.clone()); } } // now we can detach the foreign markup elements for (final Element foreignElement : foreignElements) { foreignElement.detach(); } return foreignElements; }
Example 3
Source File: RSS090Parser.java From rome with Apache License 2.0 | 6 votes |
@Override public boolean isMyType(final Document document) { final Element rssRoot = document.getRootElement(); final Namespace defaultNS = rssRoot.getNamespace(); final List<Namespace> additionalNSs = rssRoot.getAdditionalNamespaces(); boolean myType = false; if (defaultNS != null && defaultNS.equals(getRDFNamespace()) && additionalNSs != null) { for (final Namespace namespace : additionalNSs) { if (getRSSNamespace().equals(namespace)) { myType = true; break; } } } return myType; }
Example 4
Source File: NcmlCollectionReader.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static NcmlCollectionReader readXML(org.jdom2.Document doc, Formatter errlog, String ncmlLocation) { if (showParsedXML) { XMLOutputter xmlOut = new XMLOutputter(); System.out.println("*** NetcdfDataset/showParsedXML = \n" + xmlOut.outputString(doc) + "\n*******"); } Element netcdfElem = doc.getRootElement(); Namespace myNS = netcdfElem.getNamespace(); // detect incorrect namespace if (!myNS.equals(Catalog.ncmlNS) && !myNS.equals(Catalog.ncmlNSHttps)) { errlog.format("Incorrect namespace specified in NcML= %s must be %s%n or %s%n", myNS.getURI(), Catalog.ncmlNS.getURI(), Catalog.ncmlNSHttps.getURI()); return null; } Element aggElem = netcdfElem.getChild("aggregation", myNS); if (aggElem == null) { errlog.format("NcML must have aggregation element"); return null; } String type = aggElem.getAttributeValue("type"); if (!type.equals("forecastModelRunCollection") && !type.equals("forecastModelRunSingleCollection") && !type.equals("fmrc")) { errlog.format("NcML aggregation must be of type fmrc"); return null; } return new NcmlCollectionReader(ncmlLocation, netcdfElem); }
Example 5
Source File: MCRXMLHelper.java From mycore with GNU General Public License v3.0 | 5 votes |
public static boolean equivalentName(Element e1, Element e2) { Namespace ns1 = e1.getNamespace(); String localName1 = e1.getName(); Namespace ns2 = e2.getNamespace(); String localName2 = e2.getName(); return ns1.equals(ns2) && localName1.equals(localName2); }
Example 6
Source File: RSS20YahooParser.java From rome with Apache License 2.0 | 5 votes |
/** * Indicates if a JDom document is an RSS instance that can be parsed with the parser. * <p/> * It checks for RDF ("http://www.w3.org/1999/02/22-rdf-syntax-ns#") and RSS * ("http://purl.org/rss/1.0/") namespaces being defined in the root element. * * @param document document to check if it can be parsed with this parser implementation. * @return <b>true</b> if the document is RSS1., <b>false</b> otherwise. */ @Override public boolean isMyType(final Document document) { boolean ok = false; final Element rssRoot = document.getRootElement(); final Namespace defaultNS = rssRoot.getNamespace(); ok = defaultNS != null && defaultNS.equals(getRSSNamespace()); return ok; }
Example 7
Source File: ModuleParsers.java From rome with Apache License 2.0 | 5 votes |
private boolean hasElementsFrom(final Element root, final Namespace namespace) { boolean hasElements = false; for (final Element child : root.getChildren()) { final Namespace childNamespace = child.getNamespace(); if (namespace.equals(childNamespace)) { hasElements = true; break; } } return hasElements; }
Example 8
Source File: RSSRDF10Parser.java From commafeed with Apache License 2.0 | 5 votes |
@Override public boolean isMyType(Document document) { boolean ok = false; Element rssRoot = document.getRootElement(); Namespace defaultNS = rssRoot.getNamespace(); List<Namespace> additionalNSs = Lists.newArrayList(rssRoot.getAdditionalNamespaces()); List<Element> children = rssRoot.getChildren(); if (CollectionUtils.isNotEmpty(children)) { Element child = children.get(0); additionalNSs.add(child.getNamespace()); additionalNSs.addAll(child.getAdditionalNamespaces()); } ok = defaultNS != null && defaultNS.equals(getRDFNamespace()); if (ok) { if (additionalNSs == null) { ok = false; } else { ok = false; for (int i = 0; !ok && i < additionalNSs.size(); i++) { ok = getRSSNamespace().equals(additionalNSs.get(i)); } } } return ok; }
Example 9
Source File: NcMLReader.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * parse a netcdf JDOM Element, and add contents to the targetDS NetcdfDataset. * <p/> * This is a bit tricky, because it handles several cases * When targetDS == refds, we are just modifying targetDS. * When targetDS != refds, we keep them seperate, and copy from refds to newds. * <p/> * The user may be defining new elements or modifying old ones. The only way to tell is by seeing * if the elements already exist. * * @param ncmlLocation NcML URL location, or may be just a unique name for caching purposes. * @param targetDS add the info to this one, never null * @param refds the referenced dataset; may equal newds, never null * @param netcdfElem JDOM netcdf element * @param cancelTask allow user to cancel the task; may be null * @throws IOException on read error */ private void readNetcdf(String ncmlLocation, NetcdfDataset targetDS, NetcdfFile refds, Element netcdfElem, CancelTask cancelTask) throws IOException { this.location = ncmlLocation; // log messages need this if (debugOpen) System.out .println("NcMLReader.readNetcdf ncml= " + ncmlLocation + " referencedDatasetUri= " + refds.getLocation()); // detect incorrect namespace Namespace use = netcdfElem.getNamespace(); if (!use.equals(ncNSHttp) && !use.equals(ncNSHttps)) { String message = String.format("Namespace specified in NcML must be either '%s' or '%s', but was '%s'.", ncNSHttp.getURI(), ncNSHttps.getURI(), use.getURI()); throw new IllegalArgumentException(message); } if (ncmlLocation != null) targetDS.setLocation(ncmlLocation); targetDS.setId(netcdfElem.getAttributeValue("id")); targetDS.setTitle(netcdfElem.getAttributeValue("title")); // aggregation first Element aggElem = netcdfElem.getChild("aggregation", ncNS); if (aggElem != null) { Aggregation agg = readAgg(aggElem, ncmlLocation, targetDS, cancelTask); if (agg == null) return; // cancel task targetDS.setAggregation(agg); agg.finish(cancelTask); } // the root group readGroup(targetDS, refds, null, null, netcdfElem); String errors = errlog.toString(); if (!errors.isEmpty()) throw new IllegalArgumentException("NcML had fatal errors:" + errors); // transfer from groups to global containers targetDS.finish(); // enhance means do scale/offset and/or add CoordSystems Set<NetcdfDataset.Enhance> mode = NetcdfDataset.parseEnhanceMode(netcdfElem.getAttributeValue("enhance")); // if (mode == null) // mode = NetcdfDataset.getEnhanceDefault(); targetDS.enhance(mode); // optionally add record structure to netcdf-3 String addRecords = netcdfElem.getAttributeValue("addRecords"); if ("true".equalsIgnoreCase(addRecords)) targetDS.sendIospMessage(NetcdfFile.IOSP_MESSAGE_ADD_RECORD_STRUCTURE); }
Example 10
Source File: NcMLReaderNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * parse a netcdf JDOM Element, and add contents to the targetDS NetcdfDataset. * <p/> * This is a bit tricky, because it handles several cases When targetDS == refds, we are just modifying targetDS. When * targetDS != refds, * we keep them seperate, and copy from refds to newds. * <p/> * The user may be defining new elements or modifying old ones. The only way to tell is by seeing if the elements * already exist. * * @param ncmlLocation NcML URL location, or may be just a unique name for caching purposes. * @param builder add the info to this one * @param netcdfElem JDOM netcdf element * @param cancelTask allow user to cancel the task; may be null * @throws IOException on read error */ private void readNetcdf(String ncmlLocation, NetcdfDataset.Builder builder, Element netcdfElem, @Nullable CancelTask cancelTask) throws IOException { this.location = ncmlLocation; // log messages need this // detect incorrect namespace Namespace use = netcdfElem.getNamespace(); if (!use.equals(ncNSHttp) && !use.equals(ncNSHttps)) { String message = String.format("Namespace specified in NcML must be either '%s' or '%s', but was '%s'.", ncNSHttp.getURI(), ncNSHttps.getURI(), use.getURI()); throw new IllegalArgumentException(message); } if (ncmlLocation != null) { builder.setLocation(ncmlLocation); } builder.setId(netcdfElem.getAttributeValue("id")); builder.setTitle(netcdfElem.getAttributeValue("title")); Element aggElem = netcdfElem.getChild("aggregation", ncNS); if (aggElem != null) { Aggregation agg = readAgg(aggElem, ncmlLocation, builder, cancelTask); builder.setAggregation(agg); agg.build(cancelTask); // LOOK seems like we should add the agg metadata here, so that it can be modified. } // read the root group and recurse readGroup(builder, null, null, netcdfElem); String errors = errlog.toString(); if (!errors.isEmpty()) { throw new IllegalArgumentException("NcML had fatal errors:" + errors); } // enhance means do scale/offset and/or add CoordSystems Set<NetcdfDataset.Enhance> mode = parseEnhanceMode(netcdfElem.getAttributeValue("enhance")); if (mode != null) { // cant just set enhance mode if (DatasetEnhancer.enhanceNeeded(mode, null)) { DatasetEnhancer enhancer = new DatasetEnhancer(builder, mode, cancelTask); enhancer.enhance(); builder.setEnhanceMode(mode); } } /* * LOOK optionally add record structure to netcdf-3 * String addRecords = netcdfElem.getAttributeValue("addRecords"); * if ("true".equalsIgnoreCase(addRecords)) * targetDS.sendIospMessage(NetcdfFile.IOSP_MESSAGE_ADD_RECORD_STRUCTURE); */ }
Example 11
Source File: Atom10Parser.java From rome with Apache License 2.0 | 4 votes |
@Override public boolean isMyType(final Document document) { final Element rssRoot = document.getRootElement(); final Namespace defaultNS = rssRoot.getNamespace(); return defaultNS != null && defaultNS.equals(getAtomNamespace()); }
Example 12
Source File: RSS20wNSParser.java From rome with Apache License 2.0 | 4 votes |
@Override public boolean isMyType(final Document document) { final Element rssRoot = document.getRootElement(); final Namespace defaultNS = rssRoot.getNamespace(); return defaultNS != null && defaultNS.equals(getRSSNamespace()) && super.isMyType(document); }
Example 13
Source File: Atom03Parser.java From rome with Apache License 2.0 | 4 votes |
@Override public boolean isMyType(final Document document) { final Element rssRoot = document.getRootElement(); final Namespace defaultNS = rssRoot.getNamespace(); return defaultNS != null && defaultNS.equals(getAtomNamespace()); }
Example 14
Source File: RSS10Parser.java From rome with Apache License 2.0 | 3 votes |
/** * Indicates if a JDom document is an RSS instance that can be parsed with the parser. * <p/> * It checks for RDF ("http://www.w3.org/1999/02/22-rdf-syntax-ns#") namespace being defined in * the root element and for the RSS 1.0 ("http://purl.org/rss/1.0/") namespace in the channel * element. * * @param document document to check if it can be parsed with this parser implementation. * @return <b>true</b> if the document is RSS1., <b>false</b> otherwise. */ @Override public boolean isMyType(final Document document) { final Element rssRoot = document.getRootElement(); final Namespace defaultNS = rssRoot.getNamespace(); return defaultNS != null && defaultNS.equals(getRDFNamespace()) && rssRoot.getChild("channel", getRSSNamespace()) != null; }