/** @return Returns true if the pattern is present, otherwise false. */
  public boolean contains(
      NodeRef nodeRef,
      QName propertyQName,
      String googleLikePattern,
      SearchParameters.Operator defaultOperator) {
    ResultSet resultSet = null;
    try {
      // build Lucene search string specific to the node
      StringBuilder sb = new StringBuilder();
      sb.append("+ID:\"")
          .append(nodeRef.toString())
          .append("\" +(TEXT:(")
          .append(googleLikePattern.toLowerCase())
          .append(") ");
      if (propertyQName != null) {
        sb.append(" OR @")
            .append(
                SearchLanguageConversion.escapeLuceneQuery(
                    QName.createQName(
                            propertyQName.getNamespaceURI(),
                            ISO9075.encode(propertyQName.getLocalName()))
                        .toString()));
        sb.append(":(").append(googleLikePattern.toLowerCase()).append(")");
      } else {
        for (QName key : nodeService.getProperties(nodeRef).keySet()) {
          sb.append(" OR @")
              .append(
                  SearchLanguageConversion.escapeLuceneQuery(
                      QName.createQName(key.getNamespaceURI(), ISO9075.encode(key.getLocalName()))
                          .toString()));
          sb.append(":(").append(googleLikePattern.toLowerCase()).append(")");
        }
      }
      sb.append(")");

      SearchParameters sp = new SearchParameters();
      sp.setLanguage(SearchService.LANGUAGE_LUCENE);
      sp.setQuery(sb.toString());
      sp.setDefaultOperator(defaultOperator);
      sp.addStore(nodeRef.getStoreRef());

      resultSet = this.query(sp);
      boolean answer = resultSet.length() > 0;
      return answer;
    } finally {
      if (resultSet != null) {
        resultSet.close();
      }
    }
  }
  private static NodeRef followAssociations(
      ServiceRegistry services,
      ChildAssociationRef association,
      QName qnameType,
      String[] navigation,
      int indexNavigation)
      throws InvalidAssociationException, InvalidContentException {
    NodeRef finalTarget = null;
    String uri = qnameType.getNamespaceURI();
    if (association.getQName().toString().contains(uri)
        && association.getQName().toString().contains(navigation[indexNavigation])) {
      NodeRef target = association.getChildRef();
      if (target != null) {
        if (indexNavigation < navigation.length - 2) {
          QName targetType = services.getNodeService().getType(target);
          List<ChildAssociationRef> nextAssociations =
              services.getNodeService().getChildAssocs(target);
          for (ChildAssociationRef nextAssociation : nextAssociations) {
            followAssociations(
                services, nextAssociation, targetType, navigation, indexNavigation++);
          }
        } else {
          finalTarget = target;
        }
      } else {
        throw new InvalidContentException(InvalidContentException.DOES_NOT_EXISTS);
      }
    } else {
      throw new InvalidAssociationException(InvalidAssociationException.DOES_NOT_EXISTS);
    }

    return finalTarget;
  }
示例#3
0
    public Builder(String typeName_) {
      // String tableName = tagResolver.translate(typeName_);
      String tableName = databaseDictionary.resolveClassAsTableName(typeName_);
      if (tableName == null) {
        throw new InvalidTypeException(typeName_);
      }

      Collection<QName> allTypes = dictionaryService.getAllTypes();
      List<QName> correspondingTypes = new ArrayList<QName>();
      for (QName type : allTypes) {
        if (type.getLocalName().equals(typeName_)) {
          correspondingTypes.add(type);
        }
      }
      if (correspondingTypes.size() == 0) {
        throw new AlfrescoRuntimeException(
            "Cannot find type \"" + typeName_ + "\" in Alfresco types");
      }
      if (correspondingTypes.size() > 1) {
        throw new AlfrescoRuntimeException(
            "Type \"" + typeName_ + "\" has several corresponding Alfresco types");
      }

      typeQName = correspondingTypes.get(0);
      namespaceURI = typeQName.getNamespaceURI();
      this.tableName = tableName;
      this.typeName = typeName_;
    }
示例#4
0
  /* (non-Javadoc)
   * @see org.alfresco.service.cmr.view.Exporter#startNode(org.alfresco.service.cmr.repository.NodeRef)
   */
  public void startNode(NodeRef nodeRef) {
    try {
      AttributesImpl attrs = new AttributesImpl();

      Path path = nodeService.getPath(nodeRef);
      if (path.size() > 1) {
        // a child name does not exist for root
        Path.ChildAssocElement pathElement = (Path.ChildAssocElement) path.last();
        QName childQName = pathElement.getRef().getQName();
        attrs.addAttribute(
            NamespaceService.REPOSITORY_VIEW_1_0_URI,
            CHILDNAME_LOCALNAME,
            CHILDNAME_QNAME.toPrefixString(),
            null,
            toPrefixString(childQName));
      }

      QName type = nodeService.getType(nodeRef);
      contentHandler.startElement(
          type.getNamespaceURI(), type.getLocalName(), toPrefixString(type), attrs);
    } catch (SAXException e) {
      throw new ExporterException(
          "Failed to process start node event - node ref " + nodeRef.toString(), e);
    }
  }
  /** @return Returns true if the pattern is present, otherwise false. */
  public boolean like(
      NodeRef nodeRef, QName propertyQName, String sqlLikePattern, boolean includeFTS) {
    if (propertyQName == null) {
      throw new IllegalArgumentException("Property QName is mandatory for the like expression");
    }

    StringBuilder sb = new StringBuilder(sqlLikePattern.length() * 3);

    if (includeFTS) {
      // convert the SQL-like pattern into a Lucene-compatible string
      String pattern =
          SearchLanguageConversion.convertXPathLikeToLucene(sqlLikePattern.toLowerCase());

      // build Lucene search string specific to the node
      sb = new StringBuilder();
      sb.append("+ID:\"").append(nodeRef.toString()).append("\" +(");
      // FTS or attribute matches
      if (includeFTS) {
        sb.append("TEXT:(").append(pattern).append(") ");
      }
      if (propertyQName != null) {
        sb.append(" @")
            .append(
                SearchLanguageConversion.escapeLuceneQuery(
                    QName.createQName(
                            propertyQName.getNamespaceURI(),
                            ISO9075.encode(propertyQName.getLocalName()))
                        .toString()))
            .append(":(")
            .append(pattern)
            .append(")");
      }
      sb.append(")");

      ResultSet resultSet = null;
      try {
        resultSet = this.query(nodeRef.getStoreRef(), "lucene", sb.toString());
        boolean answer = resultSet.length() > 0;
        return answer;
      } finally {
        if (resultSet != null) {
          resultSet.close();
        }
      }
    } else {
      // convert the SQL-like pattern into a Lucene-compatible string
      String pattern =
          SearchLanguageConversion.convertXPathLikeToRegex(sqlLikePattern.toLowerCase());

      Serializable property = nodeService.getProperty(nodeRef, propertyQName);
      if (property == null) {
        return false;
      } else {
        String propertyString =
            DefaultTypeConverter.INSTANCE.convert(
                String.class, nodeService.getProperty(nodeRef, propertyQName));
        return propertyString.toLowerCase().matches(pattern);
      }
    }
  }
示例#6
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#endAspects(org.alfresco.service.cmr.repository.NodeRef)
  */
 public void endAspects(NodeRef nodeRef) {
   try {
     contentHandler.endElement(
         ASPECTS_QNAME.getNamespaceURI(), ASPECTS_LOCALNAME, toPrefixString(ASPECTS_QNAME));
   } catch (SAXException e) {
     throw new ExporterException("Failed to process end aspects", e);
   }
 }
示例#7
0
 /*
  * (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#endReference(org.alfresco.service.cmr.repository.NodeRef)
  */
 public void endReference(NodeRef nodeRef) {
   try {
     contentHandler.endElement(
         REFERENCE_QNAME.getNamespaceURI(), REFERENCE_LOCALNAME, toPrefixString(REFERENCE_QNAME));
   } catch (SAXException e) {
     throw new ExporterException("Failed to process end reference", e);
   }
 }
示例#8
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#endACL(org.alfresco.service.cmr.repository.NodeRef)
  */
 public void endACL(NodeRef nodeRef) {
   try {
     contentHandler.endElement(
         ACL_QNAME.getNamespaceURI(), ACL_QNAME.getLocalName(), toPrefixString(ACL_QNAME));
   } catch (SAXException e) {
     throw new ExporterException(
         "Failed to process end ACL event - node ref " + nodeRef.toString());
   }
 }
示例#9
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#endNode(org.alfresco.service.cmr.repository.NodeRef)
  */
 public void endNode(NodeRef nodeRef) {
   try {
     QName type = nodeService.getType(nodeRef);
     contentHandler.endElement(type.getNamespaceURI(), type.getLocalName(), toPrefixString(type));
   } catch (SAXException e) {
     throw new ExporterException(
         "Failed to process end node event - node ref " + nodeRef.toString(), e);
   }
 }
示例#10
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#endProperties(org.alfresco.service.cmr.repository.NodeRef)
  */
 public void endProperties(NodeRef nodeRef) {
   try {
     contentHandler.endElement(
         PROPERTIES_QNAME.getNamespaceURI(),
         PROPERTIES_LOCALNAME,
         toPrefixString(PROPERTIES_QNAME));
   } catch (SAXException e) {
     throw new ExporterException("Failed to process start properties", e);
   }
 }
示例#11
0
 public static long getCrc(QName qname) {
   CRC32 crc = new CRC32();
   try {
     crc.update(qname.getNamespaceURI().getBytes("UTF-8"));
     crc.update(qname.getLocalName().getBytes("UTF-8"));
   } catch (UnsupportedEncodingException e) {
     throw new RuntimeException("UTF-8 encoding is not supported");
   }
   return crc.getValue();
 }
示例#12
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#startAssocs(org.alfresco.service.cmr.repository.NodeRef)
  */
 public void startAssocs(NodeRef nodeRef) {
   try {
     contentHandler.startElement(
         ASSOCIATIONS_QNAME.getNamespaceURI(),
         ASSOCIATIONS_LOCALNAME,
         toPrefixString(ASSOCIATIONS_QNAME),
         EMPTY_ATTRIBUTES);
   } catch (SAXException e) {
     throw new ExporterException("Failed to process start associations", e);
   }
 }
示例#13
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#startAssoc(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
  */
 public void startAssoc(NodeRef nodeRef, QName assoc) {
   try {
     contentHandler.startElement(
         assoc.getNamespaceURI(), assoc.getLocalName(), toPrefixString(assoc), EMPTY_ATTRIBUTES);
   } catch (SAXException e) {
     throw new ExporterException(
         "Failed to process start assoc event - nodeRef "
             + nodeRef
             + "; association "
             + toPrefixString(assoc),
         e);
   }
 }
示例#14
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#endAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
  */
 public void endAspect(NodeRef nodeRef, QName aspect) {
   try {
     contentHandler.endElement(
         aspect.getNamespaceURI(), aspect.getLocalName(), toPrefixString(aspect));
   } catch (SAXException e) {
     throw new ExporterException(
         "Failed to process end aspect event - node ref "
             + nodeRef.toString()
             + "; aspect "
             + toPrefixString(aspect),
         e);
   }
 }
示例#15
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#endAssoc(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
  */
 public void endAssoc(NodeRef nodeRef, QName assoc) {
   try {
     contentHandler.endElement(
         assoc.getNamespaceURI(), assoc.getLocalName(), toPrefixString(assoc));
   } catch (SAXException e) {
     throw new ExporterException(
         "Failed to process end assoc event - nodeRef "
             + nodeRef
             + "; association "
             + toPrefixString(assoc),
         e);
   }
 }
示例#16
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#endProperty(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
  */
 public void endProperty(NodeRef nodeRef, QName property) {
   try {
     contentHandler.endElement(
         property.getNamespaceURI(), property.getLocalName(), toPrefixString(property));
   } catch (SAXException e) {
     throw new ExporterException(
         "Failed to process end property event - nodeRef "
             + nodeRef
             + "; property "
             + toPrefixString(property),
         e);
   }
 }
示例#17
0
 public void setQName(QNameDAO qnameDAO, QName qname) {
   String assocQNameNamespace = qname.getNamespaceURI();
   String assocQNameLocalName = qname.getLocalName();
   Long assocQNameNamespaceId = qnameDAO.getOrCreateNamespace(assocQNameNamespace).getFirst();
   Long assocQNameCrc = getCrc(qname);
   // get write lock
   refWriteLock.lock();
   try {
     setQnameNamespaceId(assocQNameNamespaceId);
     setQnameLocalName(assocQNameLocalName);
     setQnameCrc(assocQNameCrc);
   } finally {
     refWriteLock.unlock();
   }
 }
示例#18
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#startProperty(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
  */
 public void startProperty(NodeRef nodeRef, QName property) {
   try {
     contentHandler.startElement(
         property.getNamespaceURI(),
         property.getLocalName(),
         toPrefixString(property),
         EMPTY_ATTRIBUTES);
   } catch (SAXException e) {
     throw new ExporterException(
         "Failed to process start property event - nodeRef "
             + nodeRef
             + "; property "
             + toPrefixString(property),
         e);
   }
 }
示例#19
0
  private QName getName(QName name, String tenantDomain) {
    String namespace = name.getNamespaceURI();
    int idx1 = namespace.indexOf(SEPARATOR);
    if (idx1 == -1) {
      // no domain, so add it as a prefix (between two domain separators)
      namespace = SEPARATOR + tenantDomain + SEPARATOR + namespace;
      name = QName.createQName(namespace, name.getLocalName());
    } else {
      int idx2 = namespace.indexOf(SEPARATOR, 1);
      String nameDomain = namespace.substring(1, idx2);
      if (!tenantDomain.equals(nameDomain)) {
        throw new AlfrescoRuntimeException(
            "domain mismatch: expected = " + tenantDomain + ", actual = " + nameDomain);
      }
    }

    return name;
  }
示例#20
0
 /* (non-Javadoc)
  * @see org.alfresco.service.cmr.view.Exporter#startACL(org.alfresco.service.cmr.repository.NodeRef)
  */
 public void startACL(NodeRef nodeRef) {
   try {
     AttributesImpl attrs = new AttributesImpl();
     boolean inherit = permissionService.getInheritParentPermissions(nodeRef);
     if (!inherit) {
       attrs.addAttribute(
           NamespaceService.REPOSITORY_VIEW_1_0_URI,
           INHERITPERMISSIONS_LOCALNAME,
           INHERITPERMISSIONS_QNAME.toPrefixString(),
           null,
           "false");
     }
     contentHandler.startElement(
         ACL_QNAME.getNamespaceURI(), ACL_QNAME.getLocalName(), toPrefixString(ACL_QNAME), attrs);
   } catch (SAXException e) {
     throw new ExporterException(
         "Failed to process start ACL event - node ref " + nodeRef.toString());
   }
 }
示例#21
0
  /* (non-Javadoc)
   * @see org.alfresco.service.cmr.view.Exporter#startReference(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
   */
  public void startReference(NodeRef nodeRef, QName childName) {
    try {
      // determine format of reference e.g. node or path based
      ReferenceType referenceFormat = referenceType;
      if (nodeRef.equals(nodeService.getRootNode(nodeRef.getStoreRef()))) {
        referenceFormat = ReferenceType.PATHREF;
      }

      // output reference
      AttributesImpl attrs = new AttributesImpl();
      if (referenceFormat.equals(ReferenceType.PATHREF)) {
        Path path = createPath(context.getExportParent(), context.getExportParent(), nodeRef);
        attrs.addAttribute(
            NamespaceService.REPOSITORY_VIEW_1_0_URI,
            PATHREF_LOCALNAME,
            PATHREF_QNAME.toPrefixString(),
            null,
            path.toPrefixString(namespaceService));
      } else {
        attrs.addAttribute(
            NamespaceService.REPOSITORY_VIEW_1_0_URI,
            NODEREF_LOCALNAME,
            NODEREF_QNAME.toPrefixString(),
            null,
            nodeRef.toString());
      }
      if (childName != null) {
        attrs.addAttribute(
            NamespaceService.REPOSITORY_VIEW_1_0_URI,
            CHILDNAME_LOCALNAME,
            CHILDNAME_QNAME.toPrefixString(),
            null,
            childName.toPrefixString(namespaceService));
      }
      contentHandler.startElement(
          REFERENCE_QNAME.getNamespaceURI(),
          REFERENCE_LOCALNAME,
          toPrefixString(REFERENCE_QNAME),
          attrs);
    } catch (SAXException e) {
      throw new ExporterException("Failed to process start reference", e);
    }
  }
示例#22
0
  /* (non-Javadoc)
   * @see org.alfresco.service.cmr.view.Exporter#permission(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.security.AccessPermission)
   */
  public void permission(NodeRef nodeRef, AccessPermission permission) {
    try {
      // output access control entry
      AttributesImpl attrs = new AttributesImpl();
      attrs.addAttribute(
          NamespaceService.REPOSITORY_VIEW_1_0_URI,
          ACCESS_LOCALNAME,
          ACCESS_QNAME.toPrefixString(),
          null,
          permission.getAccessStatus().toString());
      contentHandler.startElement(
          ACE_QNAME.getNamespaceURI(), ACE_QNAME.getLocalName(), toPrefixString(ACE_QNAME), attrs);

      // output authority
      contentHandler.startElement(
          AUTHORITY_QNAME.getNamespaceURI(),
          AUTHORITY_QNAME.getLocalName(),
          toPrefixString(AUTHORITY_QNAME),
          EMPTY_ATTRIBUTES);
      String authority = permission.getAuthority();
      contentHandler.characters(authority.toCharArray(), 0, authority.length());
      contentHandler.endElement(
          AUTHORITY_QNAME.getNamespaceURI(),
          AUTHORITY_QNAME.getLocalName(),
          toPrefixString(AUTHORITY_QNAME));

      // output permission
      contentHandler.startElement(
          PERMISSION_QNAME.getNamespaceURI(),
          PERMISSION_QNAME.getLocalName(),
          toPrefixString(PERMISSION_QNAME),
          EMPTY_ATTRIBUTES);
      String strPermission = permission.getPermission();
      contentHandler.characters(strPermission.toCharArray(), 0, strPermission.length());
      contentHandler.endElement(
          PERMISSION_QNAME.getNamespaceURI(),
          PERMISSION_QNAME.getLocalName(),
          toPrefixString(PERMISSION_QNAME));

      // end access control entry
      contentHandler.endElement(
          ACE_QNAME.getNamespaceURI(), ACE_QNAME.getLocalName(), toPrefixString(ACE_QNAME));
    } catch (SAXException e) {
      throw new ExporterException(
          "Failed to process permission event - node ref "
              + nodeRef.toString()
              + "; permission "
              + permission);
    }
  }
  /**
   * Set all required fields associated with the patch <code>QName</code>.
   *
   * @param forUpdate <tt>true</tt> if the entity is going to be used for a data update i.e. the
   *     <code>QName</code> <b>must</b> exist.
   * @return Returns <tt>true</tt> if the <code>QName</code> namespace exists.
   */
  public boolean setQNameAll(QNameDAO qnameDAO, QName qname, boolean forUpdate) {
    String assocQNameNamespace = qname.getNamespaceURI();
    String assocQNameLocalName = qname.getLocalName();
    Long assocQNameNamespaceId = null;
    if (forUpdate) {
      assocQNameNamespaceId = qnameDAO.getOrCreateNamespace(assocQNameNamespace).getFirst();
    } else {
      Pair<Long, String> nsPair = qnameDAO.getNamespace(assocQNameNamespace);
      if (nsPair == null) {
        // We can't set anything
        return false;
      } else {
        assocQNameNamespaceId = nsPair.getFirst();
      }
    }
    Long assocQNameCrc = getQNameCrc(qname);

    this.qnameNamespaceId = assocQNameNamespaceId;
    this.qnameLocalName = assocQNameLocalName;
    this.qnameCrc = assocQNameCrc;

    // All set correctly
    return true;
  }
示例#24
0
 /* (non-Javadoc)
  * @see org.alfresco.repo.tenant.TenantService#getBaseName(org.alfresco.service.namespace.QName, boolean)
  */
 public QName getBaseName(QName name, boolean forceForNonTenant) {
   String baseNamespaceURI = getBaseName(name.getNamespaceURI(), forceForNonTenant);
   return QName.createQName(baseNamespaceURI, name.getLocalName());
 }
示例#25
0
  /*
   *  (non-Javadoc)
   * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
   */
  public void startElement(String uri, String localName, String qName, Attributes atts)
      throws SAXException {
    try {
      // construct qname for element
      QName elementName = decodeQName(QName.createQName(qName, importResolver));

      // setup parent context
      ParentContext parentContext = null;
      if (contextStack.empty()) {
        // create root parent context
        parentContext = new ParentContext(elementName, dictionaryService, importer);
      } else {
        // create parent context
        NodeContext parentNode = (NodeContext) contextStack.peek();
        parentContext = new ParentContext(elementName, parentNode);
      }

      // create node context
      NodeContext node = new NodeContext(elementName, parentContext, null);
      node.setChildName(elementName.toPrefixString(importResolver));
      contextStack.push(node);

      // process node properties
      for (int i = 0; i < atts.getLength(); i++) {
        QName propName = decodeQName(QName.createQName(atts.getURI(i), atts.getLocalName(i)));
        String value = atts.getValue(i);

        //
        // process "well-known" properties
        //

        if (propName.equals(JCRPrimaryTypeProperty.PROPERTY_NAME)) {
          // primary type
          QName primaryTypeQName = QName.createQName(value, importResolver);
          TypeDefinition typeDef = dictionaryService.getType(primaryTypeQName);
          if (typeDef == null) {
            throw new InvalidTypeException(primaryTypeQName);
          }
          node.setTypeDefinition(typeDef);
        } else if (propName.equals(JCRMixinTypesProperty.PROPERTY_NAME)) {
          // aspects
          String[] aspects = value.split(" ");
          for (String aspect : aspects) {
            // ignore JCR specific aspects
            QName aspectQName = QName.createQName(aspect, importResolver);
            if (!(JCRNamespace.JCR_URI.equals(aspectQName.getNamespaceURI())
                || JCRNamespace.MIX_URI.equals(aspectQName.getNamespaceURI()))) {
              AspectDefinition aspectDef = dictionaryService.getAspect(aspectQName);
              if (aspectDef == null) {
                throw new InvalidTypeException(aspectQName);
              }
              node.addAspect(aspectDef);
            }
          }
        } else if (JCRUUIDProperty.PROPERTY_NAME.equals(propName)) {
          node.setUUID(value);
        }

        //
        // Note: ignore JCR specific properties
        //

        else if (JCRNamespace.JCR_URI.equals(propName.getNamespaceURI())) {
        }

        //
        // process all other properties
        //

        else {
          // determine type of property
          PropertyDefinition propDef = dictionaryService.getProperty(propName);
          if (propDef == null) {
            throw new ImporterException(
                "Property " + propName + " is not known to the repository data dictionary");
          }
          DataTypeDefinition dataTypeDef = propDef.getDataType();

          // extract values from node xml attribute
          String[] propValues = null;
          PropertyContext propertyContext =
              new PropertyContext(elementName, node, propName, dataTypeDef.getName());
          if (dataTypeDef.getName().equals(DataTypeDefinition.CONTENT)) {
            // Note: we only support single valued content properties
            propValues = new String[] {value};
          } else {
            // attempt to split multi-value properties
            propValues = value.split(" ");
          }

          // extract values appropriately
          for (String propValue : propValues) {
            propertyContext.startValue();
            propertyContext.appendCharacters(propValue.toCharArray(), 0, propValue.length());
            propertyContext.endValue();
          }

          // add each value to the node
          if (propertyContext.isMultiValue()) {
            node.addPropertyCollection(propName);
          }
          List<StringBuffer> nodeValues = propertyContext.getValues();
          for (StringBuffer nodeValue : nodeValues) {
            // first, cast value to appropriate type (using JCR converters)
            Serializable objVal =
                (Serializable)
                    session.getTypeConverter().convert(dataTypeDef, nodeValue.toString());
            String strValue = DefaultTypeConverter.INSTANCE.convert(String.class, objVal);
            node.addProperty(propName, strValue);
          }
        }
      }

      // import node
      NodeRef nodeRef = node.getImporter().importNode(node);
      node.setNodeRef(nodeRef);
    } catch (Exception e) {
      throw new SAXException("Failed to process element " + qName, e);
    }
  }
示例#26
0
 /**
  * Decode QName
  *
  * @param name name to decode
  * @return the decoded name
  */
 private QName decodeQName(QName name) {
   return QName.createQName(name.getNamespaceURI(), ISO9075.decode(name.getLocalName()));
 }
  /**
   * Compose the query string for Afresco.
   *
   * @param parameters
   * @return
   */
  private List<String> getAlfrescoQueries(Map<String, Object> parameters) throws Exception {

    List<String> queries = new ArrayList<String>();

    switch ((String) parameters.get(PARAMETER_COUNTER)) {
      case PARAMETER_COUNTER_ASPECTS:

        // Aspect list definition.
        List<QName> aspects = null;
        try {
          JSONObject jsonTypes = new JSONObject((String) parameters.get(PARAMETER_CLASSES));
          aspects = getQNames(jsonTypes.getJSONArray(PARAMETER_CLASSES_ASPECTS));
        } catch (JSONException e) {
          throw new Exception(
              "Error " + Status.STATUS_INTERNAL_SERVER_ERROR + ": " + e.getMessage());
        }

        // Query list composition.
        for (int i = 0; i < aspects.size(); ++i) {

          QName aspectQName = aspects.get(i);

          String query = "";
          query +=
              "(ASPECT:\"{"
                  + aspectQName.getNamespaceURI()
                  + "}"
                  + aspectQName.getLocalName()
                  + "\")";
          query += "AND ";
          query += "(@" + ContentModel.PROP_MODIFIED + ":[\"2001-01-01T00:00:00.000\" TO MAX]) ";

          queries.add(query);
        }

        break;

      case PARAMETER_COUNTER_TYPES:

        // Type list definition.
        List<QName> types = null;
        try {
          JSONObject jsonTypes = new JSONObject((String) parameters.get(PARAMETER_CLASSES));
          types = getQNames(jsonTypes.getJSONArray(PARAMETER_COUNTER_TYPES));
        } catch (JSONException e) {
          throw new Exception(
              "Error " + Status.STATUS_INTERNAL_SERVER_ERROR + ": " + e.getMessage());
        }

        // Query list composition.
        for (int i = 0; i < types.size(); ++i) {

          QName typeQName = types.get(i);

          String query = "";
          query +=
              "(TYPE:\"{" + typeQName.getNamespaceURI() + "}" + typeQName.getLocalName() + "\")";
          query += "AND ";
          query += "(@" + ContentModel.PROP_MODIFIED + ":[\"2001-01-01T00:00:00.000\" TO MAX]) ";

          queries.add(query);
        }

        break;

      default:
        throw new Exception(
            "Parameter '"
                + PARAMETER_COUNTER
                + "' with value '"
                + ((String) parameters.get(PARAMETER_COUNTER))
                + "' not admitted.");
    }

    return queries;
  }
  /**
   * @see
   *     org.alfresco.service.cmr.coci.CheckOutCheckInService#checkout(org.alfresco.service.cmr.repository.NodeRef,
   *     org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName,
   *     org.alfresco.service.namespace.QName)
   */
  public NodeRef checkout(
      final NodeRef nodeRef,
      final NodeRef destinationParentNodeRef,
      final QName destinationAssocTypeQName,
      QName destinationAssocQName) {
    LockType lockType = this.lockService.getLockType(nodeRef);
    if (LockType.READ_ONLY_LOCK.equals(lockType) == true || getWorkingCopy(nodeRef) != null) {
      throw new CheckOutCheckInServiceException(MSG_ALREADY_CHECKEDOUT);
    }

    // Make sure we are no checking out a working copy node
    if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY) == true) {
      throw new CheckOutCheckInServiceException(MSG_ERR_ALREADY_WORKING_COPY);
    }

    // Apply the lock aspect if required
    if (this.nodeService.hasAspect(nodeRef, ContentModel.ASPECT_LOCKABLE) == false) {
      this.nodeService.addAspect(nodeRef, ContentModel.ASPECT_LOCKABLE, null);
    }

    // Invoke before check out policy
    invokeBeforeCheckOut(
        nodeRef, destinationParentNodeRef, destinationAssocTypeQName, destinationAssocQName);

    // Rename the working copy
    String copyName = (String) this.nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
    copyName = createWorkingCopyName(copyName);

    // Make the working copy
    final QName copyQName =
        QName.createQName(
            destinationAssocQName.getNamespaceURI(), QName.createValidLocalName(copyName));
    NodeRef workingCopy =
        AuthenticationUtil.runAs(
            new AuthenticationUtil.RunAsWork<NodeRef>() {
              public NodeRef doWork() throws Exception {
                NodeRef workingCopy =
                    copyService.copy(
                        nodeRef, destinationParentNodeRef, destinationAssocTypeQName, copyQName);
                return workingCopy;
              }
            },
            AuthenticationUtil.getSystemUserName());

    // Update the working copy name
    this.nodeService.setProperty(workingCopy, ContentModel.PROP_NAME, copyName);

    // Get the user
    String userName = getUserName();

    // Apply the working copy aspect to the working copy
    Map<QName, Serializable> workingCopyProperties = new HashMap<QName, Serializable>(1);
    workingCopyProperties.put(ContentModel.PROP_WORKING_COPY_OWNER, userName);
    this.nodeService.addAspect(
        workingCopy, ContentModel.ASPECT_WORKING_COPY, workingCopyProperties);

    // Lock the original node
    this.lockService.lock(nodeRef, LockType.READ_ONLY_LOCK);

    // Invoke on check out policy
    invokeOnCheckOut(workingCopy);

    // Return the working copy
    return workingCopy;
  }