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;
 
 
ItemInfoJSONHandler...
 
 class ItemInfoJsonHandler implements JsonHandler {
 
     private static Logger log = LoggerFactory.getLogger(ItemInfoJsonHandler.class);
 
     private static final String LEAF_NODE_HINT = "::NodeIteratorSize";
 
     private final List<ItemInfoitemInfos;
     private final NamePathResolver resolver;
     private final String rootURI;
 
     private final QValueFactoryImpl vFactory;
     private final PathFactory pFactory;
     private final IdFactory idFactory;
 
     private boolean expectingHintValue = false;
 
     private Name name;
     private int index = .;
 
     // temp. property state
     private int propertyType;
     private boolean multiValuedProperty = false;
     private List<QValuepropValues = new ArrayList<QValue>();
 
     private Stack<NodeInfonodeInfos = new Stack<NodeInfo>();
 
 
     ItemInfoJsonHandler(NamePathResolver resolverNodeInfo nInfo,
                         String rootURI,
                         QValueFactoryImpl vFactory,
                         PathFactory pFactory,
                         IdFactory idFactory) {
         this. = resolver;
         this. = rootURI;
 
         this. = vFactory;
         this. = pFactory;
         this. = idFactory;
 
          = new ArrayList<ItemInfo>();
         .add(nInfo);
         .push(nInfo);
         .push(new ArrayList<PropertyInfoImpl>(8));
     }
 
     public void object() throws IOException {
         if ( != null) {
             try {
                 NodeInfo current = getCurrentNodeInfo();
                Path relPath = .create();
                NodeId id = .createNodeId(current.getId(), relPath);
                Path currentPath = current.getPath();
                Path p = .create(currentPathrelPathtrue);
                NodeInfo nInfo = new NodeInfoImpl(idp);
                .push(nInfo);
                .push(new ArrayList<PropertyInfoImpl>(8));
            } catch (RepositoryException e) {
                throw new IOException(e.getMessage());
            }
        }
    }
    public void endObject() throws IOException {
        try {
            NodeInfoImpl nInfo = (NodeInfoImpl.pop();
            List<PropertyInfoImplprops = .pop();
            // all required information to create a node info should now be gathered
            nInfo.setPropertyInfos(props.toArray(new PropertyInfoImpl[props.size()]), );
            NodeInfo parent = getCurrentNodeInfo();
            if (parent != null) {
                if (nInfo.getPath().getAncestor(1).equals(parent.getPath())) {
                    ChildInfo ci = new ChildInfoImpl(nInfo.getName(), nInfo.getUniqueID(), nInfo.getIndex());
                    ((NodeInfoImplparent).addChildInfo(ci);
                } else {
                    .debug("NodeInfo '"nInfo.getPath() + "' out of hierarchy. Parent path = " + parent.getPath());
                }
            }
            if (nInfo.isCompleted()) {
                .addAll(props);
                .add(nInfo);
            } else {
                .debug("Incomplete NodeInfo '"nInfo.getPath() + "' -> Only present as ChildInfo with its parent.");
            }
        } catch (RepositoryException e) {
            throw new IOException(e.getMessage());
        } finally {
            // reset all node-related handler state
             = null;
             = .;
        }
    }
    public void array() throws IOException {
         = true;
        .clear();
    }
    public void endArray() throws IOException {
        try {
            if ( == .) {
                if (.isEmpty()) {
                    // make sure that type is set for mv-properties with empty value array.
                     = .retrieveType(getValueURI());
                } else {
                     = .get(0).getType();
                }
            }
            // create multi-valued property info
            NodeInfoImpl parent = getCurrentNodeInfo();
            Path p = .create(parent.getPath(), true);
            PropertyId id = .createPropertyId(parent.getId(), );
            PropertyInfoImpl propInfo = new PropertyInfoImpl(idp.toArray(new QValue[.size()]));
            propInfo.checkCompleted();
            getCurrentPropInfos().add(propInfo);
        } catch (RepositoryException e) {
            throw new IOException(e.getMessage());
        } finally {
            // reset property-related handler state
             = .;
             = false;
            .clear();
             = null;
        }
    }
    public void key(String keythrows IOException {
         = false;
        try {
            if (key.equals()) {
                 = true;
                // TODO: remember name of hint if there will be additional types of hints
                 = null;
            } else if (key.startsWith(":")) {
                 = true;
                // either
                //   :<nameOfProperty> : "PropertyTypeName"
                // or
                //   :<nameOfBinaryProperty> : <lengthOfBinaryProperty>
                //name = resolver.getQName(key.substring(1));
                 = .getQName(StringCache.fromCacheOrNew(key.substring(1)));
                 = .;
            } else if (key.endsWith("]")) {
                // sns-node name
                int pos = key.lastIndexOf('[');
                //name = resolver.getQName(key.substring(0, pos));
                 = .getQName(StringCache.fromCacheOrNew(key.substring(0, pos)));
                 = .;
                 = Integer.parseInt(key.substring(pos + 1, key.length() - 1));
            } else {
                // either node or property
                 = .getQName(StringCache.cache(key));
                 = .;
            }
        } catch (RepositoryException e) {
            throw new IOException(e.getMessage());
        }
    }

    
there is currently one special string-value hint: :<nameOfProperty> : "PropertyTypeName"

Parameters:
value The value.
Throws:
java.io.IOException
    public void value(String valuethrows IOException {
        if () {
            // :<nameOfProperty> : "PropertyTypeName"
             = PropertyType.valueFromName(value);
            return;
        }
        try {
            QValue v;
            switch () {
                case .:
                    if (!..equals()) {
                        value = StringCache.cache(value);
                    }
                    v = .create(value.);
                    break;
                case .:
                    v = .create(.getQName(value));
                    break;
                case .:
                    v = .create(.getQPath(value));
                    break;
                default:
                    v = .create(value);
            }
            value(v);
        } catch (RepositoryException e) {
            throw new IOException(e.getMessage());
        }
    }
    public void value(boolean valuethrows IOException {
        if () {
            // there are currently no special boolean value hints:
            return;
        }
        try {
            value(.create(value));
        } catch (RepositoryException e) {
            throw new IOException(e.getMessage());
        }
    }

    
there are currently 2 types of special long value hints: a) ::NodeIteratorSize : 0 ==> denotes the current node as leaf node b) :<nameOfBinaryProperty> : <lengthOfBinaryProperty>

Parameters:
value The value.
Throws:
java.io.IOException
    public void value(long valuethrows IOException {
        if () {
            if ( == null) {
                // ::NodeIteratorSize : 0
                NodeInfoImpl parent = getCurrentNodeInfo();
                if (parent != null) {
                    parent.markAsLeafNode();
                }
            } else {
                // :<nameOfBinaryProperty> : <lengthOfBinaryProperty>
                 = .;
                try {
                    int indx = (!) ? -1 : .size();
                    value(.create(valuegetValueURI(), indx));
                } catch (RepositoryException e) {
                    throw new IOException(e.getMessage());
                }
            }
            return;
        }
        try {
            value(.create(value));
        } catch (RepositoryException e) {
            throw new IOException(e.getMessage());
        }
    }
    public void value(double valuethrows IOException {
        if () {
            // currently no special double value pair -> ignore
            return;
        }
        try {
            value(.create(value));
        } catch (RepositoryException e) {
            throw new IOException(e.getMessage());
        }
    }
    //--------------------------------------------------------------------------
    

Parameters:
value
Throws:
javax.jcr.RepositoryException
    private void value(QValue valuethrows RepositoryException {
        if (!) {
            try {
                if ( == .) {
                     = value.getType();
                }
                // create single-valued property info
                NodeInfoImpl parent = getCurrentNodeInfo();
                Path p = .create(parent.getPath(), true);
                PropertyId id = .createPropertyId(parent.getId(), );
                PropertyInfoImpl propInfo = new PropertyInfoImpl(idpvalue);
                propInfo.checkCompleted();
                // add property info to current list, will be processed on endObject() event
                getCurrentPropInfos().add(propInfo);
            } finally {
                // reset property-related handler state
                 = .;
                 = false;
                .clear();
                 = null;
                 = false;
            }
        } else {
            // multi-valued property
            // add value to current list, will be processed on endArray() event
            .add(value);
        }
    }
    Iterator<? extends ItemInfogetItemInfos() {
        return Collections.unmodifiableList().iterator();
    }
    private NodeInfoImpl getCurrentNodeInfo() {
        return (.isEmpty()) ? null : (NodeInfoImpl.peek();
    }
        return (.isEmpty()) ? null : .peek();
    }
    private String getValueURI() throws RepositoryException {
        Path propertyPath = .create(getCurrentNodeInfo().getPath(), true);
        StringBuffer sb = new StringBuffer();
        sb.append(Text.escapePath(.getJCRPath(propertyPath)));
        return sb.toString();
    }
New to GrepCode? Check out our FAQ X