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.spi2dav;
 
 
 import java.util.List;

Utility to build QNodeTypeDefinition, QNodeDefinition and QPropertyDefinition from the information retrieved from the WebDAV response body.
 
 class DefinitionUtil implements NodeTypeConstants {
 
     private static Logger log = LoggerFactory.getLogger(DefinitionUtil.class);

    
Avoid instantiation.
 
     private DefinitionUtil() {}

    

Parameters:
declaringNodeType
ndefElement
resolver
Returns:
Throws:
javax.jcr.RepositoryException
 
     static QNodeDefinition createQNodeDefinition(Name declaringNodeTypeElement ndefElementNamePathResolver resolverthrows RepositoryException {
         QNodeDefinitionBuilder builder = new QNodeDefinitionBuilder();
 
         buildQItemDefinition(declaringNodeTypendefElementresolverbuilder);
         
         // TODO: webdav server sends jcr names -> nsResolver required. improve this.
         // NOTE: the server should send the namespace-mappings as addition ns-defininitions
         try {
 
             if (ndefElement.hasAttribute()) {
                 Name defaultPrimaryType = resolver.getQName(ndefElement.getAttribute());
                 builder.setDefaultPrimaryType(defaultPrimaryType);
             }
 
             Element reqPrimaryTypes = DomUtil.getChildElement(ndefElementnull);
             if (reqPrimaryTypes != null) {
                 ElementIterator it = DomUtil.getChildren(reqPrimaryTypesnull);
                 while (it.hasNext()) {
                     builder.addRequiredPrimaryType(resolver.getQName(DomUtil.getTextTrim(it.nextElement())));
                 }
             } else {
                 builder.addRequiredPrimaryType(.);
             }
 
             if (ndefElement.hasAttribute()) {
                 builder.setAllowsSameNameSiblings(Boolean.valueOf(ndefElement.getAttribute()));
             }
         } catch (NameException e) {
             throw new RepositoryException(e);
        }
        return builder.build();
    }

    

Parameters:
declaringNodeType
pdefElement
resolver
qValueFactory
Returns:
Throws:
javax.jcr.RepositoryException
    static QPropertyDefinition createQPropertyDefinition(Name declaringNodeTypeElement pdefElement,
                                                  NamePathResolver resolverQValueFactory qValueFactorythrows RepositoryException {
        QPropertyDefinitionBuilder builder = new QPropertyDefinitionBuilder();
        buildQItemDefinition(declaringNodeTypepdefElementresolverbuilder);
        if (pdefElement.hasAttribute()) {
            builder.setRequiredType(PropertyType.valueFromName(pdefElement.getAttribute()));
        }
        if (pdefElement.hasAttribute()) {
            builder.setMultiple(Boolean.valueOf(pdefElement.getAttribute()));
        }
        if (pdefElement.hasAttribute()) {
            builder.setFullTextSearchable(Boolean.valueOf(pdefElement.getAttribute()));
        }
        if (pdefElement.hasAttribute()) {
            builder.setQueryOrderable(Boolean.valueOf(pdefElement.getAttribute()));
        }
        int requiredType = builder.getRequiredType();                
        Element child = DomUtil.getChildElement(pdefElementnull);
        if (child != null) {
            ElementIterator it = DomUtil.getChildren(childnull);
            while (it.hasNext()) {
                String jcrVal = DomUtil.getText(it.nextElement());
                if (jcrVal == null) {
                    jcrVal = "";
                }
                QValue qValue;
                if (requiredType == .) {
                    // TODO: improve
                    Value v = new ValueFactoryQImpl(qValueFactoryresolver).createValue(jcrValrequiredType);
                    qValue = ValueFormat.getQValue(vresolverqValueFactory);
                } else {
                    qValue = ValueFormat.getQValue(jcrValrequiredTyperesolverqValueFactory);
                }
                builder.addDefaultValue(qValue);
            }
        } // else: no default values defined.
        child = DomUtil.getChildElement(pdefElementnull);
        if (child != null) {
            ElementIterator it = DomUtil.getChildren(childnull);
            while (it.hasNext()) {
                String qValue = DomUtil.getText(it.nextElement());
                // in case of name and path constraint, the value must be
                // converted to SPI values
                // TODO: tobefixed. path-constraint may contain trailing *
                builder.addValueConstraint(ValueConstraint.create(requiredTypeqValueresolver));
            }
        }
        child = DomUtil.getChildElement(pdefElementnull);
        if (child == null) {
            builder.setAvailableQueryOperators(new String[0]);
        } else {
            List<Stringnames = new ArrayList<String>();
            ElementIterator it = DomUtil.getChildren(childnull);
            while (it.hasNext()) {
                String str = DomUtil.getText(it.nextElement());
                names.add(str);
            }
            builder.setAvailableQueryOperators(names.toArray(new String[names.size()]));
        }
        return builder.build();
    }
                                                         QValueFactory qValueFactory)
            throws RepositoryException {
        QNodeTypeDefinitionBuilder builder = new QNodeTypeDefinitionBuilder();
        // TODO: webdav-server currently sends jcr-names -> conversion needed
        // NOTE: the server should send the namespace-mappings as addition ns-defininitions
        try {
            if (ntdElement.hasAttribute()) {
                builder.setName(resolver.getQName(ntdElement.getAttribute()));
            }
            if (ntdElement.hasAttribute()) {
                builder.setPrimaryItemName(resolver.getQName(ntdElement.getAttribute()));
            }
            Element child = DomUtil.getChildElement(ntdElementnull);
            if (child != null) {
                ElementIterator stIter = DomUtil.getChildren(childnull);
                List<NameqNames = new ArrayList<Name>();
                while (stIter.hasNext()) {
                    Name st = resolver.getQName(DomUtil.getTextTrim(stIter.nextElement()));
                    qNames.add(st);
                }
                builder.setSupertypes(qNames.toArray(new Name[qNames.size()]));
            }
            if (ntdElement.hasAttribute()) {
                builder.setMixin(Boolean.valueOf(ntdElement.getAttribute()));
            }
            if (ntdElement.hasAttribute()) {
                builder.setOrderableChildNodes(Boolean.valueOf(ntdElement.getAttribute()));
            }
            if (ntdElement.hasAttribute()) {
                builder.setAbstract(Boolean.valueOf(ntdElement.getAttribute()));
            }
            if (ntdElement.hasAttribute()) {
                builder.setQueryable(Boolean.valueOf(ntdElement.getAttribute()));
            }
            // nodeDefinitions
            ElementIterator it = DomUtil.getChildren(ntdElementnull);
            List<QNodeDefinitionnds = new ArrayList<QNodeDefinition>();
            while (it.hasNext()) {
                nds.add(createQNodeDefinition(builder.getName(), it.nextElement(), resolver));
            }
            builder.setChildNodeDefs(nds.toArray(new QNodeDefinition[nds.size()]));
            // propertyDefinitions
            it = DomUtil.getChildren(ntdElementnull);
            List<QPropertyDefinitionpds = new ArrayList<QPropertyDefinition>();
            while (it.hasNext()) {
                pds.add(createQPropertyDefinition(builder.getName(), it.nextElement(), resolverqValueFactory));
            }
            builder.setPropertyDefs(pds.toArray(new QPropertyDefinition[pds.size()]));
        } catch (NameException e) {
            .error(e.getMessage());
            throw new RepositoryException(e);
        }
        return builder.build();
    }

    

Parameters:
declaringNodeType
itemDefElement
resolver
builder
Throws:
javax.jcr.RepositoryException
    private static void buildQItemDefinition(Name declaringNodeType,
                                             Element itemDefElement,
                                             NamePathResolver resolver,
                                             QItemDefinitionBuilder builderthrows RepositoryException {
        try {
            String attr = itemDefElement.getAttribute();
            if (attr != null) {
                Name dnt = resolver.getQName(attr);
                if (declaringNodeType != null && !declaringNodeType.equals(dnt)) {
                    throw new RepositoryException("Declaring nodetype mismatch: In element = '" + dnt + "', Declaring nodetype = '" + declaringNodeType + "'");
                }
                builder.setDeclaringNodeType(dnt);
            } else {
                builder.setDeclaringNodeType(declaringNodeType);
            }
            if (itemDefElement.hasAttribute()) {
                String nAttr = itemDefElement.getAttribute();
                if (nAttr.length() > 0) {
                    builder.setName((isAnyName(nAttr)) ? . : resolver.getQName(nAttr));
                } else {
                    builder.setName(.);
                }
            } else {
                // TODO: check if correct..
                builder.setName(.);
            }
        } catch (NameException e) {
            throw new RepositoryException(e);
        }
        if (itemDefElement.hasAttribute()) {
            builder.setAutoCreated(Boolean.valueOf(itemDefElement.getAttribute()));
        }
        if (itemDefElement.hasAttribute()) {
            builder.setMandatory(Boolean.valueOf(itemDefElement.getAttribute()));
        }
        if (itemDefElement.hasAttribute()) {
            builder.setProtected(Boolean.valueOf(itemDefElement.getAttribute()));
        }
        if (itemDefElement.hasAttribute()) {
            builder.setOnParentVersion(OnParentVersionAction.valueFromName(itemDefElement.getAttribute()));
        }
    }
    private static boolean isAnyName(String nameAttribute) {
        return ..getLocalName().equals(nameAttribute);
    }
New to GrepCode? Check out our FAQ X