Methods Summary |
---|
private void | closeConfigurationXML(java.lang.StringBuffer xml)
xml.append("</configuration>\r\n");
|
protected void | collapseTree()
// collapse everything except the first category
CategoryExplorerTree tree = _monitor.getCategoryExplorerTree();
for (int i = tree.getRowCount() - 1; i > 0; i--) {
tree.collapseRow(i);
}
|
protected void | deleteConfigurationFile()
try {
File f = new File(getFilename());
if (f.exists()) {
f.delete();
}
} catch (SecurityException e) {
System.err.println("Cannot delete " + getFilename() +
" because a security violation occured.");
}
|
private void | exportLogLevelColorXMLElement(java.lang.String label, java.awt.Color color, java.lang.StringBuffer xml)
xml.append("\t\t<").append(COLORLEVEL).append(" ").append(NAME);
xml.append("=\"").append(label).append("\" ");
xml.append(RED).append("=\"").append(color.getRed()).append("\" ");
xml.append(GREEN).append("=\"").append(color.getGreen()).append("\" ");
xml.append(BLUE).append("=\"").append(color.getBlue());
xml.append("\"/>\r\n");
|
private void | exportLogLevelXMLElement(java.lang.String label, boolean selected, java.lang.StringBuffer xml)
xml.append("\t\t<").append(LEVEL).append(" ").append(NAME);
xml.append("=\"").append(label).append("\" ");
xml.append(SELECTED).append("=\"").append(selected);
xml.append("\"/>\r\n");
|
private void | exportLogTableColumnXMLElement(java.lang.String label, boolean selected, java.lang.StringBuffer xml)
xml.append("\t\t<").append(COLUMN).append(" ").append(NAME);
xml.append("=\"").append(label).append("\" ");
xml.append(SELECTED).append("=\"").append(selected);
xml.append("\"/>\r\n");
|
private void | exportXMLElement(org.apache.log4j.lf5.viewer.categoryexplorer.CategoryNode node, javax.swing.tree.TreePath path, java.lang.StringBuffer xml)
CategoryExplorerTree tree = _monitor.getCategoryExplorerTree();
xml.append("\t<").append(CATEGORY).append(" ");
xml.append(NAME).append("=\"").append(node.getTitle()).append("\" ");
xml.append(PATH).append("=\"").append(treePathToString(path)).append("\" ");
xml.append(EXPANDED).append("=\"").append(tree.isExpanded(path)).append("\" ");
xml.append(SELECTED).append("=\"").append(node.isSelected()).append("\"/>\r\n");
|
protected java.lang.String | getFilename()
String home = System.getProperty("user.home");
String sep = System.getProperty("file.separator");
return home + sep + "lf5" + sep + CONFIG_FILE_NAME;
|
protected java.lang.String | getValue(org.w3c.dom.NamedNodeMap map, java.lang.String attr)
Node n = map.getNamedItem(attr);
return n.getNodeValue();
|
protected void | load()
File file = new File(getFilename());
if (file.exists()) {
try {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.
newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(file);
processRecordFilter(doc);
processCategories(doc);
processLogLevels(doc);
processLogLevelColors(doc);
processLogTableColumns(doc);
} catch (Exception e) {
// ignore all error and just continue as if there was no
// configuration xml file but do report a message
System.err.println("Unable process configuration file at " +
getFilename() + ". Error Message=" + e.getMessage());
}
}
|
private void | openConfigurationXML(java.lang.StringBuffer xml)
xml.append("<configuration>\r\n");
|
private void | openXMLDocument(java.lang.StringBuffer xml)
xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n");
|
protected void | processCategories(org.w3c.dom.Document doc)
CategoryExplorerTree tree = _monitor.getCategoryExplorerTree();
CategoryExplorerModel model = tree.getExplorerModel();
NodeList nodeList = doc.getElementsByTagName(CATEGORY);
// determine where the starting node is
NamedNodeMap map = nodeList.item(0).getAttributes();
int j = (getValue(map, NAME).equalsIgnoreCase(FIRST_CATEGORY_NAME)) ? 1 : 0;
// iterate backwards throught the nodeList so that expansion of the
// list can occur
for (int i = nodeList.getLength() - 1; i >= j; i--) {
Node n = nodeList.item(i);
map = n.getAttributes();
CategoryNode chnode = model.addCategory(new CategoryPath(getValue(map, PATH)));
chnode.setSelected((getValue(map, SELECTED).equalsIgnoreCase("true")) ? true : false);
if (getValue(map, EXPANDED).equalsIgnoreCase("true")) ;
tree.expandPath(model.getTreePathToRoot(chnode));
}
|
private void | processConfigurationNode(org.apache.log4j.lf5.viewer.categoryexplorer.CategoryNode node, java.lang.StringBuffer xml)
CategoryExplorerModel model = _monitor.getCategoryExplorerTree().getExplorerModel();
Enumeration all = node.breadthFirstEnumeration();
CategoryNode n = null;
while (all.hasMoreElements()) {
n = (CategoryNode) all.nextElement();
exportXMLElement(n, model.getTreePathToRoot(n), xml);
}
|
private void | processLogLevelColors(java.util.Map logLevelMenuItems, java.util.Map logLevelColors, java.lang.StringBuffer xml)
xml.append("\t<loglevelcolors>\r\n");
// iterate through the list of log levels being used (log4j, jdk1.4, custom levels)
Iterator it = logLevelMenuItems.keySet().iterator();
while (it.hasNext()) {
LogLevel level = (LogLevel) it.next();
// for each level, get the associated color from the log level color map
Color color = (Color) logLevelColors.get(level);
exportLogLevelColorXMLElement(level.getLabel(), color, xml);
}
xml.append("\t</loglevelcolors>\r\n");
|
protected void | processLogLevelColors(org.w3c.dom.Document doc)
NodeList nodeList = doc.getElementsByTagName(COLORLEVEL);
LogLevel.getLogLevelColorMap();
for (int i = 0; i < nodeList.getLength(); i++) {
Node n = nodeList.item(i);
// check for backwards compatibility since this feature was added
// in version 1.3
if (n == null) {
return;
}
NamedNodeMap map = n.getAttributes();
String name = getValue(map, NAME);
try {
LogLevel level = LogLevel.valueOf(name);
int red = Integer.parseInt(getValue(map, RED));
int green = Integer.parseInt(getValue(map, GREEN));
int blue = Integer.parseInt(getValue(map, BLUE));
Color c = new Color(red, green, blue);
if (level != null) {
level.setLogLevelColorMap(level, c);
}
} catch (LogLevelFormatException e) {
// ignore it will be on by default.
}
}
|
private void | processLogLevels(java.util.Map logLevelMenuItems, java.lang.StringBuffer xml)
xml.append("\t<loglevels>\r\n");
Iterator it = logLevelMenuItems.keySet().iterator();
while (it.hasNext()) {
LogLevel level = (LogLevel) it.next();
JCheckBoxMenuItem item = (JCheckBoxMenuItem) logLevelMenuItems.get(level);
exportLogLevelXMLElement(level.getLabel(), item.isSelected(), xml);
}
xml.append("\t</loglevels>\r\n");
|
protected void | processLogLevels(org.w3c.dom.Document doc)
NodeList nodeList = doc.getElementsByTagName(LEVEL);
Map menuItems = _monitor.getLogLevelMenuItems();
for (int i = 0; i < nodeList.getLength(); i++) {
Node n = nodeList.item(i);
NamedNodeMap map = n.getAttributes();
String name = getValue(map, NAME);
try {
JCheckBoxMenuItem item =
(JCheckBoxMenuItem) menuItems.get(LogLevel.valueOf(name));
item.setSelected(getValue(map, SELECTED).equalsIgnoreCase("true"));
} catch (LogLevelFormatException e) {
// ignore it will be on by default.
}
}
|
private void | processLogRecordFilter(java.lang.String text, java.lang.StringBuffer xml)
xml.append("\t<").append(NDCTEXTFILTER).append(" ");
xml.append(NAME).append("=\"").append(text).append("\"");
xml.append("/>\r\n");
|
protected void | processLogTableColumns(org.w3c.dom.Document doc)
NodeList nodeList = doc.getElementsByTagName(COLUMN);
Map menuItems = _monitor.getLogTableColumnMenuItems();
List selectedColumns = new ArrayList();
for (int i = 0; i < nodeList.getLength(); i++) {
Node n = nodeList.item(i);
// check for backwards compatibility since this feature was added
// in version 1.3
if (n == null) {
return;
}
NamedNodeMap map = n.getAttributes();
String name = getValue(map, NAME);
try {
LogTableColumn column = LogTableColumn.valueOf(name);
JCheckBoxMenuItem item =
(JCheckBoxMenuItem) menuItems.get(column);
item.setSelected(getValue(map, SELECTED).equalsIgnoreCase("true"));
if (item.isSelected()) {
selectedColumns.add(column);
}
} catch (LogTableColumnFormatException e) {
// ignore it will be on by default.
}
if (selectedColumns.isEmpty()) {
_table.setDetailedView();
} else {
_table.setView(selectedColumns);
}
}
|
private void | processLogTableColumns(java.util.List logTableColumnMenuItems, java.lang.StringBuffer xml)
xml.append("\t<logtablecolumns>\r\n");
Iterator it = logTableColumnMenuItems.iterator();
while (it.hasNext()) {
LogTableColumn column = (LogTableColumn) it.next();
JCheckBoxMenuItem item = _monitor.getTableColumnMenuItem(column);
exportLogTableColumnXMLElement(column.getLabel(), item.isSelected(), xml);
}
xml.append("\t</logtablecolumns>\r\n");
|
protected void | processRecordFilter(org.w3c.dom.Document doc)
NodeList nodeList = doc.getElementsByTagName(NDCTEXTFILTER);
// there is only one value stored
Node n = nodeList.item(0);
// add check for backwards compatibility as this feature was added in
// version 1.2
if (n == null) {
return;
}
NamedNodeMap map = n.getAttributes();
String text = getValue(map, NAME);
if (text == null || text.equals("")) {
return;
}
_monitor.setNDCLogRecordFilter(text);
|
public void | reset()
deleteConfigurationFile();
collapseTree();
selectAllNodes();
|
public void | save()
CategoryExplorerModel model = _monitor.getCategoryExplorerTree().getExplorerModel();
CategoryNode root = model.getRootCategoryNode();
StringBuffer xml = new StringBuffer(2048);
openXMLDocument(xml);
openConfigurationXML(xml);
processLogRecordFilter(_monitor.getNDCTextFilter(), xml);
processLogLevels(_monitor.getLogLevelMenuItems(), xml);
processLogLevelColors(_monitor.getLogLevelMenuItems(),
LogLevel.getLogLevelColorMap(), xml);
processLogTableColumns(LogTableColumn.getLogTableColumns(), xml);
processConfigurationNode(root, xml);
closeConfigurationXML(xml);
store(xml.toString());
|
protected void | selectAllNodes()
CategoryExplorerModel model = _monitor.getCategoryExplorerTree().getExplorerModel();
CategoryNode root = model.getRootCategoryNode();
Enumeration all = root.breadthFirstEnumeration();
CategoryNode n = null;
while (all.hasMoreElements()) {
n = (CategoryNode) all.nextElement();
n.setSelected(true);
}
|
protected void | store(java.lang.String s)
try {
PrintWriter writer = new PrintWriter(new FileWriter(getFilename()));
writer.print(s);
writer.close();
} catch (IOException e) {
// do something with this error.
e.printStackTrace();
}
|
public static java.lang.String | treePathToString(javax.swing.tree.TreePath path)
// count begins at one so as to not include the 'Categories' - root category
StringBuffer sb = new StringBuffer();
CategoryNode n = null;
Object[] objects = path.getPath();
for (int i = 1; i < objects.length; i++) {
n = (CategoryNode) objects[i];
if (i > 1) {
sb.append(".");
}
sb.append(n.getTitle());
}
return sb.toString();
|