47
47
48
48
/**
49
49
* Abstract configuration corresponding to either a field or facet element nested inside
50
- * a index definition 'text' element. Adds the possibility to create index content based
50
+ * an index definition 'text' element. Adds the possibility to create index content based
51
51
* on an arbitrary XQuery expression.
52
52
*
53
53
* @author Wolfgang Meier
@@ -58,50 +58,52 @@ public abstract class AbstractFieldConfig {
58
58
59
59
protected static final Logger LOG = LogManager .getLogger (AbstractFieldConfig .class );
60
60
61
- protected Optional <String > expression = Optional . empty () ;
61
+ protected final Optional <String > expression ;
62
62
protected boolean isValid = true ;
63
63
private CompiledXQuery compiled = null ;
64
64
65
- public AbstractFieldConfig (LuceneConfig config , Element configElement , Map <String , String > namespaces ) {
65
+ public AbstractFieldConfig (final LuceneConfig config , final Element configElement , final Map <String , String > namespaces ) {
66
66
final String xpath = configElement .getAttribute (XPATH_ATTR );
67
67
if (xpath .isEmpty ()) {
68
-
69
- final StringBuilder sb = new StringBuilder ();
70
- namespaces .forEach ((prefix , uri ) -> {
71
- if (!"xml" .equals (prefix )) {
72
- sb .append ("declare namespace " ).append (prefix );
73
- sb .append ("=\" " ).append (uri ).append ("\" ;\n " );
74
- }
75
- });
76
- config .getImports ().ifPresent (moduleImports -> moduleImports .forEach ((moduleImport -> {
77
- sb .append ("import module namespace " );
78
- sb .append (moduleImport .prefix );
79
- sb .append ("=\" " );
80
- sb .append (moduleImport .uri );
81
- sb .append ("\" at \" " );
82
- sb .append (resolveURI (configElement .getBaseURI (), moduleImport .at ));
83
- sb .append ("\" ;\n " );
84
- })));
85
- sb .append (xpath );
86
-
87
- this .expression = Optional .of (sb .toString ());
68
+ expression = Optional .empty ();
69
+ return ;
88
70
}
71
+
72
+ final StringBuilder sb = new StringBuilder ();
73
+ namespaces .forEach ((prefix , uri ) -> {
74
+ if (!"xml" .equals (prefix )) {
75
+ sb .append ("declare namespace " ).append (prefix );
76
+ sb .append ("=\" " ).append (uri ).append ("\" ;\n " );
77
+ }
78
+ });
79
+ config .getImports ().ifPresent (moduleImports -> moduleImports .forEach ((moduleImport -> {
80
+ sb .append ("import module namespace " );
81
+ sb .append (moduleImport .prefix );
82
+ sb .append ("=\" " );
83
+ sb .append (moduleImport .uri );
84
+ sb .append ("\" at \" " );
85
+ sb .append (resolveURI (configElement .getBaseURI (), moduleImport .at ));
86
+ sb .append ("\" ;\n " );
87
+ })));
88
+ sb .append (xpath );
89
+
90
+ expression = Optional .of (sb .toString ());
89
91
}
90
92
91
93
@ Nullable
92
94
public Analyzer getAnalyzer () {
93
95
return null ;
94
96
}
95
97
96
- protected abstract void processResult (Sequence result , Document luceneDoc ) throws XPathException ;
98
+ protected abstract void processResult (final Sequence result , final Document luceneDoc ) throws XPathException ;
97
99
98
100
protected abstract void processText (CharSequence text , Document luceneDoc );
99
101
100
102
protected abstract void build (DBBroker broker , DocumentImpl document , NodeId nodeId , Document luceneDoc , CharSequence text );
101
103
102
104
protected void doBuild (DBBroker broker , DocumentImpl document , NodeId nodeId , Document luceneDoc , CharSequence text )
103
105
throws PermissionDeniedException , XPathException {
104
- if (! expression .isPresent ()) {
106
+ if (expression .isEmpty ()) {
105
107
processText (text , luceneDoc );
106
108
return ;
107
109
}
@@ -129,13 +131,13 @@ protected void doBuild(DBBroker broker, DocumentImpl document, NodeId nodeId, Do
129
131
}
130
132
}
131
133
132
- private void compile (DBBroker broker ) {
134
+ private void compile (final DBBroker broker ) {
133
135
if (compiled == null && isValid ) {
134
136
expression .ifPresent ((code ) -> compiled = compile (broker , code ));
135
137
}
136
138
}
137
139
138
- protected CompiledXQuery compile (DBBroker broker , String code ) {
140
+ protected CompiledXQuery compile (final DBBroker broker , final String code ) {
139
141
final XQuery xquery = broker .getBrokerPool ().getXQueryService ();
140
142
final XQueryContext context = new XQueryContext (broker .getBrokerPool ());
141
143
try {
@@ -147,7 +149,7 @@ protected CompiledXQuery compile(DBBroker broker, String code) {
147
149
}
148
150
}
149
151
150
- private String resolveURI (String baseURI , String location ) {
152
+ private String resolveURI (final String baseURI , final String location ) {
151
153
try {
152
154
final URI uri = new URI (location );
153
155
if (!uri .isAbsolute () && baseURI != null && baseURI .startsWith (CollectionConfigurationManager .CONFIG_COLLECTION )) {
0 commit comments