org.dom4j.DocumentFactory Java Examples

The following examples show how to use org.dom4j.DocumentFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WordTableCellContentOleObject.java    From sun-wordtable-read with Apache License 2.0 6 votes vote down vote up
/**
 * 由单元格内容xml构建Document
 * 
 * @param xml
 * @return
 */
private Document buildDocument(String xml) {
	// dom4j解析器的初始化
	SAXReader reader = new SAXReader(new DocumentFactory());
	Map<String, String> map = new HashMap<String, String>();
	map.put("o", "urn:schemas-microsoft-com:office:office");
	map.put("v", "urn:schemas-microsoft-com:vml");
	map.put("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
	map.put("a", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
	map.put("xdr", "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing");
	map.put("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
	map.put("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
	reader.getDocumentFactory().setXPathNamespaceURIs(map); // xml文档的namespace设置

	InputSource source = new InputSource(new StringReader(xml));
	source.setEncoding("utf-8");

	try {
		Document doc = reader.read(source);
		return doc;
	} catch (DocumentException e) {
		logger.error(e.getMessage(), e);
	}
	return null;
}
 
Example #2
Source File: DefaultXmlWriter.java    From yarg with Apache License 2.0 6 votes vote down vote up
@Override
public String buildXml(Report report) {
    try {
        Document document = DocumentFactory.getInstance().createDocument();
        Element root = document.addElement("report");

        root.addAttribute("name", report.getName());
        writeTemplates(report, root);
        writeInputParameters(report, root);
        writeValueFormats(report, root);
        writeRootBand(report, root);

        StringWriter stringWriter = new StringWriter();
        new XMLWriter(stringWriter, OutputFormat.createPrettyPrint()).write(document);
        return stringWriter.toString();
    } catch (IOException e) {
        throw new ReportingException(e);
    }
}
 
Example #3
Source File: TraceEvent.java    From pega-tracerviewer with Apache License 2.0 6 votes vote down vote up
protected Element createElement(String newName, Element element, String elementName) {
    Element newElement = null;
    String targetName = newName;

    if (element != null) {

        if ((newName == null) || ("".equals(newName))) {
            targetName = element.getName();
        }

        newElement = element.createCopy();
        newElement.addAttribute("name", targetName);
    } else {
        if ((elementName != null) && (!"".equals(elementName))) {
            DocumentFactory factory = DocumentFactory.getInstance();
            newElement = factory.createElement(elementName);
            newElement.addAttribute("name", targetName);
        }
    }

    return newElement;
}
 
Example #4
Source File: XMLHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public XMLHelper(ClassLoaderService classLoaderService) {
	this.documentFactory = classLoaderService.workWithClassLoader(
			new ClassLoaderService.Work<DocumentFactory>() {
				@Override
				public DocumentFactory doWork(ClassLoader classLoader) {
					final ClassLoader originalTccl = Thread.currentThread().getContextClassLoader();
					try {
						Thread.currentThread().setContextClassLoader( classLoader );
						return DocumentFactory.getInstance();
					}
					finally {
						Thread.currentThread().setContextClassLoader( originalTccl );
					}
				}
			}
	);

}
 
Example #5
Source File: BpmnXMLConverter.java    From FoxBPM with Apache License 2.0 5 votes vote down vote up
/**
 * 将bpmnModel转换成documnet
 * 
 * @param model
 *            bpmn模型
 */
public Document convertToXML(BpmnModel model) {
	
	if (null == model) {
		throw new BpmnConverterException("模型转换XML失败,模型实例不能为空!");
	}
	
	DocumentFactory factory = DocumentFactory.getInstance();
	Document doc = factory.createDocument();
	Element element = factory.createElement(BpmnXMLConstants.BPMN2_PREFIX + ':'
	        + BpmnXMLConstants.ELEMENT_DEFINITIONS, BpmnXMLConstants.BPMN2_NAMESPACE);
	element.addNamespace(BpmnXMLConstants.XSI_PREFIX, BpmnXMLConstants.XSI_NAMESPACE);
	element.addNamespace(BpmnXMLConstants.DC_PREFIX, BpmnXMLConstants.DC_NAMESPACE);
	element.addNamespace(BpmnXMLConstants.DI_PREFIX, BpmnXMLConstants.DI_NAMESPACE);
	element.addNamespace(BpmnXMLConstants.BPMNDI_PREFIX, BpmnXMLConstants.BPMNDI_NAMESPACE);
	element.addNamespace(BpmnXMLConstants.FOXBPM_PREFIX, BpmnXMLConstants.FOXBPM_NAMESPACE);
	element.addNamespace(BpmnXMLConstants.XSD_PREFIX, BpmnXMLConstants.XSD_NAMESPACE);
	element.addNamespace(BpmnXMLConstants.EMPTY_STRING, BpmnXMLConstants.XMLNS_NAMESPACE);
	// 添加属性
	element.addAttribute(BpmnXMLConstants.TARGET_NAMESPACE_ATTRIBUTE, BpmnXMLConstants.XMLNS_NAMESPACE);
	element.addAttribute(BpmnXMLConstants.ATTRIBUTE_ID, "Definitions_1");
	doc.add(element);
	// 流程转换
	try {
		for (Iterator<Process> iterator = model.getProcesses().iterator(); iterator.hasNext();) {
			ProcessExport.writeProcess(iterator.next(), element);
		}
		// 位置坐标转换
		BPMNDIExport.writeBPMNDI(model, element);
	} catch (Exception e) {
		LOGGER.error("模型转换XML失败,流程名" + model.getProcesses().get(0).getName(), e);
		if (e instanceof BpmnConverterException) {
			throw (BpmnConverterException) e;
		} else {
			throw new BpmnConverterException("模型转换XML失败,流程名:" + model.getProcesses().get(0).getName(), e);
		}
	}
	return doc;
}
 
Example #6
Source File: ResultsBuilder.java    From olat with Apache License 2.0 5 votes vote down vote up
private static void addStaticsPath(final Element el_in, final AssessmentInstance ai) {
    Element el_staticspath = (Element) el_in.selectSingleNode(STATICS_PATH);
    if (el_staticspath == null) {
        final DocumentFactory df = DocumentFactory.getInstance();
        el_staticspath = df.createElement(STATICS_PATH);
        final Resolver resolver = ai.getResolver();
        el_staticspath.addAttribute("ident", resolver.getStaticsBaseURI());
        el_in.add(el_staticspath);
    }
}
 
Example #7
Source File: ItemPreviewController.java    From olat with Apache License 2.0 5 votes vote down vote up
private String getQuestionPreview(final Item theItem) {
    final Element el = DocumentFactory.getInstance().createElement("dummy");
    theItem.addToElement(el);
    final StringBuilder sb = new StringBuilder();
    final org.olat.lms.ims.qti.container.qtielements.Item foo = new org.olat.lms.ims.qti.container.qtielements.Item((Element) el.elements().get(0));
    foo.render(sb, renderInstructions);
    final String previewWithFormattedMathElements = Formatter.formatLatexFormulas(sb.toString());
    final Filter filter = FilterFactory.getBaseURLToMediaRelativeURLFilter(qtiPackage.getMediaBaseURL());
    return filter.filter(previewWithFormattedMathElements);
}
 
Example #8
Source File: ResultsBuilder.java    From olat with Apache License 2.0 5 votes vote down vote up
private static void addStaticsPath(final Element el_in, final AssessmentInstance ai) {
    Element el_staticspath = (Element) el_in.selectSingleNode(STATICS_PATH);
    if (el_staticspath == null) {
        final DocumentFactory df = DocumentFactory.getInstance();
        el_staticspath = df.createElement(STATICS_PATH);
        final Resolver resolver = ai.getResolver();
        el_staticspath.addAttribute("ident", resolver.getStaticsBaseURI());
        el_in.add(el_staticspath);
    }
}
 
Example #9
Source File: ItemPreviewController.java    From olat with Apache License 2.0 5 votes vote down vote up
private String getQuestionPreview(final Item theItem) {
    final Element el = DocumentFactory.getInstance().createElement("dummy");
    theItem.addToElement(el);
    final StringBuilder sb = new StringBuilder();
    final org.olat.lms.ims.qti.container.qtielements.Item foo = new org.olat.lms.ims.qti.container.qtielements.Item((Element) el.elements().get(0));
    foo.render(sb, renderInstructions);
    final String previewWithFormattedMathElements = Formatter.formatLatexFormulas(sb.toString());
    final Filter filter = FilterFactory.getBaseURLToMediaRelativeURLFilter(qtiPackage.getMediaBaseURL());
    return filter.filter(previewWithFormattedMathElements);
}
 
Example #10
Source File: MultiRepresentationTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testDom4jSave() {
	TestData testData = new TestData();
	testData.create();

	Session pojos = openSession();
	Transaction txn = pojos.beginTransaction();
	org.hibernate.Session dom4j = pojos.getSession( EntityMode.DOM4J );

	Element stock = DocumentFactory.getInstance().createElement( "stock" );
	stock.addElement( "tradeSymbol" ).setText( "IBM" );

	Element val = stock.addElement( "currentValuation" ).addElement( "valuation" );
	val.appendContent( stock );
	val.addElement( "valuationDate" ).setText( new java.util.Date().toString() );
	val.addElement( "value" ).setText( "121.00" );

	dom4j.save( Stock.class.getName(), stock );
	dom4j.flush();

	txn.rollback();
	pojos.close();

	assertTrue( !pojos.isOpen() );
	assertTrue( !dom4j.isOpen() );

	prettyPrint( stock );

	testData.destroy();
}
 
Example #11
Source File: LaneSetXmlConverter.java    From FoxBPM with Apache License 2.0 5 votes vote down vote up
protected Element parseLaneToXml(Lane lane){
	Element element = DocumentFactory.getInstance().createElement(BpmnXMLConstants.BPMN2_PREFIX + ':'
	        + BpmnXMLConstants.ELEMENT_LANE, BpmnXMLConstants.BPMN2_NAMESPACE);
	
	element.addAttribute(BpmnXMLConstants.ATTRIBUTE_ID, lane.getId());
	element.addAttribute(BpmnXMLConstants.ATTRIBUTE_NAME, lane.getName());
	
	LaneSet laneSet= lane.getChildLaneSet();
	if(laneSet != null){
		List<Lane> lanes = laneSet.getLanes();
		Element laneSetElement = DocumentFactory.getInstance().createElement(BpmnXMLConstants.BPMN2_PREFIX + ':'
		        + BpmnXMLConstants.ELEMENT_CHILDLANESET, BpmnXMLConstants.BPMN2_NAMESPACE);
		laneSetElement.addAttribute("xsi:type", "bpmn2:tLaneSet");
		laneSetElement.addAttribute(BpmnXMLConstants.ATTRIBUTE_ID, laneSet.getId());
		laneSetElement.addAttribute(BpmnXMLConstants.ATTRIBUTE_NAME, laneSet.getName());
		
		
		if(lanes != null){
			for(Lane tmpLane : lanes){
				Element tmpElement = parseLaneToXml(tmpLane);
				laneSetElement.add(tmpElement);
			}
		}
		element.add(laneSetElement);
	}
	List<String> flowNodeRefs = lane.getFlowElementRefs();
	if(flowNodeRefs != null){
		for(String tmpRef : flowNodeRefs){
			Element elementFlowRef = DocumentFactory.getInstance().createElement(BpmnXMLConstants.BPMN2_PREFIX + ':'
			        + BpmnXMLConstants.ELEMENT_FLOWNODEREF, BpmnXMLConstants.BPMN2_NAMESPACE);
			elementFlowRef.addText(tmpRef);
			element.add(elementFlowRef);
		}
	}
	return element;
}
 
Example #12
Source File: PrivacyList.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an Element with the privacy list XML representation.
 *
 * @return an Element with the privacy list XML representation.
 */
public Element asElement() {
    //Element listElement = DocumentFactory.getInstance().createDocument().addElement("list");
    Element listElement = DocumentFactory.getInstance().createDocument()
            .addElement("list", "jabber:iq:privacy");
    listElement.addAttribute("name", getName());
    // Add the list items to the result
    for (PrivacyItem item : items) {
        listElement.add(item.asElement());
    }
    return listElement;
}
 
Example #13
Source File: DOM4JHandleTest.java    From java-client-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadWrite() throws SAXException, IOException {
  // create an identifier for the database document
  String docId = "/example/jdom-test.xml";

  // create a manager for XML database documents
  XMLDocumentManager docMgr = Common.client.newXMLDocumentManager();

  DocumentFactory factory = new DocumentFactory();

  // create a dom4j document
  Document writeDocument = factory.createDocument();
  Element root = factory.createElement("root");
  root.attributeValue("foo", "bar");
  root.add(factory.createElement("child"));
  root.addText("mixed");
  writeDocument.setRootElement(root);

  // create a handle for the dom4j document
  DOM4JHandle writeHandle = new DOM4JHandle(writeDocument);

  // write the document to the database
  docMgr.write(docId, writeHandle);

  // create a handle to receive the database content as a dom4j document
  DOM4JHandle readHandle = new DOM4JHandle();

  // read the document content from the database as a dom4j document
  docMgr.read(docId, readHandle);

  // access the document content
  Document readDocument = readHandle.get();
  assertNotNull("Wrote null dom4j document", readDocument);
  assertXMLEqual("dom4j document not equal",
    writeDocument.asXML(), readDocument.asXML());

  // delete the document
  docMgr.delete(docId);
}
 
Example #14
Source File: VersionUpdater.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @author 
 * @param folderPath
 * @param plug_id
 * @param lastDate
 * @param dayInpast
 */
private void genVersionLog(	File folderPath , 
							String plug_id , 
							String lastDate , 
							int dayInpast ){
	// gen the dest file path
	String parentPath = folderPath.getAbsolutePath();
	String fileName = plug_id + "_DayInPast" + ".xml";
	String fullName = parentPath + "/" + fileName;
	File dest = new File(fullName);
	System.out.println("dest file full path:\t"+fullName);
	try{
		//genarate document factory
		DocumentFactory factory = new DocumentFactory();
		//create root element
		DOMElement rootElement = new DOMElement("plugin");
		rootElement.setAttribute("id",plug_id);
		//add child:lastdate
		DOMElement dateElement = new DOMElement("LastDate");
		dateElement.setText(lastDate);
		rootElement.add(dateElement);
		//add child:dayinpast
		DOMElement dayElement = new DOMElement("DayInPast");
		dayElement.setText( Integer.toString(dayInpast));
		rootElement.add(dayElement);
		//gen the doc
		Document doc = factory.createDocument(rootElement);
	
		//PrettyFormat
		OutputFormat format = OutputFormat.createPrettyPrint();
		XMLWriter writer = new XMLWriter( new FileWriter(dest) , format );
		writer.write( doc );
		writer.close();

	}catch(Exception ex){
		ex.printStackTrace();
	}

}
 
Example #15
Source File: ConversionUtil.java    From pentaho-aggdesigner with GNU General Public License v2.0 5 votes vote down vote up
public static List<Document> generateMondrianDocsFromSSASSchema( final InputStream input )
  throws DocumentException, IOException, AggDesignerException {

  Document ssasDocument = parseAssl( input );

  // issue: if we have multi-line text, there is a problem with identing names / etc
  // solution: clean up the dom before traversal
  List allElements = ssasDocument.selectNodes( "//*" );
  for ( int i = 0; i < allElements.size(); i++ ) {
    Element element = (Element) allElements.get( i );
    element.setText( element.getText().replaceAll( "[\\s]+", " " ).trim() );
  }

  List ssasDatabases = ssasDocument.selectNodes( "//assl:Database" );
  List<Document> mondrianDocs = new ArrayList<Document>( ssasDatabases.size() );
  for ( int i = 0; i < ssasDatabases.size(); i++ ) {
    Document mondrianDoc = DocumentFactory.getInstance().createDocument();
    Element mondrianSchema = DocumentFactory.getInstance().createElement( "Schema" );
    mondrianDoc.add( mondrianSchema );
    Element ssasDatabase = (Element) ssasDatabases.get( i );
    mondrianSchema.add( DocumentFactory.getInstance()
      .createAttribute( mondrianSchema, "name", getXPathNodeText( ssasDatabase, "assl:Name" ) ) );
    populateCubes( mondrianSchema, ssasDatabase );

    mondrianDocs.add( mondrianDoc );
  }

  return mondrianDocs;
}
 
Example #16
Source File: GoConfigService.java    From gocd with Apache License 2.0 5 votes vote down vote up
protected Document documentRoot() throws Exception {
    CruiseConfig cruiseConfig = goConfigDao.loadForEditing();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    new MagicalGoConfigXmlWriter(configCache, registry).write(cruiseConfig, out, true);
    Document document = reader.read(new StringReader(out.toString()));
    Map<String, String> map = new HashMap<>();
    map.put("go", MagicalGoConfigXmlWriter.XML_NS);
    //TODO: verify this doesn't cache the factory
    DocumentFactory factory = DocumentFactory.getInstance();
    factory.setXPathNamespaceURIs(map);
    return document;
}
 
Example #17
Source File: ConversionUtil.java    From pentaho-aggdesigner with GNU General Public License v2.0 5 votes vote down vote up
public void addToMondrian( Element parentElement, String attributeName, String expressionName ) {
  if ( expression == null ) {
    parentElement.addAttribute( attributeName, dbName );
  } else {
    Element expressionElement = DocumentFactory.getInstance().createElement( expressionName );
    Element sql = DocumentFactory.getInstance().createElement( "SQL" );
    sql.addAttribute( "dialect", "generic" );
    sql.add( DocumentFactory.getInstance().createCDATA( expression ) );
    expressionElement.add( sql );
    parentElement.add( expressionElement );
  }
}
 
Example #18
Source File: UserTaskXMLConverter.java    From FoxBPM with Apache License 2.0 4 votes vote down vote up
public Element cretateXMLElement() {
	return DocumentFactory.getInstance().createElement(BpmnXMLConstants.BPMN2_PREFIX + ':'
	        + BpmnXMLConstants.ELEMENT_TASK_USER, BpmnXMLConstants.BPMN2_NAMESPACE);
}
 
Example #19
Source File: ParallelGatewayXMLConverter.java    From FoxBPM with Apache License 2.0 4 votes vote down vote up
public Element cretateXMLElement() {
	return DocumentFactory.getInstance().createElement(BpmnXMLConstants.BPMN2_PREFIX + ':'
	        + BpmnXMLConstants.ELEMENT_PARALLELGATEWAY, BpmnXMLConstants.BPMN2_NAMESPACE);
}
 
Example #20
Source File: SequenceFlowXMLConverter.java    From FoxBPM with Apache License 2.0 4 votes vote down vote up
public Element cretateXMLElement() {
	return DocumentFactory.getInstance().createElement(BpmnXMLConstants.BPMN2_PREFIX + ':'
	        + BpmnXMLConstants.ELEMENT_SEQUENCEFLOW, BpmnXMLConstants.BPMN2_NAMESPACE);
}
 
Example #21
Source File: EndEventXMLConverter.java    From FoxBPM with Apache License 2.0 4 votes vote down vote up
public Element cretateXMLElement() {
return DocumentFactory.getInstance().createElement(BpmnXMLConstants.BPMN2_PREFIX + ':'
       + BpmnXMLConstants.ELEMENT_ENDEVENT, BpmnXMLConstants.BPMN2_NAMESPACE);
  }
 
Example #22
Source File: ConversionUtil.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
/**
 * generates parent child hierarchy
 */
private static void populateParentChildHierarchy(
  Element mondrianDimension,
  Element databaseAttribute,
  Element ssasDimensionKeyAttribute,
  Element ssasDatabaseDimension,
  Table factTable,
  String factForeignKey,
  List<Table> allTables,
  String attributeID
) throws AggDesignerException {
  mondrianDimension.add( DocumentFactory.getInstance().createComment( "Parent Child Hierarchy" ) );
  Element mondrianHierarchy = DocumentFactory.getInstance().createElement( "Hierarchy" );
  mondrianHierarchy.addAttribute( "name", getXPathNodeText( databaseAttribute, "assl:Name" ) );
  String tableID =
    getXPathNodeText( ssasDimensionKeyAttribute, "assl:KeyColumns/assl:KeyColumn/assl:Source/assl:TableID" );
  String keyColumnID =
    getXPathNodeText( ssasDimensionKeyAttribute, "assl:KeyColumns/assl:KeyColumn/assl:Source/assl:ColumnID" );
  Table table = findTable( allTables, tableID );
  Column keyColumnObject = table.findColumn( keyColumnID );

  if ( keyColumnObject.expression != null ) {
    logger.warn( "Mondrian does not support primary key expressions" );
  }

  mondrianHierarchy.addAttribute( "primaryKey", keyColumnObject.dbName );

  // not certain on where to get the all member name for parent / child rels
  // ssas seems to use "All" for the default name
  // Element allMemberName = (Element)databaseHierarchy.selectSingleNode("assl:AllMemberName");
  // if (allMemberName != null) {
  mondrianHierarchy.addAttribute( "allMemberName", "All" );
  mondrianHierarchy.addAttribute( "hasAll", "true" );
  // }

  List<String> tables = new ArrayList<String>();
  tables.add( tableID );

  populateHierarchyRelation( mondrianHierarchy, tables, ssasDatabaseDimension, factTable, allTables, attributeID,
    factForeignKey );

  Element mondrianLevel = DocumentFactory.getInstance().createElement( "Level" );
  // <Level name="Employee Id" type="Numeric" uniqueMembers="true" column="employee_id"
  //        parentColumn="supervisor_id" nameColumn="full_name" nullParentValue="0">

  // for now, use the hierarchy name for the level name
  mondrianLevel.addAttribute( "name", getXPathNodeText( databaseAttribute, "assl:Name" ) );

  // mondrianLevel.addAttribute("type", "Numeric");
  mondrianLevel.addAttribute( "uniqueMembers", "true" );
  // NameColumn
  String parentID = getXPathNodeText( databaseAttribute, "assl:KeyColumns/assl:KeyColumn/assl:Source/assl:ColumnID" );
  String columnID = getXPathNodeText( databaseAttribute, "assl:NameColumn/assl:Source/assl:ColumnID" );

  keyColumnObject.addToMondrian( mondrianLevel, "column", "KeyExpression" );

  Column parentColumnObject = table.findColumn( parentID );
  parentColumnObject.addToMondrian( mondrianLevel, "parentColumn", "ParentExpression" );

  Column nameColumnObject = table.findColumn( columnID );
  nameColumnObject.addToMondrian( mondrianLevel, "nameColumn", "NameExpression" );

  // do we need ordinal col?

  // from http://msdn2.microsoft.com/en-us/library/ms174935.aspx
  // User Defined Hierarchies
  // By default, any member whose parent key equals its own member key, null, 0 (zero),
  // or a value absent from the column for member keys is assumed to be a member of the
  // top level (excluding the (All) level).

  mondrianLevel.addAttribute( "nullParentValue", "0" );
  mondrianHierarchy.add( mondrianLevel );
  mondrianDimension.add( mondrianHierarchy );
}
 
Example #23
Source File: ConversionUtil.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
private static void populateHierarchies(
  Element mondrianDimension,
  Element ssasCubeDimension,
  Element ssasDatabaseDimension,
  Element ssasDimensionKeyAttribute,
  Table factTable,
  List<Table> allTables,
  String factForeignKey
) throws AggDesignerException {

  // first do parent child hierarchies
  // for each attribute in cube dimension, see if it's database dimension attribute is USAGE PARENT
  // SSAS 2005 only supports one parent child hierarchy per dimension
  List cubeAttributes = ssasCubeDimension.selectNodes( "assl:Attributes/assl:Attribute" );
  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 + "']" );

    Element usageElement = (Element) databaseAttribute.selectSingleNode( "assl:Usage" );
    if ( usageElement != null && "Parent".equals( usageElement.getTextTrim() ) ) {
      populateParentChildHierarchy( mondrianDimension, databaseAttribute, ssasDimensionKeyAttribute,
        ssasDatabaseDimension, factTable, factForeignKey, allTables, attribID );
    }
  }

  // handle the traditional hierarchies

  List hierarchies = ssasCubeDimension.selectNodes( "assl:Hierarchies/assl:Hierarchy" );
  for ( int k = 0; k < hierarchies.size(); k++ ) {
    Element hierarchy = (Element) hierarchies.get( k );
    String databaseHierarchyID = getXPathNodeText( hierarchy, "assl:HierarchyID" );
    Element databaseHierarchy = (Element) ssasDatabaseDimension
      .selectSingleNode( "assl:Hierarchies/assl:Hierarchy[assl:ID='" + databaseHierarchyID + "']" );

    if ( databaseHierarchy == null ) {
      throw new AggDesignerException( "Failed to locate hierarchy " + databaseHierarchyID );
    }

    Element mondrianHierarchy = DocumentFactory.getInstance().createElement( "Hierarchy" );

    mondrianHierarchy.addAttribute( "name", getXPathNodeText( databaseHierarchy, "assl:Name" ) );
    String tableID =
      getXPathNodeText( ssasDimensionKeyAttribute, "assl:KeyColumns/assl:KeyColumn/assl:Source/assl:TableID" );
    Table primaryKeyTable = findTable( allTables, tableID );
    String primaryKey =
      getXPathNodeText( ssasDimensionKeyAttribute, "assl:KeyColumns/assl:KeyColumn/assl:Source/assl:ColumnID" );
    Column primaryKeyColumn = primaryKeyTable.findColumn( primaryKey );

    mondrianHierarchy.addAttribute( "primaryKey", primaryKeyColumn.dbName );

    Element allMemberName = (Element) databaseHierarchy.selectSingleNode( "assl:AllMemberName" );
    if ( allMemberName != null && allMemberName.getTextTrim().length() != 0 ) {
      mondrianHierarchy.addAttribute( "allMemberName", allMemberName.getTextTrim() );
      mondrianHierarchy.addAttribute( "hasAll", "true" );
    } else {
      mondrianHierarchy.addAttribute( "hasAll", "false" );
    }
    // determine if this hierarchy is a snow flake
    // we can tell this by looking at the levels

    // preprocess levels to determine snowflake-ness
    List ssasLevels = databaseHierarchy.selectNodes( "assl:Levels/assl:Level" );

    List<String> tables = new ArrayList<String>();
    for ( int l = 0; l < ssasLevels.size(); l++ ) {
      Element level = (Element) ssasLevels.get( l );
      String sourceAttribID = getXPathNodeText( level, "assl:SourceAttributeID" );
      Element sourceAttribute = (Element) ssasDatabaseDimension
        .selectSingleNode( "assl:Attributes/assl:Attribute[assl:ID='" + sourceAttribID + "']" );
      String levelTableID = getXPathNodeText( sourceAttribute, "assl:NameColumn/assl:Source/assl:TableID" );
      if ( !tables.contains( levelTableID ) ) {
        // insert the table in the correct order
        tables.add( 0, levelTableID );
      }
    }

    // skip if degenerate dimension
    if ( tables.size() != 1 || !tables.get( 0 ).equals( factTable.logicalName ) ) {
      populateHierarchyRelation( mondrianHierarchy, tables, ssasDatabaseDimension, factTable, allTables,
        databaseHierarchyID, factForeignKey );
    } else {
      mondrianHierarchy.add( DocumentFactory.getInstance().createComment( "Degenerate Hierarchy" ) );
    }

    // render levels
    populateHierarchyLevels( mondrianHierarchy, ssasLevels, ssasDatabaseDimension, allTables, tables.size() > 1 );

    mondrianDimension.add( mondrianHierarchy );
  }

  // finally, do attribute hierarchies
  populateAttributeHierarchies( mondrianDimension, cubeAttributes, ssasDatabaseDimension, ssasDimensionKeyAttribute,
    factTable, factForeignKey, allTables );

}
 
Example #24
Source File: CallActivityXMLConverter.java    From FoxBPM with Apache License 2.0 4 votes vote down vote up
public Element cretateXMLElement() {
return DocumentFactory.getInstance().createElement(BpmnXMLConstants.BPMN2_PREFIX + ':'
        + BpmnXMLConstants.ELEMENT_CALLACTIVITY, BpmnXMLConstants.BPMN2_NAMESPACE);
  }
 
Example #25
Source File: LaneSetXmlConverter.java    From FoxBPM with Apache License 2.0 4 votes vote down vote up
public Element cretateXMLElement() {
	return DocumentFactory.getInstance().createElement(BpmnXMLConstants.BPMN2_PREFIX + ':'
	        + BpmnXMLConstants.ELEMENT_LANESET, BpmnXMLConstants.BPMN2_NAMESPACE);
}
 
Example #26
Source File: InclusiveGatewayXMLConverter.java    From FoxBPM with Apache License 2.0 4 votes vote down vote up
public Element cretateXMLElement() {
	return DocumentFactory.getInstance().createElement(BpmnXMLConstants.BPMN2_PREFIX + ':'
	        + BpmnXMLConstants.ELEMENT_INCLUSIVEGATEWAY, BpmnXMLConstants.BPMN2_NAMESPACE);
}
 
Example #27
Source File: ConversionUtil.java    From pentaho-aggdesigner with GNU General Public License v2.0 4 votes vote down vote up
/**
 * generates <Measure> mondrian tags
 */
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 );
  }
}
 
Example #28
Source File: SubProcessXMLConverter.java    From FoxBPM with Apache License 2.0 4 votes vote down vote up
public Element cretateXMLElement() {
return DocumentFactory.getInstance().createElement(BpmnXMLConstants.BPMN2_PREFIX + ':'
        + BpmnXMLConstants.ELEMENT_SUBPROCESS, BpmnXMLConstants.BPMN2_NAMESPACE);
  }
 
Example #29
Source File: IntermediateCatchEventXMLConverter.java    From FoxBPM with Apache License 2.0 4 votes vote down vote up
public Element cretateXMLElement() {
	return DocumentFactory.getInstance().createElement(BpmnXMLConstants.BPMN2_PREFIX + ':'
	        + BpmnXMLConstants.ELEMENT_INTERMEDIATECATCHEVENT, BpmnXMLConstants.BPMN2_NAMESPACE);
}
 
Example #30
Source File: Dom4JDriver.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public Dom4JDriver(DocumentFactory documentFactory, OutputFormat outputFormat) {
    this(documentFactory, outputFormat, new XmlFriendlyNameCoder());
}