This project has retired. For details please refer to its Attic page.
XMLConstraints xref
View Javadoc

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.commons.impl;
20  
21  public final class XMLConstraints {
22  
23      public static final int MAX_STRING_LENGTH = 100 * 1024;
24  
25      public static final int MAX_EXTENSIONS_WIDTH;
26      public static final int MAX_EXTENSIONS_DEPTH;
27  
28      public static final int MAX_EXTENSIONS_WIDTH_DEFAULT = 1000;
29      public static final int MAX_EXTENSIONS_DEPTH_DEFAULT = 100;
30  
31      public static final String MAX_EXTENSIONS_WIDTH_SYSTEM_PROPERTY = "org.apache.chemistry.opencmis.XMLConstraints.maxExtensionWith";
32      public static final String MAX_EXTENSIONS_DEPTH_SYSTEM_PROPERTY = "org.apache.chemistry.opencmis.XMLConstraints.maxExtensionDepth";
33  
34      static {
35          int maxWidth = MAX_EXTENSIONS_WIDTH_DEFAULT;
36          try {
37              String maxWidthStr = System.getProperty(MAX_EXTENSIONS_WIDTH_SYSTEM_PROPERTY);
38              if (maxWidthStr != null) {
39                  maxWidth = Integer.parseInt(maxWidthStr);
40  
41                  // check for sane values
42                  if (maxWidth < 1 || maxWidth > 100000) {
43                      maxWidth = MAX_EXTENSIONS_WIDTH_DEFAULT;
44                  }
45              }
46          } catch (NumberFormatException e) {
47              // ignore
48          }
49          MAX_EXTENSIONS_WIDTH = maxWidth;
50  
51          int maxDepth = MAX_EXTENSIONS_DEPTH_DEFAULT;
52          try {
53              String maxDepthStr = System.getProperty(MAX_EXTENSIONS_DEPTH_SYSTEM_PROPERTY);
54              if (maxDepthStr != null) {
55                  maxDepth = Integer.parseInt(maxDepthStr);
56  
57                  // check for sane values
58                  if (maxDepth < 1 || maxDepth > 10000) {
59                      maxDepth = MAX_EXTENSIONS_DEPTH_DEFAULT;
60                  }
61              }
62          } catch (NumberFormatException e) {
63              // ignore
64          }
65          MAX_EXTENSIONS_DEPTH = maxDepth;
66      }
67  
68      private XMLConstraints() {
69      }
70  }