List of usage examples for org.dom4j Node valueOf
String valueOf(String xpathExpression);
valueOf
evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.
From source file:it.eng.spagobi.studio.extchart.utils.ExtChartUtils.java
License:Mozilla Public License
public static String getSerieTypeFromChartType(String chartType) throws Exception { String toReturn = null;/*from w ww.ja va2s . c om*/ InputStream is = getInputStreamFromResource(ExtChartConfigurations.INFO_FILE); Document document = new SAXReader().read(is); List charts = document.selectNodes("//EXTCHARTS/EXTCHART"); if (charts == null || charts.size() == 0) throw new Exception("No charts configured"); for (int i = 0; i < charts.size(); i++) { Node chart = (Node) charts.get(i); String type = chart.valueOf("@type"); if (chartType.equalsIgnoreCase(type)) { String imagePath = chart.valueOf("@defaultSerieType"); toReturn = imagePath; break; } } return toReturn; }
From source file:it.eng.spagobi.studio.highchart.configuration.HighChartConfigurations.java
License:Mozilla Public License
public static List getConfiguredChartTypes() throws Exception { List toReturn = null;// w ww . java 2s. co m try { InputStream is = getInputStreamFromResource(INFO_FILE); Document document = new SAXReader().read(is); List charts = document.selectNodes("//HIGHCHARTS/HIGHCHART"); if (charts == null || charts.size() == 0) return null; toReturn = new ArrayList(); for (int i = 0; i < charts.size(); i++) { Node chart = (Node) charts.get(i); String type = chart.valueOf("@type"); if (type == null || type.trim().equals("")) continue; toReturn.add(type); } } catch (Exception e) { logger.error("Error in reading configuration types from file " + INFO_FILE); } return toReturn; }
From source file:it.eng.spagobi.studio.highchart.utils.HighChartUtils.java
License:Mozilla Public License
/** Get the chart image path for the selected type * //from w ww .ja v a 2 s .c o m * @param imageType * @return * @throws Exception */ public static String getChartImagePath(String imageType) throws Exception { String toReturn = null; InputStream is = getInputStreamFromResource(HighChartConfigurations.INFO_FILE); Document document = new SAXReader().read(is); List charts = document.selectNodes("//HIGHCHARTS/HIGHCHART"); if (charts == null || charts.size() == 0) throw new Exception("No charts configured"); for (int i = 0; i < charts.size(); i++) { Node chart = (Node) charts.get(i); String type = chart.valueOf("@type"); if (imageType.equalsIgnoreCase(type)) { String imagePath = chart.valueOf("@imagePath"); toReturn = imagePath; break; } } return toReturn; }
From source file:log4JToXml.xmlToProperties.XmlToLog4jConverterImpl.java
private void processRoot() { //root node parsing, root element is optional Node rootNode = doc.selectSingleNode("/log4j:configuration/root"); if (rootNode != null) { String rootContent = ""; Node priority = rootNode.selectSingleNode("./priority | ./level"); rootContent += priority.valueOf("@value").toUpperCase(); //appenders refernces List<Node> appendersRefs = rootNode.selectNodes("./appender-ref"); for (Node appender : appendersRefs) { rootContent += ", " + appender.valueOf("@ref"); }//from w w w. j a v a2s. c om String rootName = "log4j.rootLogger"; log4jProperties.setProperty(rootName, rootContent); //root params List<Node> rootParams = rootNode.selectNodes("./param"); if (!rootParams.isEmpty()) { for (Node param : rootParams) { log4jProperties.setProperty(rootName + "." + param.valueOf("@name"), param.valueOf("@value")); } } } }
From source file:log4JToXml.xmlToProperties.XmlToLog4jConverterImpl.java
private void processRenderers() { //renderer nodes, optional List<Node> rendererNodes = doc.selectNodes("/log4j:configuration/renderer"); if (!rendererNodes.isEmpty()) { for (Node renderer : rendererNodes) { log4jProperties.setProperty("log4j.renderer." + renderer.valueOf("@renderedClass"), renderer.valueOf("@renderingClass")); }// www . ja v a2s. c o m } }
From source file:log4JToXml.xmlToProperties.XmlToLog4jConverterImpl.java
private void processAppenders() { //appender nodes, optional List<Node> appenderNodes = doc.selectNodes("/log4j:configuration/appender"); if (!appenderNodes.isEmpty()) { String appenderName = null; for (Node appender : appenderNodes) { appenderName = "log4j.appender." + appender.valueOf("@name"); log4jProperties.setProperty(appenderName, appender.valueOf("@class")); //errorHandler, optional 0-1 Node errorHandler = appender.selectSingleNode("./errorHandler"); if (errorHandler != null) { String errorHandlerName = appenderName + ".errorhandler"; log4jProperties.setProperty(errorHandlerName, errorHandler.valueOf("@class")); //EH params, optional List<Node> eHParams = errorHandler.selectNodes("./param"); if (!eHParams.isEmpty()) { for (Node param : eHParams) { log4jProperties.setProperty(errorHandlerName + "." + param.valueOf("@name"), param.valueOf("@value")); }/*from w ww . j a va 2 s . co m*/ } //EH root-ref, 0-1 Node rootRef = errorHandler.selectSingleNode("./root-ref"); if (rootRef != null) { log4jProperties.setProperty(errorHandlerName + ".root-ref", "true"); } //EH logger-ref, optional List<Node> eHLoggerRefs = errorHandler.selectNodes("./logger-ref"); if (!eHLoggerRefs.isEmpty()) { String loggersRefValue = eHLoggerRefs.get(0).valueOf("@ref"); for (int i = 1; i < eHLoggerRefs.size(); i++) { loggersRefValue += ", " + eHLoggerRefs.get(i).valueOf("@ref"); } log4jProperties.setProperty(errorHandlerName + ".logger-ref", loggersRefValue); } //EH appender-ref, 0-1 Node appenderRef = errorHandler.selectSingleNode("./appender-ref"); if (appenderRef != null) { log4jProperties.setProperty(errorHandlerName + ".appender-ref", appenderRef.valueOf("@ref")); } } //appender params, optional List<Node> appenderParams = appender.selectNodes("./param"); if (!appenderParams.isEmpty()) { for (Node param : appenderParams) { log4jProperties.setProperty(appenderName + "." + param.valueOf("@name"), param.valueOf("@value")); } } //appender layout, 0-1 Node appenderLayout = appender.selectSingleNode("./layout"); if (appenderLayout != null) { String appenderLayoutName = appenderName + ".layout"; log4jProperties.setProperty(appenderLayoutName, appenderLayout.valueOf("@class")); //AL params, optional List<Node> appenderLayoutParams = appenderLayout.selectNodes("./param"); if (!appenderLayoutParams.isEmpty()) { for (Node param : appenderLayoutParams) { log4jProperties.setProperty(appenderLayoutName + "." + param.valueOf("@name"), param.valueOf("@value")); } } } //appender filter, optional List<Node> appenderFilters = appender.selectNodes("./filter"); if (!appenderFilters.isEmpty()) { String appenderFilterName = ""; int filterCount = 0; for (Node filter : appenderFilters) { filterCount++; appenderFilterName = appenderName + ".filter." + filterCount; log4jProperties.setProperty(appenderFilterName, filter.valueOf("@class")); //filter params, optional List<Node> filterParams = filter.selectNodes("./param"); if (!filterParams.isEmpty()) { for (Node param : filterParams) { log4jProperties.setProperty(appenderFilterName + "." + param.valueOf("@name"), param.valueOf("@value")); } } } } //appender appender-refs, optional List<Node> appenderAppenderRefs = appender.selectNodes("./appender-ref"); if (!appenderAppenderRefs.isEmpty()) { String appenderRefsValue = appenderAppenderRefs.get(0).valueOf("@ref"); for (int i = 1; i < appenderAppenderRefs.size(); i++) { appenderRefsValue += ", " + appenderAppenderRefs.get(i).valueOf("@ref"); } log4jProperties.setProperty(appenderName + ".appender-ref", appenderRefsValue); } } } }
From source file:log4JToXml.xmlToProperties.XmlToLog4jConverterImpl.java
private void processCategories() { //category, optional List<Node> categoryNodes = doc.selectNodes("/log4j:configuration/category"); if (!categoryNodes.isEmpty()) { for (Node category : categoryNodes) { String categoryContent = ""; //(priority | level)? Node categoryPriority = category.selectSingleNode("./priority"); Node categoryLevel = category.selectSingleNode("./level"); if (categoryPriority != null) { categoryContent += categoryPriority.valueOf("@value").toUpperCase(); } else if (categoryLevel != null) { categoryContent += categoryLevel.valueOf("@value").toUpperCase(); }//from w w w. j a v a 2 s.c o m //appender-refs, optional List<Node> categoryAppenderRefs = category.selectNodes("./appender-ref"); if (!categoryAppenderRefs.isEmpty()) { for (Node appenderRef : categoryAppenderRefs) { categoryContent += ", " + appenderRef.valueOf("@ref"); } } String categoryName = "log4j.category." + category.valueOf("@name"); log4jProperties.setProperty(categoryName, categoryContent); //params, optional List<Node> categoryParams = category.selectNodes("./param"); if (!categoryParams.isEmpty()) { for (Node param : categoryParams) { log4jProperties.setProperty(categoryName + "." + param.valueOf("@name"), param.valueOf("@value")); } } //category additivity if (category.valueOf("@additivity").equals("false")) { log4jProperties.setProperty("log4j.additivity." + category.valueOf("@name"), "false"); } } } }
From source file:log4JToXml.xmlToProperties.XmlToLog4jConverterImpl.java
private void processLoggers() { //logger, optional List<Node> loggerNodes = doc.selectNodes("/log4j:configuration/logger"); if (!loggerNodes.isEmpty()) { for (Node logger : loggerNodes) { String loggerContent = ""; //level, 0-1 Node loggerLevel = logger.selectSingleNode("./level"); if (loggerLevel != null) { loggerContent += loggerLevel.valueOf("@value").toUpperCase(); }//from w w w . j ava2 s. co m //appender-refs, optional List<Node> loggerAppenderRefs = logger.selectNodes("./appender-ref"); if (!loggerAppenderRefs.isEmpty()) { for (Node appenderRef : loggerAppenderRefs) { loggerContent += ", " + appenderRef.valueOf("@ref"); } } String loggerName = "log4j.logger." + logger.valueOf("@name"); log4jProperties.setProperty(loggerName, loggerContent); //logger additivity if (logger.valueOf("@additivity").equals("false")) { log4jProperties.setProperty("log4j.additivity." + logger.valueOf("@name"), "false"); } } } }
From source file:main.FrevoMain.java
License:Open Source License
/** * Loads the give session file to FREVO. In case of error the components * will not be selected in FREVO.//from ww w .j av a2 s . c om * * @param loadFile * The session file to load. */ public static Document loadSession(File loadFile) { // loading session Document doc = null; // indicate if error occurs boolean error = false; // load XML tree from file doc = SafeSAX.read(loadFile, true); ProblemXMLData problem = null; ComponentXMLData method = null; ComponentXMLData representation = null; ComponentXMLData ranking = null; try { // Load configuration section Node nd = doc.selectSingleNode("/frevo/sessionconfig"); if (nd == null) { System.err.println("Warning: No config keywords found!"); } else { // load configuration List<?> npops = nd.selectNodes(".//configentry"); Iterator<?> it = npops.iterator(); // load all keys and values while (it.hasNext()) { Element el = (Element) it.next(); String key = el.valueOf("./@key"); String value = el.valueOf("./@value"); if (key.equals("CustomName")) { FrevoMain.customName = value; } else if (key.equals("NumberofRuns")) { FrevoMain.setNumberOfSimulationRuns(Integer.parseInt(value)); } else if (key.equals("StartingSeed")) { FrevoMain.setInitialSeed(Long.parseLong(value)); } } } // Load problem Node problemnode = doc.selectSingleNode("/frevo/problem"); // select appropriate component String classname = problemnode.valueOf("./@class"); problem = (ProblemXMLData) getComponent(ComponentType.FREVO_PROBLEM, classname); if (problem == null) { error = true; System.err.println("ERROR: No such problem component found: " + classname); } if (!error) { // load configuration List<?> pentries = problemnode.selectNodes(".//problementry"); Iterator<?> it = pentries.iterator(); // set problem properties while (it.hasNext()) { Element el = (Element) it.next(); String key = el.valueOf("./@key"); String value = el.valueOf("./@value"); XMLFieldEntry pe = problem.getProperties().get(key); if (pe != null) pe.setValue(value); } } // Load method Node methodnode = doc.selectSingleNode("/frevo/method"); // select appropriate component classname = methodnode.valueOf("./@class"); method = getComponent(ComponentType.FREVO_METHOD, classname); if (method == null) { if (classname.equals("")) { System.err.println("ERROR: No class entry found to load the method component!"); error = true; } else { error = true; System.err.println("ERROR: No such method component found: " + classname); } } else { // load configuration List<?> mentries = methodnode.selectNodes(".//methodentry"); Iterator<?> mit = mentries.iterator(); while (mit.hasNext()) { Element el = (Element) mit.next(); String key = el.valueOf("./@key"); String value = el.valueOf("./@value"); XMLFieldEntry pe = method.getProperties().get(key); if (pe != null) pe.setValue(value); } } // Load representation Node representationnode = doc.selectSingleNode("/frevo/representation"); // select appropriate component classname = representationnode.valueOf("./@class"); representation = getComponent(ComponentType.FREVO_REPRESENTATION, classname); if (representation == null) { if (classname.equals("")) { System.err.println("ERROR: No class entry found to load the representation component!"); error = true; } else { error = true; System.err.println("ERROR: No such representation component found: " + classname); } } else { // load configuration List<?> rentries = representationnode.selectNodes(".//representationentry"); Iterator<?> rit = rentries.iterator(); while (rit.hasNext()) { Element el = (Element) rit.next(); String key = el.valueOf("./@key"); String value = el.valueOf("./@value"); XMLFieldEntry pe = representation.getProperties().get(key); if (pe != null) pe.setValue(value); } // load core representation if (representation.getComponentType() == ComponentType.FREVO_BULKREPRESENTATION) { String corerepresentationclassname = representation.getProperties() .get("core_representation_component").getValue(); ComponentXMLData coreRepresentation = FrevoMain.getComponent(ComponentType.FREVO_REPRESENTATION, corerepresentationclassname); if (coreRepresentation == null) { System.err.println( "ERROR: Could not load specified representation: " + corerepresentationclassname); } else { rentries = representationnode.selectNodes(".//corerepresentationentry"); rit = rentries.iterator(); while (rit.hasNext()) { Element el = (Element) rit.next(); String key = el.valueOf("./@key"); String value = el.valueOf("./@value"); XMLFieldEntry pe = coreRepresentation.getProperties().get(key); if (pe != null) pe.setValue(value); } } } } // Load ranking Node rankingnode = doc.selectSingleNode("/frevo/ranking"); // select appropriate component classname = rankingnode.valueOf("./@class"); ranking = getComponent(ComponentType.FREVO_RANKING, classname); if (ranking == null) { if (classname.equals("")) { System.err.println("ERROR: No class entry found to load the ranking component!"); error = true; } else { System.err.println("ERROR: No such ranking component found: " + classname); error = true; } } else { // load configuration List<?> raentries = rankingnode.selectNodes(".//rankingentry"); Iterator<?> rait = raentries.iterator(); while (rait.hasNext()) { Element el = (Element) rait.next(); String key = el.valueOf("./@key"); String value = el.valueOf("./@value"); XMLFieldEntry pe = ranking.getProperties().get(key); if (pe != null) pe.setValue(value); } } // adjust GUI if (isFrevoWithGraphics()) { mainWindow.updateAdvancedLabels(); } } catch (OutOfMemoryError mem) { System.err.println("ERROR: Could not import! (Out of memory)"); error = true; } catch (IllegalArgumentException e) { System.out.println("IllegalArgumentException\n" + e.getMessage()); error = true; } if (error) { System.err.println("Error while importing!"); } else { SELECTED_PROBLEM = problem; SELECTED_METHOD = method; SELECTED_REPRESENTATION = representation; SELECTED_RANKING = ranking; } return doc; }
From source file:neat.NEAT.java
License:Open Source License
public NEAT(File xmlfile, int popid) { // loads properties super(xmlfile); // get population root node Document doc = SafeSAX.read(xmlfile, true); Node dpopulations = doc.selectSingleNode("/frevo/population"); List<?> nets = dpopulations.selectNodes(".//NEAT"); // Node pop = (Node) npops.get(popid); //List<?> nets = pop.selectNodes("./*"); // return the one with the highest fitness int bestID = 0; Node net = (Node) nets.get(bestID); String fitnessString = net.valueOf("./@fitness"); double bestfitness = Double.parseDouble(fitnessString); for (int i = 1; i < nets.size(); i++) { net = (Node) nets.get(i); fitnessString = net.valueOf("./@fitness"); double fitness = Double.parseDouble(fitnessString); if (fitness > bestfitness) { bestID = i;//from w w w .jav a 2s . co m bestfitness = fitness; } } loadFromXML((Node) nets.get(bestID)); }