|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| package org.apache.xindice.webadmin.util; |
|
21 |
| |
|
22 |
| import org.apache.xindice.core.Collection; |
|
23 |
| import org.apache.xindice.util.Configuration; |
|
24 |
| import org.apache.xindice.util.ReadOnlyException; |
|
25 |
| import org.apache.xindice.xml.TextWriter; |
|
26 |
| import org.apache.xindice.xml.dom.DocumentImpl; |
|
27 |
| import org.apache.commons.logging.Log; |
|
28 |
| import org.apache.commons.logging.LogFactory; |
|
29 |
| import org.w3c.dom.Document; |
|
30 |
| import org.w3c.dom.Element; |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| public class CollectionConfigurationHelper { |
|
39 |
| |
|
40 |
| private static final Log log = LogFactory.getLog(CollectionConfigurationHelper.class); |
|
41 |
| public static final String CONF_ELE = "collection"; |
|
42 |
| public static final String COL_NAME_ATTR = "name"; |
|
43 |
| public static final String INLINE_META_ATTR = "inline-metadata"; |
|
44 |
| public static final String COMPRESSED_ATTR = "compressed"; |
|
45 |
| public static final String FILER_ELE = "filer"; |
|
46 |
| public static final String FILER_CLASS_ATTR = "class"; |
|
47 |
| public static final boolean DEFAULT_INLINE_META = true; |
|
48 |
| public static final boolean DEFAULT_COMPRESSED = true; |
|
49 |
| public static final String DEFAULT_FILER_CLASS = "org.apache.xindice.core.filer.BTreeFiler"; |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
0
| public static boolean getDefaultInlineMetadata() {
|
|
67 |
0
| return DEFAULT_INLINE_META;
|
|
68 |
| } |
|
69 |
| |
|
70 |
0
| public static boolean getDefaultCompressed() {
|
|
71 |
0
| return DEFAULT_COMPRESSED;
|
|
72 |
| } |
|
73 |
| |
|
74 |
0
| public static String getDefaultFilerClass() {
|
|
75 |
0
| return DEFAULT_FILER_CLASS;
|
|
76 |
| } |
|
77 |
| |
|
78 |
2
| public static boolean isInlineMetaEnabled(final Collection col) {
|
|
79 |
2
| Configuration config = col.getConfig();
|
|
80 |
2
| return config.getBooleanAttribute(INLINE_META_ATTR, false);
|
|
81 |
| } |
|
82 |
| |
|
83 |
1
| public static Configuration createDefaultConfiguration(String name) {
|
|
84 |
1
| return createConfiguration(name, null, null, null);
|
|
85 |
| } |
|
86 |
| |
|
87 |
1
| public static Configuration createConfiguration(String name, String compressed, String inlineMeta, String filerClass) {
|
|
88 |
1
| Document doc = new DocumentImpl();
|
|
89 |
1
| Element colEle = doc.createElement(CONF_ELE);
|
|
90 |
1
| if (name == null || name.length() == 0) {
|
|
91 |
0
| throw new IllegalArgumentException("null name");
|
|
92 |
| } |
|
93 |
1
| colEle.setAttribute(COL_NAME_ATTR, name);
|
|
94 |
1
| if (compressed == null || (!compressed.equalsIgnoreCase("true") && !compressed.equalsIgnoreCase("false"))) {
|
|
95 |
1
| compressed = Boolean.toString(DEFAULT_COMPRESSED);
|
|
96 |
| } |
|
97 |
1
| colEle.setAttribute(COMPRESSED_ATTR, compressed);
|
|
98 |
1
| if (inlineMeta == null || (!inlineMeta.equalsIgnoreCase("true") && !inlineMeta.equalsIgnoreCase("false"))) {
|
|
99 |
1
| inlineMeta = Boolean.toString(DEFAULT_INLINE_META);
|
|
100 |
| } |
|
101 |
1
| colEle.setAttribute(INLINE_META_ATTR, inlineMeta);
|
|
102 |
1
| doc.appendChild(colEle);
|
|
103 |
1
| Element filEle = doc.createElement(FILER_ELE);
|
|
104 |
1
| if (filerClass == null || filerClass.length() == 0) {
|
|
105 |
1
| filerClass = DEFAULT_FILER_CLASS;
|
|
106 |
| } |
|
107 |
1
| filEle.setAttribute(FILER_CLASS_ATTR, filerClass);
|
|
108 |
1
| colEle.appendChild(filEle);
|
|
109 |
1
| if (log.isDebugEnabled()) {
|
|
110 |
0
| log.debug("Created Configuration: \n" + TextWriter.toString(doc));
|
|
111 |
| } |
|
112 |
1
| return new Configuration(doc.getDocumentElement(), false);
|
|
113 |
| } |
|
114 |
| |
|
115 |
0
| public static Configuration copyConfiguration(final Configuration srcConfig) {
|
|
116 |
0
| Configuration newConfig = createConfiguration();
|
|
117 |
0
| try {
|
|
118 |
0
| return copyConfigurationContent(srcConfig, newConfig);
|
|
119 |
| } catch (ReadOnlyException e) { |
|
120 |
0
| log.error(e);
|
|
121 |
0
| return null;
|
|
122 |
| } |
|
123 |
| } |
|
124 |
| |
|
125 |
3
| public static Configuration copyConfiguration(String name, final Configuration srcConfig) {
|
|
126 |
3
| Configuration destConfig = createConfiguration();
|
|
127 |
3
| try {
|
|
128 |
3
| copyConfigurationContent(srcConfig, destConfig);
|
|
129 |
3
| destConfig.setAttribute(COL_NAME_ATTR, name);
|
|
130 |
| } catch (ReadOnlyException e) { |
|
131 |
| |
|
132 |
| } |
|
133 |
| |
|
134 |
3
| return destConfig;
|
|
135 |
| } |
|
136 |
| |
|
137 |
17
| private static Configuration copyConfigurationContent(final Configuration srcConfig, Configuration destConfig)
|
|
138 |
| throws ReadOnlyException { |
|
139 |
| |
|
140 |
17
| if (srcConfig.hasAttributes()) {
|
|
141 |
10
| String[] attrs = srcConfig.listAttributes();
|
|
142 |
10
| for (int i = 0; i < attrs.length; i++) {
|
|
143 |
20
| destConfig.setAttribute(attrs[i], srcConfig.getAttribute(attrs[i]));
|
|
144 |
| } |
|
145 |
| } |
|
146 |
17
| if (srcConfig.hasValue()) {
|
|
147 |
0
| String value = srcConfig.getValue(null);
|
|
148 |
0
| if (value != null) {
|
|
149 |
0
| destConfig.setValue(value);
|
|
150 |
| } |
|
151 |
| } |
|
152 |
17
| if (srcConfig.hasChildren()) {
|
|
153 |
7
| Configuration[] childConf = srcConfig.getChildren();
|
|
154 |
7
| for (int i = 0; i < childConf.length; i++) {
|
|
155 |
14
| Configuration childDestConfig = destConfig.getChild(childConf[i].getName(), true);
|
|
156 |
14
| copyConfigurationContent(childConf[i], childDestConfig);
|
|
157 |
| } |
|
158 |
| } |
|
159 |
| |
|
160 |
17
| return destConfig;
|
|
161 |
| } |
|
162 |
| |
|
163 |
3
| private static Configuration createConfiguration() {
|
|
164 |
3
| Document doc = new DocumentImpl();
|
|
165 |
3
| return new Configuration(doc.createElement(CONF_ELE), false);
|
|
166 |
| } |
|
167 |
| } |