/**
   * It parses the feature typelist tag
   *
   * @param parser
   * @throws IOException
   * @throws XmlPullParserException
   */
  private void parseFeatureTypeListTag(KXmlParser parser)
      throws IOException, XmlPullParserException {
    int currentTag;
    boolean end = false;

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

    while (!end) {
      switch (currentTag) {
        case KXmlParser.START_TAG:
          if (parser.getName().compareToIgnoreCase(CapabilitiesTags.WFS_FEATURETYPE) == 0) {
            // Parse the namespaces...
            parseNamespaces(parser);
            WFSFeature1_0_0 feature = new WFSFeature1_0_0();
            feature.parse(parser);
            features.put(feature.getName(), feature);
          }
          break;
        case KXmlParser.END_TAG:
          if (parser.getName().compareTo(CapabilitiesTags.WFS_FEATURETYPELIST) == 0) end = true;
          break;
        case KXmlParser.TEXT:
          break;
      }
      if (!end) {
        currentTag = parser.next();
      }
    }
  }
  /**
   * Parse an operation into a DcpType tag
   *
   * @param parser The KXMLParser
   * @param operation The WFS operation to parse
   * @throws IOException
   * @throws XmlPullParserException
   */
  private void parserDcpType(KXmlParser parser, int operation)
      throws XmlPullParserException, IOException {
    int currentTag;
    boolean end = false;

    currentTag = parser.next();

    while (!end) {
      switch (currentTag) {
        case KXmlParser.START_TAG:
          if (parser.getName().compareTo(CapabilitiesTags.HTTP) == 0) {
            parseHTTPTag(parser, operation);
          }
          break;
        case KXmlParser.END_TAG:
          if (parser.getName().compareTo(CapabilitiesTags.DCPTYPE) == 0) end = true;
          break;
        case KXmlParser.TEXT:
          break;
      }
      if (!end) {
        currentTag = parser.next();
      }
    }
  }
  private void parseCapabilityTag(KXmlParser parser) throws IOException, XmlPullParserException {
    int currentTag;
    boolean end = false;

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

    while (!end) {
      switch (currentTag) {
        case KXmlParser.START_TAG:
          if (parser.getName().compareTo(CapabilitiesTags.REQUEST) == 0) {
            parseRequestTag(parser);
          } else if (parser.getName().compareTo(CapabilitiesTags.EXCEPTION) == 0) {
            // TODO Parse exception tags...
            parser.skipSubTree();
          } else if ((parser.getName().compareTo(CapabilitiesTags.VENDORSPECIFICCAPABILITIES) == 0)
              || (parser.getName().compareTo(CapabilitiesTags.USERDEFINEDSYMBOLIZATION) == 0)) {
            parser.skipSubTree();
          }
          break;
        case KXmlParser.END_TAG:
          if (parser.getName().compareTo(CapabilitiesTags.CAPABILITY) == 0) end = true;
          break;
        case KXmlParser.TEXT:
          break;
      }
      if (!end) {
        currentTag = parser.next();
      }
    }
  }
  @Override
  public XmlResourceParser getLayout(int id) throws NotFoundException {
    IResourceValue value = getResourceValue(id, mPlatformResourceFlag);

    if (value != null) {
      File xml = new File(value.getValue());
      if (xml.isFile()) {
        // we need to create a pull parser around the layout XML file, and then
        // give that to our XmlBlockParser
        try {
          KXmlParser parser = new KXmlParser();
          parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
          parser.setInput(new FileReader(xml));

          return new BridgeXmlBlockParser(parser, mContext, mPlatformResourceFlag[0]);
        } catch (XmlPullParserException e) {
          mContext.getLogger().error(e);

          // we'll return null below.
        } catch (FileNotFoundException e) {
          // this shouldn't happen since we check above.
        }
      }
    }

    // id was not found or not resolved. Throw a NotFoundException.
    throwException(id);

    // this is not used since the method above always throws
    return null;
  }
  /** Parses the Request tag */
  private void parseRequestTag(KXmlParser parser) throws IOException, XmlPullParserException {
    int currentTag;
    boolean end = false;

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

    while (!end) {
      switch (currentTag) {
        case KXmlParser.START_TAG:
          if (parser.getName().compareTo(CapabilitiesTags.GETCAPABILITIES) == 0) {
            parserDcpType(parser, WFSOperation.GETCAPABILITIES);
          } else if (parser.getName().compareTo(CapabilitiesTags.WFS_DESCRIBEFEATURETYPE) == 0) {
            parserDcpType(parser, WFSOperation.DESCRIBEFEATURETYPE);
          } else if (parser.getName().compareTo(CapabilitiesTags.WFS_GETFEATURE) == 0) {
            parserDcpType(parser, WFSOperation.GETFEATURE);
          } else if (parser.getName().compareTo(CapabilitiesTags.WFS_LOCKFEATURE) == 0) {
            parserDcpType(parser, WFSOperation.LOCKFEATURE);
          } else if (parser.getName().compareTo(CapabilitiesTags.WFS_TRANSACTION) == 0) {
            parserDcpType(parser, WFSOperation.TRANSACTION);
          }
          break;
        case KXmlParser.END_TAG:
          if (parser.getName().compareTo(CapabilitiesTags.REQUEST) == 0) end = true;
          break;
        case KXmlParser.TEXT:
          break;
      }
      if (!end) {
        currentTag = parser.next();
      }
    }
  }
Exemplo n.º 6
0
 /** put the information from obr.xml into ressourceBundle object. */
 private void parseObrXml() throws MojoExecutionException {
   try {
     InputStream is = new FileInputStream(new File(m_obrXml));
     try {
       KXmlParser kxp = new KXmlParser();
       kxp.setInput(is, null);
       kxp.nextTag(); // skip top level element
       kxp.nextTag(); // go to first child element
       parseObrXml(kxp);
     } finally {
       is.close();
     }
   } catch (Exception e) {
     throw new MojoExecutionException("Unable to parse obr xml: " + m_obrXml, e);
   }
 }
  /**
   * Parse an operation into a HTTP tag
   *
   * @param parser The KXMLParser
   * @param operation The WFS operation to parse
   * @throws IOException
   * @throws XmlPullParserException
   */
  private void parseHTTPTag(KXmlParser parser, int operation)
      throws XmlPullParserException, IOException {
    int currentTag;
    boolean end = false;

    currentTag = parser.next();

    while (!end) {
      switch (currentTag) {
        case KXmlParser.START_TAG:
          int protocol = -1;
          if (parser.getName().compareTo(CapabilitiesTags.GET) == 0) {
            protocol = WFSOperation.PROTOCOL_GET;
          }
          if (parser.getName().compareTo(CapabilitiesTags.POST) == 0) {
            protocol = WFSOperation.PROTOCOL_POST;
          }
          if (protocol > -1) {
            String value = null;
            for (int i = 0; i < parser.getAttributeCount(); i++) {
              if (parser
                      .getAttributeName(i)
                      .toUpperCase()
                      .compareTo(CapabilitiesTags.ONLINERESOURCE.toUpperCase())
                  == 0) {
                value = parser.getAttributeValue(i);
              }
            }
            if (value == null) {
              serviceInfo.addOperation(operation, protocol);
            } else {
              serviceInfo.addOperation(operation, protocol, value);
            }
          }
          break;
        case KXmlParser.END_TAG:
          if (parser.getName().compareTo(CapabilitiesTags.HTTP) == 0) end = true;
          break;
        case KXmlParser.TEXT:
          break;
      }
      if (!end) {
        currentTag = parser.next();
      }
    }
  }
  @Override
  public XmlResourceParser getXml(int id) throws NotFoundException {
    IResourceValue value = getResourceValue(id, mPlatformResourceFlag);

    if (value != null) {
      String v = value.getValue();

      if (v != null) {
        // check this is a file
        File f = new File(value.getValue());
        if (f.isFile()) {
          try {
            KXmlParser parser = new KXmlParser();
            parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
            parser.setInput(new FileReader(f));

            return new BridgeXmlBlockParser(parser, mContext, mPlatformResourceFlag[0]);
          } catch (XmlPullParserException e) {
            NotFoundException newE = new NotFoundException();
            newE.initCause(e);
            throw newE;
          } catch (FileNotFoundException e) {
            NotFoundException newE = new NotFoundException();
            newE.initCause(e);
            throw newE;
          }
        }
      }
    }

    // id was not found or not resolved. Throw a NotFoundException.
    throwException(id);

    // this is not used since the method above always throws
    return null;
  }
Exemplo n.º 9
0
 private void parseObrXml(KXmlParser kxp) throws Exception {
   PullParser parser = new PullParser();
   while (kxp.getEventType() == XmlPullParser.START_TAG) {
     if (RepositoryParser.CATEGORY.equals(kxp.getName())) {
       m_resourceBundle.addCategory(parser.parseCategory(kxp));
     } else if (RepositoryParser.REQUIRE.equals(kxp.getName())) {
       m_resourceBundle.addRequire(parser.parseRequire(kxp));
     } else if (RepositoryParser.CAPABILITY.equals(kxp.getName())) {
       m_resourceBundle.addCapability(parser.parseCapability(kxp));
     } else {
       kxp.nextTag();
       parseObrXml(kxp);
     }
     kxp.nextTag();
   }
 }
Exemplo n.º 10
0
  public static Parameter deserialize(final KXmlParser parser)
      throws XmlPullParserException, IOException {

    String sParent = null;
    boolean bMandatory = true;

    int tag = parser.nextTag();

    boolean bOver = false;
    while (!bOver) {
      switch (tag) {
        case XmlPullParser.START_TAG:
          if (parser.getName().compareTo(ATTRIBUTE) == 0) {
            final String sName = parser.getAttributeValue("", NAME);
            if (sName.compareTo(PARENT) == 0) {
              sParent = parser.getAttributeValue("", VALUE);
            } else if (sName.compareTo(PARENT) == 0) {
              final String sMandatory = parser.getAttributeValue("", VALUE);
              bMandatory = Boolean.parseBoolean(sMandatory);
            }
          }
          break;
        case XmlPullParser.END_TAG:
          if (parser.getName().compareTo(INPUT) == 0) {
            bOver = true;
          }
          break;
        case XmlPullParser.TEXT:
          break;
      }

      if (!bOver) {
        tag = parser.next();
      }
    }

    final ParameterTableField param = new ParameterTableField();
    final AdditionalInfoTableField ai = new AdditionalInfoTableField(sParent, bMandatory);
    param.setParameterAdditionalInfo(ai);

    return param;
  }
Exemplo n.º 11
0
 public void parseConfigurationFile(InputStream in) throws IOException {
   KXmlParser parser = new KXmlParser();
   try {
     parser.setInput(in, "SJIS");
     parser.nextTag();
     parser.require(XmlPullParser.START_TAG, null, "page");
     currentPage = new Page();
     while (parser.nextTag() == XmlPullParser.START_TAG) {
       String tagName = parser.getName();
       System.out.println(tagName);
       if (tagName.equalsIgnoreCase("line")) currentPage.add(createLine(parser));
       else if (tagName.equalsIgnoreCase("box")) currentPage.add(createBox(parser));
       else if (tagName.equalsIgnoreCase("image")) currentPage.add(createPicture(parser));
       // 何故かここでもnextTagしないとうまく動かない。
       parser.nextTag();
     }
   } catch (XmlPullParserException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 12
0
  public Feed parse(final InputStream inputStream) throws FeedParserException, IOException {
    final Feed feed = new Feed();
    final KXmlParser parser = new KXmlParser();

    try {
      parser.setInput(new InputStreamReader(inputStream));
      parser.nextTag();

      parser.require(XmlPullParser.START_TAG, null, "rss");
      parser.nextTag();

      parser.require(XmlPullParser.START_TAG, null, "channel");
      parser.nextTag();

      parseChannel(feed, parser);
    } catch (XmlPullParserException e) {
      throw new FeedParserException(e.getMessage(), e);
    }

    return feed;
  }
Exemplo n.º 13
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();
    }
  }
Exemplo n.º 14
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();
   }
 }
Exemplo n.º 15
0
  /**
   * Crea los ficheros que forman la paleta de color de la version 1.1 a traves de un XML que se le
   * pasa por parametro
   *
   * @param palettesPath
   */
  private static void createVersionFromXML(String palettesBasePath, String xml) {
    new File(palettesBasePath).mkdir();
    KXmlParser parser = new KXmlParser();
    StringReader reader = new StringReader(xml);
    try {
      parser.setInput(reader);
      int tag = parser.nextTag();

      parser.require(KXmlParser.START_TAG, null, "palettes");
      tag = parser.nextTag();
      parser.require(KXmlParser.START_TAG, null, "palette_list");
      parser.skipSubTree();
      parser.require(KXmlParser.END_TAG, null, "palette_list");
      tag = parser.nextTag();

      while (tag == KXmlParser.START_TAG) {
        parser.require(KXmlParser.START_TAG, null, "palette");
        if (parser.getAttributeCount() == 2) {
          // Generar nuevo fichero
          KXmlSerializer parserOutput = new KXmlSerializer();
          FileOutputStream fileOutputStream =
              new FileOutputStream(
                  palettesBasePath + File.separator + parser.getAttributeValue(0) + ".xml");

          parserOutput.setOutput(fileOutputStream, null);
          parserOutput.startDocument("UTF-8", null);
          parserOutput.startTag(null, "ColorTable");
          parserOutput.attribute(null, "name", parser.getAttributeValue(0));
          parserOutput.attribute(null, "version", "1.1");

          tag = parser.nextTag();
          parser.require(KXmlParser.START_TAG, null, "table");
          tag = parser.nextTag();

          parserOutput.text("\n");
          ArrayList items = new ArrayList();
          while (tag == KXmlParser.START_TAG) {
            parser.require(KXmlParser.START_TAG, null, "entry");
            if (parser.getAttributeCount() == 3) {
              String rgb =
                  parser
                      .getAttributeValue(1)
                      .substring(
                          parser.getAttributeValue(1).indexOf(",") + 1,
                          parser.getAttributeValue(1).length());

              int a =
                  Integer.valueOf(
                          parser
                              .getAttributeValue(1)
                              .substring(0, parser.getAttributeValue(1).indexOf(",")))
                      .intValue();
              int r = Integer.valueOf(rgb.substring(0, rgb.indexOf(","))).intValue();
              int g =
                  Integer.valueOf(rgb.substring(rgb.indexOf(",") + 1, rgb.lastIndexOf(",")))
                      .intValue();
              int b =
                  Integer.valueOf(rgb.substring(rgb.lastIndexOf(",") + 1, rgb.length())).intValue();

              ColorItem colorItem = new ColorItem();
              colorItem.setColor(new Color(r, g, b, a));
              colorItem.setInterpolated(50);
              colorItem.setNameClass(parser.getAttributeValue(0));
              colorItem.setValue(Double.parseDouble(parser.getAttributeValue(2)));
              items.add(colorItem);
            }
            tag = parser.nextTag();
            parser.require(KXmlParser.END_TAG, null, "entry");
            tag = parser.nextTag();
          }
          parser.require(KXmlParser.END_TAG, null, "table");
          tag = parser.nextTag();

          ColorTable colorTable = new ColorTable();
          colorTable.createPaletteFromColorItems(items, true);
          items = colorTable.getColorItems();
          for (int i = 0; i < items.size(); i++) {
            ColorItem colorItem = (ColorItem) items.get(i);
            parserOutput.startTag(null, "Color");
            parserOutput.attribute(null, "value", String.valueOf(colorItem.getValue()));
            parserOutput.attribute(null, "name", String.valueOf(colorItem.getNameClass()));
            Color color = colorItem.getColor();
            parserOutput.attribute(
                null,
                "rgb",
                String.valueOf(color.getRed() + "," + color.getGreen() + "," + color.getBlue()));
            parserOutput.attribute(
                null, "interpolated", String.valueOf(colorItem.getInterpolated()));
            parserOutput.endTag(null, "Color");
            parserOutput.text("\n");
          }

          for (int i = 0; i < items.size(); i++) {
            ColorItem colorItem = (ColorItem) items.get(i);
            parserOutput.startTag(null, "Alpha");
            parserOutput.attribute(null, "value", String.valueOf(colorItem.getValue()));
            parserOutput.attribute(null, "alpha", String.valueOf(colorItem.getColor().getAlpha()));
            parserOutput.attribute(
                null, "interpolated", String.valueOf(colorItem.getInterpolated()));
            parserOutput.endTag(null, "Alpha");
            parserOutput.text("\n");
          }

          parserOutput.endTag(null, "ColorTable");
          parserOutput.text("\n");
          parserOutput.endDocument();
          // Cerrar nuevo fichero
          fileOutputStream.close();
        }
        parser.require(KXmlParser.END_TAG, null, "palette");
        tag = parser.nextTag();
      }
      parser.require(KXmlParser.END_TAG, null, "palettes");
    } catch (XmlPullParserException xmlEx) {
      System.out.println(
          "El fichero de paletas predeterminadas no tiene la estructura correcta:\n	"
              + xmlEx.getMessage());
    } catch (IOException e) {
    }
  }
Exemplo n.º 16
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) {
        }
    }
  }
Exemplo n.º 17
0
  public static ArrayList open(final String sFilename) {

    ArrayList images = null;
    final ArrayList elements = new ArrayList();
    HelpElement element = null;
    final KXmlParser parser = new KXmlParser();

    try {
      final File file = new File(sFilename);
      parser.setInput(new FileInputStream(file), encoding);
      int tag = parser.nextTag();
      boolean bOut = false;

      if (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
        while ((tag != XmlPullParser.END_DOCUMENT) && !bOut) {
          switch (tag) {
            case XmlPullParser.START_TAG:
              if (parser.getName().compareTo(HELP) == 0) {
              } else if (parser.getName().compareTo(HelpElement.ELEMENT) == 0) {
                images = new ArrayList();
                final String sText = parser.getAttributeValue("", HelpElement.TEXT);
                final String sName = parser.getAttributeValue("", HelpElement.NAME);
                final String sDescription = parser.getAttributeValue("", HelpElement.DESCRIPTION);
                final int iType = Integer.parseInt(parser.getAttributeValue("", HelpElement.TYPE));
                element = new HelpElement();
                element.setText(sText);
                element.setName(sName);
                element.setType(iType);
                element.setDescription(sDescription);
              } else if (parser.getName().compareTo(ImageAndDescription.IMAGE) == 0) {
                final ImageAndDescription iad = new ImageAndDescription();
                final String sImageFilename =
                    parser.getAttributeValue("", ImageAndDescription.FILE);
                final String sDesc = parser.getAttributeValue("", ImageAndDescription.DESCRIPTION);
                iad.setDescription(sDesc);
                iad.setFilename(sImageFilename);
                images.add(iad);
              }
              break;
            case XmlPullParser.END_TAG:
              if (parser.getName().compareTo(HELP) == 0) {
                bOut = true;
              } else if (parser.getName().compareTo(HelpElement.ELEMENT) == 0) {
                element.setImages(images);
                elements.add(element);
              }
              break;
            case XmlPullParser.TEXT:
              break;
          }
          if (!bOut) {
            tag = parser.next();
          }
        }
      }

    } catch (final Exception e) {
      return null;
    }
    return elements;
  }
Exemplo n.º 18
0
  /**
   * Lee una paleta del fichero xml de paletas y la carga en la tabla del panel.
   *
   * @param palettesPath Camino al fichero de paletas predefinidas.
   * @param paletteName Nombre de paleta a cargar desde el fichero xml.
   * @return Nombre de la paleta
   */
  public static String loadPalette(
      String palettesBasePath, String paletteFileName, ArrayList items) {
    updateVersion(palettesBasePath);

    items.clear();

    File palettesFile = new File(palettesBasePath + File.separator + paletteFileName);
    if (!palettesFile.exists()) return null;

    try {
      String paletteName = "";
      ArrayList rows = new ArrayList();

      KXmlParser parser = new KXmlParser();
      FileInputStream in = new FileInputStream(palettesBasePath + File.separator + paletteFileName);

      InputStreamReader reader = new InputStreamReader(in, "UTF8");
      parser.setInput(reader);
      int tag = parser.nextTag();

      parser.require(KXmlParser.START_TAG, null, "ColorTable");
      for (int i = 0; i < parser.getAttributeCount(); i++) {
        if (parser.getAttributeName(i).equals("name")) {
          paletteName = parser.getAttributeValue(i);
        }
      }
      tag = parser.nextTag();

      while (!((tag == KXmlParser.END_TAG) && (parser.getName().equals("ColorTable")))) {
        try {
          if (tag == KXmlParser.START_TAG) {
            if (parser.getName().equals("Color")) {
              ColorItem colorItem = new ColorItem();
              int a = 255;
              for (int i = 0; i < parser.getAttributeCount(); i++) {
                if (parser.getAttributeName(i).equals("value")) {
                  colorItem.setValue(Double.parseDouble((String) parser.getAttributeValue(i)));
                  ColorItem aux =
                      getColorItem(rows, Double.parseDouble((String) parser.getAttributeValue(i)));
                  if (aux != null) a = aux.getColor().getAlpha();
                }
                if (parser.getAttributeName(i).equals("name")) {
                  colorItem.setNameClass((String) parser.getAttributeValue(i));
                }
                if (parser.getAttributeName(i).equals("rgb")) {
                  String rgb = parser.getAttributeValue(i);
                  int r = Integer.valueOf(rgb.substring(0, rgb.indexOf(","))).intValue();
                  int g =
                      Integer.valueOf(rgb.substring(rgb.indexOf(",") + 1, rgb.lastIndexOf(",")))
                          .intValue();
                  int b =
                      Integer.valueOf(rgb.substring(rgb.lastIndexOf(",") + 1, rgb.length()))
                          .intValue();

                  colorItem.setColor(new Color(r, g, b, a));
                }
                if (parser.getAttributeName(i).equals("interpolated")) {
                  colorItem.setInterpolated(
                      Double.parseDouble((String) parser.getAttributeValue(i)));
                }
              }

              rows.add(colorItem);
              continue;
            }
            if (parser.getName().equals("Alpha")) {
              ColorItem colorItem = new ColorItem();
              for (int i = 0; i < parser.getAttributeCount(); i++) {
                if (parser.getAttributeName(i).equals("value")) {
                  colorItem.setValue(Double.parseDouble((String) parser.getAttributeValue(i)));
                  ColorItem aux =
                      getColorItem(rows, Double.parseDouble((String) parser.getAttributeValue(i)));
                  if (aux != null) {
                    colorItem.setNameClass(aux.getNameClass());
                    colorItem.setInterpolated(aux.getInterpolated());
                    colorItem.setColor(
                        new Color(
                            aux.getColor().getRed(),
                            aux.getColor().getGreen(),
                            aux.getColor().getBlue(),
                            colorItem.getColor().getAlpha()));
                  }
                }
                if (parser.getAttributeName(i).equals("alpha")) {
                  int a = Integer.parseInt(parser.getAttributeValue(i));

                  colorItem.setColor(
                      new Color(
                          colorItem.getColor().getRed(),
                          colorItem.getColor().getGreen(),
                          colorItem.getColor().getBlue(),
                          a));
                }
                if (parser.getAttributeName(i).equals("interpolated")) {
                  colorItem.setInterpolated(
                      Double.parseDouble((String) parser.getAttributeValue(i)));
                }
              }

              rows.add(colorItem);
              continue;
            }
          }
        } finally {
          tag = parser.nextTag();
        }
      }

      for (int i = 0; i < rows.size(); i++) items.add(rows.get(i));

      reader.close();
      return paletteName;
    } catch (FileNotFoundException fnfEx) {
      fnfEx.printStackTrace();
    } catch (XmlPullParserException xmlEx) {
      System.out.println(
          "El fichero de paletas predeterminadas no tiene la estructura correcta:\n	"
              + xmlEx.getMessage());
    } catch (IOException e) {
    }
    return null;
  }
  /** 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();
      }
    }
  }
Exemplo n.º 20
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);
  }
  /**
   * Reads the public.xml file in data/res/values/ for a given resource folder and builds up a map
   * of public resources.
   *
   * <p>This map is a subset of the full resource map that only contains framework resources that
   * are public.
   *
   * @param logger a logger to report issues to
   */
  public void loadPublicResources(@Nullable ILogger logger) {
    IAbstractFolder valueFolder = getResFolder().getFolder(SdkConstants.FD_RES_VALUES);
    if (valueFolder.exists() == false) {
      return;
    }

    IAbstractFile publicXmlFile = valueFolder.getFile("public.xml"); // $NON-NLS-1$
    if (publicXmlFile.exists()) {
      Reader reader = null;
      try {
        reader =
            new BufferedReader(new InputStreamReader(publicXmlFile.getContents(), Charsets.UTF_8));
        KXmlParser parser = new KXmlParser();
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
        parser.setInput(reader);

        ResourceType lastType = null;
        String lastTypeName = "";
        while (true) {
          int event = parser.next();
          if (event == XmlPullParser.START_TAG) {
            // As of API 15 there are a number of "java-symbol" entries here
            if (!parser.getName().equals("public")) { // $NON-NLS-1$
              continue;
            }

            String name = null;
            String typeName = null;
            for (int i = 0, n = parser.getAttributeCount(); i < n; i++) {
              String attribute = parser.getAttributeName(i);

              if (attribute.equals("name")) { // $NON-NLS-1$
                name = parser.getAttributeValue(i);
                if (typeName != null) {
                  // Skip id attribute processing
                  break;
                }
              } else if (attribute.equals("type")) { // $NON-NLS-1$
                typeName = parser.getAttributeValue(i);
              }
            }

            if (name != null && typeName != null) {
              ResourceType type = null;
              if (typeName.equals(lastTypeName)) {
                type = lastType;
              } else {
                type = ResourceType.getEnum(typeName);
                lastType = type;
                lastTypeName = typeName;
              }
              if (type != null) {
                ResourceItem match = null;
                Map<String, ResourceItem> map = mResourceMap.get(type);
                if (map != null) {
                  match = map.get(name);
                }

                if (match != null) {
                  List<ResourceItem> publicList = mPublicResourceMap.get(type);
                  if (publicList == null) {
                    // Pick initial size for the list to hold the public
                    // resources. We could just use map.size() here,
                    // but they're usually much bigger; for example,
                    // in one platform version, there are 1500 drawables
                    // and 1200 strings but only 175 and 25 public ones
                    // respectively.
                    int size;
                    switch (type) {
                      case STYLE:
                        size = 500;
                        break;
                      case ATTR:
                        size = 1000;
                        break;
                      case DRAWABLE:
                        size = 200;
                        break;
                      case ID:
                        size = 50;
                        break;
                      case LAYOUT:
                      case COLOR:
                      case STRING:
                      case ANIM:
                      case INTERPOLATOR:
                        size = 30;
                        break;
                      default:
                        size = 10;
                        break;
                    }
                    publicList = new ArrayList<ResourceItem>(size);
                    mPublicResourceMap.put(type, publicList);
                  }

                  publicList.add(match);
                } else {
                  // log that there's a public resource that doesn't actually
                  // exist?
                }
              } else {
                // log that there was a reference to a typo that doesn't actually
                // exist?
              }
            }
          } else if (event == XmlPullParser.END_DOCUMENT) {
            break;
          }
        }
      } catch (Exception e) {
        if (logger != null) {
          logger.error(e, "Can't read and parse public attribute list");
        }
      } finally {
        if (reader != null) {
          try {
            reader.close();
          } catch (IOException e) {
            // Nothing to be done here - we don't care if it closed or not.
          }
        }
      }
    }

    // put unmodifiable list for all res type in the public resource map
    // this will simplify access
    for (ResourceType type : ResourceType.values()) {
      List<ResourceItem> list = mPublicResourceMap.get(type);
      if (list == null) {
        list = Collections.emptyList();
      } else {
        list = Collections.unmodifiableList(list);
      }

      // put the new list in the map
      mPublicResourceMap.put(type, list);
    }
  }