Search in sources :

Example 6 with ParseException

use of org.apache.sling.jcr.contentparser.ParseException in project sling by apache.

the class ParserHelper method convertSingleTypeArray.

public Object convertSingleTypeArray(Object[] values) {
    if (values.length == 0) {
        return values;
    }
    Class<?> itemType = null;
    for (Object value : values) {
        if (value == null) {
            throw new ParseException("Multivalue array must not contain null values.");
        }
        if (value instanceof Map || value instanceof JsonObject) {
            throw new ParseException("Multivalue array must not contain maps/objects.");
        }
        if (itemType == null) {
            itemType = value.getClass();
        } else if (itemType != value.getClass()) {
            throw new ParseException("Multivalue array must not contain values with different types " + "(" + itemType.getName() + ", " + value.getClass().getName() + ").");
        }
    }
    Object convertedArray = Array.newInstance(itemType, values.length);
    for (int i = 0; i < values.length; i++) {
        Array.set(convertedArray, i, values[i]);
    }
    return convertedArray;
}
Also used : JsonObject(javax.json.JsonObject) JsonObject(javax.json.JsonObject) ParseException(org.apache.sling.jcr.contentparser.ParseException) Map(java.util.Map)

Example 7 with ParseException

use of org.apache.sling.jcr.contentparser.ParseException in project sling by apache.

the class JcrXmlContentParser method parse.

@Override
public void parse(ContentHandler handler, InputStream is) throws IOException, ParseException {
    try {
        XmlHandler xmlHandler = new XmlHandler(handler);
        SAXParser parser = saxParserFactory.newSAXParser();
        parser.parse(is, xmlHandler);
        if (xmlHandler.hasError()) {
            throw xmlHandler.getError();
        }
    } catch (ParserConfigurationException | SAXException ex) {
        throw new ParseException("Error parsing JCR XML content.", ex);
    }
}
Also used : SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXParseException(org.xml.sax.SAXParseException) ParseException(org.apache.sling.jcr.contentparser.ParseException) SAXException(org.xml.sax.SAXException)

Aggregations

ParseException (org.apache.sling.jcr.contentparser.ParseException)7 IOException (java.io.IOException)2 JsonObject (javax.json.JsonObject)2 JsonString (javax.json.JsonString)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXException (org.xml.sax.SAXException)2 StringReader (java.io.StringReader)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JsonArray (javax.json.JsonArray)1 JsonNumber (javax.json.JsonNumber)1 JsonReader (javax.json.JsonReader)1 JsonParsingException (javax.json.stream.JsonParsingException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 SAXParser (javax.xml.parsers.SAXParser)1 Resource (org.apache.sling.api.resource.Resource)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 SAXParseException (org.xml.sax.SAXParseException)1