List of usage examples for org.dom4j DocumentFactory getInstance
public static synchronized DocumentFactory getInstance()
From source file:org.pentaho.aggdes.model.ssas.ConversionUtil.java
License:Open Source License
/** * generates ssas attribute hierarchies// ww w. j a v a 2s . c o m */ private static void populateAttributeHierarchies(Element mondrianDimension, List cubeAttributes, Element ssasDatabaseDimension, Element ssasDimensionKeyAttribute, Table factTable, String factForeignKey, List<Table> allTables) throws AggDesignerException { mondrianDimension.add(DocumentFactory.getInstance().createComment("Attribute Hierarchies")); for (int i = 0; i < cubeAttributes.size(); i++) { Element cubeAttribute = (Element) cubeAttributes.get(i); // retrieve database attribute String attribID = getXPathNodeText(cubeAttribute, "assl:AttributeID"); Element databaseAttribute = (Element) ssasDatabaseDimension .selectSingleNode("assl:Attributes/assl:Attribute[assl:ID='" + attribID + "']"); // note: databaseAttribute also has an AttributeHierarchyEnabled flag // should we also check "visible"? if (cubeAttribute.selectSingleNode("assl:AttributeHierarchyEnabled") != null && "true".equals(getXPathNodeText(cubeAttribute, "assl:AttributeHierarchyEnabled"))) { Element usageElement = (Element) databaseAttribute.selectSingleNode("assl:Usage"); if (usageElement != null && "Parent".equals(usageElement.getTextTrim())) { // skip parent hierarchies continue; } Element mondrianHierarchy = DocumentFactory.getInstance().createElement("Hierarchy"); String attribName = getXPathNodeText(databaseAttribute, "assl:Name"); mondrianHierarchy.addAttribute("name", attribName); String tableID = getXPathNodeText(ssasDimensionKeyAttribute, "assl:KeyColumns/assl:KeyColumn/assl:Source/assl:TableID"); Table table = findTable(allTables, tableID); String primaryKey = getXPathNodeText(ssasDimensionKeyAttribute, "assl:KeyColumns/assl:KeyColumn/assl:Source/assl:ColumnID"); Column primaryKeyColumn = table.findColumn(primaryKey); List<Element> nodes = (List<Element>) ssasDimensionKeyAttribute .selectNodes("assl:KeyColumns/assl:KeyColumn/assl:Source/assl:ColumnID"); if (nodes.size() > 1) { logger.warn("SKIPPING ATTRIBUTE HIERARCHY " + attribName + ", MORE THAN ONE FOREIGN KEY"); continue; } mondrianHierarchy.addAttribute("primaryKey", primaryKeyColumn.dbName); // AttributeAllMemberName Element allMemberName = (Element) ssasDatabaseDimension .selectSingleNode("assl:AttributeAllMemberName"); if (allMemberName != null && allMemberName.getTextTrim().length() != 0) { mondrianHierarchy.addAttribute("allMemberName", allMemberName.getTextTrim()); mondrianHierarchy.addAttribute("hasAll", "true"); } else { mondrianHierarchy.addAttribute("hasAll", "false"); } String levelTableID = getXPathNodeText(databaseAttribute, "assl:NameColumn/assl:Source/assl:TableID"); List<String> tables = new ArrayList<String>(); tables.add(tableID); if (levelTableID != null && !levelTableID.equals(tableID)) { tables.add(levelTableID); table = findTable(allTables, levelTableID); } // skip if degenerate dimension if (tables.size() != 1 || !tables.get(0).equals(factTable.logicalName)) { populateHierarchyRelation(mondrianHierarchy, tables, ssasDatabaseDimension, factTable, allTables, attribID, factForeignKey); } Element mondrianLevel = DocumentFactory.getInstance().createElement("Level"); mondrianLevel.addAttribute("name", attribName); Element keyUniquenessGuarantee = (Element) databaseAttribute .selectSingleNode("assl:KeyUniquenessGuarantee"); boolean keyUniqueness = false; if (keyUniquenessGuarantee != null) { keyUniqueness = "true".equals(keyUniquenessGuarantee.getTextTrim()); } mondrianLevel.addAttribute("uniqueMembers", "" + keyUniqueness); if (tables.size() > 1) { mondrianLevel.addAttribute("table", table.dbName); // tableName); } nodes = (List<Element>) databaseAttribute .selectNodes("assl:KeyColumns/assl:KeyColumn/assl:Source/assl:ColumnID"); String keyColumn = nodes.get(nodes.size() - 1).getTextTrim(); String nameColumn = getXPathNodeText(databaseAttribute, "assl:NameColumn/assl:Source/assl:ColumnID"); if (keyColumn == null || keyColumn.equals(nameColumn)) { Column nameColumnObject = table.findColumn(nameColumn); nameColumnObject.addToMondrian(mondrianLevel, "column", "KeyExpression"); } else { Column keyColumnObject = table.findColumn(keyColumn); keyColumnObject.addToMondrian(mondrianLevel, "column", "KeyExpression"); Column nameColumnObject = table.findColumn(nameColumn); nameColumnObject.addToMondrian(mondrianLevel, "nameColumn", "NameExpression"); } String datatype = getXPathNodeText(databaseAttribute, "assl:NameColumn/assl:DataType"); // TODO: create example with numeric column, // this code is more stubbed then tested if (datatype.equals("Numeric")) { mondrianLevel.addAttribute("type", "Numeric"); } mondrianHierarchy.add(mondrianLevel); mondrianDimension.add(mondrianHierarchy); } } }
From source file:org.pentaho.aggdes.model.ssas.ConversionUtil.java
License:Open Source License
/** * generates <Measure> mondrian tags *//*from w w w .ja v a 2s . c o m*/ private static void populateCubeMeasures(Element mondrianCube, Element ssasMeasureGroup, Table factTable, String cubeName) throws AggDesignerException { List allMeasures = ssasMeasureGroup.selectNodes("assl:Measures/assl:Measure"); for (int j = 0; j < allMeasures.size(); j++) { Element measure = (Element) allMeasures.get(j); // assert Source/Source xsi:type="ColumnBinding" if (measure.selectSingleNode("assl:Source/assl:Source[@xsi:type='ColumnBinding']") == null && measure.selectSingleNode("assl:Source/assl:Source[@xsi:type='RowBinding']") == null) { logger.warn("SKIPPING MEASURE, INVALID MEASURE IN CUBE " + cubeName + " : " + measure.asXML()); continue; } Element mondrianMeasure = DocumentFactory.getInstance().createElement("Measure"); String measureName = getXPathNodeText(measure, "assl:Name"); mondrianMeasure.addAttribute("name", measureName); logger.trace("MEASURE: " + measureName); String aggType = "sum"; Element aggFunction = (Element) measure.selectSingleNode("assl:AggregateFunction"); if (aggFunction != null) { aggType = aggFunction.getTextTrim().toLowerCase(); } if (aggType.equals("distinctcount")) { aggType = "distinct-count"; } mondrianMeasure.addAttribute("aggregator", aggType); if (measure.selectSingleNode("assl:Source/assl:Source[@xsi:type='ColumnBinding']") != null) { String column = getXPathNodeText(measure, "assl:Source/assl:Source/assl:ColumnID"); Column columnObj = factTable.findColumn(column); columnObj.addToMondrian(mondrianMeasure, "column", "MeasureExpression"); } else { // select the first fact column in the star mondrianMeasure.addAttribute("column", factTable.columns.get(0)); } mondrianCube.add(mondrianMeasure); } }
From source file:org.sipfoundry.sipxconfig.admin.commserver.imdb.DataSetGenerator.java
License:Contributor Agreement License
/** * This is for testing only./* www .j a v a 2 s . c o m*/ * * @return XML representation of dataset */ @Deprecated public Document generateXml() { List<Map<String, String>> items = generate(); DocumentFactory factory = DocumentFactory.getInstance(); Document document = factory.createDocument(); Element itemsEl = document.addElement("items"); itemsEl.addAttribute("type", getType().getName()); for (Map<String, String> item : items) { Element itemEl = itemsEl.addElement("item"); for (Map.Entry<String, String> entry : item.entrySet()) { itemEl.addElement(entry.getKey()).setText(entry.getValue()); } } return document; }
From source file:org.sipfoundry.sipxconfig.rest.ActiveGreetingResource.java
License:Contributor Agreement License
private Document getDom(String greeting) { DocumentFactory factory = DocumentFactory.getInstance(); Document document = factory.createDocument(); document.addElement("activegreeting").addText(greeting); return document; }
From source file:org.sipfoundry.sipxconfig.rest.PhonebookResource.java
License:Contributor Agreement License
static Document getPhonebookXml(Collection<PhonebookEntry> entries) { DocumentFactory factory = DocumentFactory.getInstance(); Document document = factory.createDocument(); Element rootItem = document.addElement("phonebook"); for (PhonebookEntry entry : entries) { Element entryEl = rootItem.addElement("entry"); entryEl.addElement("first-name").setText(entry.getFirstName()); entryEl.addElement("last-name").setText(entry.getLastName()); entryEl.addElement("number").setText(entry.getNumber()); }/*from ww w .ja v a2 s . c om*/ return document; }
From source file:org.sipfoundry.sipxconfig.rest.PhonebooksResource.java
License:Contributor Agreement License
private Document getDom() { DocumentFactory factory = DocumentFactory.getInstance(); Document document = factory.createDocument(); Element rootItem = document.addElement("phonebooks"); for (Phonebook phonebook : m_phonebookManager.getPhonebooks()) { Element phonebookEl = rootItem.addElement("phonebook"); phonebookEl.addAttribute("name", phonebook.getName()); }//from w ww .j av a2 s . c om return document; }
From source file:org.talend.updates.runtime.nexus.component.ComponentIndexManager.java
License:Open Source License
public boolean createIndexFile(File indexFile, List<ComponentIndexBean> newIndexList) throws IOException { if (newIndexList == null || newIndexList.isEmpty() || indexFile == null) { return false; }//from ww w .j ava2s. c o m XMLWriter xmlWriter = null; boolean created = false; try { // write to index final DocumentFactory docFactory = DocumentFactory.getInstance(); final Element components = docFactory.createElement(ELEM_COMPONENTS); Document newDoc = docFactory.createDocument(components); for (ComponentIndexBean b : newIndexList) { final Element elem = createXmlElement(b); if (elem != null) { components.add(elem); } } // 4 spaces OutputFormat format = new OutputFormat(); format.setEncoding("UTF-8"); //$NON-NLS-1$ format.setIndentSize(4); format.setNewlines(true); xmlWriter = new XMLWriter(new FileOutputStream(indexFile), format); xmlWriter.write(newDoc); created = true; return true; } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException e) { // } } if (!created && indexFile.exists()) { indexFile.delete(); // remove the wrong file. } } }
From source file:org.talend.updates.runtime.nexus.component.ComponentIndexManager.java
License:Open Source License
Element createXmlElement(ComponentIndexBean indexBean) { if (indexBean == null) { return null; }/*from w w w. j av a2s . co m*/ if (!indexBean.validRequired()) { return null; // no valid } final DocumentFactory docFactory = DocumentFactory.getInstance(); final Element component = docFactory.createElement(ComponentIndexManager.ELEM_COMPONENT); for (ComponentIndexNames in : ComponentIndexNames.values()) { final String value = indexBean.getValue(in); if (StringUtils.isBlank(value)) { continue; // not value } switch (in) { case name: case bundle_id: case version: case mvn_uri: case license_uri: case product: case image_mvn_uri: case types: case categories: case degradable: case compatibleStudioVersion: default: // attribute component.add(docFactory.createAttribute(component, in.getName(), value)); break; case description: case license: // child element final Element child = docFactory.createElement(in.getName()); child.setText(value); component.add(child); break; } } return component; }
From source file:pt.webdetails.cda.settings.CdaSettings.java
License:Open Source License
/** * Creates a representation of a CDA via API * * @param id/*from ww w. ja v a2s . c om*/ * @param key * @throws UnsupportedConnectionException * @throws UnsupportedDataAccessException */ public CdaSettings(final String id, final ResourceKey key) { this.contextKey = key; this.id = id; genDoc = DocumentFactory.getInstance().createDocument("UTF-8"); genDoc.addElement("CDADescriptor"); this.root = genDoc.getRootElement(); connectionsMap = new HashMap<String, Connection>(); dataAccessMap = new HashMap<String, DataAccess>(); }
From source file:pt.webdetails.cda.xml.DomTraversalHelper.java
License:Open Source License
public Document traverse(CdaSettings cda) { // The root element is always the same, so it does not need to be // visited/*ww w . j av a 2 s. c o m*/ Document doc = DocumentFactory.getInstance().createDocument("UTF-8"); doc.addElement("CDADescriptor"); //should use a copy of the dom so it doesnt destroy those that come from a file this.root = doc.getRootElement(); Element consEle = this.root.addElement("DataSources"); // Traverse the connections. Iterator<Entry<String, Connection>> it = cda.getConnectionsMap().entrySet().iterator(); while (it.hasNext()) { @SuppressWarnings("rawtypes") Map.Entry pairs = (Map.Entry) it.next(); Connection con = (Connection) pairs.getValue(); con.accept(new DomVisitor(), consEle); } // Traverse the dataacesses Iterator<Entry<String, DataAccess>> iter = cda.getDataAccessMap().entrySet().iterator(); while (iter.hasNext()) { @SuppressWarnings("rawtypes") Map.Entry pairs = (Map.Entry) iter.next(); DataAccess da = (DataAccess) pairs.getValue(); String daType = "DataAccess"; if (da instanceof CompoundDataAccess) daType = "CompoundDataAccess"; Element daEle = this.root.addElement(daType); da.accept(new DomVisitor(), daEle); // Traverse the columns ArrayList<ColumnDefinition> columns = da.getColumnDefinitions(); if (!columns.isEmpty()) { Element colsEle = daEle.addElement("Columns"); for (ColumnDefinition columnDefinition : columns) { columnDefinition.accept(new DomVisitor(), colsEle); } } // Traverse the parameters if (da instanceof AbstractDataAccess) { ArrayList<Parameter> params = ((AbstractDataAccess) da).getParameters(); if (!params.isEmpty()) { Element paramsEle = daEle.addElement("Parameters"); for (Parameter param : params) { param.accept(new DomVisitor(), paramsEle); } } } // Banded Mode if (da instanceof MdxDataAccess && ((MdxDataAccess) da).getBandedMode().equals(MdxDataAccess.BANDED_MODE.COMPACT)) { daEle.addElement("BandedMode").addText(MdxDataAccess.BANDED_MODE.COMPACT.name().toLowerCase()); } // Outputs if (!da.getOutputs().isEmpty()) { String idxs = StringUtils.join(da.getOutputs().toArray(), ","); Element output = daEle.addElement("Output"); if (da.getOutputMode().equals(DataAccess.OutputMode.EXCLUDE)) { output.addAttribute("mode", da.getOutputMode().name().toLowerCase()); } output.addAttribute("indexes", idxs); } } return doc; }