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;
}
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);
}
}
Aggregations