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.jpivotaddins.bean.TemplateBean.java
License:Mozilla Public License
public void saveTemplate(RequestContext reqContext) { Logger logger = Logger.getLogger(this.getClass()); HttpSession session = reqContext.getSession(); IEngUserProfile profile = (IEngUserProfile) session.getAttribute(IEngUserProfile.ENG_USER_PROFILE); String userUniqueIdentifier = (String) profile.getUserUniqueIdentifier(); String user = (String) ((UserProfile) profile).getUserId(); String schema = (String) session.getAttribute("selectedSchema"); String documentId = (String) session.getAttribute("document"); Node selectedConnectionNode = (Node) session.getAttribute("selectedConnectionNode"); String connectionType = (String) selectedConnectionNode.valueOf("@type"); String catalogUri = (String) session.getAttribute("catalogUri"); //String spagoBIBaseUrl = (String) session.getAttribute("spagobiurl"); //String path = (String) session.getAttribute("biobject_path"); OlapModel olapModel = (OlapModel) session.getAttribute("query01"); MdxQuery mdxQuery = (MdxQuery) olapModel.getExtension("mdxQuery"); String query = mdxQuery.getMdxQuery(); // the queryWithParameters is added by the addParameter.jsp String queryWithParameters = (String) session.getAttribute("queryWithParameters"); String initialQueryWithParameters = (String) session.getAttribute("initialQueryWithParameters"); String initialMondrianQuery = (String) session.getAttribute("initialMondrianQuery"); if (initialQueryWithParameters != null && initialMondrianQuery != null) { if (query.trim().equalsIgnoreCase(initialMondrianQuery.trim())) { // the initial Mondrian query was not modified if (queryWithParameters == null) { // if the queryWithParameters is not null it means that the user modified manually the query; // if it is null instead it means that the user did not modify manually the query. queryWithParameters = initialQueryWithParameters; }//from w w w .jav a 2 s .c om } } if (queryWithParameters == null) queryWithParameters = query; HashMap parameters = (HashMap) session.getAttribute("parameters"); if (query != null) { String xmlString = "<olap>\n"; //****************************// if (connectionType.equalsIgnoreCase("xmla")) { xmlString += " <cube reference='" + schema + "' name='" + schema + "' />\n"; } else { xmlString += " <cube reference='" + catalogUri + "' />\n"; } xmlString += " <MDXquery>\n"; xmlString += queryWithParameters; if (parameters != null && parameters.size() > 0) { Set keys = parameters.keySet(); Iterator keyIt = keys.iterator(); while (keyIt.hasNext()) { String parameterName = (String) keyIt.next(); String parameterUrlName = (String) parameters.get(parameterName); xmlString += "<parameter name='" + parameterUrlName + "' as='" + parameterName + "' />"; } } xmlString += " </MDXquery>\n"; xmlString += " <MDXMondrianQuery>\n"; xmlString += query; xmlString += " </MDXMondrianQuery>\n"; xmlString += "</olap>"; // controls that the produced String is a valid xml format Document document = null; try { SAXReader reader = new SAXReader(); byte[] templateContent = xmlString.getBytes(); ByteArrayInputStream is = new ByteArrayInputStream(templateContent); document = reader.read(is); } catch (Exception e) { logger.error("Error while parsing xml template " + xmlString, e); return; } xmlString = document.asXML(); try { //ContentServiceProxy proxy=new ContentServiceProxy(user,session); ContentServiceProxy proxy = new ContentServiceProxy(userUniqueIdentifier, session); String result = proxy.saveObjectTemplate(documentId, templateName, xmlString); //byte[] response = sbiutils.saveObjectTemplate(spagoBIBaseUrl, path, templateName, xmlString); } catch (Exception gse) { logger.error("Error while saving template", gse); //session.setAttribute("saveTemplateMessage", "KO - " + gse.getMessage()); } } else { logger.error("Could not retrieve MDX query"); //session.setAttribute("saveTemplateMessage", "KO - Could not retrieve MDX query"); } }
From source file:it.eng.spagobi.jpivotaddins.engines.jpivot.security.SecurityUtilities.java
License:Mozilla Public License
/** * Get the SpagoBI Public Key for a DSA alghoritm * @return Public Key for SpagoBI (DSA alghoritm) *//*w ww. j av a 2s. c o m*/ public PublicKey getPublicKey() { PublicKey pubKey = null; SAXReader reader = new SAXReader(); Document document = null; try { document = reader.read(getClass().getResourceAsStream("/security-config.xml")); Node publicKeyNode = document.selectSingleNode("//SECURITY-CONFIGURATION/KEYS/SPAGOBI_PUBLIC_KEY_DSA"); String namePubKey = publicKeyNode.valueOf("@keyname"); InputStream publicKeyIs = this.getClass().getClassLoader().getResourceAsStream(namePubKey); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len; while ((len = publicKeyIs.read(buffer)) >= 0) baos.write(buffer, 0, len); publicKeyIs.close(); baos.close(); byte[] pubKeyByte = baos.toByteArray(); // get the public key from bytes KeyFactory keyFactory = KeyFactory.getInstance("DSA"); EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(pubKeyByte); pubKey = keyFactory.generatePublic(publicKeySpec); } catch (DocumentException de) { logger.error("Engines" + this.getClass().getName() + "getPublicKey:" + "Error during parsing of the security configuration file", de); } catch (IOException e) { logger.error("Engines" + this.getClass().getName() + "getPublicKey:" + "Error retriving the key file", e); } catch (NoSuchAlgorithmException e) { logger.error("Engines" + this.getClass().getName() + "getPublicKey:" + "DSA Alghoritm not avaiable", e); } catch (InvalidKeySpecException e) { logger.error("Engines" + this.getClass().getName() + "getPublicKey:" + "Invalid Key", e); } return pubKey; }
From source file:it.eng.spagobi.jpivotaddins.roles.SpagoBIMondrianRole.java
License:Mozilla Public License
/** * Creates a role with no permissions.//w ww .j av a 2s. com * @param profile */ public SpagoBIMondrianRole(String filersStr, IEngUserProfile profile) { this.profile = profile; this.filters = new HashSet<String>(); if (filersStr != null) { try { InputStream is = new java.io.ByteArrayInputStream(filersStr.getBytes()); org.dom4j.io.SAXReader reader = new org.dom4j.io.SAXReader(); org.dom4j.Document document; document = reader.read(is); org.dom4j.Node attribute = document.selectSingleNode("//DATA-ACCESS/FILTERED-DIMENSIONS"); String filterAll = attribute.valueOf("@filterAll"); if (filterAll != null && filterAll.equalsIgnoreCase("true")) { allDimension = true; logger.debug("ALL dimension will be filtered"); } List dimensions = document.selectNodes("//DATA-ACCESS/FILTERED-DIMENSIONS/DIMENSION"); if (dimensions != null) { Iterator it = dimensions.iterator(); while (it.hasNext()) { org.dom4j.Node aDimension = (org.dom4j.Node) it.next(); String aDimensionName = aDimension.valueOf("@name"); filters.add(aDimensionName); logger.debug("ADD dimension to filtered SET"); } } } catch (DocumentException e) { logger.error("DocumentException, reading template"); } } }
From source file:it.eng.spagobi.jpivotaddins.util.ParameterHandler.java
License:Mozilla Public License
public String substituteQueryParameters(String queryStr, List parameters, HttpServletRequest request) { String newQuery = queryStr;//from w ww. j a v a 2 s . com if (parameters != null && parameters.size() > 0) { for (int i = 0; i < parameters.size(); i++) { //update the query if there is more than one parameter (else only the last is correctly settled) if (i > 0) { queryStr = newQuery; } Node parameter = (Node) parameters.get(i); String name = ""; String as = ""; if (parameter != null) { name = parameter.valueOf("@name"); as = parameter.valueOf("@as"); } String parameterValue = request.getParameter(name); if ((parameterValue == null) || parameterValue.trim().equals("")) { continue; } String decodedParameterValue = parameterValue; ParametersDecoder decoder = new ParametersDecoder(); if (decoder.isMultiValues(parameterValue)) { decodedParameterValue = (String) decoder.decode(parameterValue).get(0); } newQuery = ParameterSetter.setParameters(queryStr, as, parameterValue); } } return newQuery; }
From source file:it.eng.spagobi.jpivotaddins.util.ParameterUtilities.java
License:Mozilla Public License
public static String substituteQueryParameters(String queryStr, List parameters, HttpServletRequest request) { String newQuery = queryStr;//www.ja va2 s. c o m if (parameters != null && parameters.size() > 0) { for (int i = 0; i < parameters.size(); i++) { //update the query if there is more than one parameter (else only the last is correctly settled) if (i > 0) { queryStr = newQuery; } Node parameter = (Node) parameters.get(i); String name = ""; String as = ""; if (parameter != null) { name = parameter.valueOf("@name"); as = parameter.valueOf("@as"); } String parameterValue = request.getParameter(name); if ((parameterValue == null) || parameterValue.trim().equals("")) { continue; } String decodedParameterValue = parameterValue; ParametersDecoder decoder = new ParametersDecoder(); if (decoder.isMultiValues(parameterValue)) { decodedParameterValue = (String) decoder.decode(parameterValue).get(0); } newQuery = ParameterUtilities.setParameters(queryStr, as, parameterValue); } } return newQuery; }
From source file:it.eng.spagobi.studio.chart.editors.ChartEditorUtils.java
License:Mozilla Public License
/** Get the chart template file path; if subtype is specified go and check in the configuration file wich is the particular template * otherwise getDefault//w w w . j a va 2 s . c o m * * @param chartType * @return * @throws Exception */ public static String getDefaultSubtype(String chartType) throws Exception { String toReturn = null; InputStream is = getInputStreamFromResource(ChartModel.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 (chartType.equalsIgnoreCase(type)) { ChartEditorUtils.print("CHART", chart); String def = chart.valueOf("@defaultSubType"); toReturn = def; break; } } return toReturn; }
From source file:it.eng.spagobi.studio.chart.editors.ChartEditorUtils.java
License:Mozilla Public License
/** Get the configuration file path for the selected type * /*from w w w. j a va 2 s . com*/ * @param chartType * @return * @throws Exception */ public static String getChartConfigPath(String chartType) throws Exception { String toReturn = null; InputStream is = getInputStreamFromResource(ChartModel.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 (chartType.equalsIgnoreCase(type)) { String templatePath = chart.valueOf("@configPath"); toReturn = templatePath; break; } } return toReturn; }
From source file:it.eng.spagobi.studio.chart.editors.ChartEditorUtils.java
License:Mozilla Public License
/** Get the chart image path for the selected type * /*from w w w . ja v a 2 s .com*/ * @param imageType * @return * @throws Exception */ public static String getChartImagePath(String imageType) throws Exception { String toReturn = null; InputStream is = getInputStreamFromResource(ChartModel.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 (imageType.equalsIgnoreCase(type)) { String imagePath = chart.valueOf("@imagePath"); toReturn = imagePath; break; } } return toReturn; }
From source file:it.eng.spagobi.studio.chart.editors.model.chart.ChartModel.java
License:Mozilla Public License
/** * The constuctor search in the present file and fill all the field with present data * @param type//from www.j a v a 2s .c o m * @param file * @throws Exception */ public ChartModel(String type_, String subType_, IFile thisFile, Document configDocument_) throws Exception { logger.debug("Start model constructor"); // Initialise some fields this.type = type_; this.subType = subType_; // This is like BarchartsConfig.xml this.configDocument = configDocument_; // Read the present file InputStream thisIs = null; thisIs = thisFile.getContents(); SAXReader reader = new SAXReader(); thisDocument = reader.read(thisIs); // Get the title String typeUpperCase = type.toUpperCase(); Node chart = thisDocument.selectSingleNode("//" + typeUpperCase); if (chart == null) { logger.error("Error in reading the actual file root"); throw new Exception("xml not valid"); } title = chart.valueOf("@name"); if (title != null && !title.equalsIgnoreCase("")) { logger.debug("Title is " + title != null ? title : ""); } Node subTitleNode = thisDocument.selectSingleNode("//" + typeUpperCase + "/STYLE_SUBTITLE"); if (subTitleNode != null) { String subTitleS = subTitleNode.valueOf("@name"); if (subTitleS != null) { subTitle = subTitleS; } } if (subTitle == null) subTitle = ""; // finds the dimension String widthStr = null; String heightStr = null; Node dimensioneNode = thisDocument.selectSingleNode("//" + typeUpperCase + "/DIMENSION"); if (dimensioneNode != null) { widthStr = dimensioneNode.valueOf("@width"); heightStr = dimensioneNode.valueOf("@height"); } else { Node heightNode = configDocument.selectSingleNode("//" + type.toUpperCase() + "S/" + type.toUpperCase() + "/DIMENSIONS/DIMENSION[@name='height']"); if (heightNode != null) heightStr = heightNode.valueOf("@defaultValue"); Node widthNode = configDocument.selectSingleNode( "//" + type.toUpperCase() + "S/" + type.toUpperCase() + "/DIMENSIONS/DIMENSION[@name='width']"); if (widthNode != null) widthStr = widthNode.valueOf("@defaultValue"); if (heightStr == null || heightStr.equals("")) heightStr = "400"; if (widthStr == null || widthStr.equals("")) widthStr = "400"; } int width; int height; try { width = Integer.parseInt(widthStr); height = Integer.parseInt(heightStr); } catch (NumberFormatException nfe) { logger.error("Dimensions value not number", nfe); throw new Exception("Dimension not valid"); } Dimension dimension = new Dimension(width, height); setDimension(dimension); logger.debug("Dimensions set"); // find the backround Color String colorString = ""; Node colorNode = thisDocument.selectSingleNode("//" + typeUpperCase + "/COLORS"); if (colorNode != null) { colorString = colorNode.valueOf("@background"); } if (colorString == null || colorString.equals("")) { colorNode = configDocument.selectSingleNode( "//" + type.toUpperCase() + "S/" + type.toUpperCase() + "/COLORS[@name='background']"); if (colorNode != null) { colorString = colorNode.valueOf("@defaultValue"); } else { colorString = "#FFFFFF"; } } backgroundColor = ChartEditor.convertHexadecimalToRGB(colorString); // Fill style parameters fillStyleParameters(); // Fill configurations parameter belonging to that type fillCommonsConfParameters(); // Fill configurations parameter belonging to default subtyp fillSpecificConfParameters(); // Fill series personalization fillSeriesPersonalization(); }
From source file:it.eng.spagobi.studio.chart.editors.model.chart.ChartModel.java
License:Mozilla Public License
/** * Static method that returns all possibile subtypes for a given type, as configured in config file * @param chartType//w ww .j a v a2 s. c om * @return * @throws Exception */ public static List getConfiguredChartSubTypes(String chartType) throws Exception { List toReturn = new ArrayList(); String configPath = ChartEditorUtils.getChartConfigPath(chartType); InputStream is = ChartEditorUtils.getInputStreamFromResource(configPath); Document document = new SAXReader().read(is); String upperCaseNameSl = chartType.toUpperCase(); String upperCaseNamePl = upperCaseNameSl + "S"; List allCharts = document.selectNodes("//" + upperCaseNamePl + "/" + upperCaseNameSl); if (allCharts == null || allCharts.isEmpty()) throw new Exception("No common configuration set"); for (Iterator iterator = allCharts.iterator(); iterator.hasNext();) { Node chart = (Node) iterator.next(); String name = chart.valueOf("@name"); if (!name.equalsIgnoreCase("commons")) { logger.debug("Add possible subtype " + name); toReturn.add(name); } } return toReturn; }