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 class XMLConfig { 27 28 /** id attribute name */ 29 public final static String ATT_ID = "id"; 30 /** name attribute name */ 31 public final static String ATT_NAME = "name"; 32 /** license reference attribute name */ 33 public final static String ATT_LICENSE_REF = "license_ref"; 34 /** class name attribute name */ 35 public final static String ATT_CLASS_NAME = "class"; 36 /** resource file name attribute name. */ 37 public final static String ATT_RESOURCE = "resource"; 38 /** root of the configuration file */ 39 public final static String ROOT = "rat-config"; 40 /** families element name */ 41 public final static String FAMILIES = "families"; 42 /** licenses element name */ 43 public final static String LICENSES = "licenses"; 44 /** license element name */ 45 public final static String LICENSE = "license"; 46 /** approved element name */ 47 public final static String APPROVED = "approved"; 48 /** family element name */ 49 public final static String FAMILY = "family"; 50 /** note element name */ 51 public final static String NOTE = "note"; 52 /** matchers element name */ 53 public final static String MATCHERS = "matchers"; 54 /** matcher element name */ 55 public final static 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(String parent, String child) { 86 return Arrays.stream(INLINE_NODES).filter(s -> s[0].equals(parent) && s[1].equals(child)).findAny().isPresent(); 87 } 88 89 /** 90 * Returns true if the child should be a child node of a license node, as 91 * opposed to a 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(String child) { 97 return Arrays.stream(LICENSE_CHILDREN).filter(s -> s.equals(child)).findAny().isPresent(); 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(String child) { 107 return Arrays.stream(LICENSE_INLINE).filter(s -> s.equals(child)).findAny().isPresent(); 108 } 109 }