use of javax.xml.stream.Location in project karaf by apache.
the class StaxParser method parseResource.
private static ResourceImpl parseResource(URI repositoryUrl, XMLStreamReader reader) {
try {
if (reader.getAttributeCount() > 0) {
throw new IllegalStateException("Unexpected attribute '" + reader.getAttributeLocalName(0) + "'");
}
ResourceImpl resource = new ResourceImpl();
int event;
while ((event = reader.nextTag()) == START_ELEMENT) {
String element = reader.getLocalName();
switch(element) {
case CAPABILITY:
CapabilityImpl cap = parseCapability(reader, resource);
// Resolve relative resource urls now
if (repositoryUrl != null && ContentNamespace.CONTENT_NAMESPACE.equals(cap.getNamespace())) {
Object url = cap.getAttributes().get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE);
if (url instanceof String) {
url = repositoryUrl.resolve(url.toString()).toString();
cap.getAttributes().put(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, url);
}
}
resource.addCapability(cap);
break;
case REQUIREMENT:
resource.addRequirement(parseRequirement(reader, resource));
break;
default:
while ((event = reader.next()) != END_ELEMENT) {
switch(event) {
case START_ELEMENT:
throw new IllegalStateException("Unexpected element '" + reader.getLocalName() + "' inside 'resource' element");
case CHARACTERS:
throw new IllegalStateException("Unexpected text inside 'resource' element");
default:
break;
}
}
break;
}
}
// Sanity check
sanityCheckEndElement(reader, event, RESOURCE);
return resource;
} catch (Exception e) {
Location loc = reader.getLocation();
if (loc != null) {
throw new IllegalStateException("Error while parsing resource at line " + loc.getLineNumber() + " and column " + loc.getColumnNumber(), e);
} else {
throw new IllegalStateException("Error while parsing resource", e);
}
}
}
Aggregations