Example #1
0
  public T walk(XmlPullParser parser) throws XmlPullParserException {
    final T result = prepareTarget(parser, new QName(parser.getNamespace(), parser.getName()));

    next(parser);

    // walk through all tags
    while (true) {
      int event = parser.getEventType();
      if (event == XmlPullParser.START_TAG) {
        QName name = new QName(parser.getNamespace(), parser.getName());
        if (!read(parser, name, result)) {
          if (result instanceof ExtensionsData) {
            handleExtension(parser, (ExtensionsData) result);
          } else {
            skip(parser);
          }
        }
      } else if (event == XmlPullParser.END_TAG) {
        break;
      } else {
        if (!next(parser)) {
          break;
        }
      }
    }

    next(parser);

    return result;
  }
Example #2
0
  private CmisExtensionElement handleExtensionLevel(final XmlPullParser parser, final int level)
      throws XmlPullParserException {
    final QName name = new QName(parser.getNamespace(), parser.getName());
    Map<String, String> attributes = null;
    StringBuilder sb = new StringBuilder();
    List<CmisExtensionElement> children = null;

    if (parser.getAttributeCount() > 0) {
      attributes = new HashMap<String, String>();

      for (int i = 0; i < parser.getAttributeCount(); i++) {
        attributes.put(parser.getAttributeName(i), parser.getAttributeValue(i));
      }
    }

    next(parser);

    while (true) {
      int event = parser.getEventType();
      if (event == XmlPullParser.END_TAG) {
        break;
      } else if (event == XmlPullParser.TEXT) {
        String s = parser.getText();
        if (s != null) {
          if (sb.length() + s.length() > XMLConstraints.MAX_STRING_LENGTH) {
            throw new CmisInvalidArgumentException("String limit exceeded!");
          }
          sb.append(s);
        }
      } else if (event == XmlPullParser.START_TAG) {
        if (level + 1 > XMLConstraints.MAX_EXTENSIONS_DEPTH) {
          throw new CmisInvalidArgumentException("Extensions tree too deep!");
        }

        if (children == null) {
          children = new ArrayList<CmisExtensionElement>();
        }

        if (children.size() + 1 > XMLConstraints.MAX_EXTENSIONS_WIDTH) {
          throw new CmisInvalidArgumentException("Extensions tree too wide!");
        }

        children.add(handleExtensionLevel(parser, level + 1));

        continue;
      }

      if (!next(parser)) {
        break;
      }
    }

    next(parser);

    if (children != null) {
      return new CmisExtensionElementImpl(
          name.getNamespaceURI(), name.getLocalPart(), attributes, children);
    } else {
      return new CmisExtensionElementImpl(
          name.getNamespaceURI(), name.getLocalPart(), attributes, sb.toString());
    }
  }