Return-Path: X-Original-To: apmail-chemistry-commits-archive@www.apache.org Delivered-To: apmail-chemistry-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 69BD0996B for ; Tue, 3 Apr 2012 05:18:26 +0000 (UTC) Received: (qmail 45445 invoked by uid 500); 3 Apr 2012 05:18:25 -0000 Delivered-To: apmail-chemistry-commits-archive@chemistry.apache.org Received: (qmail 45245 invoked by uid 500); 3 Apr 2012 05:18:24 -0000 Mailing-List: contact commits-help@chemistry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@chemistry.apache.org Delivered-To: mailing list commits@chemistry.apache.org Received: (qmail 44984 invoked by uid 99); 3 Apr 2012 05:18:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Apr 2012 05:18:21 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Apr 2012 05:17:45 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A92C22388CDF for ; Tue, 3 Apr 2012 05:16:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r811235 [33/42] - in /websites/staging/chemistry/trunk/content: ./ java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/ java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/css/ java/0.7.0/... Date: Tue, 03 Apr 2012 05:16:00 -0000 To: commits@chemistry.apache.org From: buildbot@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120403051607.A92C22388CDF@eris.apache.org> Added: websites/staging/chemistry/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentImpl.html ============================================================================== --- websites/staging/chemistry/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentImpl.html (added) +++ websites/staging/chemistry/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentImpl.html Tue Apr 3 05:15:55 2012 @@ -0,0 +1,182 @@ + + + + +DocumentImpl xref + + + +
+
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one
+3    * or more contributor license agreements.  See the NOTICE file
+4    * distributed with this work for additional information
+5    * regarding copyright ownership.  The ASF licenses this file
+6    * to you under the Apache License, Version 2.0 (the
+7    * "License"); you may not use this file except in compliance
+8    * with the License.  You may obtain a copy of the License at
+9    *
+10   * http://www.apache.org/licenses/LICENSE-2.0
+11   *
+12   * Unless required by applicable law or agreed to in writing,
+13   * software distributed under the License is distributed on an
+14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+15   * KIND, either express or implied.  See the License for the
+16   * specific language governing permissions and limitations
+17   * under the License.
+18   */
+19  package org.apache.chemistry.opencmis.inmemory.storedobj.impl;
+20  
+21  import java.io.IOException;
+22  import java.math.BigInteger;
+23  import java.util.List;
+24  import java.util.Map;
+25  
+26  import org.apache.chemistry.opencmis.commons.PropertyIds;
+27  import org.apache.chemistry.opencmis.commons.data.ContentStream;
+28  import org.apache.chemistry.opencmis.commons.data.PropertyData;
+29  import org.apache.chemistry.opencmis.commons.spi.BindingsObjectFactory;
+30  import org.apache.chemistry.opencmis.inmemory.ConfigConstants;
+31  import org.apache.chemistry.opencmis.inmemory.ConfigurationSettings;
+32  import org.apache.chemistry.opencmis.inmemory.FilterParser;
+33  import org.apache.chemistry.opencmis.inmemory.storedobj.api.Document;
+34  import org.apache.chemistry.opencmis.inmemory.storedobj.api.Folder;
+35  import org.apache.commons.logging.Log;
+36  import org.apache.commons.logging.LogFactory;
+37  
+38  /**
+39   * InMemory Stored Document A document is a stored object that has a path and
+40   * (optional) content
+41   *
+42   * @author Jens
+43   *
+44   */
+45  
+46  public class DocumentImpl extends AbstractMultiFilingImpl implements Document {
+47      private ContentStreamDataImpl fContent;
+48  
+49      private static final Log LOG = LogFactory.getLog(AbstractSingleFilingImpl.class.getName());
+50      private final Long MAX_CONTENT_SIZE_KB = ConfigurationSettings.getConfigurationValueAsLong(ConfigConstants.MAX_CONTENT_SIZE_KB);
+51  
+52      DocumentImpl(ObjectStoreImpl objStore) { // visibility should be package
+53          super(objStore);
+54      }
+55  
+56      public ContentStream getContent(long offset, long length) {
+57          if (null == fContent) {
+58              return null;
+59          } else if (offset <= 0 && length < 0) {
+60              return fContent;
+61          } else {
+62              return fContent.getCloneWithLimits(offset, length);
+63          }
+64      }
+65  
+66      public void setContent(ContentStream content, boolean mustPersist) {
+67          if (null == content) {
+68              fContent = null;
+69          } else {
+70              fContent = new ContentStreamDataImpl(MAX_CONTENT_SIZE_KB == null ? 0 : MAX_CONTENT_SIZE_KB);
+71              String fileName = content.getFileName();
+72              if (null == fileName || fileName.length() <= 0) {
+73                  fileName = getName(); // use name of document as fallback
+74              }
+75              fContent.setFileName(fileName);
+76              String mimeType = content.getMimeType();
+77              if (null == mimeType || mimeType.length() <= 0) {
+78                  mimeType = "application/octet-stream"; // use as fallback
+79              }
+80              fContent.setMimeType(mimeType);
+81              try {
+82                  fContent.setContent(content.getStream());
+83              } catch (IOException e) {
+84                  e.printStackTrace();
+85                  throw new RuntimeException("Failed to get content from InputStream", e);
+86              }
+87          }
+88      }
+89  
+90      @Override
+91      public void fillProperties(Map<String, PropertyData<?>> properties, BindingsObjectFactory objFactory,
+92              List<String> requestedIds) {
+93  
+94          super.fillProperties(properties, objFactory, requestedIds);
+95  
+96          // fill the version related properties (versions should override this
+97          // but the spec requires some
+98          // properties always to be set
+99  
+100         if (FilterParser.isContainedInFilter(PropertyIds.IS_IMMUTABLE, requestedIds)) {
+101             properties.put(PropertyIds.IS_IMMUTABLE, objFactory.createPropertyBooleanData(PropertyIds.IS_IMMUTABLE,
+102                     false));
+103         }
+104 
+105         // Set the content related properties
+106         if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_FILE_NAME, requestedIds)) {
+107             properties.put(PropertyIds.CONTENT_STREAM_FILE_NAME, objFactory.createPropertyStringData(
+108                     PropertyIds.CONTENT_STREAM_FILE_NAME, null != fContent ? fContent.getFileName() : (String)null) );
+109         }
+110         if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_ID, requestedIds)) {
+111             properties.put(PropertyIds.CONTENT_STREAM_ID, objFactory.createPropertyStringData(
+112                     PropertyIds.CONTENT_STREAM_ID, (String) null));
+113         }
+114         if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_LENGTH, requestedIds)) {
+115             properties.put(PropertyIds.CONTENT_STREAM_LENGTH, objFactory.createPropertyIntegerData(
+116                     PropertyIds.CONTENT_STREAM_LENGTH, null != fContent ? fContent.getBigLength() : BigInteger.ZERO));
+117         }
+118         if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_MIME_TYPE, requestedIds)) {
+119             properties.put(PropertyIds.CONTENT_STREAM_MIME_TYPE, objFactory.createPropertyStringData(
+120                     PropertyIds.CONTENT_STREAM_MIME_TYPE, null != fContent ? fContent.getMimeType() : (String)null) );
+121         }
+122         
+123         // Spec requires versioning properties even for unversioned documents
+124         // overwrite the version related properties
+125         if (FilterParser.isContainedInFilter(PropertyIds.VERSION_SERIES_ID, requestedIds)) {
+126             properties.put(PropertyIds.VERSION_SERIES_ID, objFactory.createPropertyIdData(
+127                     PropertyIds.VERSION_SERIES_ID, (String)null));
+128         }
+129         if (FilterParser.isContainedInFilter(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, requestedIds)) {
+130             properties.put(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, objFactory.createPropertyBooleanData(
+131                     PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, false));
+132         }
+133         if (FilterParser.isContainedInFilter(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, requestedIds)) {
+134             properties.put(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, objFactory.createPropertyStringData(
+135                     PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, (String)null));
+136         }
+137         if (FilterParser.isContainedInFilter(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, requestedIds)) {
+138             properties.put(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, objFactory.createPropertyIdData(
+139                     PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, (String)null));
+140         }
+141         if (FilterParser.isContainedInFilter(PropertyIds.IS_LATEST_VERSION, requestedIds)) {
+142             properties.put(PropertyIds.IS_LATEST_VERSION, objFactory.createPropertyBooleanData(
+143                     PropertyIds.IS_LATEST_VERSION, true));
+144         }
+145         if (FilterParser.isContainedInFilter(PropertyIds.IS_MAJOR_VERSION, requestedIds)) {
+146             properties.put(PropertyIds.IS_MAJOR_VERSION, objFactory.createPropertyBooleanData(
+147                     PropertyIds.IS_MAJOR_VERSION, true));
+148         }
+149         if (FilterParser.isContainedInFilter(PropertyIds.IS_LATEST_MAJOR_VERSION, requestedIds)) {
+150             properties.put(PropertyIds.IS_LATEST_MAJOR_VERSION, objFactory.createPropertyBooleanData(
+151                     PropertyIds.IS_LATEST_MAJOR_VERSION, true));
+152         }
+153         if (FilterParser.isContainedInFilter(PropertyIds.CHECKIN_COMMENT, requestedIds)) {
+154             properties.put(PropertyIds.CHECKIN_COMMENT, objFactory.createPropertyStringData(
+155                     PropertyIds.CHECKIN_COMMENT, (String )null));
+156         }
+157         if (FilterParser.isContainedInFilter(PropertyIds.VERSION_LABEL, requestedIds)) {
+158             properties.put(PropertyIds.VERSION_LABEL, objFactory.createPropertyStringData(PropertyIds.VERSION_LABEL,
+159                     (String) null));
+160         }
+161         
+162     }
+163 
+164     public boolean hasContent() {
+165         return null != fContent;
+166     }
+167 
+168 }
+
+
+ + Added: websites/staging/chemistry/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.html ============================================================================== --- websites/staging/chemistry/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.html (added) +++ websites/staging/chemistry/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref/org/apache/chemistry/opencmis/inmemory/storedobj/impl/DocumentVersionImpl.html Tue Apr 3 05:15:55 2012 @@ -0,0 +1,302 @@ + + + + +DocumentVersionImpl xref + + + +
+
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one
+3    * or more contributor license agreements.  See the NOTICE file
+4    * distributed with this work for additional information
+5    * regarding copyright ownership.  The ASF licenses this file
+6    * to you under the Apache License, Version 2.0 (the
+7    * "License"); you may not use this file except in compliance
+8    * with the License.  You may obtain a copy of the License at
+9    *
+10   * http://www.apache.org/licenses/LICENSE-2.0
+11   *
+12   * Unless required by applicable law or agreed to in writing,
+13   * software distributed under the License is distributed on an
+14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+15   * KIND, either express or implied.  See the License for the
+16   * specific language governing permissions and limitations
+17   * under the License.
+18   */
+19  package org.apache.chemistry.opencmis.inmemory.storedobj.impl;
+20  
+21  import java.io.IOException;
+22  import java.util.HashMap;
+23  import java.util.List;
+24  import java.util.Map;
+25  
+26  import org.apache.chemistry.opencmis.commons.PropertyIds;
+27  import org.apache.chemistry.opencmis.commons.data.ContentStream;
+28  import org.apache.chemistry.opencmis.commons.data.PropertyData;
+29  import org.apache.chemistry.opencmis.commons.enums.VersioningState;
+30  import org.apache.chemistry.opencmis.commons.spi.BindingsObjectFactory;
+31  import org.apache.chemistry.opencmis.inmemory.ConfigConstants;
+32  import org.apache.chemistry.opencmis.inmemory.ConfigurationSettings;
+33  import org.apache.chemistry.opencmis.inmemory.FilterParser;
+34  import org.apache.chemistry.opencmis.inmemory.storedobj.api.DocumentVersion;
+35  import org.apache.chemistry.opencmis.inmemory.storedobj.api.Folder;
+36  import org.apache.chemistry.opencmis.inmemory.storedobj.api.VersionedDocument;
+37  
+38  /**
+39   * A class representing a single version of a document
+40   *
+41   * @author Jens
+42   *
+43   */
+44  public class DocumentVersionImpl extends StoredObjectImpl implements DocumentVersion {
+45  
+46      private final Long MAX_CONTENT_SIZE_KB = ConfigurationSettings.getConfigurationValueAsLong(ConfigConstants.MAX_CONTENT_SIZE_KB);
+47  
+48      private ContentStreamDataImpl fContent;
+49      private final VersionedDocument fContainer; // the document this version belongs
+50      // to
+51      private String fComment; // checkin comment
+52      boolean fIsMajor;
+53      boolean fIsPwc; // true if this is the PWC
+54  
+55      public DocumentVersionImpl(String repositoryId, VersionedDocument container, ContentStream content,
+56              VersioningState verState, ObjectStoreImpl objStore) {
+57          super(objStore);
+58          setRepositoryId(repositoryId);
+59          fContainer = container;
+60          setContent(content, false);
+61          fIsMajor = verState == VersioningState.MAJOR;
+62          fIsPwc = verState == VersioningState.CHECKEDOUT;
+63          fProperties = new HashMap<String, PropertyData<?>>(); // ensure that we
+64          // have a map
+65      }
+66  
+67      public void setContent(ContentStream content, boolean mustPersist) {
+68          if (null == content) {
+69              fContent = null;
+70          } else {
+71              fContent = new ContentStreamDataImpl(MAX_CONTENT_SIZE_KB == null ? 0 : MAX_CONTENT_SIZE_KB);
+72              fContent.setFileName(content.getFileName());
+73              fContent.setMimeType(content.getMimeType());
+74              try {
+75                  fContent.setContent(content.getStream());
+76              } catch (IOException e) {
+77                  e.printStackTrace();
+78                  throw new RuntimeException("Failed to get content from InputStream", e);
+79              }
+80          }
+81      }
+82  
+83      public void setCheckinComment(String comment) {
+84          fComment = comment;
+85      }
+86  
+87      public String getCheckinComment() {
+88          return fComment;
+89      }
+90  
+91      public String getVersionLabel() {
+92          int majorNo = 0;
+93          int minorNo = 0;
+94          List<DocumentVersion> allVersions = fContainer.getAllVersions();
+95          for (DocumentVersion ver : allVersions) {
+96              if (ver.isMajor()) {
+97                  ++majorNo;
+98                  minorNo = 0;
+99              } else {
+100                 ++minorNo;
+101             }
+102             if (ver == this) {
+103                 break;
+104             }
+105         }
+106         String label = "V " + majorNo + "." + minorNo;
+107         return label;
+108     }
+109 
+110     public boolean isMajor() {
+111         return fIsMajor && !isPwc();
+112     }
+113 
+114     public boolean isPwc() {
+115         return fIsPwc;
+116     }
+117 
+118     public void commit(boolean isMajor) {
+119         fIsPwc = false; // unset working copy flag
+120         fIsMajor = isMajor;
+121     }
+122 
+123     public ContentStream getContent(long offset, long length) {
+124         if (offset <= 0 && length < 0) {
+125             return fContent;
+126         } else {
+127             return fContent.getCloneWithLimits(offset, length);
+128         }
+129     }
+130 
+131     public VersionedDocument getParentDocument() {
+132         return fContainer;
+133     }
+134 
+135     private boolean isLatestVersion() {
+136         List<DocumentVersion> allVers = fContainer.getAllVersions();
+137         boolean isLatestVersion;
+138         if (isPwc()) {
+139             isLatestVersion = allVers.size() > 1 && allVers.get(allVers.size() - 2).equals(this);
+140         } else {
+141             isLatestVersion = allVers.get(allVers.size() - 1).equals(this);
+142         }
+143         return isLatestVersion;
+144     }
+145 
+146     private boolean isLatestMajorVersion() {
+147         if (!fIsMajor) {
+148             return false;
+149         }
+150 
+151         List<DocumentVersion> allVersions = fContainer.getAllVersions();
+152         DocumentVersion latestMajor = null;
+153 
+154         for (DocumentVersion ver : allVersions) {
+155             if (ver.isMajor() && !ver.isPwc()) {
+156                 latestMajor = ver;
+157             }
+158         }
+159 
+160         boolean isLatestMajorVersion = latestMajor == this;
+161         return isLatestMajorVersion;
+162     }
+163 
+164     // public void persist() {
+165     // if (null==fId)
+166     // fId = UUID.randomUUID().toString();
+167     // }
+168 
+169     @Override
+170     public void fillProperties(Map<String, PropertyData<?>> properties, BindingsObjectFactory objFactory,
+171             List<String> requestedIds) {
+172 
+173         DocumentVersion pwc = fContainer.getPwc();
+174 
+175         // First get the properties of the container (like custom type
+176         // properties, etc)
+177         fContainer.fillProperties(properties, objFactory, requestedIds);
+178 
+179         // overwrite the version specific properties (like modification date,
+180         // user, etc.)
+181         // and set some properties specific to the version
+182         super.fillProperties(properties, objFactory, requestedIds);
+183 
+184 
+185         if (FilterParser.isContainedInFilter(PropertyIds.IS_IMMUTABLE, requestedIds)) {
+186             properties.put(PropertyIds.IS_IMMUTABLE, objFactory.createPropertyBooleanData(PropertyIds.IS_IMMUTABLE,
+187                     false));
+188         }
+189 
+190         // fill the version related properties
+191         if (FilterParser.isContainedInFilter(PropertyIds.IS_LATEST_VERSION, requestedIds)) {
+192             properties.put(PropertyIds.IS_LATEST_VERSION, objFactory.createPropertyBooleanData(
+193                     PropertyIds.IS_LATEST_VERSION, isLatestVersion()));
+194         }
+195         if (FilterParser.isContainedInFilter(PropertyIds.IS_MAJOR_VERSION, requestedIds)) {
+196             properties.put(PropertyIds.IS_MAJOR_VERSION, objFactory.createPropertyBooleanData(
+197                     PropertyIds.IS_MAJOR_VERSION, fIsMajor));
+198         }
+199         if (FilterParser.isContainedInFilter(PropertyIds.IS_LATEST_MAJOR_VERSION, requestedIds)) {
+200             properties.put(PropertyIds.IS_LATEST_MAJOR_VERSION, objFactory.createPropertyBooleanData(
+201                     PropertyIds.IS_LATEST_MAJOR_VERSION, isLatestMajorVersion()));
+202         }
+203         if (FilterParser.isContainedInFilter(PropertyIds.VERSION_SERIES_ID, requestedIds)) {
+204             properties.put(PropertyIds.VERSION_SERIES_ID, objFactory.createPropertyIdData(
+205                     PropertyIds.VERSION_SERIES_ID, fContainer.getId()));
+206         }
+207         if (FilterParser.isContainedInFilter(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, requestedIds)) {
+208             properties.put(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, objFactory.createPropertyBooleanData(
+209                     PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, fContainer.isCheckedOut()));
+210         }
+211         if (FilterParser.isContainedInFilter(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, requestedIds)) {
+212             properties.put(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, objFactory.createPropertyStringData(
+213                     PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, fContainer.getCheckedOutBy()));
+214         }
+215         if (FilterParser.isContainedInFilter(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, requestedIds)) {
+216             properties.put(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, objFactory.createPropertyIdData(
+217                     PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, pwc == null ? null : pwc.getId()));
+218         }
+219         if (FilterParser.isContainedInFilter(PropertyIds.CHECKIN_COMMENT, requestedIds)) {
+220             properties.put(PropertyIds.CHECKIN_COMMENT, objFactory.createPropertyStringData(
+221                     PropertyIds.CHECKIN_COMMENT, fComment));
+222         }
+223         if (FilterParser.isContainedInFilter(PropertyIds.VERSION_LABEL, requestedIds)) {
+224             properties.put(PropertyIds.VERSION_LABEL, objFactory.createPropertyStringData(PropertyIds.VERSION_LABEL,
+225                     getVersionLabel()));
+226         }
+227 
+228         // Set the content related properties
+229         if (null != fContent) {
+230             if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_FILE_NAME, requestedIds)) {
+231                 properties.put(PropertyIds.CONTENT_STREAM_FILE_NAME, objFactory.createPropertyStringData(
+232                         PropertyIds.CONTENT_STREAM_FILE_NAME, fContent.getFileName()));
+233             }
+234             if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_ID, requestedIds)) {
+235                 properties.put(PropertyIds.CONTENT_STREAM_ID, objFactory.createPropertyStringData(
+236                         PropertyIds.CONTENT_STREAM_ID, (String) null));
+237             }
+238             if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_LENGTH, requestedIds)) {
+239                 properties.put(PropertyIds.CONTENT_STREAM_LENGTH, objFactory.createPropertyIntegerData(
+240                         PropertyIds.CONTENT_STREAM_LENGTH, fContent.getBigLength()));
+241             }
+242             if (FilterParser.isContainedInFilter(PropertyIds.CONTENT_STREAM_MIME_TYPE, requestedIds)) {
+243                 properties.put(PropertyIds.CONTENT_STREAM_MIME_TYPE, objFactory.createPropertyStringData(
+244                         PropertyIds.CONTENT_STREAM_MIME_TYPE, fContent.getMimeType()));
+245             }
+246         }
+247     }
+248 
+249     @Override
+250     public int getAclId() {
+251         return ((StoredObjectImpl)fContainer).getAclId();
+252     }    
+253 
+254     @Override
+255     public void setAclId(int id) {
+256         ((StoredObjectImpl)fContainer).setAclId(id);
+257     }    
+258     
+259     public List<Folder> getParents(String user) {
+260         return fContainer.getParents(user);
+261     }
+262 
+263     public String getPathSegment() {
+264         return fContainer.getPathSegment();
+265     }
+266 
+267     public void move(Folder oldParent, Folder newParent) {
+268         fContainer.move(oldParent, newParent);
+269     }
+270 
+271     public void addParent(Folder parent) {
+272         fContainer.addParent(parent);
+273     }
+274 
+275     public void removeParent(Folder parent) {
+276         fContainer.removeParent(parent);
+277     }
+278 
+279     public boolean hasContent() {
+280         return null != fContent;
+281     }
+282 
+283     public boolean hasParent() {
+284       return true;
+285     }
+286 
+287 
+288 }
+
+
+ + Added: websites/staging/chemistry/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.html ============================================================================== --- websites/staging/chemistry/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.html (added) +++ websites/staging/chemistry/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref/org/apache/chemistry/opencmis/inmemory/storedobj/impl/FolderImpl.html Tue Apr 3 05:15:55 2012 @@ -0,0 +1,271 @@ + + + + +FolderImpl xref + + + +
+
+1   package org.apache.chemistry.opencmis.inmemory.storedobj.impl;
+2   /*
+3    *
+4    * Licensed to the Apache Software Foundation (ASF) under one
+5    * or more contributor license agreements.  See the NOTICE file
+6    * distributed with this work for additional information
+7    * regarding copyright ownership.  The ASF licenses this file
+8    * to you under the Apache License, Version 2.0 (the
+9    * "License"); you may not use this file except in compliance
+10   * with the License.  You may obtain a copy of the License at
+11   *
+12   *   http://www.apache.org/licenses/LICENSE-2.0
+13   *
+14   * Unless required by applicable law or agreed to in writing,
+15   * software distributed under the License is distributed on an
+16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+17   * KIND, either express or implied.  See the License for the
+18   * specific language governing permissions and limitations
+19   * under the License.
+20   *
+21   */
+22  
+23  
+24  import java.util.ArrayList;
+25  import java.util.Collections;
+26  import java.util.Comparator;
+27  import java.util.List;
+28  import java.util.Map;
+29  
+30  import org.apache.chemistry.opencmis.commons.PropertyIds;
+31  import org.apache.chemistry.opencmis.commons.data.PropertyData;
+32  import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
+33  import org.apache.chemistry.opencmis.commons.exceptions.CmisNameConstraintViolationException;
+34  import org.apache.chemistry.opencmis.commons.spi.BindingsObjectFactory;
+35  import org.apache.chemistry.opencmis.inmemory.FilterParser;
+36  import org.apache.chemistry.opencmis.inmemory.NameValidator;
+37  import org.apache.chemistry.opencmis.inmemory.storedobj.api.Document;
+38  import org.apache.chemistry.opencmis.inmemory.storedobj.api.DocumentVersion;
+39  import org.apache.chemistry.opencmis.inmemory.storedobj.api.Filing;
+40  import org.apache.chemistry.opencmis.inmemory.storedobj.api.Folder;
+41  import org.apache.chemistry.opencmis.inmemory.storedobj.api.MultiFiling;
+42  import org.apache.chemistry.opencmis.inmemory.storedobj.api.SingleFiling;
+43  import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoredObject;
+44  import org.apache.chemistry.opencmis.inmemory.storedobj.api.VersionedDocument;
+45  import org.apache.commons.logging.Log;
+46  import org.apache.commons.logging.LogFactory;
+47  
+48  public class FolderImpl extends AbstractSingleFilingImpl implements Folder {
+49      private static final Log LOG = LogFactory.getLog(AbstractSingleFilingImpl.class.getName());
+50  
+51      FolderImpl(ObjectStoreImpl objStore) {
+52          super(objStore);
+53      }
+54  
+55      public FolderImpl(ObjectStoreImpl objStore, String name, Folder parent) {
+56          super(objStore);
+57          init(name, parent);
+58      }
+59  
+60      public void addChildFolder(Folder folder) {
+61          try {
+62              fObjStore.lock();
+63              boolean hasChild;
+64              String name = folder.getName();
+65              hasChild = hasChild(name);
+66              if (hasChild) {
+67                  throw new CmisNameConstraintViolationException("Cannot create folder " + name + ". Name already exists in parent folder");
+68              }
+69              folder.setParent(this);
+70          } finally {
+71              fObjStore.unlock();
+72          }
+73      }
+74  
+75      /*
+76       * (non-Javadoc)
+77       *
+78       * @see
+79       * org.opencmis.client.provider.spi.inmemory.IFolder#addChildDocument(org
+80       * .opencmis.client.provider .spi.inmemory.storedobj.impl.DocumentImpl)
+81       */
+82      public void addChildDocument(Document doc) {
+83          addChildObject(doc);
+84      }
+85  
+86      public void addChildDocument(VersionedDocument doc) {
+87          addChildObject(doc);
+88      }
+89  
+90      private void addChildObject(StoredObject so) {
+91          try {
+92              fObjStore.lock();
+93              String name = so.getName();
+94              if (!NameValidator.isValidId(name)) {
+95                  throw new CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_NAME);
+96              }
+97  
+98              boolean hasChild;
+99              hasChild = hasChild(name);
+100             if (hasChild) {
+101                 throw new CmisNameConstraintViolationException(
+102                         "Cannot create object: " + name + ". Name already exists in parent folder");
+103             }
+104 
+105             if (so instanceof SingleFiling) {
+106                 ((SingleFiling) so).setParent(this);
+107             } else if (so instanceof MultiFiling) {
+108                 ((MultiFiling) so).addParent(this);
+109             } else {
+110                 throw new CmisInvalidArgumentException("Cannot create document, object is not fileable.");
+111             }
+112 
+113         } finally {
+114             fObjStore.unlock();
+115         }
+116     }
+117 
+118     public List<StoredObject> getChildren(int maxItems, int skipCount, String user) {
+119         List<StoredObject> result = new ArrayList<StoredObject>();
+120         for (String id : fObjStore.getIds()) {
+121             StoredObject obj = fObjStore.getObject(id);
+122             Filing pathObj = (Filing) obj;
+123             if (fObjStore.hasReadAccess(user, obj) && pathObj.getParents(user).contains(this)) {
+124                 if (pathObj instanceof VersionedDocument) {
+125                     DocumentVersion ver = ((VersionedDocument) pathObj).getLatestVersion(false);
+126                     result.add(ver);
+127                 } else if (pathObj instanceof DocumentVersion) {
+128                     // ignore
+129                 } else {
+130                     result.add(obj);
+131                 }
+132             }
+133         }
+134         sortFolderList(result);
+135 
+136         if (maxItems < 0) {
+137             maxItems = result.size();
+138         }
+139         if (skipCount < 0) {
+140             skipCount = 0;
+141         }
+142         int from = Math.min(skipCount, result.size());
+143         int to = Math.min(maxItems + from, result.size());
+144         result = result.subList(from, to);
+145         return result;
+146     }
+147 
+148     public List<Folder> getFolderChildren(int maxItems, int skipCount, String user) {
+149         List<Folder> result = new ArrayList<Folder>();
+150         for (String id : fObjStore.getIds()) {
+151             StoredObject obj = fObjStore.getObject(id);
+152             if (fObjStore.hasReadAccess(user, obj) && obj instanceof SingleFiling) {
+153                 SingleFiling pathObj = (SingleFiling) obj;
+154                 if (pathObj.getParent() == this && pathObj instanceof Folder) {
+155                     result.add((Folder) obj);
+156                 }
+157             }
+158         }
+159         sortFolderList(result);
+160         int from = Math.min(skipCount, result.size());
+161         int to = Math.min(maxItems + from, result.size());
+162         result = result.subList(from, to);
+163         return result;
+164     }
+165 
+166     public boolean hasChild(String name) {
+167         for (String id : fObjStore.getIds()) {
+168             StoredObject obj = fObjStore.getObject(id);
+169             if (obj instanceof Filing) {
+170                 Filing pathObj = (Filing) obj;
+171                 if (pathObj.getParents(null).contains(this) && obj.getName().equals(name)) {
+172                     return true;
+173                 }
+174             }
+175         }
+176         return false;
+177     }
+178 
+179     @Override
+180     public void fillProperties(Map<String, PropertyData<?>> properties, BindingsObjectFactory objFactory,
+181             List<String> requestedIds) {
+182 
+183         super.fillProperties(properties, objFactory, requestedIds);
+184 
+185         // add folder specific properties
+186 
+187         if (FilterParser.isContainedInFilter(PropertyIds.PARENT_ID, requestedIds)) {
+188             String parentId = getParent() == null ? null : getParent().getId();
+189             properties.put(PropertyIds.PARENT_ID, objFactory.createPropertyIdData(PropertyIds.PARENT_ID,
+190                     parentId));
+191         }
+192 
+193         if (FilterParser.isContainedInFilter(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS, requestedIds)) {
+194             String allowedChildObjects = "*"; // TODO: not yet supported
+195             properties.put(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS, objFactory.createPropertyIdData(
+196                     PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS, allowedChildObjects));
+197         }
+198 
+199         if (FilterParser.isContainedInFilter(PropertyIds.PATH, requestedIds)) {
+200             String path = getPath();
+201             properties.put(PropertyIds.PATH, objFactory.createPropertyStringData(PropertyIds.PATH, path));
+202         }
+203     }
+204 
+205     // Helper functions
+206     private void init(String name, Folder parent) {
+207         if (!NameValidator.isValidId(name)) {
+208             throw new CmisInvalidArgumentException(NameValidator.ERROR_ILLEGAL_NAME);
+209         }
+210         setName(name);
+211         setParent(parent);
+212     }
+213 
+214     private static void sortFolderList(List<? extends StoredObject> list) {
+215         // TODO evaluate orderBy, for now sort by path segment
+216         class FolderComparator implements Comparator<StoredObject> {
+217 
+218             public int compare(StoredObject f1, StoredObject f2) {
+219                 String segment1 = f1.getName();
+220                 String segment2 = f2.getName();
+221 
+222                 return segment1.compareTo(segment2);
+223             }
+224         }
+225 
+226         Collections.sort(list, new FolderComparator());
+227     }
+228 
+229     public void moveChildDocument(StoredObject so, Folder oldParent, Folder newParent) {
+230         try {
+231             fObjStore.lock();
+232             if (newParent.hasChild(so.getName())) {
+233                 throw new IllegalArgumentException("Cannot move object, this name already exists in target.");
+234             }
+235             if (!(so instanceof Filing)) {
+236                 throw new IllegalArgumentException("Cannot move object, object does not have a path.");
+237             }
+238 
+239             if (so instanceof SingleFiling) {
+240                 SingleFiling pathObj = (SingleFiling) so;
+241                 pathObj.setParent(newParent);
+242             } else if (so instanceof MultiFiling) {
+243                 MultiFiling pathObj = (MultiFiling) so;
+244                 pathObj.addParent(newParent);
+245                 pathObj.removeParent(oldParent);
+246             }
+247         } finally {
+248             fObjStore.unlock();
+249         }
+250     }
+251 
+252     public List<String> getAllowedChildObjectTypeIds() {
+253         // TODO implement this.
+254         return null;
+255     }
+256 
+257 }
+
+
+ +