This project has retired. For details please refer to its Attic page.
ListCommand 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.commander;
20  
21  import java.io.PrintWriter;
22  
23  import org.apache.chemistry.opencmis.commons.PropertyIds;
24  import org.apache.chemistry.opencmis.commons.data.ObjectInFolderData;
25  import org.apache.chemistry.opencmis.commons.data.ObjectInFolderList;
26  import org.apache.chemistry.opencmis.commons.data.PropertyData;
27  import org.apache.chemistry.opencmis.commons.spi.CmisBinding;
28  
29  public class ListCommand implements Command {
30  
31      /*
32       * (non-Javadoc)
33       *
34       * @see org.apache.opencmis.commander.Command#getCommandName()
35       */
36      public String getCommandName() {
37          return "list";
38      }
39  
40      /*
41       * (non-Javadoc)
42       *
43       * @see org.apache.opencmis.commander.Command#getUsage()
44       */
45      public String getUsage() {
46          return "LIST <repository id> <folder id>";
47      }
48  
49      public void execute(CmisBinding binding, String[] args, PrintWriter output) {
50          if (args.length < 2) {
51              output.println(getUsage());
52              return;
53          }
54  
55          String repositoryId = args[0];
56          String folderId = args[1];
57  
58          ObjectInFolderList list = binding.getNavigationService().getChildren(repositoryId, folderId, null, null, null,
59                  null, null, null, null, null, null);
60  
61          for (ObjectInFolderData object : list.getObjects()) {
62              output.println(getPropertyValue(object, PropertyIds.OBJECT_ID) + "\t"
63                      + getPropertyValue(object, PropertyIds.NAME) + "\t"
64                      + getPropertyValue(object, PropertyIds.OBJECT_TYPE_ID));
65          }
66      }
67  
68      /**
69       * Returns a property value as string.
70       */
71      private static String getPropertyValue(ObjectInFolderData object, String name) {
72          if ((object == null) || (object.getObject() == null) || (object.getObject().getProperties() == null)
73                  || (object.getObject().getProperties().getProperties() == null)) {
74              return "?";
75          }
76  
77          PropertyData<?> property = object.getObject().getProperties().getProperties().get(name);
78          if ((property == null) || (property.getFirstValue() == null)) {
79              return "<not set>";
80          }
81  
82          return property.getFirstValue().toString();
83      }
84  }