예제 #1
0
  private void parseNoteOwner(XmlPullParser parser, SnapticNote note)
      throws XmlPullParserException, IOException {
    int eventType = parser.next();

    while (eventType != XmlPullParser.END_DOCUMENT) {
      if (eventType == XmlPullParser.START_TAG) {
        String startTag = parser.getName();

        if (XML_TAG_ID.equals(startTag)) {
          long ownerId = Long.parseLong(parser.nextText());
          note.ownerId = ownerId;
          parse_trace("Owner ID = " + note.ownerId);
        } else if (XML_TAG_USER_NAME.equals(startTag)) {
          String owner = parser.nextText();
          note.owner = owner;
          parse_trace("Owner name = " + note.owner);
        } else {
          parse_trace("(parseNoteOwner) unknown XML tag: <" + startTag + ">");
        }
      } else if (eventType == XmlPullParser.END_TAG) {
        String endTag = parser.getName();

        if (XML_TAG_USER.equals(endTag)) {
          parse_trace("Parsing owner data complete.");
          break;
        }
      }

      eventType = parser.next();
    }
  }
예제 #2
0
  private void parseTags(XmlPullParser parser, SnapticNote note)
      throws XmlPullParserException, IOException {
    ArrayList<CharSequence> tags = new ArrayList<CharSequence>();
    int eventType = parser.next();

    while (eventType != XmlPullParser.END_DOCUMENT) {
      if (eventType == XmlPullParser.START_TAG) {
        String startTag = parser.getName();

        if (XML_TAG_TAG.equals(startTag)) {
          String tag = parser.nextText();
          tags.add(tag);
          parse_trace("Added tag \"" + tag + '"');
        } else {
          parse_trace("(parseTags) unknown XML tag: <" + startTag + ">");
        }
      } else if (eventType == XmlPullParser.END_TAG) {
        String endTag = parser.getName();

        if (XML_TAG_TAGS.equals(endTag)) {
          note.tags = tags;
          parse_trace("Note had " + note.tags.size() + " tag(s).");
          break;
        }
      }

      eventType = parser.next();
    }
  }
예제 #3
0
  private void parseLocation(XmlPullParser parser, SnapticNote note)
      throws XmlPullParserException, IOException {
    int eventType = parser.next();

    while (eventType != XmlPullParser.END_DOCUMENT) {
      if (eventType == XmlPullParser.START_TAG) {
        String startTag = parser.getName();

        if (XML_TAG_LATITUDE.equals(startTag)) {
          double latitude = Double.parseDouble(parser.nextText());
          note.latitude = latitude;
          parse_trace("Latitude = " + note.latitude);
        } else if (XML_TAG_LONGITUDE.equals(startTag)) {
          double longitude = Double.parseDouble(parser.nextText());
          note.longitude = longitude;
          parse_trace("Longitude = " + note.longitude);
        } else if (XML_TAG_ALTITUDE.equals(startTag)) {
          double altitude = Double.parseDouble(parser.nextText());
          note.altitude = altitude;
          parse_trace("Altitude = " + note.altitude);
        } else if (XML_TAG_SPEED.equals(startTag)) {
          double speed = Double.parseDouble(parser.nextText());
          note.speed = speed;
          parse_trace("Speed = " + note.speed);
        } else if (XML_TAG_BEARING.equals(startTag)) {
          double bearing = Double.parseDouble(parser.nextText());
          note.bearing = bearing;
          parse_trace("Bearing = " + note.bearing);
        } else if (XML_TAG_ACCURACY_POSITION.equals(startTag)) {
          double accuracyPosition = Double.parseDouble(parser.nextText());
          note.accuracyPosition = accuracyPosition;
          parse_trace("Positional accuracy = " + note.accuracyPosition);
        } else if (XML_TAG_ACCURACY_ALTITUDE.equals(startTag)) {
          double accuracyAltitude = Double.parseDouble(parser.nextText());
          note.accuracyAltitude = accuracyAltitude;
          parse_trace("Altitude accuracy = " + note.accuracyAltitude);
        } else {
          parse_trace("(parseLocation) unknown XML tag: <" + startTag + ">");
        }
      } else if (eventType == XmlPullParser.END_TAG) {
        String endTag = parser.getName();

        if (XML_TAG_LOCATION.equals(endTag)) {
          parse_trace("Parsing geotag complete.");
          break;
        }
      }

      eventType = parser.next();
    }
  }
예제 #4
0
  private void parseNote(XmlPullParser parser, ArrayList<SnapticNote> returnVal)
      throws XmlPullParserException, IOException {
    // Create a blank note object
    SnapticNote note = new SnapticNote();
    returnVal.add(note);
    int eventType = parser.next();

    while (eventType != XmlPullParser.END_DOCUMENT) {
      if (eventType == XmlPullParser.START_TAG) {
        String startTag = parser.getName();

        // one-liners:
        if (XML_TAG_ID.equals(startTag)) {
          long nodeId = Long.parseLong(parser.nextText());
          note.id = nodeId;
          parse_trace("Note ID is " + note.id);
        } else if (XML_TAG_PARENT_ID.equals(startTag)) {
          long parentId = Long.parseLong(parser.nextText());
          note.parentId = parentId;
          parse_trace("Parent ID is " + note.parentId);
        } else if (XML_TAG_SOURCE.equals(startTag)) {
          String source = parser.nextText();
          note.source = source;
          parse_trace("Note source is " + note.source);
        } else if (XML_TAG_SOURCE_URL.equals(startTag)) {
          String sourceUrl = parser.nextText();
          note.sourceUrl = sourceUrl;
          parse_trace("Note source URL is " + note.sourceUrl);
        } else if (XML_TAG_CREATED.equals(startTag)) {
          String creationTime = parser.nextText();
          note.creationTime = parse3339(creationTime);
          parse_trace("Creation time is " + creationTime + " (" + note.creationTime + ')');
        } else if (XML_TAG_MODIFIED.equals(startTag)) {
          String modificationTime = parser.nextText();
          note.modificationTime = parse3339(modificationTime);
          parse_trace(
              "Modification time is " + modificationTime + " (" + note.modificationTime + ')');
        } else if (XML_TAG_REMINDER.equals(startTag)) {
          String reminderTime = parser.nextText();
          note.reminderTime = parse3339(reminderTime);
          parse_trace("Reminder time is " + reminderTime + " (" + note.reminderTime + ')');
        } else if (XML_TAG_TEXT.equals(startTag)) {
          String text = parser.nextText();
          note.text = text;
          parse_trace("Note text is \"" + note.text + '"');
        } else if (XML_TAG_SUMMARY.equals(startTag)) {
          String summary = parser.nextText();
          note.summary = summary;
          parse_trace("Note summary is \"" + note.summary + '"');
        } else if (XML_TAG_CHILDREN.equals(startTag)) {
          long childCount = Long.parseLong(parser.nextText());
          note.children = childCount;
          parse_trace("Child count is " + note.children);
        } else if (XML_TAG_MODE.equals(startTag)) {
          String mode = parser.nextText();
          note.mode = mode;
          parse_trace("Mode is " + note.mode);
        } else if (XML_TAG_PUBLIC_URL.equals(startTag)) {
          String publicUrl = parser.nextText();
          note.publicUrl = publicUrl;
          parse_trace("Public URL is " + note.publicUrl);
        }
        // new blocks:
        else if (XML_TAG_USER.equals(startTag)) {
          parse_trace("Parsing note owner data.");
          parseNoteOwner(parser, note);
        } else if (XML_TAG_TAGS.equals(startTag)) {
          parse_trace("Parsing note tags.");
          parseTags(parser, note);
        } else if (XML_TAG_LOCATION.equals(startTag)) {
          parse_trace("Parsing geotag.");
          parseLocation(parser, note);
        } else if (XML_TAG_MEDIA.equals(startTag)) {
          parse_trace("Parsing media list.");
          parseMedia(parser, note);
        } else {
          parse_trace("(parseNote) unknown XML tag: <" + startTag + ">");
        }
      } else if (eventType == XmlPullParser.END_TAG) {
        String endTag = parser.getName();

        if (XML_TAG_NOTE.equals(endTag)) {
          parse_trace("Parsing note complete.");
          break;
        }
      }

      eventType = parser.next();
    }
  }