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.chart.editors.model.chart.ChartModel.java
License:Mozilla Public License
public static List getConfiguredChartTypes() throws Exception { List toReturn = new ArrayList(); InputStream is = ChartEditorUtils.getInputStreamFromResource(CHART_INFO_FILE); Document document = new SAXReader().read(is); List charts = document.selectNodes("//CHARTS/CHART"); 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 (type == null || type.trim().equals("")) continue; toReturn.add(type);//from w w w.j a v a 2s .c om } return toReturn; }
From source file:it.eng.spagobi.studio.chart.editors.model.chart.ChartModel.java
License:Mozilla Public License
public void fillStyleParameters() throws Exception { logger.debug("Filling style configurations from actual file, otherwise from template"); String upperCaseNameSl = type.toUpperCase(); String upperCaseNamePl = upperCaseNameSl + "S"; logger.debug("Read all styles parameters from config file and record"); Node commonConfig = configDocument .selectSingleNode("//" + upperCaseNamePl + "/" + upperCaseNameSl + "[@name='commons']"); if (commonConfig == null) throw new Exception("No common configuration set"); List allStyles = commonConfig.selectNodes("//STYLES/STYLE"); // Iterate over the styles filling StyleParametersEditors for (Iterator iterator = allStyles.iterator(); iterator.hasNext();) { Element styleEl = (Element) iterator.next(); Style toInsert = new Style(); String nameStyle = styleEl.valueOf("@name"); toInsert.setName(nameStyle);/*from w w w . j a va2 s . com*/ String descriptionStyle = styleEl.valueOf("@description"); if (descriptionStyle == null || descriptionStyle.equalsIgnoreCase("")) { descriptionStyle = nameStyle; } toInsert.setDescription(descriptionStyle); String tooltipStyle = styleEl.valueOf("@tooltip"); toInsert.setTooltip(tooltipStyle); toInsert.setHasFont(true); toInsert.setHasSize(true); toInsert.setHasColor(true); toInsert.setHasOrientation(true); // first I must check wich of these parameters are configurable Node fontNode1 = commonConfig .selectSingleNode("//STYLES/STYLE[@name='" + nameStyle + "']/STYLE_INFO[@name='font']"); if (fontNode1 == null) { toInsert.setHasFont(false); } Node colorNode1 = commonConfig .selectSingleNode("//STYLES/STYLE[@name='" + nameStyle + "']/STYLE_INFO[@name='color']"); if (colorNode1 == null) { toInsert.setHasFont(false); } Node orientationNode1 = commonConfig .selectSingleNode("//STYLES/STYLE[@name='" + nameStyle + "']/STYLE_INFO[@name='orientation']"); if (orientationNode1 == null) { toInsert.setHasOrientation(false); } Node sizeNode1 = commonConfig .selectSingleNode("//STYLES/STYLE[@name='" + nameStyle + "']/STYLE_INFO[@name='size']"); if (sizeNode1 == null) { toInsert.setHasSize(false); } // Fill the style values!! boolean useThisDocument = false; Node thisStyleNode = thisDocument .selectSingleNode("//" + type.toUpperCase() + "/" + nameStyle.toUpperCase()); if (thisStyleNode != null) useThisDocument = true; if (toInsert.isHasFont()) { String fontVal = null; if (useThisDocument == true) { fontVal = thisStyleNode.valueOf("@font"); } else { Node fontNode = commonConfig .selectSingleNode("//STYLES/STYLE[@name='" + nameStyle + "']/STYLE_INFO[@name='font']"); if (fontNode != null) { fontVal = fontNode.valueOf("@defaultValue"); } } if (fontVal != null) toInsert.setFont(fontVal); } if (toInsert.isHasOrientation()) { String orientationVal = null; if (useThisDocument == true) { orientationVal = thisStyleNode.valueOf("@orientation"); } else { Node orientationNode = commonConfig.selectSingleNode( "//STYLES/STYLE[@name='" + nameStyle + "']/STYLE_INFO[@name='orientation']"); if (orientationNode != null) { orientationVal = orientationNode.valueOf("@defaultValue"); } } if (orientationVal != null) toInsert.setOrientation(orientationVal); } if (toInsert.isHasColor()) { String colorVal = null; if (useThisDocument == true) { colorVal = thisStyleNode.valueOf("@color"); } else { Node colorNode = commonConfig.selectSingleNode( "//STYLES/STYLE[@name='" + nameStyle + "']/STYLE_INFO[@name='color']"); if (colorNode != null) { colorVal = colorNode.valueOf("@defaultValue"); } } if (colorVal != null) toInsert.setColor(ChartEditor.convertHexadecimalToRGB(colorVal)); } if (toInsert.isHasSize()) { String sizeVal = null; if (useThisDocument == true) { sizeVal = thisStyleNode.valueOf("@size"); } else { Node sizeNode = commonConfig .selectSingleNode("//STYLES/STYLE[@name='" + nameStyle + "']/STYLE_INFO[@name='size']"); if (sizeNode != null) { sizeVal = sizeNode.valueOf("@defaultValue"); } } if (sizeVal != null) { Integer intt = null; try { intt = Integer.valueOf(sizeVal); } catch (Exception e) { intt = 10; } toInsert.setSize(intt); } } styleParametersEditors.put(toInsert.getName(), toInsert); } }
From source file:it.eng.spagobi.studio.chart.editors.model.chart.ChartModel.java
License:Mozilla Public License
/** Record commons configuration parameters, then fills model with values in actuale or in template file * /*from w w w.j ava2 s. c o m*/ * @throws Exception */ public void fillCommonsConfParameters() throws Exception { logger.debug("Start recording commons configuration parameters"); // search for the root String upperCaseNameSl = type.toUpperCase(); String upperCaseNamePl = upperCaseNameSl + "S"; Node commonConfig = configDocument .selectSingleNode("//" + upperCaseNamePl + "/" + upperCaseNameSl + "[@name='commons']"); if (commonConfig == null) throw new Exception("No common configuration set"); List allSections = commonConfig .selectNodes("//" + upperCaseNamePl + "/" + upperCaseNameSl + "[@name='commons']/CONF/SECTION"); // Iterate over the section for (Iterator iterator = allSections.iterator(); iterator.hasNext();) { Element section = (Element) iterator.next(); String nameSection = section.valueOf("@name"); // iterate over the parameters for the current section List configuredParameters = section.selectNodes("//" + upperCaseNamePl + "/" + upperCaseNameSl + "[@name='commons']/CONF/SECTION[@name='" + nameSection + "']/PARAMETER"); for (int j = 0; j < configuredParameters.size(); j++) { Node aConfiguredParameter = (Node) configuredParameters.get(j); String namePar = aConfiguredParameter.valueOf("@name"); String description = aConfiguredParameter.valueOf("@description"); String typeStr = aConfiguredParameter.valueOf("@type"); String toolTipStr = aConfiguredParameter.valueOf("@tooltip"); ArrayList<String> predefinedValues = null; int type; if (typeStr.equals("INTEGER")) type = Parameter.INTEGER_TYPE; else if (typeStr.equals("FLOAT")) type = Parameter.FLOAT_TYPE; else if (typeStr.equals("STRING")) type = Parameter.STRING_TYPE; else if (typeStr.equals("COLOR")) type = Parameter.COLOR_TYPE; else if (typeStr.equals("BOOLEAN")) type = Parameter.BOOLEAN_TYPE; else if (typeStr.equals("COMBO")) { type = Parameter.COMBO_TYPE; predefinedValues = new ArrayList<String>(); String valueString = aConfiguredParameter.valueOf("@values"); StringTokenizer st = new StringTokenizer(valueString, ","); while (st.hasMoreTokens()) { String val = st.nextToken(); predefinedValues.add(val); } } else throw new Exception("Parameter type for parameter " + namePar + " not supported"); Parameter par = new Parameter(namePar, "", description, type); par.setTooltip(toolTipStr); if (predefinedValues != null) { par.setPredefinedValues(predefinedValues); } // Add parameter in confParameterEditor if (!confParametersEditor.containsKey(par)) { confParametersEditor.put(par.getName(), par); // add in section information, a map that gets name section and list of parameters in her. if (confSectionParametersEditor.get(nameSection) == null) { confSectionParametersEditor.put(nameSection, new ArrayList<String>()); } ArrayList<String> list = confSectionParametersEditor.get(nameSection); list.add(par.getName()); } // Get the value, search first in thisDocument, otherwise in configDocument as defaultValue Node parameterNode = thisDocument.selectSingleNode( "//" + this.type.toUpperCase() + "/CONF/PARAMETER[@name='" + par.getName() + "'"); String val = null; if (parameterNode != null && parameterNode.valueOf("@value") != null) { val = parameterNode.valueOf("@value"); } else // search in config { parameterNode = configDocument .selectSingleNode("//" + this.type.toUpperCase() + "S/" + this.type.toUpperCase() + "[@name='commons']/CONF/SECTION/PARAMETER[@name='" + par.getName() + "']"); if (parameterNode != null && parameterNode.valueOf("@defaultValue") != null) { val = parameterNode.valueOf("@defaultValue"); } } if (type == Parameter.INTEGER_TYPE) { // if it is not a number (maybe empty) don't fill anything try { Integer d = Integer.valueOf(val); par.setValue(d); } catch (Exception e) { logger.warn("Not a number"); } } else if (type == Parameter.FLOAT_TYPE) { // if it is not a number (maybe empty) don't fill anything try { Double d = Double.valueOf(val); par.setValue(d); } catch (Exception e) { logger.warn("Not a number"); } } else if (type == Parameter.STRING_TYPE || type == Parameter.COMBO_TYPE) { par.setValue(val); } else if (type == Parameter.COLOR_TYPE) { try { RGB d = ChartEditor.convertHexadecimalToRGB(val); par.setValue(d); } catch (Exception e) { logger.warn("Not a Hexadecimal color rapresentation"); } } else if (type == Parameter.BOOLEAN_TYPE) { try { Boolean d = Boolean.valueOf(val); par.setValue(d); } catch (Exception e) { logger.warn("Not a bool, set default false"); par.setValue(new Boolean("false")); } } } } return; }
From source file:it.eng.spagobi.studio.chart.editors.model.chart.ChartModel.java
License:Mozilla Public License
/** Fill the specific conf parameters founf in the actual document, otherwise in the template docuement * // ww w . j av a 2 s. c om * @throws Exception */ public void fillSpecificConfParameters() throws Exception { logger.debug("Record and fill specific conf parameters"); // search for the root String upperCaseNameSl = getType().toUpperCase(); String upperCaseNamePl = upperCaseNameSl + "S"; Node specificConfig = configDocument .selectSingleNode("//" + upperCaseNamePl + "/" + upperCaseNameSl + "[@name='" + subType + "']"); if (specificConfig == null) throw new Exception("No specific configuration set"); List allSections = specificConfig .selectNodes("//" + type.toUpperCase() + "[@name='" + subType + "']/CONF/SECTION"); // Iterate over the section for (Iterator iterator = allSections.iterator(); iterator.hasNext();) { Element section = (Element) iterator.next(); String nameSection = section.valueOf("@name"); // iterate over the parameters for the current section List configuredParameters = section .selectNodes("//" + type.toString() + "[@name='" + subType + "']/CONF/SECTION/PARAMETER"); for (int j = 0; j < configuredParameters.size(); j++) { Node aConfiguredParameter = (Node) configuredParameters.get(j); // System.out.println(aConfiguredParameter.asXML()); String namePar = aConfiguredParameter.valueOf("@name"); String description = aConfiguredParameter.valueOf("@description"); String typeStr = aConfiguredParameter.valueOf("@type"); String tooltipStr = aConfiguredParameter.valueOf("@tooltip"); ArrayList<String> predefinedValues = null; int type; if (typeStr.equals("INTEGER")) type = Parameter.INTEGER_TYPE; else if (typeStr.equals("FLOAT")) type = Parameter.FLOAT_TYPE; else if (typeStr.equals("STRING")) type = Parameter.STRING_TYPE; else if (typeStr.equals("COLOR")) type = Parameter.COLOR_TYPE; else if (typeStr.equals("BOOLEAN")) type = Parameter.BOOLEAN_TYPE; else if (typeStr.equals("COMBO")) { type = Parameter.COMBO_TYPE; predefinedValues = new ArrayList<String>(); String valueString = aConfiguredParameter.valueOf("@values"); StringTokenizer st = new StringTokenizer(valueString, ","); while (st.hasMoreTokens()) { String val = st.nextToken(); predefinedValues.add(val); } } else throw new Exception("Parameter type for parameter " + namePar + " not supported"); Parameter par = new Parameter(namePar, "", description, type); par.setTooltip(tooltipStr); if (predefinedValues != null) { par.setPredefinedValues(predefinedValues); } if (!confSpecificParametersEditor.containsKey(par)) { confSpecificParametersEditor.put(par.getName(), par); // add in section information if (confSpecificSectionParametersEditor.get(nameSection) == null) { confSpecificSectionParametersEditor.put(nameSection, new ArrayList<String>()); } ArrayList<String> list = confSpecificSectionParametersEditor.get(nameSection); list.add(par.getName()); } // Get the value, search first in thisDocument, otherwise in configDocument as defaultValue Node parameterNode = thisDocument.selectSingleNode( "//" + this.type.toUpperCase() + "/CONF/PARAMETER[@name='" + par.getName() + "'"); String val = null; if (parameterNode != null && parameterNode.valueOf("@value") != null) { val = parameterNode.valueOf("@value"); } else // search in config { //parameterNode=thisDocument.selectSingleNode("//"+this.type.toUpperCase()+"/CONF/PARAMETER[@name='"+par.getName()+"'"); parameterNode = configDocument.selectSingleNode( "//" + this.type.toUpperCase() + "S/" + this.type.toUpperCase() + "[@name='" + this.subType + "']/CONF/SECTION/PARAMETER[@name='" + par.getName() + "']"); if (parameterNode != null && parameterNode.valueOf("@defaultValue") != null) { val = parameterNode.valueOf("@defaultValue"); } } if (type == Parameter.INTEGER_TYPE) { // if it is not a number (maybe empty) don't fill anything try { Integer d = Integer.valueOf(val); par.setValue(d); } catch (Exception e) { logger.warn("Not a number"); } } else if (type == Parameter.FLOAT_TYPE) { // if it is not a number (maybe empty) don't fill anything try { Double d = Double.valueOf(val); par.setValue(d); } catch (Exception e) { logger.warn("Not a number"); } } else if (type == Parameter.STRING_TYPE || type == Parameter.COMBO_TYPE) { par.setValue(val); } else if (type == Parameter.COLOR_TYPE) { try { RGB d = ChartEditor.convertHexadecimalToRGB(val); par.setValue(d); } catch (Exception e) { logger.warn("Not a Hexadecimal color rapresentation"); } } else if (type == Parameter.BOOLEAN_TYPE) { try { Boolean d = Boolean.valueOf(val); par.setValue(d); } catch (Exception e) { logger.warn("Not a bool, set default false"); par.setValue(new Boolean("false")); } } } } return; }
From source file:it.eng.spagobi.studio.chart.editors.model.chart.DialChartModel.java
License:Mozilla Public License
public void fillIntervalsInformation(String type, Document thisDocument) { // Search in present template and fill the field from presentDocument, otherwise from templateDocument logger.debug("Recording and Filling intervals from file or from template"); Node intervalsN = thisDocument.selectSingleNode("//" + type.toUpperCase() + "/INTERVALS"); if (intervalsN != null) { ChartEditorUtils.print("Doc to insert", thisDocument); List<Node> allIntervals = thisDocument.selectNodes("//" + type.toUpperCase() + "/INTERVALS/INTERVAL"); // run intervals found in actual document or in template and record them in model for (Iterator iterator = allIntervals.iterator(); iterator.hasNext();) { Node node = (Node) iterator.next(); Interval interval = new Interval(); String label = node.valueOf("@label"); String min = node.valueOf("@min"); String max = node.valueOf("@max"); String color = node.valueOf("@color"); if (label != null) { interval.setLabel(label); }/*from w w w .j a v a2 s . c o m*/ if (min != null) { Double minValD; try { minValD = Double.valueOf(min); } catch (Exception e) { logger.error("Not double format for min parameter in interval; set default 0", e); minValD = new Double(0); } interval.setMin(minValD); } if (max != null) { Double maxValD; try { maxValD = Double.valueOf(max); } catch (Exception e) { logger.error("Not double format for max parameter in interval; set default 0", e); maxValD = new Double(0); } interval.setMax(maxValD); } if (color != null) { interval.setColor(ChartEditor.convertHexadecimalToRGB(color)); } // Add interval to Vector this.intervals.add(interval); } } }
From source file:it.eng.spagobi.studio.chart.editors.model.chart.XYChartModel.java
License:Mozilla Public License
public void fillXYRanges(String type, Document thisDocument) { // Search in present template and fill the field from presentDocument, otherwise from templateDocument logger.debug("Recording and Filling ranges from file"); Node yRangesNode = thisDocument.selectSingleNode("//" + type.toUpperCase() + "/YRANGES"); if (yRangesNode != null) { ChartEditorUtils.print("Doc to insert", thisDocument); List<Node> allYRanges = thisDocument.selectNodes("//" + type.toUpperCase() + "/YRANGES/RANGE"); // run intervals found in actual document or in template and record them in model for (Iterator iterator = allYRanges.iterator(); iterator.hasNext();) { Node node = (Node) iterator.next(); String label = node.valueOf("@label"); if (label != null && !label.equalsIgnoreCase("")) { this.yRanges.add(label); }//from www .j a v a2s. c o m } } Node zRangesNode = thisDocument.selectSingleNode("//" + type.toUpperCase() + "/ZRANGES"); if (zRangesNode != null) { ChartEditorUtils.print("Doc to insert", thisDocument); List<Node> allZRanges = thisDocument.selectNodes("//" + type.toUpperCase() + "/ZRANGES/RANGE"); // run intervals found in actual document or in template and record them in model for (Iterator iterator = allZRanges.iterator(); iterator.hasNext();) { Node node = (Node) iterator.next(); ChartEditorUtils.print("", node); String label = node.valueOf("@label"); String valueLow = node.valueOf("@value_low"); String valueHigh = node.valueOf("@value_high"); String color = node.valueOf("@colour"); if (label == null || label.equalsIgnoreCase("")) { logger.warn("not accepted z range without label"); } else { ZRanges zRange = new ZRanges(); zRange.setLabel(label); if (valueLow != null) { Double minValD; try { minValD = Double.valueOf(valueLow); } catch (Exception e) { logger.error("Not integer format for low value in range; set default 0", e); minValD = new Double(0); } zRange.setValueLow(minValD); } if (valueHigh != null) { Double maxValD; try { maxValD = Double.valueOf(valueHigh); } catch (Exception e) { logger.error("Not Integer format for high parameter in interval; set default 0", e); maxValD = new Double(0); } zRange.setValueHigh(maxValD); } if (color != null) { zRange.setColor(ChartEditor.convertHexadecimalToRGB(color)); } // Add interval to Vector this.zRanges.put(zRange.getLabel(), zRange); } // label not null } // iterate over ranges } // if zRanges }
From source file:it.eng.spagobi.studio.chart.utils.DrillConfiguration.java
License:Mozilla Public License
public void fillDrillConfigurations(String type, Document thisDocument) { logger.debug("Recording and Filling te drill configurations"); Node drill = thisDocument.selectSingleNode("//" + type.toUpperCase() + "/DRILL"); if (drill != null) { ChartEditorUtils.print("", drill); String document = drill.valueOf("@document"); if (document != null) url = document;/*from ww w . j av a 2s .c om*/ } if (url != null) { logger.debug("Url for drill is: " + url); } Node catUrlName = thisDocument .selectSingleNode("//" + type.toUpperCase() + "/DRILL/PARAM[@name='categoryurlname']"); if (catUrlName != null) { String catUrlNameVal = catUrlName.valueOf("@value"); if (catUrlNameVal != null) { categoryUrlName = catUrlNameVal; } } if (categoryUrlName != null) { logger.debug("Category name label is: " + categoryUrlName); } Node serUrlName = thisDocument .selectSingleNode("//" + type.toUpperCase() + "/DRILL/PARAM[@name='seriesurlname']"); if (serUrlName != null) { String serUrlNameVal = serUrlName.valueOf("@value"); if (serUrlNameVal != null) { seriesUrlName = serUrlNameVal; } } if (seriesUrlName != null) { logger.debug("Serie name label is: " + seriesUrlName); } logger.debug("check other parameters for drill"); ChartEditorUtils.print("", thisDocument); //Node hasDrill=thisDocument.selectSingleNode("//"+type.toUpperCase()+"/DRILL"); // If has no drill does not go to search on template, otherwise yes if (drill != null) { List<Node> listOthers = thisDocument.selectNodes("//" + type.toUpperCase() + "/DRILL/PARAM"); for (Iterator iterator = listOthers.iterator(); iterator.hasNext();) { Node node = (Node) iterator.next(); String nameParam = node.valueOf("@name"); String valueParam = node.valueOf("@value"); valueParam = valueParam != null ? valueParam : ""; String typeParam = node.valueOf("@type"); typeParam = typeParam != null ? typeParam : DrillParameters.ABSOLUTE; if (!nameParam.equalsIgnoreCase("categoryurlname") && !nameParam.equalsIgnoreCase("seriesurlname")) { if (!drillParameters.containsKey(nameParam)) { DrillParameters drillParams = new DrillParameters(nameParam, valueParam, typeParam); drillParameters.put(nameParam, drillParams); } else { DrillParameters drillParams = drillParameters.get(nameParam); drillParams.setType(typeParam); drillParams.setValue(valueParam); } } } } }
From source file:it.eng.spagobi.studio.chart.utils.ScatterRangeMarker.java
License:Mozilla Public License
public void fillScatterRangeRankConfigurations(String type, Document thisDocument) { logger.debug("Recording and Filling te range and marker configurations"); // Search if there is info to fill Node xRangeNode = thisDocument.selectSingleNode("//" + type.toUpperCase() + "/PARAMETER[@name='x_range']"); if (xRangeNode != null) { String valueLowS = xRangeNode.valueOf("@value_low"); try {/*from w w w .java2 s .com*/ Double lowD = Double.valueOf(valueLowS); xRangeValueLow = lowD; } catch (Exception e) { xRangeValueLow = 0.0; } String valueHighS = xRangeNode.valueOf("@value_high"); try { Double highD = Double.valueOf(valueHighS); xRangeValueHigh = highD; } catch (Exception e) { xRangeValueHigh = 0.0; } } Node yRangeNode = thisDocument.selectSingleNode("//" + type.toUpperCase() + "/PARAMETER[@name='y_range']"); if (yRangeNode != null) { String valueLowS = yRangeNode.valueOf("@value_low"); try { Double lowD = Double.valueOf(valueLowS); yRangeValueLow = lowD; } catch (Exception e) { yRangeValueLow = 0.0; } String valueHighS = yRangeNode.valueOf("@value_high"); try { Double highD = Double.valueOf(valueHighS); yRangeValueHigh = highD; } catch (Exception e) { yRangeValueHigh = 0.0; } } Node xMarkerNode = thisDocument .selectSingleNode("//" + type.toUpperCase() + "/PARAMETER[@name='x_marker']"); xMarker.fillMarkerConfigurations(xMarkerNode); Node yMarkerNode = thisDocument .selectSingleNode("//" + type.toUpperCase() + "/PARAMETER[@name='y_marker']"); yMarker.fillMarkerConfigurations(yMarkerNode); }
From source file:it.eng.spagobi.studio.chart.utils.XYMarker.java
License:Mozilla Public License
public void fillMarkerConfigurations(Node node) { if (node != null) { String xLabel = node.valueOf("@label"); if (xLabel != null) { label = xLabel;/* w ww. j a v a2s.c o m*/ } String valueStartIntS = node.valueOf("@value_start_int"); if (valueStartIntS != null) { Integer valI = null; try { valI = Integer.valueOf(valueStartIntS); } catch (Exception e) { valI = 0; } valueStartInt = valI; } String valueEndIntS = node.valueOf("@value_end_int"); if (valueEndIntS != null) { Integer valI = null; try { valI = Integer.valueOf(valueEndIntS); } catch (Exception e) { valI = 0; } valueEndInt = valI; } String valueMarkerS = node.valueOf("@value_marker"); if (valueMarkerS != null) { Double valD = null; try { valD = Double.valueOf(valueMarkerS); } catch (Exception e) { valD = 0.0; } valueMarker = valD; } String colorIntS = node.valueOf("@color_int"); if (colorIntS != null) { Integer valI = null; try { valI = Integer.valueOf(colorIntS); } catch (Exception e) { valI = 0; } colorInt = valI; } String colorS = node.valueOf("@color"); if (colorIntS != null) { RGB val = null; try { val = ChartEditor.convertHexadecimalToRGB(colorS); } catch (Exception e) { } color = val; } } }
From source file:it.eng.spagobi.studio.core.wizards.downloadWizard.SpagoBIDownloadWizard.java
License:Mozilla Public License
public boolean downloadContainedTemplate(Document document) { logger.debug("IN"); boolean toReturn = true; Integer id = document.getId(); Template template = null;//from w ww. j a v a 2 s . c o m SpagoBIServerObjectsFactory proxyServerObjects = null; try { proxyServerObjects = new SpagoBIServerObjectsFactory(projectName); } catch (NoActiveServerException e1) { SpagoBILogger.errorLog("No active server found", e1); MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", "No active server found"); return false; } int numDocs = 0; try { template = proxyServerObjects.getServerDocuments().downloadTemplate(id); } catch (NullPointerException e) { logger.error("No comunication with server, check SpagoBi Server definition in preferences page", e); MessageDialog.openError(getShell(), "Error", "No comunication with server, check SpagoBi Server definition in preferences page"); return false; } catch (Exception e) { logger.error("No comunication with SpagoBI server, could not retrieve template", e); MessageDialog.openError(getShell(), "Error", "Could not get the template from server for document with id " + id); return false; } template.getContent(); String xmlString = null; DataHandler dh = template.getContent(); InputStream is = null; try { is = dh.getInputStream(); xmlString = readInputStreamAsString(is); xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + xmlString; is = new ByteArrayInputStream(xmlString.getBytes("UTF-8")); // put all the labels in an array, so if there is a problem in parsing does not download anything boolean correctParsing = true; SAXReader reader = new SAXReader(); org.dom4j.Document thisDocument = null; List<String> labels = new ArrayList<String>(); try { thisDocument = reader.read(is); List docs = thisDocument.selectNodes("//DOCUMENTS_COMPOSITION/DOCUMENTS_CONFIGURATION/DOCUMENT"); for (int i = 0; i < docs.size(); i++) { Node doc = (Node) docs.get(i); String label = doc.valueOf("@sbi_obj_label"); if (label != null) { labels.add(label); } else { correctParsing = false; } } } catch (Exception e) { correctParsing = false; } if (correctParsing == false) { logger.error("error in reading the file searching for document labels "); MessageDialog.openWarning(getShell(), "Warning", "error in reading template searching for document labels: will not download contained documents but only composed one"); return false; } for (int i = 0; i < labels.size(); i++) { Document docToDownload = proxyServerObjects.getServerDocuments().getDocumentByLabel(labels.get(i)); if (docToDownload != null) { toReturn = downloadTemplate(docToDownload); if (toReturn == true) { numDocs++; logger.debug("Download document with label " + docToDownload.getName()); } } } } catch (Exception e1) { logger.error("Error in writing the file", e1); MessageDialog.openWarning(getShell(), "Warning", "Error in downloading contained documents; will not download contained documents but only composed one"); return false; } logger.debug("Downloaded # document " + numDocs); logger.debug("OUT"); return toReturn; }