37
37
38
38
/**
39
39
* Builds a {@link Metamorph} from an xml description
40
- *
40
+ *
41
41
* @author Markus Michael Geipel
42
42
*/
43
43
public abstract class AbstractMetamorphDomWalker {
44
44
45
45
/**
46
46
* XML tags
47
47
*/
48
- public static enum MMTAG {
48
+ public static enum Tags {
49
49
META , FUNCTIONS , RULES , MACROS , MACRO , MAPS , ENTITY , MAP , ENTRY , TEXT , VARS
50
50
}
51
51
52
52
/**
53
53
* XML attributes
54
54
*/
55
- public static enum ATTRITBUTE {
55
+ public static enum AttributeName {
56
56
VERSION ("version" ),
57
57
SOURCE ("source" ),
58
58
VALUE ("value" ),
@@ -64,7 +64,7 @@ public static enum ATTRITBUTE {
64
64
65
65
private final String string ;
66
66
67
- private ATTRITBUTE (final String string ) {
67
+ private AttributeName (final String string ) {
68
68
this .string = string ;
69
69
}
70
70
@@ -75,7 +75,7 @@ public String getString() {
75
75
76
76
private static final String DATA = "data" ;
77
77
private static final String MAP = "map" ;
78
- private static final String MACRO = "call-macro" ;
78
+ private static final String CALL_MACRO = "call-macro" ;
79
79
private static final String IF = "if" ;
80
80
private static final String POSTPROCESS = "postprocess" ;
81
81
private static final String ENTITY_NAME = "entity-name" ;
@@ -124,7 +124,7 @@ public final void walk(final Reader reader) {
124
124
}
125
125
walk (DomLoader .parse (SCHEMA_FILE , new InputSource (reader )));
126
126
}
127
-
127
+
128
128
public final void walk (final Reader morphDefReader , final Map <String , String > vars ) {
129
129
this .vars .putAll (vars );
130
130
walk (morphDefReader );
@@ -135,53 +135,53 @@ public final void walk(final String morphDef, final Map<String, String> vars) {
135
135
this .vars .putAll (vars );
136
136
walk (morphDef );
137
137
}
138
-
138
+
139
139
public final void walk (final InputStream inputStream , final Map <String , String > vars ) {
140
140
this .vars .putAll (vars );
141
141
walk (inputStream );
142
142
}
143
143
144
- private static MMTAG tagOf (final Node child ) {
145
- return MMTAG .valueOf (child .getLocalName ().toUpperCase ());
144
+ private static Tags tagOf (final Node child ) {
145
+ return Tags .valueOf (child .getLocalName ().toUpperCase ());
146
146
}
147
147
148
- protected static String attribute (final Node node , final ATTRITBUTE attr ) {
149
- final Node attribute = node .getAttributes ().getNamedItem (attr .getString ());
150
- if (attribute != null ) {
151
- return attribute .getNodeValue ();
148
+ protected static String attribute (final Node node , final AttributeName attr ) {
149
+ final Node attrNode = node .getAttributes ().getNamedItem (attr .getString ());
150
+ if (attrNode != null ) {
151
+ return attrNode .getNodeValue ();
152
152
}
153
153
return null ;
154
154
}
155
155
156
- protected static Map <String , String > attributeMap (final Node node ) {
156
+ protected static Map <String , String > attributeMap (final Node elementNode ) {
157
157
final Map <String , String > attributes = new HashMap <String , String >();
158
- final NamedNodeMap attrNode = node .getAttributes ();
158
+ final NamedNodeMap attrNodes = elementNode .getAttributes ();
159
159
160
- for (int i = 0 ; i < attrNode .getLength (); ++i ) {
161
- final Node itemNode = attrNode .item (i );
162
- attributes .put (itemNode .getLocalName (), itemNode .getNodeValue ());
160
+ for (int i = 0 ; i < attrNodes .getLength (); ++i ) {
161
+ final Node attrNode = attrNodes .item (i );
162
+ attributes .put (attrNode .getLocalName (), attrNode .getNodeValue ());
163
163
}
164
164
return attributes ;
165
165
}
166
-
166
+
167
167
protected final String resolveVars (final String string ){
168
168
return StringUtil .format (string , Metamorph .VAR_START , Metamorph .VAR_END , ignoreMissingVars , vars );
169
169
}
170
-
170
+
171
171
protected final void setIgnoreMissingVars (final boolean ignoreMissingVars ) {
172
172
this .ignoreMissingVars = ignoreMissingVars ;
173
173
}
174
-
175
- protected final String resolvedAttribute (final Node node , final ATTRITBUTE attr ){
174
+
175
+ protected final String resolvedAttribute (final Node node , final AttributeName attr ){
176
176
final String value = attribute (node , attr );
177
177
if (null ==value ){
178
178
return null ;
179
179
}
180
180
return resolveVars (value );
181
-
181
+
182
182
}
183
-
184
- protected final Map <String , String > resolvedAttributeMap (final Node node ){
183
+
184
+ protected final Map <String , String > resolvedAttributeMap (final Node node ){
185
185
final Map <String , String > attributes = new HashMap <String , String >();
186
186
final NamedNodeMap attrNode = node .getAttributes ();
187
187
@@ -191,11 +191,11 @@ protected final Map<String, String> resolvedAttributeMap(final Node node){
191
191
}
192
192
return attributes ;
193
193
}
194
-
194
+
195
195
private void handleVars (final Node varsNode ) {
196
196
for (Node varNode = varsNode .getFirstChild (); varNode != null ; varNode = varNode .getNextSibling ()) {
197
- final String varName = attribute (varNode , ATTRITBUTE .NAME );
198
- final String varValue = attribute (varNode , ATTRITBUTE .VALUE );
197
+ final String varName = attribute (varNode , AttributeName .NAME );
198
+ final String varValue = attribute (varNode , AttributeName .VALUE );
199
199
vars .put (varName , varValue );
200
200
}
201
201
vars = new ScopedHashMap <String , String >(vars );
@@ -209,10 +209,10 @@ protected final void walk(final Document doc) {
209
209
init ();
210
210
211
211
final Element root = doc .getDocumentElement ();
212
- final int version = Integer .parseInt (attribute (root , ATTRITBUTE .VERSION ));
212
+ final int version = Integer .parseInt (attribute (root , AttributeName .VERSION ));
213
213
checkVersionCompatibility (version );
214
214
215
- setEntityMarker (attribute (root , ATTRITBUTE .ENTITY_MARKER ));
215
+ setEntityMarker (attribute (root , AttributeName .ENTITY_MARKER ));
216
216
217
217
for (Node node = root .getFirstChild (); node != null ; node = node .getNextSibling ()) {
218
218
@@ -244,7 +244,7 @@ protected final void walk(final Document doc) {
244
244
245
245
private void handleMacros (final Node node ) {
246
246
for (Node macroNode = node .getFirstChild (); macroNode != null ; macroNode = macroNode .getNextSibling ()) {
247
- final String name = attribute (macroNode , ATTRITBUTE .NAME );
247
+ final String name = attribute (macroNode , AttributeName .NAME );
248
248
macros .put (name , macroNode );
249
249
}
250
250
}
@@ -272,11 +272,11 @@ private void handleMacros(final Node node) {
272
272
protected abstract void exitCollect (Node node );
273
273
274
274
protected abstract void enterName (Node node );
275
-
275
+
276
276
protected abstract void exitName (Node node );
277
277
278
278
protected abstract void enterIf (Node node );
279
-
279
+
280
280
protected abstract void exitIf (Node node );
281
281
282
282
protected abstract void handleFunction (Node functionNode );
@@ -305,8 +305,8 @@ private void handleRule(final Node node) {
305
305
enterData (node );
306
306
handlePostprocess (node );
307
307
exitData (node );
308
- } else if (MACRO .equals (nodeName )){
309
- final String macroName = attribute (node , ATTRITBUTE .NAME );
308
+ } else if (CALL_MACRO .equals (nodeName )){
309
+ final String macroName = attribute (node , AttributeName .NAME );
310
310
final Node macroNode = macros .get (macroName );
311
311
if (macroNode ==null ){
312
312
throw new MorphDefException ("Macro '" + macroName + "' undefined!" );
@@ -320,10 +320,6 @@ private void handleRule(final Node node) {
320
320
}
321
321
}
322
322
323
- private void handleIf (final Node node ) {
324
-
325
- }
326
-
327
323
private void handlePostprocess (final Node node ) {
328
324
for (Node functionNode = node .getFirstChild (); functionNode != null ; functionNode = functionNode
329
325
.getNextSibling ()) {
0 commit comments