Package org.apache.jackrabbit.core.value

Examples of org.apache.jackrabbit.core.value.InternalValue


        // values
        int count = in.readInt();   // count
        InternalValue[] values = new InternalValue[count];
        String[] blobIds = new String[count];
        for (int i = 0; i < count; i++) {
            InternalValue val;
            switch (type) {
                case PropertyType.BINARY:
                    int size = in.readInt();
                    if (size == BINARY_IN_DATA_STORE) {
                        val = InternalValue.create(dataStore, in.readUTF());
View Full Code Here


        out.writeUTF(state.getPropDefId().toString());
        // values
        InternalValue[] values = state.getValues();
        out.writeInt(values.length); // count
        for (int i = 0; i < values.length; i++) {
            InternalValue val = values[i];
            switch (state.getType()) {
                case PropertyType.BINARY:
                    BLOBFileValue blobVal = val.getBLOBFileValue();
                    long size = blobVal.getLength();
                    if (InternalValue.USE_DATA_STORE && dataStore != null) {
                        int maxMemorySize = dataStore.getMinRecordLength() - 1;
                        if (size < maxMemorySize) {
                            writeSmallBinary(out, blobVal, state, i);
                        } else {
                            out.writeInt(BINARY_IN_DATA_STORE);
                            try {
                                val.store(dataStore);
                            } catch (RepositoryException e) {
                                String msg = "Error while storing blob. id="
                                    + state.getId() + " idx=" + i + " size=" + val.getBLOBFileValue().getLength();
                                log.error(msg, e);
                                throw new IOException(msg);
                            }
                            out.writeUTF(val.toString());
                        }
                        break;
                    }
                    // special handling required for binary value:
                    // spool binary value to file in blob store
                    if (size < 0) {
                        log.warn("Blob has negative size. Potential loss of data. "
                                + "id={} idx={}", state.getId(), String.valueOf(i));
                        out.writeInt(0);
                        values[i] = InternalValue.create(new byte[0]);
                        blobVal.discard();
                    } else if (size > minBlobSize) {
                        out.writeInt(BINARY_IN_BLOB_STORE);
                        String blobId = state.getBlobId(i);
                        if (blobId == null) {
                            try {
                                InputStream in = blobVal.getStream();
                                try {
                                    blobId = blobStore.createId(state.getId(), i);
                                    blobStore.put(blobId, in, size);
                                    state.setBlobId(blobId, i);
                                } finally {
                                    IOUtils.closeQuietly(in);
                                }
                            } catch (Exception e) {
                                String msg = "Error while storing blob. id="
                                        + state.getId() + " idx=" + i + " size=" + size;
                                log.error(msg, e);
                                throw new IOException(msg);
                            }
                            try {
                                // replace value instance with value
                                // backed by resource in blob store and delete temp file
                                if (blobStore instanceof ResourceBasedBLOBStore) {
                                    values[i] = InternalValue.create(((ResourceBasedBLOBStore) blobStore).getResource(blobId));
                                } else {
                                    values[i] = InternalValue.create(blobStore.get(blobId));
                                }
                            } catch (Exception e) {
                                log.error("Error while reloading blob. truncating. id="
                                        + state.getId() + " idx=" + i + " size=" + size, e);
                                values[i] = InternalValue.create(new byte[0]);
                            }
                            blobVal.discard();
                        }
                        // store id of blob as property value
                        out.writeUTF(blobId);   // value
                    } else {
                        // delete evt. blob
                        byte[] data = writeSmallBinary(out, blobVal, state, i);
                        // replace value instance with value
                        // backed by resource in blob store and delete temp file
                        values[i] = InternalValue.create(data);
                        blobVal.discard();
                    }
                    break;
                case PropertyType.DOUBLE:
                    out.writeDouble(val.getDouble());
                    break;
                case PropertyType.LONG:
                    out.writeLong(val.getLong());
                    break;
                case PropertyType.BOOLEAN:
                    out.writeBoolean(val.getBoolean());
                    break;
                case PropertyType.NAME:
                    writeQName(out, val.getQName());
                    break;
                case PropertyType.REFERENCE:
                    writeUUID(out, val.getUUID());
                    break;
                default:
                    // because writeUTF(String) has a size limit of 64k,
                    // we're using write(byte[]) instead
                    byte[] bytes = val.toString().getBytes("UTF-8");
                    out.writeInt(bytes.length); // length of byte[]
                    out.write(bytes);   // byte[]
            }
        }
    }
View Full Code Here

                         * IMPORT_UUID_COLLISION_REPLACE_EXISTING;
                         * otherwise create a new version history
                         */
                        VersionHistoryInfo history =
                            vMgr.getVersionHistory(session, nodeState, null);
                        InternalValue historyId = InternalValue.create(
                                history.getVersionHistoryId());
                        InternalValue versionId = InternalValue.create(
                                history.getRootVersionId());
                        node.internalSetProperty(
                                NameConstants.JCR_VERSIONHISTORY, historyId);
                        node.internalSetProperty(
                                NameConstants.JCR_BASEVERSION, versionId);
View Full Code Here

    public void showResult(File file, TextFilter filter) throws Exception {
        PropertyId id = new PropertyId(null, new QName("", ""));
        PropertyState state = new PropertyState(id, 1, true);

        InternalValue value = InternalValue.create(file);
        state.setValues(new InternalValue[]{value});

        Map fields = filter.doFilter(state, System.getProperty("encoding"));
        for (Iterator it = fields.keySet().iterator(); it.hasNext();) {
            String field = (String) it.next();
View Full Code Here

    public void testCanExtractAttributes() throws Exception {
        String xml = "<config><city name=\"Stockholm\"/></config>";
        PropertyId id = new PropertyId(new NodeId(new UUID(1, 1)), new QName("", ""));
        PropertyState state = new PropertyState(id, 1, true);

        InternalValue value = InternalValue.create(xml.getBytes());
        state.setValues(new InternalValue[]{value});

        TextFilter filter = new XMLTextFilter();
        Map fields = filter.doFilter(state, System.getProperty("encoding"));
        Reader reader = (Reader)fields.get(FieldNames.FULLTEXT);
View Full Code Here

    public void testCanExtractCData() throws Exception {
        String xml = "<config><city>Stockholm</city></config>";
        PropertyId id = new PropertyId(new NodeId(new UUID(1, 1)), new QName("", ""));
        PropertyState state = new PropertyState(id, 1, true);

        InternalValue value = InternalValue.create(xml.getBytes());
        state.setValues(new InternalValue[]{value});

        TextFilter filter = new XMLTextFilter();
        Map fields = filter.doFilter(state, System.getProperty("encoding"));
        Reader reader = (Reader)fields.get(FieldNames.FULLTEXT);
View Full Code Here

     * Returns the node id of the base version, retrieved from the node state
     * @param state node state
     * @return the node id of the base version or <code>null</code> if not defined
     */
    protected NodeId getBaseVersionId(NodeStateEx state) {
        InternalValue value = state.getPropertyValue(NameConstants.JCR_BASEVERSION);
        return value == null ? null : value.getNodeId();
    }
View Full Code Here

            if (!jcrData.equals(fieldName)) {
                // don't know how to index
                return;
            }

            InternalValue type = getValue(NameConstants.JCR_MIMETYPE);
            if (type != null) {
                Metadata metadata = new Metadata();
                metadata.set(Metadata.CONTENT_TYPE, type.getString());

                // jcr:encoding is not mandatory
                InternalValue encoding = getValue(NameConstants.JCR_ENCODING);
                if (encoding != null) {
                    metadata.set(
                            Metadata.CONTENT_ENCODING, encoding.getString());
                }

                doc.add(createFulltextField(internalValue, metadata));
            }
        } catch (Throwable t) {
View Full Code Here

        NodeId versionId = new NodeId();
        NodeStateEx vNode = node.addNode(name, NameConstants.NT_VERSION, versionId, true);

        // check for jcr:activity
        if (src.hasProperty(NameConstants.JCR_ACTIVITY)) {
            InternalValue act = src.getPropertyValue(NameConstants.JCR_ACTIVITY);
            vNode.setPropertyValue(NameConstants.JCR_ACTIVITY, act);
        }

        // initialize 'created', 'predecessors' and 'successors'
        if (created == null) {
View Full Code Here

             * IMPORT_UUID_COLLISION_REPLACE_EXISTING;
             * otherwise create a new version history
             */
            VersionHistoryInfo history =
                versionManager.getVersionHistory(session, node, null);
            InternalValue historyId = InternalValue.create(
                    history.getVersionHistoryId());
            InternalValue versionId = InternalValue.create(
                    history.getRootVersionId());

            // jcr:isCheckedOut
            conditionalAddProperty(
                    node, NameConstants.JCR_ISCHECKEDOUT,
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.core.value.InternalValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.