Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.apache.jackrabbit.spi2davex;
 
 import java.util.List;
 import java.util.Map;
 
RepositoryServiceImpl...
 
 
     private static Logger log = LoggerFactory.getLogger(RepositoryServiceImpl.class);
 
     private static final String PARAM_DIFF = ":diff";
     private static final String PARAM_COPY = ":copy";
     private static final String PARAM_CLONE = ":clone";
 
     private static final char SYMBOL_ADD_NODE = '+';
     private static final char SYMBOL_MOVE = '>';
     private static final char SYMBOL_REMOVE = '-';
     private static final char SYMBOL_SET_PROPERTY = '^';
 
     private static final String ORDER_POSITION_LAST = "#last";
     private static final String ORDER_POSITION_BEFORE = "#before";
 
    private static final String DEFAULT_CHARSET = "UTF-8";
    private static final DavPropertyName JCR_TYPE =
            DavPropertyName.create(..);
    private static final DavPropertyName JCR_LENGTH =
    private static final DavPropertyName JCR_LENGTHS =
    private static final DavPropertyName JCR_GET_STRING =
    private static final DavPropertyNameSet LAZY_PROPERTY_NAME_SET = new DavPropertyNameSet(){{
        add();
        add();
        add();
        add();
    }};

    
base uri to the extended jcr-server that can handle the GET and POST (or PATCH) requests sent by this service implementation.
    private final String jcrServerURI;

    
the name of the default workspace or null. NOTE: with JCR-1842 the RepositoryConfiguration doesn't provide the default workspace name any more. In order to provide backwards compatibility with jcr-server < 1.5.0 the workspace name can be passed to the RepositoryService implementation.
    private final String defaultWorkspaceName;

    
The configuration map used to determine the maximal depth of child items to be accessed upon a call to org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.getNodeInfo(org.apache.jackrabbit.spi.SessionInfo,org.apache.jackrabbit.spi.NodeId).
    private final BatchReadConfig batchReadConfig;
    private final Map<SessionInfoQValueFactoryImplqvFactories = new HashMap<SessionInfoQValueFactoryImpl>();

    
Same as RepositoryServiceImpl(String, String, BatchReadConfig, int, int)) using null workspace name, ItemInfoCacheImpl.DEFAULT_CACHE_SIZE) as size for the item cache and org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.MAX_CONNECTIONS_DEFAULT for the maximum number of connections on the client.

Parameters:
jcrServerURI The server uri.
batchReadConfig The batch read configuration.
Throws:
javax.jcr.RepositoryException If an exception occurs.
    public RepositoryServiceImpl(String jcrServerURIBatchReadConfig batchReadConfigthrows RepositoryException {
        this(jcrServerURInullbatchReadConfig.);
    }

    
Same as RepositoryServiceImpl(String, String, BatchReadConfig, int, int)) using org.apache.jackrabbit.spi2dav.RepositoryServiceImpl.MAX_CONNECTIONS_DEFAULT for the maximum number of connections on the client.

Parameters:
jcrServerURI The server uri.
defaultWorkspaceName The default workspace name.
batchReadConfig The batch read configuration.
itemInfoCacheSize The size of the item info cache.
Throws:
javax.jcr.RepositoryException If an exception occurs.
    public RepositoryServiceImpl(String jcrServerURIString defaultWorkspaceName,
                                 BatchReadConfig batchReadConfigint itemInfoCacheSizethrows RepositoryException {
        this(jcrServerURIdefaultWorkspaceNamebatchReadConfigitemInfoCacheSize);
    }

    
Creates a new instance of this repository service.

Parameters:
jcrServerURI The server uri.
defaultWorkspaceName The default workspace name.
batchReadConfig The batch read configuration.
itemInfoCacheSize The size of the item info cache.
maximumHttpConnections maximumHttpConnections A int >0 defining the maximum number of connections per host to be configured on org.apache.commons.httpclient.params.HttpConnectionManagerParams.setDefaultMaxConnectionsPerHost(int).
Throws:
javax.jcr.RepositoryException If an exception occurs.
    public RepositoryServiceImpl(String jcrServerURIString defaultWorkspaceName,
                                 BatchReadConfig batchReadConfigint itemInfoCacheSize,
                                 int maximumHttpConnectionsthrows RepositoryException {
        super(jcrServerURI, IdFactoryImpl.getInstance(), NameFactoryImpl.getInstance(),
                PathFactoryImpl.getInstance(), new QValueFactoryImpl(), itemInfoCacheSizemaximumHttpConnections);
        this. = jcrServerURI.endsWith("/") ? jcrServerURI : jcrServerURI + "/";
        this. = defaultWorkspaceName;
        if (batchReadConfig == null) {
            this. = new BatchReadConfig() {
                public int getDepth(Path pathPathResolver resolver) {
                    return 0;
                }
            };
        } else {
            this. = batchReadConfig;
        }
    }
    private Path getPath(ItemId itemIdSessionInfo sessionInfothrows RepositoryException {
        return getPath(itemIdsessionInfosessionInfo.getWorkspaceName());
    }
    private Path getPath(ItemId itemIdSessionInfo sessionInfoString workspaceNamethrows RepositoryException {
        if (itemId.denotesNode()) {
            Path p = itemId.getPath();
            String uid = itemId.getUniqueID();
            if (uid == null) {
                return p;
            } else {
                NamePathResolver resolver = getNamePathResolver(sessionInfo);
                String uri = super.getItemUri(itemIdsessionInfoworkspaceName);
                String rootUri = getRootURI(sessionInfo);
                String jcrPath;
                if (uri.startsWith(rootUri)) {
                    jcrPath = uri.substring(rootUri.length());
                } else {
                    .warn("ItemURI " + uri + " doesn't start with rootURI (" + rootUri + ").");
                    // fallback:
                    // calculated uri does not start with the rootURI
                    // -> search /jcr:root and start sub-string behind.
                    String rootSegment = Text.escapePath(.);
                    jcrPath = uri.substring(uri.indexOf(rootSegment) + rootSegment.length());
                }
                jcrPath = Text.unescape(jcrPath);
                return resolver.getQPath(jcrPath);
            }
        } else {
            PropertyId pId = (PropertyIditemId;
            Path parentPath = getPath(pId.getParentId(), sessionInfoworkspaceName);
            return getPathFactory().create(parentPathpId.getName(), true);
        }
    }
    private String getURI(Path pathSessionInfo sessionInfothrows RepositoryException {
        StringBuilder sb = new StringBuilder(getRootURI(sessionInfo));
        String jcrPath = getNamePathResolver(sessionInfo).getJCRPath(path);
        sb.append(Text.escapePath(jcrPath));
        return sb.toString();
    }
    private String getURI(ItemId itemIdSessionInfo sessionInfothrows RepositoryException {
        Path p = getPath(itemIdsessionInfo);
        if (p == null) {
            return super.getItemUri(itemIdsessionInfo);
        } else {
            return getURI(psessionInfo);
        }
    }
    private String getRootURI(SessionInfo sessionInfo) {
        StringBuilder sb = new StringBuilder(getWorkspaceURI(sessionInfo));
        return sb.toString();
    }
    private String getWorkspaceURI(SessionInfo sessionInfo) {
        StringBuilder sb = new StringBuilder();
        sb.append();
        sb.append(Text.escape(sessionInfo.getWorkspaceName()));
        return sb.toString();
    }

    
    public QValueFactoryImpl getQValueFactory(SessionInfo sessionInfothrows RepositoryException {
        QValueFactoryImpl qv;
        if (.containsKey(sessionInfo)) {
            qv = .get(sessionInfo);
        } else {
            ValueLoader loader = new ValueLoader(getClient(sessionInfo));
            qv = new QValueFactoryImpl(getNamePathResolver(sessionInfo), loader);
            .put(sessionInfoqv);
        }
        return qv;
    }
    //--------------------------------------------------< RepositoryService >---
    // exists && getPropertyInfo -> to be done
    // getNodeInfo: omitted for requires list of 'references'

    
If the specified workspaceName the default workspace name is used for backwards compatibility with jackrabbit-jcr-server < 1.5.0

    @Override
    public SessionInfo obtain(Credentials credentialsString workspaceName)
            throws  RepositoryException {
        // for backwards compatibility with jcr-server < 1.5.0
        String wspName = (workspaceName == null) ?  : workspaceName;
        return super.obtain(credentialswspName);
    }

    
If the specified workspaceName the default workspace name is used for backwards compatibility with jackrabbit-jcr-server < 1.5.0

    @Override
    public SessionInfo obtain(SessionInfo sessionInfoString workspaceName)
            throws RepositoryException {
        // for backwards compatibility with jcr-server < 1.5.0
        String wspName = (workspaceName == null) ?  : workspaceName;
        return super.obtain(sessionInfowspName);
    }

    
    @Override
    public void dispose(SessionInfo sessionInfothrows RepositoryException {
        super.dispose(sessionInfo);
        // remove the qvalue factory created for the given SessionInfo from the
        // map of valuefactories.
        .remove(sessionInfo);
    }

    
    @Override
    public Iterator<? extends ItemInfogetItemInfos(SessionInfo sessionInfoItemId itemIdthrows ItemNotFoundExceptionRepositoryException {
        if (!itemId.denotesNode()) {
            PropertyInfo propertyInfo = getPropertyInfo(sessionInfo, (PropertyIditemId);
            return Iterators.singleton(propertyInfo);
        } else {
            NodeId nodeId = (NodeIditemId;
            Path path = getPath(itemIdsessionInfo);
            String uri = getURI(pathsessionInfo);
            int depth = .getDepth(paththis.getNamePathResolver(sessionInfo));
            GetMethod method = new GetMethod(uri + "." + depth + ".json");
            try {
                int statusCode = getClient(sessionInfo).executeMethod(method);
                if (statusCode == .) {
                    if (method.getResponseContentLength() == 0) {
                        // no JSON response -> no such node on the server
                        throw new ItemNotFoundException("No such item " + nodeId);
                    }
                    NamePathResolver resolver = getNamePathResolver(sessionInfo);
                    NodeInfoImpl nInfo = new NodeInfoImpl(nodeIdpath);
                    ItemInfoJsonHandler handler = new ItemInfoJsonHandler(resolvernInfogetRootURI(sessionInfo), getQValueFactory(sessionInfo), getPathFactory(), getIdFactory());
                    JsonParser ps = new JsonParser(handler);
                    ps.parse(method.getResponseBodyAsStream(), method.getResponseCharSet());
                    Iterator<? extends ItemInfoit = handler.getItemInfos();
                    if (!it.hasNext()) {
                        throw new ItemNotFoundException("No such node " + uri);
                    }
                    return handler.getItemInfos();
                } else {
                    throw ExceptionConverter.generate(new DavException(statusCode"Unable to retrieve NodeInfo for " + uri), method);
                }
            } catch (HttpException e) {
                throw ExceptionConverter.generate(new DavException(method.getStatusCode(), "Unable to retrieve NodeInfo for " + uri));
            } catch (IOException e) {
                .error("Internal error while retrieving NodeInfo.",e);
                throw new RepositoryException(e.getMessage());
            } finally {
                method.releaseConnection();
            }
        }
    }

    
    @Override
    public PropertyInfo getPropertyInfo(SessionInfo sessionInfoPropertyId propertyIdthrows RepositoryException {
        Path p = getPath(propertyIdsessionInfo);
        String uri = getURI(psessionInfo);
        PropFindMethod method = null;
        try {
            method = new PropFindMethod(uri.);
            getClient(sessionInfo).executeMethod(method);
            method.checkSuccess();
            MultiStatusResponse[] responses = method.getResponseBodyAsMultiStatus().getResponses();
            if (responses.length != 1) {
                throw new ItemNotFoundException("Unable to retrieve the PropertyInfo. No such property " + uri);
            }
            MultiStatusResponse response = responses[0];
            DavPropertySet props = response.getProperties(.);
            int propertyType = PropertyType.valueFromName(props.get().getValue().toString());
            if (propertyType == .) {
                DavProperty<?> lengthsProp = props.get();
                if (lengthsProp != null) {
                    // multivalued binary property
                    long[] lengths = ValueUtil.lengthsFromXml(lengthsProp.getValue());
                    QValue[] qValues = new QValue[lengths.length];
                    for (int i = 0 ; i < lengths.length ; i ++) {
                        qValues[i] = getQValueFactory(sessionInfo).create(lengths[i], urii);
                    }
                    return new PropertyInfoImpl(propertyIdppropertyTypeqValues);
                } else {
                    // single valued binary property
                    long length = Long.parseLong(props.get().getValue().toString());
                    QValue qValue = getQValueFactory(sessionInfo).create(lengthuri.) ;
                    return new PropertyInfoImpl(propertyIdppropertyTypeqValue);
                }
            } else if (props.contains()) {
                // single valued non-binary property
                Object v = props.get().getValue();
                String str = (v == null) ? "" : v.toString();
                QValue qValue = ValueFormat.getQValue(strpropertyTypegetNamePathResolver(sessionInfo), getQValueFactory(sessionInfo));
                return new PropertyInfoImpl(propertyIdppropertyTypeqValue);
            } else {
                // multivalued non-binary property or some other property that
                // didn't expose the JCR_GET_STRING dav property.
                return super.getPropertyInfo(sessionInfopropertyId);
            }
        } catch (IOException e) {
            .error("Internal error while retrieving ItemInfo.",e);
            throw new RepositoryException(e.getMessage());
        } catch (DavException e) {
            throw ExceptionConverter.generate(e);
        } finally {
            if (method != null) {
                method.releaseConnection();
            }
        }
    }
    @Override
    public Batch createBatch(SessionInfo sessionInfoItemId itemIdthrows RepositoryException {
        return new BatchImpl(itemIdsessionInfo);
    }
    @Override
    public void submit(Batch batchthrows RepositoryException {
        if (!(batch instanceof BatchImpl)) {
            throw new RepositoryException("Unknown Batch implementation.");
        }
        BatchImpl batchImpl = (BatchImplbatch;
        try {
            if (!batchImpl.isEmpty()) {
                batchImpl.start();
            }
        } finally {
            batchImpl.dispose();
        }
    }
    @Override
    public void copy(SessionInfo sessionInfoString srcWorkspaceNameNodeId srcNodeIdNodeId destParentNodeIdName destNamethrows RepositoryException {
        if (srcWorkspaceName.equals(sessionInfo.getWorkspaceName())) {
            super.copy(sessionInfosrcWorkspaceNamesrcNodeIddestParentNodeIddestName);
            return;
        }
        PostMethod method = null;
        try {
            method = new PostMethod(getWorkspaceURI(sessionInfo));
            NamePathResolver resolver = getNamePathResolver(sessionInfo);
            StringBuilder args = new StringBuilder();
            args.append(srcWorkspaceName);
            args.append(",");
            args.append(resolver.getJCRPath(getPath(srcNodeIdsessionInfosrcWorkspaceName)));
            args.append(",");
            String destParentPath = resolver.getJCRPath(getPath(destParentNodeIdsessionInfo));
            String destPath = (destParentPath.endsWith("/") ?
                    destParentPath + resolver.getJCRName(destName) :
                    destParentPath + "/" + resolver.getJCRName(destName));
            args.append(destPath);
            method.addParameter(args.toString());
            addIfHeader(sessionInfomethod);
            getClient(sessionInfo).executeMethod(method);
            method.checkSuccess();
        } catch (IOException e) {
            throw new RepositoryException(e);
        } catch (DavException e) {
            throw ExceptionConverter.generate(emethod);
        } finally {
            if (method != null) {
                method.releaseConnection();
            }
        }
    }
    @Override
    public void clone(SessionInfo sessionInfoString srcWorkspaceNameNodeId srcNodeIdNodeId destParentNodeIdName destNameboolean removeExistingthrows RepositoryException {
        PostMethod method = null;
        try {
            method = new PostMethod(getWorkspaceURI(sessionInfo));
            NamePathResolver resolver = getNamePathResolver(sessionInfo);
            StringBuilder args = new StringBuilder();
            args.append(srcWorkspaceName);
            args.append(",");
            args.append(resolver.getJCRPath(getPath(srcNodeIdsessionInfosrcWorkspaceName)));
            args.append(",");
            String destParentPath = resolver.getJCRPath(getPath(destParentNodeIdsessionInfo));
            String destPath = (destParentPath.endsWith("/") ?
                    destParentPath + resolver.getJCRName(destName) :
                    destParentPath + "/" + resolver.getJCRName(destName));
            args.append(destPath);
            args.append(",");
            args.append(Boolean.toString(removeExisting));
            method.addParameter(args.toString());
            addIfHeader(sessionInfomethod);
            getClient(sessionInfo).executeMethod(method);
            method.checkSuccess();
            if (removeExisting) {
                clearItemUriCache(sessionInfo);
            }
        } catch (IOException e) {
            throw new RepositoryException(e);
        } catch (DavException e) {
            throw ExceptionConverter.generate(emethod);
        } finally {
            if (method != null) {
                method.releaseConnection();
            }
        }
    }
    private static void addIfHeader(SessionInfo sInfoHttpMethod method) {
        try {
            initMethod(methodsInfotrue);
        } catch (RepositoryException e) {
            // should never get here
            .error("Unable to retrieve lock tokens: omitted from request header.");
        }
    }
    //--------------------------------------------------------------------------
    private class BatchImpl implements Batch {
        private final ItemId targetId;
        private final SessionInfo sessionInfo;
        private final List<Partparts;
        private final List<Stringdiff;
        /*
          If this batch needs to remove multiple same-name-siblings starting
          from lower index, the index of the following siblings must be reset
          in order to avoid PathNotFoundException.
        */
        private final Map<PathPathremoved = new HashMap<PathPath>();
        private PostMethod method// TODO: use PATCH request instead.
        private boolean isConsumed;
        // flag to determine if the uri-lookup needs to be cleared... e.g.
        // after a move operation.
        private boolean clear;
        private BatchImpl(ItemId targetIdSessionInfo sessionInfo) {
            this. = targetId;
            this. = sessionInfo;
             = new ArrayList<Part>();
             = new ArrayList<String>();
        }
        private void start() throws RepositoryException {
            checkConsumed();
            // add lock tokens
            addIfHeader();
            // insert the content of 'batchMap' part containing the ordered list
            // of methods to be executed:
            StringBuilder buf = new StringBuilder();
            for (Iterator<Stringit = .iterator(); it.hasNext();) {
                buf.append(it.next());
                if (it.hasNext()) {
                    buf.append("\r");
                }
            }
            if (.isEmpty()) {
                // only a diff part. no multipart required.
                .addParameter(buf.toString());
            } else {
                // other parts are present -> add the diff part
                addPart(buf.toString());
                // ... and create multipart-entity (and set it to method)
                Part[] partArr = .toArray(new Part[.size()]);
                RequestEntity entity = new MultipartRequestEntity(partArr.getParams());
                .setRequestEntity(entity);
            }
            HttpClient client = getClient();
            try {
                client.executeMethod();
                .checkSuccess();
                if () {
                    RepositoryServiceImpl.super.clearItemUriCache();
                }
            }  catch (IOException e) {
                throw new RepositoryException(e);
            } catch (DavException e) {
                throw ExceptionConverter.generate(e);
            } finally {
                .releaseConnection();
            }
        }
        private void dispose() {
             = null;
             = true;
            // discard binary parts (JCR-2582)
            if ( != null) {
                for (Part part : ) {
                    if (part instanceof BinaryPart) {
                        ((BinaryPartpart).dispose();
                    }
                }
            }
        }
        private void checkConsumed() {
            if () {
                throw new IllegalStateException("Batch has already been consumed.");
            }
        }
        private boolean isEmpty() {
            return  == null;
        }
        private void assertMethod() throws RepositoryException {
            if ( == null) {
                String uri = getURI();
                 = new PostMethod(uri);
                // ship lock-tokens as if-header to circumvent problems with
                // locks created by this session.
                String[] locktokens = .getLockTokens();
                if (locktokens != null && locktokens.length > 0) {
                    IfHeader ifH = new IfHeader(locktokens);
                    .setRequestHeader(ifH.getHeaderName(), ifH.getHeaderValue());
                }
            }
        }
        //----------------------------------------------------------< Batch >---
        

InheritDoc:
        public void addNode(NodeId parentIdName nodeNameName nodetypeName,
                            String uuidthrows RepositoryException {
            assertMethod();
            NamePathResolver resolver = getNamePathResolver();
            Path p = getPathFactory().create(getPath(parentId), nodeNametrue);
            String jcrPath = resolver.getJCRPath(p);
            StringWriter wr = new StringWriter();
            wr.write('{');
            wr.write(getJsonKey(.));
            wr.write(JsonUtil.getJsonString(getNamePathResolver().getJCRName(nodetypeName)));
            if (uuid != null) {
                wr.write(',');
                wr.write(getJsonKey(.));
                wr.write(JsonUtil.getJsonString(uuid));
            }
            wr.write('}');
            appendDiff(jcrPathwr.toString());
        }

        

InheritDoc:
        public void addProperty(NodeId parentIdName propertyNameQValue valuethrows RepositoryException {
            assertMethod();
            Path p = getPathFactory().create(getPath(parentId), propertyNametrue);
            setProperty(pvaluefalse);
        }

        

InheritDoc:
        public void addProperty(NodeId parentIdName propertyNameQValue[] valuesthrows RepositoryException {
            assertMethod();
            Path p = getPathFactory().create(getPath(parentId), propertyNametrue);
            setProperty(pvaluesfalse);
        }

        

InheritDoc:
        public void setValue(PropertyId propertyIdQValue valuethrows RepositoryException {
            assertMethod();
            Path p = getPath(propertyId);
            setProperty(pvaluetrue);
        }

        

InheritDoc:
        public void setValue(PropertyId propertyIdQValue[] valuesthrows RepositoryException {
            assertMethod();
            Path p = getPath(propertyId);
            setProperty(pvaluestrue);
        }

        

InheritDoc:
        public void remove(ItemId itemIdthrows RepositoryException {
            assertMethod();
            Path rmPath = getPath(itemId);
            if (itemId.denotesNode()) {
                rmPath = calcRemovePath(rmPath);
            }
            String rmJcrPath = getNamePathResolver().getJCRPath(rmPath);
            appendDiff(rmJcrPathnull);
            // clear the uri-lookup in case the itemID contains a uniqueID part.
            if (itemId.getPath() == null) {
                 = true;
            }
        }

        

InheritDoc:
        public void reorderNodes(NodeId parentIdNodeId srcNodeIdNodeId beforeNodeIdthrows RepositoryException {
            assertMethod();
            // TODO: multiple reorder of SNS nodes requires readjustment of path -> see remove()
            String srcPath = getNamePathResolver().getJCRPath(getPath(srcNodeId));
            StringBuilder val = new StringBuilder();
            if (beforeNodeId != null) {
                Path beforePath = getPath(beforeNodeId);
                String beforeJcrPath = getNamePathResolver().getJCRPath(beforePath);
                val.append(Text.getName(beforeJcrPath));
                val.append();
            } else {
                val.append();
            }
            appendDiff(srcPathval.toString());
            // clear the uri-lookup in case the itemID contains a uniqueID part.
            if (srcNodeId.getPath() == null || (beforeNodeId != null && beforeNodeId.getPath() == null)) {
                 = true;
            }
        }

        

InheritDoc:
        public void setMixins(NodeId nodeIdName[] mixinNodeTypeNamesthrows RepositoryException {
            assertMethod();
            QValue[] vs = new QValue[mixinNodeTypeNames.length];
            for (int i = 0; i < mixinNodeTypeNames.lengthi++) {
                vs[i] = getQValueFactory().create(mixinNodeTypeNames[i]);
            }
            Path p = getPathFactory().create(getPath(nodeId), .true);
            // register the diff entry including clearing previous calls to
            // setMixins for the same node.
            setProperty(pvstrue);
        }

        

InheritDoc:
        public void setPrimaryType(NodeId nodeIdName primaryNodeTypeNamethrows RepositoryException {
            assertMethod();
            QValue v = getQValueFactory().create(primaryNodeTypeName);
            Path p = getPathFactory().create(getPath(nodeId), .true);
            // register the diff entry including clearing previous calls to
            // setPrimaryType for the same node.
            setProperty(pvtrue);
        }

        

InheritDoc:
        public void move(NodeId srcNodeIdNodeId destParentNodeIdName destNamethrows RepositoryException {
            assertMethod();
            String srcPath = getNamePathResolver().getJCRPath(getPath(srcNodeId));
            Path destPath = getPathFactory().create(getPath(destParentNodeId), destNametrue);
            String destJcrPath = getNamePathResolver().getJCRPath(destPath);
            appendDiff(srcPathdestJcrPath);
             = true;
        }

        

Parameters:
symbol
targetPath
value
        private void appendDiff(char symbolString targetPathString value) {
            StringBuilder bf = new StringBuilder();
            bf.append(symbol).append(targetPath).append(" : ");
            if (value != null) {
                bf.append(value);
            }
            .add(bf.toString());
        }

        

Parameters:
propPath
value
Throws:
javax.jcr.RepositoryException
        private void setProperty(Path propPathQValue valueboolean clearPreviousthrows RepositoryException {
            NamePathResolver resolver = getNamePathResolver();
            String jcrPropPath = resolver.getJCRPath(propPath);
            if (clearPrevious) {
                clearPreviousSetProperty(jcrPropPath);
            }
            String strValue = getJsonString(value);
            appendDiff(jcrPropPathstrValue);
            if (strValue == null) {
                addPart(jcrPropPathvalueresolver);
            }
        }
        private void setProperty(Path propPathQValue[] valuesboolean clearPreviousthrows RepositoryException {
            NamePathResolver resolver = getNamePathResolver();
            String jcrPropPath = resolver.getJCRPath(propPath);
            if (clearPrevious) {
                clearPreviousSetProperty(jcrPropPath);
            }
            StringBuilder strVal = new StringBuilder("[");
            for (int i = 0; i < values.lengthi++) {
                String str = getJsonString(values[i]);
                if (str == null) {
                    addPart(jcrPropPathvalues[i], resolver);
                } else {
                    String delim = (i == 0) ? "" : ",";
                    strVal.append(delim).append(str);
                }
            }
            strVal.append("]");
            appendDiff(jcrPropPathstrVal.toString());
        }
        private void clearPreviousSetProperty(String jcrPropPath) {
            String key =  + jcrPropPath + " : ";
            // make sure that multiple calls to setProperty for a given path
            // are only reflected once in the multipart, otherwise this will
            // cause consistency problems as the various calls cannot be separated
            // (missing unique identifier for the parts).
            for (Iterator<Stringit = .iterator(); it.hasNext();) {
                String entry = it.next();
                if (entry.startsWith(key)) {
                    it.remove();
                    removeParts(jcrPropPath);
                    return;
                }
            }
        }

        

Parameters:
paramName
value
        private void addPart(String paramNameString value) {
            .add(new StringPart(paramNamevalue));
        }

        

Parameters:
paramName
value
resolver
Throws:
javax.jcr.RepositoryException
        private void addPart(String paramNameQValue valueNamePathResolver resolverthrows RepositoryException {
            Part part;
            switch (value.getType()) {
                case .:
                    part = new BinaryPart(paramNamenew BinaryPartSource(value), JcrValueType.contentTypeFromType(.), );
                    break;
                case .:
                    part = new StringPart(paramNameresolver.getJCRName(value.getName()), );
                    break;
                case .:
                    part = new StringPart(paramNameresolver.getJCRPath(value.getPath()), );
                    break;
                default:
                    part = new StringPart(paramNamevalue.getString(), );
            }
            String ctype = JcrValueType.contentTypeFromType(value.getType());
            ((PartBasepart).setContentType(ctype);
            .add(part);
        }
        private void removeParts(String paramName) {
            for (Iterator<Partit = .iterator(); it.hasNext();) {
                Part part = it.next();
                if (part.getName().equals(paramName)) {
                    it.remove();
                }
            }
        }
        private String getJsonKey(String str) {
            return JsonUtil.getJsonString(str) + ":";
        }
        private String getJsonString(QValue valuethrows RepositoryException {
            String str;
            switch (value.getType()) {
                case .:
                    str = JsonUtil.getJsonString(value.getString());
                    break;
                case .:
                case .:
                    str = value.getString();
                    break;
                case .:
                    double d = value.getDouble();
                    if (Double.isNaN(d) || Double.isInfinite(d)) {
                    // JSON cannot specifically handle this property type...
                        str = null;
                    } else {
                        str = value.getString();
                        if (str.indexOf('.') == -1) {
                            str += ".0";
                        }
                    }
                    break;
                default:
                    // JSON cannot specifically handle this property type...
                    str = null;
            }
            return str;
        }
        private Path calcRemovePath(Path removedNodePaththrows RepositoryException {
            .put(removedNodePathremovedNodePath);
            Name name = removedNodePath.getName();
            int index = removedNodePath.getNormalizedIndex();
            if (index > .) {
                Path.Element[] elems = removedNodePath.getElements();
                PathBuilder pb = new PathBuilder();
                for (int i = 0; i <= elems.length - 2; i++) {
                    pb.addLast(elems[i]);
                }
                Path parent = pb.getPath();
                while (index > .) {
                    Path siblingP = getPathFactory().create(parentname, --indextrue);
                    if (.containsKey(siblingP)) {
                        // as the previous sibling has been remove -> the same index
                        // must be used to remove the node at removedNodePath.
                        siblingP = .get(siblingP);
                        .put(removedNodePathsiblingP);
                        return siblingP;
                    }
                }
            }
            // first of siblings or no sibling at all
            return removedNodePath;
        }
    }