コード例 #1
0
ファイル: HelpIO.java プロジェクト: Yaqiang/sextante
  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;
  }