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.qbe.datasource.configuration.dao.fileimpl.CalculatedFieldsDAOFileImpl.java
License:Mozilla Public License
private void loadCalculatedFieldsFromFile(File calculatedFieldsFile, Map<String, List<ModelCalculatedField>> calculatedFiledsMap) { FileInputStream in;/*w w w. j a va2 s . c o m*/ SAXReader reader; Document document; String entity; String name; String type; String nature; Boolean inlineCalculatedField; String expression; ModelCalculatedField calculatedField; List calculatedFieldNodes; Iterator it; Node calculatedFieldNode; List<ModelCalculatedField> calculatedFileds; logger.debug("IN"); in = null; try { logger.debug("Load calculated fields from file [" + calculatedFieldsFile + "]"); if (calculatedFieldsFile != null && calculatedFieldsFile.exists()) { document = guardedRead(calculatedFieldsFile); Assert.assertNotNull(document, "Document cannot be null"); calculatedFieldNodes = document.selectNodes("//" + ROOT_TAG + "/" + FIELD_TAG + ""); logger.debug("Found [" + calculatedFieldNodes.size() + "] calculated field/s"); it = calculatedFieldNodes.iterator(); while (it.hasNext()) { calculatedFieldNode = (Node) it.next(); entity = calculatedFieldNode.valueOf("@" + FIELD_TAG_ENTIY_ATTR); name = calculatedFieldNode.valueOf("@" + FIELD_TAG_NAME_ATTR); type = calculatedFieldNode.valueOf("@" + FIELD_TAG_TYPE_ATTR); nature = calculatedFieldNode.valueOf("@" + FIELD_TAG_NATURE_ATTR); inlineCalculatedField = new Boolean(calculatedFieldNode.valueOf("@" + FIELD_TAG_IN_LINE_ATTR)); expression = loadExpression(calculatedFieldNode); calculatedField = new ModelCalculatedField(name, type, expression, inlineCalculatedField.booleanValue()); calculatedField.setNature(nature); // parse slots List<ModelCalculatedField.Slot> slots = loadSlots(calculatedFieldNode); calculatedField.addSlots(slots); if (slots.size() > 0) { String defaultSlotValue = loadDefaultSlotValue(calculatedFieldNode); calculatedField.setDefaultSlotValue(defaultSlotValue); } if (!calculatedFiledsMap.containsKey(entity)) { calculatedFiledsMap.put(entity, new ArrayList()); } calculatedFileds = calculatedFiledsMap.get(entity); ModelCalculatedField calculatedFieldToRemove = null; for (ModelCalculatedField cf : calculatedFileds) { if (cf.getName().equals(calculatedField.getName())) { calculatedFieldToRemove = cf; break; } } if (calculatedFieldToRemove != null) { boolean removed = calculatedFileds.remove(calculatedFieldToRemove); logger.debug("Calculated field [" + calculatedFieldToRemove.getName() + "] already defined. The old version will be replaced with this one"); } calculatedFileds.add(calculatedField); logger.debug("Calculated filed [" + calculatedField.getName() + "] loaded succesfully"); } } else { logger.debug("File [" + calculatedFieldsFile + "] does not exist. No calculated fields have been loaded."); } } catch (Throwable t) { if (t instanceof DAOException) throw (DAOException) t; throw new DAOException("An unpredicted error occurred while loading calculated fields on file [" + calculatedFieldsFile + "]", t); } finally { if (in != null) { try { in.close(); } catch (IOException e) { throw new DAOException( "Impossible to properly close stream to file file [" + calculatedFieldsFile + "]", e); } } logger.debug("OUT"); } }
From source file:it.eng.qbe.datasource.configuration.dao.fileimpl.CalculatedFieldsDAOFileImpl.java
License:Mozilla Public License
private String loadDefaultSlotValue(Node calculatedFieldNode) { String defaultSlotValue = null; Node slotBlock = calculatedFieldNode.selectSingleNode(SLOTS_TAG); if (slotBlock != null) { defaultSlotValue = slotBlock.valueOf("@defaultSlotValue"); }/*from w w w .j a v a2s. c o m*/ return defaultSlotValue; }
From source file:it.eng.qbe.datasource.configuration.dao.fileimpl.CalculatedFieldsDAOFileImpl.java
License:Mozilla Public License
private ModelCalculatedField.Slot loadSlot(Node slotNode) { ModelCalculatedField.Slot slot;// w w w . j av a 2 s . com String slotValue = slotNode.valueOf("@value"); slot = new ModelCalculatedField.Slot(slotValue); List<Node> mappedValues = slotNode.selectNodes(VALUESET_TAG); for (Node mappedValuesNode : mappedValues) { ModelCalculatedField.Slot.IMappedValuesDescriptor descriptor = loadDescriptor(mappedValuesNode); slot.addMappedValuesDescriptors(descriptor); } return slot; }
From source file:it.eng.qbe.datasource.configuration.dao.fileimpl.CalculatedFieldsDAOFileImpl.java
License:Mozilla Public License
private ModelCalculatedField.Slot.IMappedValuesDescriptor loadDescriptor(Node mappedValuesNode) { ModelCalculatedField.Slot.IMappedValuesDescriptor descriptor = null; String descriptorType = mappedValuesNode.valueOf("@type"); if (descriptorType.equalsIgnoreCase("range")) { descriptor = loadRangeDescriptor(mappedValuesNode); } else if (descriptorType.equalsIgnoreCase("punctual")) { descriptor = loadPunctualDescriptor(mappedValuesNode); }/*ww w. j a va2 s .co m*/ return descriptor; }
From source file:it.eng.qbe.datasource.configuration.dao.fileimpl.CalculatedFieldsDAOFileImpl.java
License:Mozilla Public License
private ModelCalculatedField.Slot.MappedValuesPunctualDescriptor loadPunctualDescriptor(Node mappedValuesNode) { ModelCalculatedField.Slot.MappedValuesPunctualDescriptor punctualDescriptor; punctualDescriptor = new ModelCalculatedField.Slot.MappedValuesPunctualDescriptor(); List<Node> punctualValueNodes = mappedValuesNode.selectNodes(VALUE_TAG); for (Node punctualValueNode : punctualValueNodes) { String punctualValue = punctualValueNode.valueOf("@value"); punctualDescriptor.addValue(punctualValue); }// w w w. ja v a 2 s . co m return punctualDescriptor; }
From source file:it.eng.qbe.datasource.configuration.dao.fileimpl.CalculatedFieldsDAOFileImpl.java
License:Mozilla Public License
private ModelCalculatedField.Slot.MappedValuesRangeDescriptor loadRangeDescriptor(Node mappedValuesNode) { ModelCalculatedField.Slot.MappedValuesRangeDescriptor rangeDescriptor = null; Node fomrNode = mappedValuesNode.selectSingleNode(FROM_TAG); String fromValue = fomrNode.valueOf("@value"); Node toNode = mappedValuesNode.selectSingleNode(TO_TAG); String toValue = toNode.valueOf("@value"); rangeDescriptor = new ModelCalculatedField.Slot.MappedValuesRangeDescriptor(fromValue, toValue); String includeValue = null;/*from w w w . j a va 2 s .c o m*/ includeValue = fomrNode.valueOf("@include"); if (includeValue != null && (includeValue.equalsIgnoreCase("TRUE") || includeValue.equalsIgnoreCase("FALSE"))) { rangeDescriptor.setIncludeMinValue(Boolean.parseBoolean(includeValue)); } includeValue = toNode.valueOf("@include"); if (includeValue != null && (includeValue.equalsIgnoreCase("TRUE") || includeValue.equalsIgnoreCase("FALSE"))) { rangeDescriptor.setIncludeMaxValue(Boolean.parseBoolean(includeValue)); } return rangeDescriptor; }
From source file:it.eng.qbe.datasource.configuration.dao.fileimpl.InLineFunctionsDAOFileImpl.java
License:Mozilla Public License
public HashMap<String, InLineFunction> loadInLineFunctions(String dialect) { FileInputStream in;// w ww.j a va2 s .c o m InputStream is; Document document; String group; String name; String desc; String nParams; String code; List functionsNodes; Iterator it; Node functionNode; Node dialectNode; logger.debug("IN"); in = null; try { if (getInLineFunctions() != null && getInLineFunctions().size() > 0) { logger.info("Functions for dialect " + dialect + " yet loaded."); return getInLineFunctions(); } is = getClass().getClassLoader().getResourceAsStream(FUNCTIONS_FILE_NAME); Assert.assertNotNull(is, "Input stream cannot be null"); logger.debug("Functions will be loaded from file [" + FUNCTIONS_FILE_NAME + "]"); document = readFile(is); Assert.assertNotNull(document, "Document cannot be null"); functionsNodes = document.selectNodes("//" + ROOT_TAG + "/" + FIELD_TAG + ""); logger.debug("Found [" + functionsNodes.size() + "] functions"); it = functionsNodes.iterator(); while (it.hasNext()) { functionNode = (Node) it.next(); group = functionNode.valueOf("@" + FIELD_TAG_GROUP_ATTR); name = functionNode.valueOf("@" + FIELD_TAG_NAME_ATTR); desc = functionNode.valueOf("@" + FIELD_TAG_DESC_ATTR); nParams = functionNode.valueOf("@" + FIELD_TAG_NPARAMS_ATTR); dialectNode = null; //get the code function only for the dialect managed if (dialect.equalsIgnoreCase(QuerySerializationConstants.DIALECT_MYSQL)) { dialectNode = functionNode .selectSingleNode(functionNode.getUniquePath() + "/" + FIELD_TAG_MYSQL_DIALECT + ""); } else if (dialect.equalsIgnoreCase(QuerySerializationConstants.DIALECT_HSQL)) { dialectNode = functionNode .selectSingleNode(functionNode.getUniquePath() + "/" + FIELD_TAG_HQL_DIALECT + ""); } else if (dialect.equalsIgnoreCase(QuerySerializationConstants.DIALECT_ORACLE) || dialect.equalsIgnoreCase(QuerySerializationConstants.DIALECT_ORACLE9i10g)) { dialectNode = functionNode .selectSingleNode(functionNode.getUniquePath() + "/" + FIELD_TAG_ORACLE_DIALECT + ""); } else if (dialect.equalsIgnoreCase(QuerySerializationConstants.DIALECT_INGRES)) { dialectNode = functionNode .selectSingleNode(functionNode.getUniquePath() + "/" + FIELD_TAG_INGRES_DIALECT + ""); } else if (dialect.equalsIgnoreCase(QuerySerializationConstants.DIALECT_POSTGRES)) { dialectNode = functionNode .selectSingleNode(functionNode.getUniquePath() + "/" + FIELD_TAG_POSTGRES_DIALECT + ""); } else { dialectNode = functionNode.selectSingleNode( functionNode.getUniquePath() + "/" + FIELD_TAG_SQLSERVER_DIALECT + ""); } code = ""; if (dialectNode != null) { code = dialectNode.valueOf("@" + FIELD_TAG_CODE_ATTR); } InLineFunction func = new InLineFunction(); func.setDialect(dialect); func.setName(name); func.setGroup(group); func.setDesc(desc); func.setnParams(Integer.valueOf(nParams)); func.setCode(code); addInLineFunction(func); logger.debug("Function [" + mapInLineFunctions.get(func.name) + "] loaded succesfully"); } } catch (Throwable t) { if (t instanceof DAOException) throw (DAOException) t; throw new DAOException( "An unpredicted error occurred while loading functions on file [" + FUNCTIONS_FILE_NAME + "]", t); } finally { if (in != null) { try { in.close(); } catch (IOException e) { throw new DAOException( "Impossible to properly close stream to file file [" + FUNCTIONS_FILE_NAME + "]", e); } } logger.debug("OUT"); } return getInLineFunctions(); }
From source file:it.eng.spagobi.engines.talend.client.JobDeploymentDescriptor.java
License:Open Source License
public void load(InputStream is) throws DocumentException { SAXReader reader = new org.dom4j.io.SAXReader(); Document document = null;//from w ww. j ava 2 s . co m document = reader.read(is); Node job = document.selectSingleNode("//etl/job"); //$NON-NLS-1$ if (job != null) { this.project = job.valueOf("@project"); //$NON-NLS-1$ this.language = job.valueOf("@language"); //$NON-NLS-1$ } }
From source file:it.eng.spagobi.engines.talend.runtime.JobDeploymentDescriptor.java
License:Mozilla Public License
/** * Load./*from w w w.j av a2 s. c o m*/ * * @param is the is * * @throws DocumentException the document exception */ public void load(InputStream is) throws DocumentException { SAXReader reader = new org.dom4j.io.SAXReader(); Document document = null; document = reader.read(is); Node job = document.selectSingleNode("//etl/job"); if (job != null) { this.project = job.valueOf("@project"); this.language = job.valueOf("@language"); } }
From source file:it.eng.spagobi.jpivotaddins.bean.AnalysisBeanHandler.java
License:Mozilla Public License
public void getAnalysisBean(HttpSession session, HttpServletRequest request) throws IOException, DocumentException { List parameters = null;/* w ww. j a v a2 s . c o m*/ InputStream is = null; String reference = null, name = null, nameConnection = null, query = null; AnalysisBean analysis = null; SaveAnalysisBean analysisBean = (SaveAnalysisBean) session.getAttribute("save01"); String nameSubObject = request.getParameter("nameSubObject"); // if into the request is defined the attribute "nameSubObject" the engine must run a subQuery if (nameSubObject != null) { String jcrPath = (String) session.getAttribute("templatePath"); String spagoBIBaseUrl = (String) session.getAttribute("spagobiurl"); String user = (String) session.getAttribute("user"); // if subObject execution in the request there are the description and visibility String descrSO = request.getParameter("descriptionSubObject"); if (descrSO == null) { descrSO = ""; } String visSO = request.getParameter("visibilitySubObject"); if (visSO == null) { visSO = "Private"; } analysisBean.setAnalysisName(nameSubObject); analysisBean.setAnalysisDescription(descrSO); // the possible values of the visibility are (Private/Public) analysisBean.setAnalysisVisibility(visSO); // get content from cms String subobjdata64Coded = request.getParameter("subobjectdata"); BASE64Decoder bASE64Decoder = new BASE64Decoder(); byte[] subobjBytes = bASE64Decoder.decodeBuffer(subobjdata64Coded); is = new java.io.ByteArrayInputStream(subobjBytes); InputStreamReader isr = new InputStreamReader(is); XStream dataBinder = new XStream(); try { analysis = (AnalysisBean) dataBinder.fromXML(isr, new AnalysisBean()); isr.close(); query = analysis.getMdxQuery(); nameConnection = analysis.getConnectionName(); reference = analysis.getCatalogUri(); } catch (Throwable t) { t.printStackTrace(); } // normal execution (no subObject) } else { String templateBase64Coded = request.getParameter("template"); BASE64Decoder bASE64Decoder = new BASE64Decoder(); byte[] template = bASE64Decoder.decodeBuffer(templateBase64Coded); is = new java.io.ByteArrayInputStream(template); org.dom4j.io.SAXReader reader = new org.dom4j.io.SAXReader(); Document document = reader.read(is); nameConnection = request.getParameter("connectionName"); query = document.selectSingleNode("//olap/MDXquery").getStringValue(); Node cube = document.selectSingleNode("//olap/cube"); reference = cube.valueOf("@reference"); name = cube.valueOf("@name"); parameters = document.selectNodes("//olap/MDXquery/parameter"); analysis = new AnalysisBean(); analysis.setConnectionName(nameConnection); analysis.setCatalogUri(reference); session.setAttribute("analysisBean", analysis); } }