Search in sources :

Example 6 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException 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 7 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.

the class DocViewImportHandler method startElement.

//-------------------------------------------------------< ContentHandler >
/**
     * {@inheritDoc}
     * <p>
     * See also {@link org.apache.jackrabbit.commons.xml.Exporter#exportProperties(Node)}
     * regarding special handling of multi-valued properties on export.
     */
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
    // process buffered character data
    processCharacters();
    try {
        Name nodeName = NameFactoryImpl.getInstance().create(namespaceURI, localName);
        // process node name
        nodeName = processName(nodeName);
        // properties
        NodeId id = null;
        Name nodeTypeName = null;
        Name[] mixinTypes = null;
        List<PropInfo> props = new ArrayList<PropInfo>(atts.getLength());
        for (int i = 0; i < atts.getLength(); i++) {
            if (atts.getURI(i).equals(Name.NS_XMLNS_URI)) {
                // see http://issues.apache.org/jira/browse/JCR-620#action_12448164
                continue;
            }
            Name propName = NameFactoryImpl.getInstance().create(atts.getURI(i), atts.getLocalName(i));
            // process property name
            propName = processName(propName);
            // value(s)
            String attrValue = atts.getValue(i);
            TextValue[] propValues;
            // always assume single-valued property for the time being
            // until a way of properly serializing/detecting multi-valued
            // properties on re-import is found (see JCR-325);
            // see also DocViewSAXEventGenerator#leavingProperties(Node, int)
            // todo proper multi-value serialization support
            propValues = new TextValue[1];
            propValues[0] = new StringValue(attrValue, resolver, valueFactory);
            if (propName.equals(NameConstants.JCR_PRIMARYTYPE)) {
                // jcr:primaryType
                if (attrValue.length() > 0) {
                    try {
                        nodeTypeName = resolver.getQName(attrValue);
                    } catch (NameException ne) {
                        throw new SAXException("illegal jcr:primaryType value: " + attrValue, ne);
                    }
                }
            } else if (propName.equals(NameConstants.JCR_MIXINTYPES)) {
                // jcr:mixinTypes
                mixinTypes = parseNames(attrValue);
            } else if (propName.equals(NameConstants.JCR_UUID)) {
                // jcr:uuid
                if (attrValue.length() > 0) {
                    id = NodeId.valueOf(attrValue);
                }
            } else {
                props.add(new PropInfo(propName, PropertyType.UNDEFINED, propValues));
            }
        }
        NodeInfo node = new NodeInfo(nodeName, nodeTypeName, mixinTypes, id);
        // all information has been collected, now delegate to importer
        importer.startNode(node, props);
        // push current node data onto stack
        stack.push(node);
    } catch (RepositoryException re) {
        throw new SAXException(re);
    }
}
Also used : ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) SAXException(org.xml.sax.SAXException) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) IllegalNameException(org.apache.jackrabbit.spi.commons.conversion.IllegalNameException) NodeId(org.apache.jackrabbit.core.id.NodeId)

Example 8 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.

the class URIResolverImpl method buildPropertyId.

PropertyId buildPropertyId(NodeId parentId, MultiStatusResponse response, String workspaceName, NamePathResolver resolver) throws RepositoryException {
    IdURICache cache = getCache(workspaceName);
    if (cache.containsUri(response.getHref())) {
        ItemId id = cache.getItemId(response.getHref());
        if (!id.denotesNode()) {
            return (PropertyId) id;
        }
    }
    try {
        DavPropertySet propSet = response.getProperties(DavServletResponse.SC_OK);
        Name name = resolver.getQName(propSet.get(JcrRemotingConstants.JCR_NAME_LN, ItemResourceConstants.NAMESPACE).getValue().toString());
        PropertyId propertyId = service.getIdFactory().createPropertyId(parentId, name);
        cache.add(response.getHref(), propertyId);
        return propertyId;
    } catch (NameException e) {
        throw new RepositoryException(e);
    }
}
Also used : DavPropertySet(org.apache.jackrabbit.webdav.property.DavPropertySet) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) RepositoryException(javax.jcr.RepositoryException) ItemId(org.apache.jackrabbit.spi.ItemId) PropertyId(org.apache.jackrabbit.spi.PropertyId) Name(org.apache.jackrabbit.spi.Name)

Example 9 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException 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 10 with NameException

use of org.apache.jackrabbit.spi.commons.conversion.NameException in project jackrabbit by apache.

the class InternalValue method create.

/**
     * Create a new internal value from the given JCR value.
     * If the data store is enabled, large binary values are stored in the data store.
     *
     * @param value the JCR value
     * @param resolver
     * @param store the data store
     * @return the created internal value
     * @throws RepositoryException
     * @throws ValueFormatException
     */
public static InternalValue create(Value value, NamePathResolver resolver, DataStore store) throws ValueFormatException, RepositoryException {
    switch(value.getType()) {
        case PropertyType.BINARY:
            BLOBFileValue blob = null;
            if (value instanceof BinaryValueImpl) {
                BinaryValueImpl bin = (BinaryValueImpl) value;
                DataIdentifier identifier = bin.getDataIdentifier();
                if (identifier != null) {
                    if (bin.usesDataStore(store)) {
                        // access the record to ensure it is not garbage collected
                        store.getRecord(identifier);
                        blob = BLOBInDataStore.getInstance(store, identifier);
                    } else {
                        if (store.getRecordIfStored(identifier) != null) {
                            // it exists - so we don't need to stream it again
                            // but we need to create a new object because the original
                            // one might be in a different data store (repository)
                            blob = BLOBInDataStore.getInstance(store, identifier);
                        }
                    }
                }
            }
            if (blob == null) {
                Binary b = value.getBinary();
                boolean dispose = false;
                try {
                    if (b instanceof BLOBFileValue) {
                        // use as is
                        blob = (BLOBFileValue) b;
                    } else {
                        // create a copy from the stream
                        dispose = true;
                        blob = getBLOBFileValue(store, b.getStream(), true);
                    }
                } finally {
                    if (dispose) {
                        b.dispose();
                    }
                }
            }
            return new InternalValue(blob);
        case PropertyType.BOOLEAN:
            return create(value.getBoolean());
        case PropertyType.DATE:
            return create(value.getDate());
        case PropertyType.DOUBLE:
            return create(value.getDouble());
        case PropertyType.DECIMAL:
            return create(value.getDecimal());
        case PropertyType.LONG:
            return create(value.getLong());
        case PropertyType.REFERENCE:
            return create(new NodeId(value.getString()));
        case PropertyType.WEAKREFERENCE:
            return create(new NodeId(value.getString()), true);
        case PropertyType.URI:
            try {
                return create(new URI(value.getString()));
            } catch (URISyntaxException e) {
                throw new ValueFormatException(e.getMessage());
            }
        case PropertyType.NAME:
            try {
                if (value instanceof QValueValue) {
                    QValue qv = ((QValueValue) value).getQValue();
                    if (qv instanceof InternalValue) {
                        return (InternalValue) qv;
                    } else {
                        return create(qv.getName());
                    }
                } else {
                    return create(resolver.getQName(value.getString()));
                }
            } catch (NameException e) {
                throw new ValueFormatException(e.getMessage());
            }
        case PropertyType.PATH:
            try {
                if (value instanceof QValueValue) {
                    QValue qv = ((QValueValue) value).getQValue();
                    if (qv instanceof InternalValue) {
                        return (InternalValue) qv;
                    } else {
                        return create(qv.getPath());
                    }
                } else {
                    return create(resolver.getQPath(value.getString(), false));
                }
            } catch (MalformedPathException mpe) {
                throw new ValueFormatException(mpe.getMessage());
            }
        case PropertyType.STRING:
            return create(value.getString());
        default:
            throw new IllegalArgumentException("illegal value");
    }
}
Also used : QValueValue(org.apache.jackrabbit.spi.commons.value.QValueValue) AbstractQValue(org.apache.jackrabbit.spi.commons.value.AbstractQValue) QValue(org.apache.jackrabbit.spi.QValue) DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) MalformedPathException(org.apache.jackrabbit.spi.commons.conversion.MalformedPathException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) NodeId(org.apache.jackrabbit.core.id.NodeId) ValueFormatException(javax.jcr.ValueFormatException) Binary(javax.jcr.Binary)

Aggregations

NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)65 RepositoryException (javax.jcr.RepositoryException)44 Name (org.apache.jackrabbit.spi.Name)38 Path (org.apache.jackrabbit.spi.Path)20 NamespaceException (javax.jcr.NamespaceException)17 ArrayList (java.util.ArrayList)16 IllegalNameException (org.apache.jackrabbit.spi.commons.conversion.IllegalNameException)9 SAXException (org.xml.sax.SAXException)8 Node (javax.jcr.Node)6 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)6 InvalidQueryException (javax.jcr.query.InvalidQueryException)6 NodeId (org.apache.jackrabbit.core.id.NodeId)6 IOException (java.io.IOException)5 ItemNotFoundException (javax.jcr.ItemNotFoundException)5 PathNotFoundException (javax.jcr.PathNotFoundException)5 Value (javax.jcr.Value)5 LocationStepQueryNode (org.apache.jackrabbit.spi.commons.query.LocationStepQueryNode)5 AccessDeniedException (javax.jcr.AccessDeniedException)4 NodeType (javax.jcr.nodetype.NodeType)4 VersionException (javax.jcr.version.VersionException)4