This project has retired. For details please refer to its Attic page.
ClientOperationContext 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.workbench.model;
20  
21  import java.util.Map;
22  
23  import org.apache.chemistry.opencmis.client.runtime.OperationContextImpl;
24  import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
25  
26  public class ClientOperationContext extends OperationContextImpl {
27  
28      private static final long serialVersionUID = 1L;
29  
30      public static final String FILTER = "filter";
31      public static final String INCLUDE_ACLS = "includeAcls";
32      public static final String INCLUDE_ALLOWABLE_ACTIONS = "includeAllowableActions";
33      public static final String INCLUDE_POLICIES = "includePolicies";
34      public static final String INCLUDE_RELATIONSHIPS = "includeRelationships";
35      public static final String RENDITION_FILTER = "renditionFilter";
36      public static final String ORDER_BY = "orderBy";
37      public static final String MAX_ITEMS_PER_PAGE = "maxItemsPerPage";
38  
39      public ClientOperationContext(String prefix, Map<String, String> map) {
40          loadContext(prefix, map);
41          setIncludePathSegments(false);
42          setCacheEnabled(true);
43      }
44  
45      public void loadContext(String prefix, Map<String, String> map) {
46          setFilterString(map.get(prefix + FILTER));
47          setIncludeAcls(parseBoolean(map.get(prefix + INCLUDE_ACLS), false));
48          setIncludeAllowableActions(parseBoolean(map.get(prefix + INCLUDE_ALLOWABLE_ACTIONS), false));
49          setIncludePolicies(parseBoolean(map.get(prefix + INCLUDE_POLICIES), false));
50          setIncludeRelationships(parseIncludeRelationships(map.get(prefix + INCLUDE_RELATIONSHIPS),
51                  IncludeRelationships.NONE));
52          setRenditionFilterString(map.get(prefix + RENDITION_FILTER));
53          setOrderBy(map.get(prefix + ORDER_BY));
54          setMaxItemsPerPage(parseInteger(map.get(prefix + MAX_ITEMS_PER_PAGE), 1000));
55      }
56  
57      private boolean parseBoolean(String s, boolean defaultValue) {
58          return (s == null ? defaultValue : Boolean.parseBoolean(s));
59      }
60  
61      private IncludeRelationships parseIncludeRelationships(String s, IncludeRelationships defaultValue) {
62          if (s == null) {
63              return defaultValue;
64          }
65  
66          try {
67              return IncludeRelationships.fromValue(s);
68          } catch (Exception e) {
69              return defaultValue;
70          }
71      }
72  
73      private int parseInteger(String s, int defaultValue) {
74          if (s == null) {
75              return defaultValue;
76          }
77  
78          try {
79              return Integer.parseInt(s);
80          } catch (NumberFormatException e) {
81              return defaultValue;
82          }
83      }
84  }