in uimaj-ep-cev/src/main/java/org/apache/uima/cev/data/StyleMapReader.java [107:173]
public static Map<String, StyleMapEntry> parseStyleMapDOM(String styleFileString) {
File styleMapFile = new File(styleFileString);
Map<String, StyleMapEntry> result = new HashMap<String, StyleMapEntry>();
Document parse = null;
// Einlesen/parsen
try {
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
FileInputStream stream = new FileInputStream(styleMapFile);
parse = db.parse(stream);
stream.close();
} catch (FileNotFoundException e) {
CEVPlugin.error(e);
return null;
} catch (ParserConfigurationException e) {
CEVPlugin.error(e);
return null;
} catch (FactoryConfigurationError e) {
CEVPlugin.error(e);
return null;
} catch (SAXException e) {
CEVPlugin.error(e);
return null;
} catch (IOException e) {
CEVPlugin.error(e);
return null;
}
final Node root = parse.getDocumentElement();
final NodeList nodeList = root.getChildNodes();
for (int i = 0; i < nodeList.getLength(); ++i) {
final Node node = nodeList.item(i);
final String nodeName = node.getNodeName();
// "rule" node ?
if (!nodeName.equals("rule")) { //$NON-NLS-1$
continue;
}
// Collect type or pattern, label, and color text style
NodeList childrenList = node.getChildNodes();
String type = ""; //$NON-NLS-1$
String label = ""; //$NON-NLS-1$
String colorText = ""; //$NON-NLS-1$
for (int j = 0; j < childrenList.getLength(); ++j) {
final Node child = childrenList.item(j);
final String childName = child.getNodeName();
if (childName.equals("pattern")) { //$NON-NLS-1$
type = getTextValue(child);
} else if (childName.equals("label")) { //$NON-NLS-1$
label = getTextValue(child);
} else if (childName.equals("style")) { //$NON-NLS-1$
colorText = getTextValue(child);
}
}
StyleMapEntry styleMapEntry = getStyleMapEntry(type, label, colorText);
result.put(styleMapEntry.getAnnotationTypeName(), styleMapEntry);
}
return result;
}