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.rat.configuration;
20  
21  import java.util.Arrays;
22  
23  /**
24   * Configuration definitions for XMLConfiguration reader and writer.
25   */
26  public final class XMLConfig {
27  
28      /** id attribute name */
29      public static final String ATT_ID = "id";
30      /** name attribute name */
31      public static final String ATT_NAME = "name";
32      /** license reference attribute name */
33      public static final String ATT_LICENSE_REF = "license_ref";
34      /** class name attribute name */
35      public static final String ATT_CLASS_NAME = "class";
36      /** resource file name attribute name. */
37      public static final String ATT_RESOURCE = "resource";
38      /** root of the configuration file */
39      public static final String ROOT = "rat-config";
40      /** families element name */
41      public static final String FAMILIES = "families";
42      /** licenses element name */
43      public static final String LICENSES = "licenses";
44      /** license element name */
45      public static final String LICENSE = "license";
46      /** approved element name */
47      public static final String APPROVED = "approved";
48      /** family element name */
49      public static final String FAMILY = "family";
50      /** note element name */
51      public static final String NOTE = "note";
52      /** matchers element name */
53      public static final String MATCHERS = "matchers";
54      /** matcher element name */
55      public static final String MATCHER = "matcher";
56  
57      /** License property names that should be children */
58      static final String[] LICENSE_CHILDREN = { NOTE, MATCHER };
59      /**
60       * License property names that should not be displayed contents should be placed
61       * inline
62       */
63      static final String[] LICENSE_INLINE = { MATCHER };
64  
65      /**
66       * Matcher properties that should be directly inlined Entries are matcher node
67       * name / property name pairs. A matcher may only have one inline node and then
68       * only if there is no other non-property node.
69       */
70      static final String[][] INLINE_NODES = { { "any", "enclosed" }, { "all", "enclosed" }, { "not", "enclosed" },
71              { "text", "simpleText" } };
72  
73      private XMLConfig() {
74          // do not instantiate
75      }
76  
77      /**
78       * Returns true if the specified child node should be placed inline in the XML
79       * document.
80       *
81       * @param parent the parent node name.
82       * @param child the child node name.
83       * @return true if the child should be inlined.
84       */
85      public static boolean isInlineNode(final String parent, final String child) {
86          return Arrays.stream(INLINE_NODES).anyMatch(s -> s[0].equals(parent) && s[1].equals(child));
87      }
88  
89      /**
90       * Returns true if the child should be a child node of a license node, as
91       * opposed to an attribute of the license.
92       *
93       * @param child the name of the child node.
94       * @return true if the child should be a child node.
95       */
96      public static boolean isLicenseChild(final String child) {
97          return Arrays.asList(LICENSE_CHILDREN).contains(child);
98      }
99  
100     /**
101      * Return true if the child should be inlined in the parent node.
102      *
103      * @param child the name of the child node.
104      * @return true if the child should be inlined.
105      */
106     public static boolean isLicenseInline(final String child) {
107         return Arrays.asList(LICENSE_INLINE).contains(child);
108     }
109 }