Search in sources :

Example 1 with NamespaceException

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;
}
Also used : NamespaceException(javax.jcr.NamespaceException) IOException(java.io.IOException)

Example 2 with NamespaceException

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));
    }
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) InvalidSerializedDataException(javax.jcr.InvalidSerializedDataException) NamespaceException(javax.jcr.NamespaceException) Name(org.apache.jackrabbit.spi.Name) SAXException(org.xml.sax.SAXException)

Example 3 with NamespaceException

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);
    }
}
Also used : StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) NamespaceException(javax.jcr.NamespaceException) PrivilegeDefinitionWriter(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionWriter) IOException(java.io.IOException) Name(org.apache.jackrabbit.spi.Name)

Example 4 with NamespaceException

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);
    }
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) NamespaceException(javax.jcr.NamespaceException) Name(org.apache.jackrabbit.spi.Name)

Example 5 with NamespaceException

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();
}
Also used : Path(org.apache.jackrabbit.spi.Path) NamespaceException(javax.jcr.NamespaceException)

Aggregations

NamespaceException (javax.jcr.NamespaceException)56 Name (org.apache.jackrabbit.spi.Name)26 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)17 Path (org.apache.jackrabbit.spi.Path)13 InvalidQueryException (javax.jcr.query.InvalidQueryException)10 RepositoryException (javax.jcr.RepositoryException)7 PathQueryNode (org.apache.jackrabbit.spi.commons.query.PathQueryNode)7 NamespaceRegistry (javax.jcr.NamespaceRegistry)6 IllegalNameException (org.apache.jackrabbit.spi.commons.conversion.IllegalNameException)6 LocationStepQueryNode (org.apache.jackrabbit.spi.commons.query.LocationStepQueryNode)6 IOException (java.io.IOException)5 Session (javax.jcr.Session)5 DerefQueryNode (org.apache.jackrabbit.spi.commons.query.DerefQueryNode)5 PropertyFunctionQueryNode (org.apache.jackrabbit.spi.commons.query.PropertyFunctionQueryNode)5 SAXException (org.xml.sax.SAXException)5 InvalidSerializedDataException (javax.jcr.InvalidSerializedDataException)4 NodeTypeQueryNode (org.apache.jackrabbit.spi.commons.query.NodeTypeQueryNode)4 NotQueryNode (org.apache.jackrabbit.spi.commons.query.NotQueryNode)4 OrderQueryNode (org.apache.jackrabbit.spi.commons.query.OrderQueryNode)4 QueryNode (org.apache.jackrabbit.spi.commons.query.QueryNode)4