Java Code Examples for org.jdom.Element#getNamespace()

The following examples show how to use org.jdom.Element#getNamespace() . 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: PmdProfileImporter.java    From sonar-p3c-pmd with MIT License 5 votes vote down vote up
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 2
Source File: LyricsService.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
private LyricsInfo parseSearchResult(String xml) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    Document document = builder.build(new StringReader(xml));

    Element root = document.getRootElement();
    Namespace ns = root.getNamespace();

    String lyric = StringUtils.trimToNull(root.getChildText("Lyric", ns));
    String song =  root.getChildText("LyricSong", ns);
    String artist =  root.getChildText("LyricArtist", ns);

    return new LyricsInfo(lyric, artist, song);
}
 
Example 3
Source File: PlaylistService.java    From subsonic with GNU General Public License v3.0 5 votes vote down vote up
public Pair<List<MediaFile>, List<String>> parse(BufferedReader reader, MediaFileService mediaFileService) throws IOException {
    List<MediaFile> ok = new ArrayList<MediaFile>();
    List<String> error = new ArrayList<String>();

    SAXBuilder builder = new SAXBuilder();
    Document document;
    try {
        document = builder.build(reader);
    } catch (JDOMException x) {
        LOG.warn("Failed to parse XSPF playlist.", x);
        throw new IOException("Failed to parse XSPF playlist.");
    }

    Element root = document.getRootElement();
    Namespace ns = root.getNamespace();
    Element trackList = root.getChild("trackList", ns);
    List<?> tracks = trackList.getChildren("track", ns);

    for (Object obj : tracks) {
        Element track = (Element) obj;
        String location = track.getChildText("location", ns);
        if (location != null && location.startsWith("file://")) {
            location = location.replaceFirst("file://", "");
            MediaFile file = getMediaFile(location);
            if (file != null) {
                ok.add(file);
            } else {
                error.add(location);
            }
        }
    }
    return new Pair<List<MediaFile>, List<String>>(ok, error);
}
 
Example 4
Source File: JDOMStreamReader.java    From cxf with Apache License 2.0 5 votes vote down vote up
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 5
Source File: NATO4676Decoder.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public NATO4676Message readNext(final InputStream is) {
  NATO4676Message msg = null;
  try {
    if (printNotParse) {
      final String trackStr = IOUtils.toString(is, "UTF-8");
      is.reset();
    } else {
      final SAXBuilder builder = new SAXBuilder();
      final Document doc = builder.build(is);

      final Element rootEl = doc.getRootElement();
      final Namespace xmlns = rootEl.getNamespace();

      final String name = rootEl.getName();
      if ("TrackMessage".equals(name)) {
        msg = readTrackMessage(rootEl, xmlns);
        LOGGER.info(
            "TrackMessage read "
                + trackStatsNumTracks
                + " Tracks and "
                + trackStatsNumDots
                + " TrackPoints.");
      } else if ("MissionSummary".equals(name)) {
        msg = readMissionSummaryMessage(rootEl, xmlns);
      }
    }
  } catch (final JDOMParseException jdomPe) {
    LOGGER.info("jdomParseException: " + jdomPe.getLocalizedMessage(), jdomPe);
    return null;
  } catch (final IOException ioe) {
    LOGGER.info("IO exception: " + ioe.getLocalizedMessage(), ioe);
    return null;
  } catch (final JDOMException jdome) {
    LOGGER.info("jdomException: " + jdome.getLocalizedMessage(), jdome);
    return null;
  }

  return msg;
}