Package org.exoplatform.services.jcr.datamodel

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


         if (checkRemoveChildVersionStorages && !data.isNode()
            && Constants.JCR_VERSIONHISTORY.equals(data.getQPath().getName()))
         {
            try
            {
               PropertyData vhPropertyData = (PropertyData)getItemData(data.getIdentifier());
               removeVersionHistory(new String(vhPropertyData.getValues().get(0).getAsByteArray()), null,
                  ancestorToSave);
            }
            catch (IllegalStateException e)
            {
               throw new RepositoryException(e.getLocalizedMessage(), e);
View Full Code Here


         List<ValueData> data = null;
         if (node.getQPath().getName().equals(Constants.JCR_CONTENT))
         {

            // seems nt:file found, try for nt:resource props
            PropertyData pmime =
               (PropertyData)stateProvider.getItemData(node, new QPathEntry(Constants.JCR_MIMETYPE, 0));
            if (pmime != null)
            {
               // ok, have a reader
               // if the prop obtainer from cache it will contains a values,
               // otherwise read prop with values from DM
               PropertyData propData =
                  prop.getValues().size() > 0 ? prop : ((PropertyData)stateProvider.getItemData(node, new QPathEntry(
                     Constants.JCR_DATA, 0)));

               // index if have jcr:mimeType sibling for this binary property only
               try
               {
                  DocumentReader dreader =
                     extractor.getDocumentReader(new String(pmime.getValues().get(0).getAsByteArray()));

                  data = propData.getValues();

                  if (data == null)
                  {
                     log.warn("null value found at property " + prop.getQPath().getAsString());
                  }

                  // check the jcr:encoding property
                  PropertyData encProp =
                     (PropertyData)stateProvider.getItemData(node, new QPathEntry(Constants.JCR_ENCODING, 0));

                  if (encProp != null)
                  {
                     // encoding parameter used
                     String encoding = new String(encProp.getValues().get(0).getAsByteArray());
                     for (ValueData pvd : data)
                     {
                        InputStream is = null;
                        try
                        {
View Full Code Here

               if (propStates != null)
               {
                  ruleMatched = true;
                  for (int j = 0; j < propStates.length; j++)
                  {
                     PropertyData propState = propStates[j];
                     String namePrefix =
                        FieldNames.createNamedValue(getNamespaceMappings()
                           .translateName(propState.getQPath().getName()), "");
                     NodeData parent = (NodeData)ism.getItemData(propState.getParentIdentifier());
                     Document aDoc = createDocument(parent, getNamespaceMappings(), getIndex().getIndexFormatVersion());
                     try
                     {
                        // find the right fields to transfer
                        Fieldable[] fields = aDoc.getFieldables(FieldNames.PROPERTIES);
View Full Code Here

         List<ValueData> data = null;
         if (node.getQPath().getName().equals(Constants.JCR_CONTENT))
         {

            // seems nt:file found, try for nt:resource props
            PropertyData pmime = node.getProperty(Constants.JCR_MIMETYPE.getAsString());
            if (pmime == null && !node.containAllProperties())
            {
               pmime =
                  (PropertyData)stateProvider.getItemData(node, new QPathEntry(Constants.JCR_MIMETYPE, 0),
                     ItemType.PROPERTY);
            }

            if (pmime != null && pmime.getValues() != null && !pmime.getValues().isEmpty())
            {
               // ok, have a reader
               // if the prop obtainer from cache it will contains a values,
               // otherwise read prop with values from DM
               PropertyData propData =
                  prop.getValues() != null && !prop.getValues().isEmpty() ? prop : ((PropertyData)stateProvider
                     .getItemData(node, new QPathEntry(Constants.JCR_DATA, 0), ItemType.PROPERTY));

               // index if have jcr:mimeType sibling for this binary property only
               try
               {
                  if (propData == null || (data = propData.getValues()) == null || data.isEmpty())
                  {
                     if (LOG.isDebugEnabled())
                     {
                        LOG.debug("No value found for the property located at " + prop.getQPath().getAsString());
                     }
                     return;
                  }

                  DocumentReader dreader =
                     extractor.getDocumentReader(new String(pmime.getValues().get(0).getAsByteArray(),
                        Constants.DEFAULT_ENCODING));

                  // check the jcr:encoding property
                  PropertyData encProp = node.getProperty(Constants.JCR_ENCODING.getAsString());
                  if (encProp == null && !node.containAllProperties())
                  {
                     encProp =
                        (PropertyData)stateProvider.getItemData(node, new QPathEntry(Constants.JCR_ENCODING, 0),
                           ItemType.PROPERTY);
                  }

                  String encoding = null;
                  if (encProp != null && encProp.getValues() != null && !encProp.getValues().isEmpty())
                  {
                     // encoding parameter used
                     encoding = new String(encProp.getValues().get(0).getAsByteArray(), Constants.DEFAULT_ENCODING);
                  }
                  else
                  {
                     if (LOG.isDebugEnabled())
                     {
                        LOG.debug("No encoding found for the node located at " + node.getQPath().getAsString());
                     }
                  }

                  if (dreader instanceof AdvancedDocumentReader)
                  {
                     // its a tika document reader that supports getContentAsReader
                     for (ValueData pvd : data)
                     {
                        // tikaDocumentReader will close inputStream, so no need to close it at finally
                        // statement

                        InputStream is = null;
                        is = pvd.getAsStream();
                        Reader reader;
                        if (encoding != null)
                        {
                           reader = ((AdvancedDocumentReader)dreader).getContentAsReader(is, encoding);
                        }
                        else
                        {
                           reader = ((AdvancedDocumentReader)dreader).getContentAsReader(is);
                        }
                        doc.add(createFulltextField(reader));
                     }
                  }
                  else
                  {
                     // old-style document reader
                     for (ValueData pvd : data)
                     {
                        InputStream is = null;
                        try
                        {
                           is = pvd.getAsStream();
                           Reader reader;
                           if (encoding != null)
                           {
                              reader = new StringReader(dreader.getContentAsText(is, encoding));
                           }
                           else
                           {
                              reader = new StringReader(dreader.getContentAsText(is));
                           }
                           doc.add(createFulltextField(reader));
                        }
                        finally
                        {
                           try
                           {
                              is.close();
                           }
                           catch (Throwable e)
                           {
                              if (LOG.isTraceEnabled())
                              {
                                 LOG.trace("An exception occurred: " + e.getMessage());
                              }
                           }
                        }
                     }
                  }

                  if (data.size() > 1)
                  {
                     // real multi-valued
                     addMVPName(doc, prop.getQPath().getName());
                  }

               }
               catch (DocumentReadException e)
               {
                  LOG.error("Can not indexing the document by path " + propData.getQPath().getAsString()
                     + ", propery id '" + propData.getIdentifier() + "' : " + e, e);
               }
               catch (HandlerNotFoundException e)
               {
                  // no handler - no index
                  if (LOG.isDebugEnabled())
                  {
                     LOG.debug("Can not indexing the document by path " + propData.getQPath().getAsString()
                        + ", propery id '" + propData.getIdentifier() + "' : " + e, e);
                  }
               }
               catch (IOException e)
               {
                  // no data - no index
                  if (LOG.isWarnEnabled())
                  {
                     LOG.warn("Binary value indexer IO error, document by path " + propData.getQPath().getAsString()
                        + ", propery id '" + propData.getIdentifier() + "' : " + e, e);
                  }
               }
               catch (Exception e)
               {
                  LOG.error("Binary value indexer error, document by path " + propData.getQPath().getAsString()
                     + ", propery id '" + propData.getIdentifier() + "' : " + e, e);
               }
            }
            else
            {
               if (LOG.isDebugEnabled())
               {
                  LOG.debug("no mime type found for the node located at " + node.getQPath().getAsString());
               }
            }
         }
      }
      else
      {
         try
         {
            // if the prop obtainer from cache it will contains a values, otherwise
            // read prop with values from DM
            // WARN. DON'T USE access item BY PATH - it's may be a node in case of
            // residual definitions in NT
            PropertyData propData =
               prop.getValues() != null && !prop.getValues().isEmpty() ? prop : (PropertyData)stateProvider
                  .getItemData(prop.getIdentifier());

            List<ValueData> data;
              
            if (propData == null || (data = propData.getValues()) == null || data.isEmpty())
            {
               if (LOG.isDebugEnabled())
               {
                  LOG.debug("No value found for the property located at " + prop.getQPath().getAsString());
               }
View Full Code Here

   private void removeVersionHistory(NodeData mixVersionableNode) throws RepositoryException,
      ConstraintViolationException, VersionException
   {
      try
      {
         PropertyData vhpd =
            (PropertyData)dataConsumer.getItemData(mixVersionableNode, new QPathEntry(Constants.JCR_VERSIONHISTORY, 1),
               ItemType.PROPERTY);
         try
         {
            String vhID = new String(vhpd.getValues().get(0).getAsByteArray());
            VersionHistoryRemover historyRemover =
               new VersionHistoryRemover(vhID, dataConsumer, nodeTypeDataManager, repository, currentWorkspaceName,
                  null, ancestorToSave, changesLog, accessManager, userState);
            historyRemover.remove();
         }
View Full Code Here

         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)
                           {
                              isMultivalue = (vhdefs.getDefinition(true) != null ? true : false);
                           }
                        }
                     }
                  }
 
                  // there is single-value defeniton
                  if (vhdefs == null && defs.getDefinition(false) != null)
                  {
                        isMultivalue = false;
                  }
               }
               else
               {
                  if ((defs.getDefinition(true) == null) && (defs.getDefinition(false) != null))
                  {
                     throw new ValueFormatException("Can not assign multiple-values Value"
                        + " to a single-valued property " + propName.getAsString() + " node " + jcrName.getName());
                  }
               }

               newProperty =
                  TransientPropertyData.createPropertyData(getParent(), propName, pType, isMultivalue, values);

               if (nodeData.isMixVersionable())
               {
                  endVersionable(nodeData, values, propName);
               }
            }
         }
         // skip versionable

         if ((newProperty.getQPath().isDescendantOf(Constants.JCR_VERSION_STORAGE_PATH) || (!Constants.JCR_VERSIONHISTORY
            .equals(propName)
            && !Constants.JCR_BASEVERSION.equals(propName) && !Constants.JCR_PREDECESSORS.equals(propName))))
         {
            changesLog.add(new ItemState(newProperty, ItemState.ADDED, true, getAncestorToSave()));
         }
View Full Code Here

      return newProperty;
   }

   private PropertyData endMixinTypes(List<InternalQName> mixinNodeTypes, InternalQName key)
   {
      PropertyData newProperty;
      List<ValueData> valuesData = new ArrayList<ValueData>(mixinNodeTypes.size());

      for (InternalQName mixinQname : mixinNodeTypes)
      {
         valuesData.add(new TransientValueData(mixinQname));
View Full Code Here

      return newProperty;
   }

   private PropertyData endPrimaryType(InternalQName primaryTypeName)
   {
      PropertyData newProperty;
      if (log.isDebugEnabled())
      {
         log.debug("Property NAME: " + primaryTypeName);
      }
      newProperty =
View Full Code Here

   }

   private PropertyData endUuid(ImportNodeData nodeData, InternalQName key, String properyValueUUID) throws ValueFormatException,
      UnsupportedRepositoryOperationException, RepositoryException, IllegalStateException
   {
      PropertyData newProperty;
     
      if (nodeData.getQPath().isDescendantOf(Constants.JCR_VERSION_STORAGE_PATH))
      {
         newProperty =
            TransientPropertyData.createPropertyData(getParent(), Constants.JCR_UUID, PropertyType.STRING, false,
View Full Code Here

      {
         final List<PropertyData> childs = new ArrayList<PropertyData>();

         for (Object child : set)
         {
            PropertyData prop = (PropertyData)cache.get(makeItemFqn((String)child), ITEM_DATA);
            if (prop == null || prop instanceof NullItemData)
            {
               return null;
            }
            if (prop.getValues().size() <= 0)
            {
               // don't return list of empty-valued props (but listChildProperties() can)
               return null;
            }
            childs.add(prop);
View Full Code Here

TOP

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

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.