This project has retired. For details please refer to its Attic page.
FilterParser 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;
20  
21  
22  import java.util.ArrayList;
23  import java.util.Arrays;
24  import java.util.Collections;
25  import java.util.List;
26  
27  import org.apache.chemistry.opencmis.commons.PropertyIds;
28  
29  /**
30   * @author Jens
31   */
32  public class FilterParser {
33  
34      // Utility class
35      private FilterParser() {
36      }
37  
38      public static boolean isContainedInFilter(String propertyId, List<String> requestedIds) {
39          if (requestedIds.contains("*")) {
40              return true;
41          }
42          return requestedIds.contains(propertyId);
43      }
44  
45      public static List<String> getRequestedIdsFromFilter(String filter) {
46          if (filter == null || filter.length() == 0) {
47              return Collections.singletonList("*");
48          } else {
49              List<String> requestedIds = Arrays.asList(filter.split(",\\s*")); // comma
50              // plus
51              // whitespace
52  
53              // add object id because this is always needed in AtomPub binding:
54              if (!(requestedIds.contains(PropertyIds.OBJECT_ID))) {
55                  requestedIds = new ArrayList<String>(requestedIds); // copy immutable list
56                  requestedIds.add(PropertyIds.OBJECT_ID);
57              }
58  
59              if (requestedIds.contains("*")) {
60                  requestedIds = Collections.singletonList("*");
61              }
62              return requestedIds;
63          }
64      }
65  
66  }