Пример #1
0
  private void parseItem(Feed feed, KXmlParser parser) throws IOException, XmlPullParserException {
    final Entry entry = new Entry();
    feed.getEntries().add(entry);

    parser.nextTag();

    while (parser.getEventType() != XmlPullParser.END_TAG) {
      final String nodeName = parser.getName();

      if ("title".equals(nodeName)) {
        entry.setTitle(parser.nextText());
      } else if ("link".equals(nodeName)) {
        entry.setLink(parser.nextText());
      } else if ("description".equals(nodeName)) {
        entry.setDescription(parser.nextText());
      } else if ("author".equals(nodeName)) {
        entry.setAuthor(parser.nextText());
      } else if ("category".equals(nodeName)) {
        entry.setCategory(parser.nextText());
      } else if ("comments".equals(nodeName)) {
        entry.setComments(parser.nextText());
      } else if ("enclosure".equals(nodeName)) {
        entry.setEnclosure(parser.nextText());
      } else if ("guid".equals(nodeName)) {
        entry.setGuid(parser.nextText());
      } else if ("pubDate".equals(nodeName)) {
        entry.setPubDate(parser.nextText());
      } else if ("source".equals(nodeName)) {
        entry.setSource(parser.nextText());
      } else {
        parser.skipSubTree();
      }
      parser.nextTag();
    }
  }
Пример #2
0
 private void parseChannel(Feed feed, KXmlParser parser)
     throws XmlPullParserException, IOException {
   while (parser.getEventType() != XmlPullParser.END_TAG) {
     final String nodeName = parser.getName();
     if ("title".equals(nodeName)) {
       feed.setTitle(parser.nextText());
     } else if ("link".equals(nodeName)) {
       feed.setLink(parser.nextText());
     } else if ("description".equals(nodeName)) {
       feed.setDescription(parser.nextText());
     } else if ("language".endsWith(nodeName)) {
       feed.setLanguage(parser.nextText());
     } else if ("pubDate".endsWith(nodeName)) {
       feed.setPubDate(parser.nextText());
     } else if ("lastBuildDate".endsWith(nodeName)) {
       feed.setLastBuildDate(parser.nextText());
     } else if ("generator".endsWith(nodeName)) {
       feed.setGenerator(parser.nextText());
     } else if ("managingEditor".endsWith(nodeName)) {
       feed.setManagingEditor(parser.nextText());
     } else if ("webMaster".endsWith(nodeName)) {
       feed.setWebMaster(parser.nextText());
     } else if ("item".endsWith(nodeName)) {
       parseItem(feed, parser);
     } else if ("image".endsWith(nodeName)) {
       feed.setImage(parser.nextText());
     } else {
       parser.skipSubTree();
     }
     parser.nextTag();
   }
 }
  /** Parses the Service Information */
  private void parseServiceTag(KXmlParser parser) throws IOException, XmlPullParserException {
    int currentTag;
    boolean end = false;

    parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.SERVICE);
    currentTag = parser.next();

    while (!end) {
      switch (currentTag) {
        case KXmlParser.START_TAG:
          if (parser.getName().compareToIgnoreCase(CapabilitiesTags.NAME) == 0) {
            serviceInfo.name = parser.nextText();
          } else if (parser.getName().compareTo(CapabilitiesTags.WFS_TITLE) == 0) {
            serviceInfo.title = parser.nextText();
          } else if (parser.getName().compareTo(CapabilitiesTags.WFS_ABSTRACT) == 0) {
            serviceInfo.abstr = parser.nextText();
          } else if (parser.getName().compareTo(CapabilitiesTags.ONLINERESOURCE) == 0) {
            serviceInfo.online_resource = parser.nextText();
          }
          break;
        case KXmlParser.END_TAG:
          if (parser.getName().compareTo(CapabilitiesTags.SERVICE) == 0) end = true;
          break;
        case KXmlParser.TEXT:
          break;
      }
      if (!end) {
        currentTag = parser.next();
      }
    }
  }
Пример #4
0
  /**
   * Comprueba si un fichero VRT esta en correcto estado, en caso contrario lanza una excepcion
   * indicando el tipo de error en la apertura.
   *
   * @param file
   * @throws FileOpenVRTException
   */
  private void checkFileVRT(File file) throws FileOpenVRTException {
    KXmlParser parser = new KXmlParser();

    FileReader fileReader = null;
    try {
      fileReader = new FileReader(file);
      parser.setInput(fileReader);

      parser.nextTag();

      parser.require(XmlPullParser.START_TAG, null, "VRTDataset");

      while (parser.nextTag() != XmlPullParser.END_TAG) {
        parser.require(XmlPullParser.START_TAG, null, "VRTRasterBand");

        String name;
        while (parser.nextTag() != XmlPullParser.END_TAG) {
          parser.require(XmlPullParser.START_TAG, null, null);
          boolean relativePath = false;
          for (int i = 0; i < parser.getAttributeCount(); i++) {
            if (parser.getAttributeName(i).equals("relativetoVRT")
                && parser.getAttributeValue(i).equals("1")) relativePath = true;
          }
          name = parser.getName();
          String nameFile = parser.nextText();
          if (name.equals("SourceFilename")) {
            if (relativePath) nameFile = file.getParent() + File.separator + nameFile;
            File tryFile = new File(nameFile);
            if (!tryFile.exists())
              throw new FileOpenVRTException(
                  PluginServices.getText(this, "no_existe_fichero") + " " + nameFile);
          }
          parser.require(XmlPullParser.END_TAG, null, name);
        }

        parser.require(XmlPullParser.END_TAG, null, "VRTRasterBand");
      }
      parser.require(XmlPullParser.END_TAG, null, "VRTDataset");
      parser.next();
      parser.require(XmlPullParser.END_DOCUMENT, null, null);
    } catch (XmlPullParserException e) {
      throw new FileOpenVRTException(
          PluginServices.getText(this, "el_fichero")
              + " "
              + file.getName().toString()
              + " "
              + PluginServices.getText(this, "esta_formato_desconocido"));
    } catch (IOException e) {
      throw new FileOpenVRTException(
          PluginServices.getText(this, "no_puede_abrir_fichero") + " " + file.getName().toString());
    } finally {
      if (fileReader != null)
        try {
          fileReader.close();
        } catch (IOException e) {
        }
    }
  }
Пример #5
0
  /**
   * Parses the legendURL tag.
   *
   * @param parser
   * @throws IOException
   * @throws XmlPullParserException
   */
  protected void parseLegendURL(KXmlParser parser) throws IOException, XmlPullParserException {
    int currentTag;
    boolean end = false;

    parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.LEGENDURL);

    String value = new String();
    legendURL = new LegendURL();

    // First of all set whether the layer is Queryable reading the
    // attribute.
    value = parser.getAttributeValue("", CapabilitiesTags.WIDTH);
    if (value != null) {
      legendURL.width = Integer.parseInt(value);
    }
    value = parser.getAttributeValue("", CapabilitiesTags.HEIGHT);
    if (value != null) {
      legendURL.height = Integer.parseInt(value);
    }
    currentTag = parser.nextTag();

    while (!end) {
      switch (currentTag) {
        case KXmlParser.START_TAG:
          if (parser.getName().compareTo(CapabilitiesTags.FORMAT) == 0) {
            legendURL.format = parser.nextText();
          } else if (parser.getName().compareTo(CapabilitiesTags.ONLINERESOURCE) == 0) {
            value = parser.getAttributeValue("", CapabilitiesTags.XLINK_TYPE);
            if (value != null) legendURL.onlineResource_type = value;
            value = parser.getAttributeValue("", CapabilitiesTags.XLINK_HREF);
            if (value != null) legendURL.onlineResource_href = value;
          }
          break;
        case KXmlParser.END_TAG:
          if (parser.getName().compareTo(CapabilitiesTags.LEGENDURL) == 0) end = true;
          break;
        case KXmlParser.TEXT:
          break;
      }
      if (!end) {
        currentTag = parser.next();
      }
    }
    parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.LEGENDURL);
  }