use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class PathConstraint method create.
static PathConstraint create(String jcrPath, PathResolver resolver) throws InvalidConstraintException {
try {
// constraint format: absolute or relative path with optional
// trailing wild card
boolean deep = jcrPath.endsWith(JCR_WILDCARD);
Path path;
if (JCR_WILDCARD.equals(jcrPath)) {
path = PATH_FACTORY.getRootPath();
} else {
if (deep) {
// trim trailing wild card before building path
jcrPath = jcrPath.substring(0, jcrPath.length() - JCR_WILDCARD.length());
}
path = resolver.getQPath(jcrPath);
}
StringBuffer definition = new StringBuffer(path.getString());
if (deep) {
definition.append(WILDCARD);
}
return new PathConstraint(definition.toString(), path, deep);
} catch (NameException e) {
String msg = "Invalid path expression specified as value constraint: " + jcrPath;
log.debug(msg);
throw new InvalidConstraintException(msg, e);
} catch (NamespaceException e) {
String msg = "Invalid path expression specified as value constraint: " + jcrPath;
log.debug(msg);
throw new InvalidConstraintException(msg, e);
}
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class NodeTypeWriter method write.
/**
* Writes a node type definition file. The file contents are written
* to the given output stream and will contain the given node type
* definitions. The given namespace registry is used for namespace
* mappings.
*
* @param xml XML output stream
* @param registry namespace registry
* @param types node types
* @throws IOException if the node type definitions cannot
* be written
* @throws RepositoryException on repository errors
*/
public static void write(OutputStream xml, QNodeTypeDefinition[] types, NamespaceRegistry registry) throws IOException, RepositoryException {
try {
NodeTypeWriter writer = new NodeTypeWriter(registry);
for (QNodeTypeDefinition type : types) {
writer.addNodeTypeDef(type);
}
writer.write(xml);
} catch (ParserConfigurationException e) {
IOException e2 = new IOException(e.getMessage());
e2.initCause(e);
throw e2;
} catch (NamespaceException e) {
throw new RepositoryException("Invalid namespace reference in a node type definition", e);
}
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class EventState method setupCachingPathResolver.
private static void setupCachingPathResolver() {
if (cachingPathResolver != null) {
return;
}
PathResolver pathResolver = new ParsingPathResolver(PathFactoryImpl.getInstance(), new NameResolver() {
public Name getQName(String name) throws IllegalNameException, NamespaceException {
return null;
}
public String getJCRName(Name name) throws NamespaceException {
return name.getLocalName();
}
});
cachingPathResolver = new CachingPathResolver(pathResolver);
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class AbstractSession method setNamespacePrefix.
/**
* Modifies the session local namespace mappings to contain the given
* prefix to URI mapping.
* <p>
* This behaviour is based on JSR 283 (JCR 2.0), but remains backwards
* compatible with JCR 1.0.
*
* @param prefix namespace prefix
* @param uri namespace URI
* @throws NamespaceException if the mapping is illegal
* @throws RepositoryException if a repository error occurs
*/
public void setNamespacePrefix(String prefix, String uri) throws NamespaceException, RepositoryException {
if (prefix == null) {
throw new IllegalArgumentException("Prefix must not be null");
} else if (uri == null) {
throw new IllegalArgumentException("Namespace must not be null");
} else if (prefix.length() == 0) {
throw new NamespaceException("Empty prefix is reserved and can not be remapped");
} else if (uri.length() == 0) {
throw new NamespaceException("Default namespace is reserved and can not be remapped");
} else if (prefix.toLowerCase().startsWith("xml")) {
throw new NamespaceException("XML prefixes are reserved: " + prefix);
} else if (!XMLChar.isValidNCName(prefix)) {
throw new NamespaceException("Prefix is not a valid XML NCName: " + prefix);
}
synchronized (namespaces) {
// Remove existing mapping for the given prefix
namespaces.remove(prefix);
// Remove existing mapping(s) for the given URI
Set<String> prefixes = new HashSet<String>();
for (Map.Entry<String, String> entry : namespaces.entrySet()) {
if (entry.getValue().equals(uri)) {
prefixes.add(entry.getKey());
}
}
namespaces.keySet().removeAll(prefixes);
// Add the new mapping
namespaces.put(prefix, uri);
}
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class ParserTest method fuzz.
public void fuzz(String query) throws Exception {
for (int i = 0; i < 100; i++) {
StringBuffer buff = new StringBuffer(query);
int changes = 1 + (int) Math.abs(random.nextGaussian() * 2);
for (int j = 0; j < changes; j++) {
char newChar;
if (random.nextBoolean()) {
String s = "<>_.+\"*%&/()=?[]{}_:;,.-1234567890.qersdf";
newChar = s.charAt(random.nextInt(s.length()));
} else {
newChar = (char) random.nextInt(255);
}
int pos = random.nextInt(buff.length());
if (random.nextBoolean()) {
// 50%: change one character
buff.setCharAt(pos, newChar);
} else {
if (random.nextBoolean()) {
// 25%: delete one character
buff.deleteCharAt(pos);
} else {
// 25%: insert one character
buff.insert(pos, newChar);
}
}
}
String q = buff.toString();
try {
parser.createQueryObjectModel(q);
} catch (ValueFormatException e) {
// OK
} catch (InvalidQueryException e) {
// OK
} catch (NamespaceException e) {
// OK?
} catch (Throwable t) {
t.printStackTrace();
assertTrue("Unexpected exception for query " + q + ": " + t, false);
}
}
}
Aggregations