use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class FileBasedNamespaceMappings method getPrefix.
/**
* Returns a prefix for the namespace <code>uri</code>. If a namespace
* mapping exists, the already known prefix is returned; otherwise a new
* prefix is created and assigned to the namespace uri.
*
* @param uri the namespace uri.
* @return the prefix for the namespace uri.
* @throws NamespaceException if an yet unknown namespace uri / prefix
* mapping could not be stored.
*/
public synchronized String getPrefix(String uri) throws NamespaceException {
String prefix = uriToPrefix.get(uri);
if (prefix == null) {
// make sure prefix is not taken
while (prefixToURI.get(String.valueOf(prefixCount)) != null) {
prefixCount++;
}
prefix = String.valueOf(prefixCount);
prefixToURI.put(prefix, uri);
uriToPrefix.put(uri, prefix);
log.debug("adding new namespace mapping: " + prefix + " -> " + uri);
try {
store();
} catch (IOException e) {
throw new NamespaceException("Could not obtain a prefix for uri: " + uri, e);
}
}
return prefix;
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class SysViewImportHandler method startElement.
//-------------------------------------------------------< ContentHandler >
/**
* {@inheritDoc}
*/
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
Name name = NameFactoryImpl.getInstance().create(namespaceURI, localName);
// check element name
if (name.equals(NameConstants.SV_NODE)) {
// sv:node element
// node name (value of sv:name attribute)
String svName = getAttribute(atts, NameConstants.SV_NAME);
if (svName == null) {
throw new SAXException(new InvalidSerializedDataException("missing mandatory sv:name attribute of element sv:node"));
}
if (!stack.isEmpty()) {
// process current node first
ImportState current = stack.peek();
// need to start current node
if (!current.started) {
processNode(current, true, false);
current.started = true;
}
}
// push new ImportState instance onto the stack
ImportState state = new ImportState();
try {
state.nodeName = resolver.getQName(svName);
} catch (NameException e) {
throw new SAXException(new InvalidSerializedDataException("illegal node name: " + name, e));
} catch (NamespaceException e) {
throw new SAXException(new InvalidSerializedDataException("illegal node name: " + name, e));
}
stack.push(state);
} else if (name.equals(NameConstants.SV_PROPERTY)) {
// sv:property element
// reset temp fields
currentPropValues.clear();
// property name (value of sv:name attribute)
String svName = getAttribute(atts, NameConstants.SV_NAME);
if (svName == null) {
throw new SAXException(new InvalidSerializedDataException("missing mandatory sv:name attribute of element sv:property"));
}
try {
currentPropName = resolver.getQName(svName);
} catch (NameException e) {
throw new SAXException(new InvalidSerializedDataException("illegal property name: " + name, e));
} catch (NamespaceException e) {
throw new SAXException(new InvalidSerializedDataException("illegal property name: " + name, e));
}
// property type (sv:type attribute)
String type = getAttribute(atts, NameConstants.SV_TYPE);
if (type == null) {
throw new SAXException(new InvalidSerializedDataException("missing mandatory sv:type attribute of element sv:property"));
}
try {
currentPropType = PropertyType.valueFromName(type);
} catch (IllegalArgumentException e) {
throw new SAXException(new InvalidSerializedDataException("Unknown property type: " + type, e));
}
// 'multi-value' hint (sv:multiple attribute)
String multiple = getAttribute(atts, NameConstants.SV_MULTIPLE);
if (multiple != null) {
currentPropMultipleStatus = MultipleStatus.MULTIPLE;
} else {
currentPropMultipleStatus = MultipleStatus.UNKNOWN;
}
} else if (name.equals(NameConstants.SV_VALUE)) {
// sv:value element
currentPropValue = new BufferedStringValue(resolver, valueFactory);
String xsiType = atts.getValue("xsi:type");
currentPropValue.setBase64("xs:base64Binary".equals(xsiType));
} else {
throw new SAXException(new InvalidSerializedDataException("Unexpected element in system view xml document: " + name));
}
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class AbstractRecord method writePrivilegeDef.
/**
* {@inheritDoc}
*/
public void writePrivilegeDef(PrivilegeDefinition privilegeDefinition) throws JournalException {
try {
Map<String, String> nsMapping = new HashMap<String, String>();
String uri = privilegeDefinition.getName().getNamespaceURI();
nsMapping.put(nsResolver.getPrefix(uri), uri);
for (Name n : privilegeDefinition.getDeclaredAggregateNames()) {
nsMapping.put(nsResolver.getPrefix(n.getNamespaceURI()), n.getNamespaceURI());
}
StringWriter sw = new StringWriter();
PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter("text/xml");
writer.writeDefinitions(sw, new PrivilegeDefinition[] { privilegeDefinition }, nsMapping);
sw.close();
writeString(sw.toString());
} catch (IOException e) {
String msg = "I/O error while writing privilege definition.";
throw new JournalException(msg, e);
} catch (NamespaceException e) {
String msg = "NamespaceException error while writing privilege definition.";
throw new JournalException(msg, e);
}
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class AbstractRecord method readPathElement.
/**
* {@inheritDoc}
*/
public Path readPathElement() throws JournalException {
try {
Name name = resolver.getQName(readString());
int index = readInt();
if (index != 0) {
return PathFactoryImpl.getInstance().create(name, index);
} else {
return PathFactoryImpl.getInstance().create(name);
}
} catch (NameException e) {
String msg = "Unknown prefix error while reading path element.";
throw new JournalException(msg, e);
} catch (NamespaceException e) {
String msg = "Illegal name error while reading path element.";
throw new JournalException(msg, e);
}
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class RepositoryServiceImpl method saveGetIdString.
private String saveGetIdString(ItemId id, NamePathResolver resolver) {
StringBuffer bf = new StringBuffer();
String uid = id.getUniqueID();
if (uid != null) {
bf.append(uid);
}
Path p = id.getPath();
if (p != null) {
if (resolver == null) {
bf.append(p.toString());
} else {
try {
bf.append(resolver.getJCRPath(p));
} catch (NamespaceException e) {
bf.append(p.toString());
}
}
}
return bf.toString();
}
Aggregations