Package org.exoplatform.services.jcr.datamodel

Examples of org.exoplatform.services.jcr.datamodel.InternalQName


      //            // is running in a cluster.
      //            throw new RepositoryException(
      //                    "Missing child node entry for node with id: "
      //                    + node.getNodeId());
      //        }
      InternalQName name = node.getQPath().getName();
      addNodeName(doc, name.getNamespace(), name.getName());
   }
View Full Code Here


      if (steps.length > 0)
      {
         if (node.isAbsolute() && !steps[0].getIncludeDescendants())
         {
            // eat up first step
            InternalQName nameTest = steps[0].getNameTest();
            if (nameTest == null)
            {
               // this is equivalent to the root node
               context = new JcrTermQuery(new Term(FieldNames.UUID, Constants.ROOT_UUID));
            }
            else if (nameTest.getName().length() == 0)
            {
               // root node
               context = new JcrTermQuery(new Term(FieldNames.UUID, Constants.ROOT_UUID));
            }
            else
View Full Code Here

               || node.getOperation() == QueryConstants.OPERATION_EQ_VALUE
               || node.getOperation() == QueryConstants.OPERATION_NE_GENERAL
               || node.getOperation() == QueryConstants.OPERATION_NE_VALUE)
            {
               // only use coercing on non-range operations
               InternalQName propertyName = node.getRelativePath().getName();
               stringValues = getStringValues(propertyName, node.getStringValue());
            }
            else
            {
               stringValues[0] = node.getStringValue();
            }
            break;
         case QueryConstants.TYPE_POSITION :
            // ignore position. is handled in the location step
            return null;
         default :
            throw new IllegalArgumentException("Unknown relation type: " + node.getValueType());
      }

      if (node.getRelativePath() == null && node.getOperation() != QueryConstants.OPERATION_SIMILAR
         && node.getOperation() != QueryConstants.OPERATION_SPELLCHECK)
      {
         exceptions.add(new InvalidQueryException("@* not supported in predicate"));
         return data;
      }

      // get property transformation
      final int[] transform = new int[]{TransformConstants.TRANSFORM_NONE};
      node.acceptOperands(new DefaultQueryNodeVisitor()
      {
         @Override
         public Object visit(PropertyFunctionQueryNode node, Object data)
         {
            if (node.getFunctionName().equals(PropertyFunctionQueryNode.LOWER_CASE))
            {
               transform[0] = TransformConstants.TRANSFORM_LOWER_CASE;
            }
            else if (node.getFunctionName().equals(PropertyFunctionQueryNode.UPPER_CASE))
            {
               transform[0] = TransformConstants.TRANSFORM_UPPER_CASE;
            }
            return data;
         }
      }, null);

      QPath relPath = node.getRelativePath();

      InternalQName propName;

      if (node.getOperation() == QueryConstants.OPERATION_SIMILAR)
      {
         // this is a bit ugly:
         // add the name of a dummy property because relPath actually
         // references a property. whereas the relPath of the similar
         // operation references a node
         //relPath = QPath.makeChildPath(relPath, Constants.JCR_PRIMARYTYPE);
         propName = Constants.JCR_PRIMARYTYPE;
      }
      else
      {
         propName = relPath.getName();
      }

      String field = "";
      try
      {
         field = resolver.createJCRName(propName).getAsString();
      }
      catch (NamespaceException e)
      {
         // should never happen
         exceptions.add(e);
      }

      // support for fn:name()
      //InternalQName propName = relPath.getName();
      if (propName.getNamespace().equals(NS_FN_URI) && propName.getName().equals("name()"))
      {
         if (node.getValueType() != QueryConstants.TYPE_STRING)
         {
            exceptions.add(new InvalidQueryException("Name function can "
               + "only be used in conjunction with a string literal"));
            return data;
         }
         if (node.getOperation() != QueryConstants.OPERATION_EQ_VALUE
            && node.getOperation() != QueryConstants.OPERATION_EQ_GENERAL)
         {
            exceptions.add(new InvalidQueryException("Name function can "
               + "only be used in conjunction with an equals operator"));
            return data;
         }
         // check if string literal is a valid XML Name
         if (XMLChar.isValidName(node.getStringValue()))
         {
            // parse string literal as JCR Name
            try
            {
               InternalQName n =
                  session.getLocationFactory().parseJCRName(ISO9075.decode(node.getStringValue())).getInternalName();
               query = new NameQuery(n, indexFormatVersion, nsMappings);
            }
            catch (RepositoryException e)
            {
View Full Code Here

         {
            case PropertyType.NAME :
               // try to translate name
               try
               {
                  InternalQName n = session.getLocationFactory().parseJCRName(literal).getInternalName();
                  values.add(nsMappings.translateName(n));
                  LOG.debug("Coerced " + literal + " into NAME.");
               }
               catch (RepositoryException e)
               {
                  if (types.length == 1)
                  {
                     LOG.warn("Unable to coerce '" + literal + "' into a NAME: " + e.toString());
                  }
               }
               catch (IllegalNameException e)
               {
                  if (types.length == 1)
                  {
                     LOG.warn("Unable to coerce '" + literal + "' into a NAME: " + e.toString());
                  }
               }
               break;
            case PropertyType.PATH :
               // try to translate path
               try
               {
                  QPath p = session.getLocationFactory().parseJCRPath(literal).getInternalPath();
                  values.add(resolver.createJCRPath(p).getAsString(true));
                  LOG.debug("Coerced " + literal + " into PATH.");
               }
               catch (RepositoryException e)
               {
                  if (types.length == 1)
                  {
                     LOG.warn("Unable to coerce '" + literal + "' into a PATH: " + e.toString());
                  }
               }
               break;
            case PropertyType.DATE :
               // try to parse date
               Calendar c = ISO8601.parse(literal);
               if (c != null)
               {
                  values.add(DateField.timeToString(c.getTimeInMillis()));
                  LOG.debug("Coerced " + literal + " into DATE.");
               }
               else
               {
                  if (types.length == 1)
                  {
                     LOG.warn("Unable to coerce '" + literal + "' into a DATE.");
                  }
               }
               break;
            case PropertyType.DOUBLE :
               // try to parse double
               try
               {
                  double d = Double.parseDouble(literal);
                  values.add(DoubleField.doubleToString(d));
                  LOG.debug("Coerced " + literal + " into DOUBLE.");
               }
               catch (NumberFormatException e)
               {
                  if (types.length == 1)
                  {
                     LOG.warn("Unable to coerce '" + literal + "' into a DOUBLE: " + e.toString());
                  }
               }
               break;
            case PropertyType.LONG :
               // try to parse long
               try
               {
                  long l = Long.parseLong(literal);
                  values.add(LongField.longToString(l));
                  LOG.debug("Coerced " + literal + " into LONG.");
               }
               catch (NumberFormatException e)
               {
                  if (types.length == 1)
                  {
                     LOG.warn("Unable to coerce '" + literal + "' into a LONG: " + e.toString());
                  }
               }
               break;
            case PropertyType.STRING :
               values.add(literal);
               LOG.debug("Using literal " + literal + " as is.");
               break;
         }
      }

      if (values.size() == 0)
      {
         // use literal as is then try to guess other types
         values.add(literal);

         // try to guess property type
         if (literal.indexOf('/') > -1)
         {
            // might be a path
            try
            {
               QPath p = session.getLocationFactory().parseJCRPath(literal).getInternalPath();
               values.add(resolver.createJCRPath(p).getAsString(true));
               LOG.debug("Coerced " + literal + " into PATH.");
            }
            catch (Exception e)
            {
               if (LOG.isTraceEnabled())
               {
                  LOG.trace("An exception occurred: " + e.getMessage());
               }
            }
         }
         if (XMLChar.isValidName(literal))
         {
            // might be a name
            try
            {
               InternalQName n = session.getLocationFactory().parseJCRName(literal).getInternalName();
               values.add(nsMappings.translateName(n));
               LOG.debug("Coerced " + literal + " into NAME.");
            }
            catch (Exception e)
            {
View Full Code Here

      List<NodeTypeData> nodeTypes = new ArrayList<NodeTypeData>();

      HashMap<InternalQName, String> propertiesMap = new HashMap<InternalQName, String>();

      List<InternalQName> mixinNodeTypes = new ArrayList<InternalQName>();
      InternalQName jcrName = locationFactory.parseJCRName(nodeName).getInternalName();

      parseAttr(atts, nodeTypes, mixinNodeTypes, propertiesMap, jcrName);

      ImportNodeData nodeData = createNode(nodeTypes, propertiesMap, mixinNodeTypes, jcrName);

      NodeData parentNodeData = getParent();
     
      changesLog.add(new ItemState(nodeData, ItemState.ADDED, true, getAncestorToSave()));

      tree.push(nodeData);

      if (log.isDebugEnabled())
      {
         log.debug("Node " + ": " + nodeData.getQPath().getAsString());
      }

      Iterator<InternalQName> keys = propertiesMap.keySet().iterator();

      PropertyData newProperty;

      while (keys.hasNext())
      {
         newProperty = null;

         InternalQName propName = keys.next();
         if (log.isDebugEnabled())
         {
            log.debug("Property NAME: " + propName + "=" + propertiesMap.get(propName));
         }

         if (propName.equals(Constants.JCR_PRIMARYTYPE))
         {
            InternalQName childName =
               locationFactory.parseJCRName(propertiesMap.get(Constants.JCR_PRIMARYTYPE)).getInternalName();
            if (!nodeTypeDataManager.isChildNodePrimaryTypeAllowed(childName, parentNodeData.getPrimaryTypeName(),
               parentNodeData.getMixinTypeNames()))
            {
               throw new ConstraintViolationException("Can't add node " + nodeData.getQName().getAsString() + " to "
                  + parentNodeData.getQPath().getAsString() + " node type "
                  + propertiesMap.get(Constants.JCR_PRIMARYTYPE)
                  + " is not allowed as child's node type for parent node type "
                  + parentNodeData.getPrimaryTypeName().getAsString());

            }
            newProperty = endPrimaryType(nodeData.getPrimaryTypeName());
         }
         else if (propName.equals(Constants.JCR_MIXINTYPES))
         {
            newProperty = endMixinTypes(mixinNodeTypes, propName);
         }
         else if (nodeData.isMixReferenceable() && propName.equals(Constants.JCR_UUID))
         {
            newProperty = endUuid(nodeData, propName, propertiesMap.get(Constants.JCR_UUID));
         }
         else
         {
            PropertyDefinitionData pDef;
            PropertyDefinitionDatas defs;
            InternalQName[] nTypes = mixinNodeTypes.toArray(new InternalQName[mixinNodeTypes.size() + 1]);
            nTypes[nTypes.length - 1] = nodeData.getPrimaryTypeName();
            defs = nodeTypeDataManager.getPropertyDefinitions(propName, nTypes);
            if (defs == null || defs.getAnyDefinition() == null)
            {
               if (!((Boolean)context.get(ContentImporter.RESPECT_PROPERTY_DEFINITIONS_CONSTRAINTS)))
               {
                  log.warn("Property definition not found for " + propName.getAsString());
                  continue;
               }
               throw new RepositoryException("Property definition not found for " + propName.getAsString());
            }

            pDef = defs.getAnyDefinition();

            if ((pDef == null) || (defs == null))
            {
               throw new RepositoryException("no propertyDefinition found");
            }

            if (pDef.getRequiredType() == PropertyType.BINARY)
            {
               newProperty = endBinary(propertiesMap, newProperty, propName);
            }
            else
            {
               StringTokenizer spaceTokenizer = new StringTokenizer(propertiesMap.get(propName));

               List<ValueData> values = new ArrayList<ValueData>();
               int pType = pDef.getRequiredType() > 0 ? pDef.getRequiredType() : PropertyType.STRING;
              
               if (defs.getAnyDefinition().isResidualSet())
               {
                  if (nodeData.getQPath().isDescendantOf(Constants.JCR_VERSION_STORAGE_PATH))
                  {
                     if (nodeData.getPrimaryTypeName().equals(Constants.NT_FROZENNODE))
                     {
                        // get primaryType
                        InternalQName fptName = locationFactory.parseJCRName(atts.get("jcr:frozenPrimaryType")).getInternalName();

                        // get mixin types
                        List<JCRName> mtNames = getJCRNames(atts.get("jcr:frozenMixinTypes"));

                        InternalQName fmtName[] = new InternalQName[mtNames.size()];

                        for (int i = 0; i < mtNames.size(); i++)
                        {
                           fmtName[i] = new InternalQName(mtNames.get(i).getNamespace(), mtNames.get(i).getName());
                        }

                        PropertyDefinitionDatas ptVhdefs = nodeTypeDataManager.getPropertyDefinitions(propName, fptName, fmtName);

                        if (ptVhdefs != null)
                        {
                           pType = (ptVhdefs.getAnyDefinition().getRequiredType() > 0 ? ptVhdefs.getAnyDefinition()
                                             .getRequiredType() : PropertyType.STRING);
                        }
                     }
                  }
               }
              
               if ("".equals(propertiesMap.get(propName)))
               {
                  // Skip empty non string values
                  if (pType != PropertyType.STRING)
                  {
                     continue;
                  }
                 
                  String denormalizeString = StringConverter.denormalizeString(propertiesMap.get(propName));
                  Value value = valueFactory.createValue(denormalizeString, pType);
                  values.add(((BaseValue)value).getInternalData());
                  if (Constants.EXO_OWNER.equals(propName))
                  {
                     nodeData.setExoOwner(denormalizeString);
                  }
               }
               else
               {
                  List<String> denormalizeStrings = new ArrayList<String>();

                  while (spaceTokenizer.hasMoreTokens())
                  {
                     String elem = spaceTokenizer.nextToken();
                     String denormalizeString = StringConverter.denormalizeString(elem);
                     denormalizeStrings.add(denormalizeString);
                     Value value = valueFactory.createValue(denormalizeString, pType);
                     if (log.isDebugEnabled())
                     {
                        String valueAsString = null;
                        try
                        {
                           valueAsString = value.getString();
                        }
                        catch (Exception e)
                        {
                           log.error("Can't present value as string. " + e.getMessage());
                           valueAsString = "[Can't present value as string]";
                        }
                        log.debug("Property " + ExtendedPropertyType.nameFromValue(pType) + ": " + propName + "="
                           + valueAsString);
                     }
                     values.add(((BaseValue)value).getInternalData());

                  }
                  if (pType == ExtendedPropertyType.PERMISSION)
                  {
                     nodeData.setExoPrivileges(denormalizeStrings);
                  }
                  else if (Constants.EXO_OWNER.equals(propName))
                  {
                     nodeData.setExoOwner(denormalizeStrings.get(0));
                  }
               }

               boolean isMultivalue = true;

               // determinating is property multivalue;
               if (values.size() == 1)
               {
                 
                  PropertyDefinitionDatas vhdefs = null;
                  if (defs.getAnyDefinition().isResidualSet())
                  {
                     if (nodeData.getQPath().isDescendantOf(Constants.JCR_VERSION_STORAGE_PATH))
                     {
                        if (nodeData.getPrimaryTypeName().equals(Constants.NT_FROZENNODE))
                        {
                           // get primaryType
                           InternalQName fptName =
                                    locationFactory.parseJCRName(atts.get("jcr:frozenPrimaryType")).getInternalName();
  
                           // get mixin types
                           List<JCRName> mtNames = getJCRNames(atts.get("jcr:frozenMixinTypes"));
  
                           InternalQName fmtName[] = new InternalQName[mtNames.size()];
  
                           for (int i = 0; i < mtNames.size(); i++)
                           {
                              fmtName[i] = new InternalQName(mtNames.get(i).getNamespace(), mtNames.get(i).getName());
                           }
  
                           vhdefs = nodeTypeDataManager.getPropertyDefinitions(propName, fptName, fmtName);
  
                           if (vhdefs != null)
View Full Code Here

            String propName = ISO9075.decode(key);
            if (log.isDebugEnabled())
            {
               log.debug(propName + ":" + attValue);
            }
            InternalQName propInternalQName = locationFactory.parseJCRName(propName).getInternalName();

            if (Constants.JCR_PRIMARYTYPE.equals(propInternalQName))
            {
               String primaryNodeType = StringConverter.denormalizeString(attValue);
               InternalQName ntName = locationFactory.parseJCRName(primaryNodeType).getInternalName();
               NodeTypeData nodeType = nodeTypeDataManager.getNodeType(ntName);
               if (nodeType == null)
                  throw new ConstraintViolationException("Can not find node type " + primaryNodeType);
               nodeTypes.add(nodeType);
               props.put(propInternalQName, primaryNodeType);
            }
            else if (Constants.JCR_MIXINTYPES.equals(propInternalQName))
            {
               String[] amTypes = attValue.split(" ");
               for (int mi = 0; mi < amTypes.length; mi++)
               {
                  amTypes[mi] = StringConverter.denormalizeString(amTypes[mi]);
                  InternalQName name = locationFactory.parseJCRName(amTypes[mi]).getInternalName();
                  mixinNodeTypes.add(name);
                  NodeTypeData nodeType = nodeTypeDataManager.getNodeType(name);
                  if (nodeType == null)
                     throw new ConstraintViolationException("Can not find node type " + amTypes[mi]);
View Full Code Here

            tmp.addAll(Arrays.asList(properties));
            propertySet = tmp;
         }
         try
         {
            InternalQName prop = resolver.parseJCRName(propertyName).getInternalName();
            if (!propertySet.contains(prop))
            {
               if (isExcerptFunction(propertyName))
               {
                  // excerpt function with parameter
View Full Code Here

    */
   public boolean canAddChildNode(String childNodeName)
   {
      try
      {
         InternalQName cname = locationFactory.parseJCRName(childNodeName).getInternalName();

         NodeDefinitionData childNodeDef = nodeTypeDataManager.getChildNodeDefinition(cname, nodeTypeData.getName());
         return !(childNodeDef == null || childNodeDef.isProtected() || childNodeDef.getDefaultPrimaryType() == null);
      }
      catch (RepositoryException e)
View Full Code Here

    */
   public boolean canAddChildNode(String childNodeName, String nodeTypeName)
   {
      try
      {
         InternalQName cname = locationFactory.parseJCRName(childNodeName).getInternalName();
         InternalQName ntname = locationFactory.parseJCRName(nodeTypeName).getInternalName();

         NodeDefinitionData childNodeDef =
            nodeTypeDataManager.getChildNodeDefinition(cname, ntname, nodeTypeData.getName());
         return !(childNodeDef == null || childNodeDef.isProtected()) && isChildNodePrimaryTypeAllowed(nodeTypeName);
      }
View Full Code Here

    */
   public boolean canRemoveItem(String itemName)
   {
      try
      {
         InternalQName iname = locationFactory.parseJCRName(itemName).getInternalName();

         PropertyDefinitionDatas pdefs = nodeTypeDataManager.getPropertyDefinitions(iname, nodeTypeData.getName());
         if (pdefs != null)
         {
            PropertyDefinitionData pd = pdefs.getAnyDefinition();
View Full Code Here

TOP

Related Classes of org.exoplatform.services.jcr.datamodel.InternalQName

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.