Search in sources :

Example 1 with XmlParseException

use of org.openforis.idm.metamodel.xml.XmlParseException in project collect by openforis.

the class UIOptionsBinder method unmarshalTabSet.

private UITabSet unmarshalTabSet(XmlPullParser parser, UIOptions uiOptions) throws IOException, XmlPullParserException, XmlParseException {
    try {
        UITabSetPR tabSetPR = new UITabSetPR(this, uiOptions);
        tabSetPR.parse(parser);
        UITabSet tabSet = tabSetPR.getTabSet();
        return tabSet;
    } catch (XmlParseException e) {
        if (parser != null && parser.getEventType() == XmlPullParser.END_DOCUMENT) {
            return null;
        } else {
            throw e;
        }
    }
}
Also used : UITabSetPR(org.openforis.collect.persistence.xml.internal.unmarshal.UITabSetPR) UITabSet(org.openforis.collect.metamodel.ui.UITabSet) XmlParseException(org.openforis.idm.metamodel.xml.XmlParseException)

Example 2 with XmlParseException

use of org.openforis.idm.metamodel.xml.XmlParseException in project collect by openforis.

the class NumericAttributeDefinitionPR method onStartDefinition.

@Override
protected void onStartDefinition() throws XmlParseException, XmlPullParserException, IOException {
    super.onStartDefinition();
    String typeStr = getAttribute(TYPE, false);
    NumericAttributeDefinition defn = (NumericAttributeDefinition) getDefinition();
    try {
        Type type = typeStr == null ? Type.REAL : Type.valueOf(typeStr.toUpperCase());
        defn.setType(type);
    } catch (IllegalArgumentException e) {
        throw new XmlParseException(getParser(), "unknown type " + typeStr);
    }
}
Also used : Type(org.openforis.idm.metamodel.NumericAttributeDefinition.Type) XmlParseException(org.openforis.idm.metamodel.xml.XmlParseException) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition)

Example 3 with XmlParseException

use of org.openforis.idm.metamodel.xml.XmlParseException in project collect by openforis.

the class XmlPullReader method readElement.

protected void readElement(XmlSerializer out, boolean includeOuterTag) throws XmlParseException, XmlPullParserException, IOException {
    XmlPullParser in = getParser();
    if (in.getEventType() != START_TAG) {
        throw new XmlParseException(in, "start tag expected");
    }
    if (out != null && includeOuterTag) {
        out.startTag(in.getNamespace(), in.getName());
    }
    int depth = 1;
    while (depth != 0) {
        switch(in.next()) {
            case START_TAG:
                if (out != null) {
                    out.setPrefix("", in.getNamespace());
                    out.startTag(in.getNamespace(), in.getName());
                    for (int i = 0; i < in.getAttributeCount(); i++) {
                        String attributeNamespace = in.getAttributeNamespace(i);
                        String attributeName = in.getAttributeName(i);
                        String attributeValue = in.getAttributeValue(i);
                        out.attribute(attributeNamespace, attributeName, attributeValue);
                    }
                }
                depth++;
                break;
            case END_TAG:
                if (out != null && (includeOuterTag || depth > 1)) {
                    out.endTag(in.getNamespace(), in.getName());
                }
                depth--;
                break;
            case TEXT:
                if (out != null) {
                    out.text(in.getText());
                }
                break;
            case CDSECT:
                if (out != null) {
                    out.cdsect(in.getText());
                }
                break;
            case ENTITY_REF:
                if (out != null) {
                    out.entityRef(in.getText());
                }
                break;
        }
    }
    if (out != null) {
        out.flush();
    }
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlParseException(org.openforis.idm.metamodel.xml.XmlParseException)

Example 4 with XmlParseException

use of org.openforis.idm.metamodel.xml.XmlParseException in project collect by openforis.

the class XmlPullReader method getAttribute.

protected String getAttribute(String attr, boolean required) throws XmlParseException {
    XmlPullParser parser = getParser();
    String value = getAttributeValue(parser, namespace, attr);
    if (required && (value == null || value.isEmpty())) {
        throw new XmlParseException(parser, "missing required attribute " + attr);
    }
    return value;
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlParseException(org.openforis.idm.metamodel.xml.XmlParseException)

Example 5 with XmlParseException

use of org.openforis.idm.metamodel.xml.XmlParseException in project collect by openforis.

the class XmlPullReader method parse.

public synchronized void parse(Reader reader) throws XmlParseException, IOException {
    try {
        XmlPullParser parser = createParser();
        parser.setInput(reader);
        parse(parser);
    } catch (XmlPullParserException e) {
        throw new XmlParseException(getParser(), e.getMessage(), e);
    }
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) XmlParseException(org.openforis.idm.metamodel.xml.XmlParseException)

Aggregations

XmlParseException (org.openforis.idm.metamodel.xml.XmlParseException)9 XmlPullParser (org.xmlpull.v1.XmlPullParser)5 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)4 UITabSet (org.openforis.collect.metamodel.ui.UITabSet)1 UITabSetPR (org.openforis.collect.persistence.xml.internal.unmarshal.UITabSetPR)1 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)1 Type (org.openforis.idm.metamodel.NumericAttributeDefinition.Type)1 TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)1