use of org.dom4j.Element in project tdi-studio-se by Talend.
the class ScdComponentDocumentation method generateXMLInfo.
/**
* Generates all information which for XML file.
*/
private void generateXMLInfo() {
document = DocumentHelper.createDocument();
//$NON-NLS-1$
Element externalNodeElement = document.addElement("externalNode");
//$NON-NLS-1$
externalNodeElement.addAttribute("name", HTMLDocUtils.checkString(this.componentName));
//$NON-NLS-1$
externalNodeElement.addAttribute("preview", HTMLDocUtils.checkString(this.previewPicPath));
}
use of org.dom4j.Element in project tdi-studio-se by Talend.
the class HTMLDocGenerator method generateContextInfo.
/**
* DOC YeXiaowei Comment method "generateContextInfo".
*
* @return
*/
private void generateContextInfo(final Item item, final Element element) {
EList contexts = null;
if (item instanceof ProcessItem) {
contexts = ((ProcessItem) item).getProcess().getContext();
} else if (item instanceof JobletProcessItem) {
contexts = ((JobletProcessItem) item).getJobletProcess().getContext();
}
if (contexts == null || contexts.isEmpty()) {
return;
}
// Context root //$NON-NLS-1$
Element contextListElement = DocumentHelper.createElement("contextList");
for (int i = 0, n = contexts.size(); i < n; i++) {
// export single context infomation
//$NON-NLS-1$
Element contextElement = DocumentHelper.createElement("context");
ContextType context = (ContextType) contexts.get(i);
// Attributes
//$NON-NLS-1$
contextElement.addAttribute("name", HTMLDocUtils.checkString(context.getName()));
IProxyRepositoryFactory repositoryFactory = CorePlugin.getDefault().getProxyRepositoryFactory();
// Context parameters as children
EList params = context.getContextParameter();
if (params != null && !params.isEmpty()) {
for (int j = 0, k = params.size(); j < k; j++) {
/*
* <contextParameter comment="Give server name" name="server" prompt="Default Server "
* promptNeeded="false" repositoryContextId="_crJMkCCQEd2Oweh7yRMWjQ" type=""
* value="'192.168.0.109'"/>
*/
ContextParameterType param = (ContextParameterType) params.get(j);
//$NON-NLS-1$
Element contextParamElement = DocumentHelper.createElement("contextParameter");
//$NON-NLS-1$
contextParamElement.addAttribute("name", HTMLDocUtils.checkString(param.getName()));
//$NON-NLS-1$
contextParamElement.addAttribute("prompt", HTMLDocUtils.checkString(param.getPrompt()));
contextParamElement.addAttribute("promptNeeded", HTMLDocUtils.checkString(Boolean.toString(//$NON-NLS-1$
param.isPromptNeeded())));
//$NON-NLS-1$
contextParamElement.addAttribute("type", HTMLDocUtils.checkString(param.getType()));
//$NON-NLS-1$
contextParamElement.addAttribute("value", ParameterValueUtil.getValue4Doc(param));
// replace repository id with context label
if (param.getRepositoryContextId() != null) {
ContextItem contextItem = ContextUtils.getContextItemById2(param.getRepositoryContextId());
if (contextItem != null) {
// bug 5978: repository link to context item might be lost.
String label = contextItem.getProperty().getLabel();
//$NON-NLS-1$
contextParamElement.addAttribute("source", HTMLDocUtils.checkString(label));
}
}
contextElement.add(contextParamElement);
}
}
contextListElement.add(contextElement);
}
element.add(contextListElement);
}
use of org.dom4j.Element in project tdi-studio-se by Talend.
the class HTMLDocGenerator method generateSourceCodeInfo.
/**
* DOC qwei Comment method "generateSourceCodeInfo".
*/
private void generateSourceCodeInfo(ProcessItem item, Element element) {
if (CorePlugin.getDefault().getPreferenceStore().getBoolean(ITalendCorePrefConstants.DOC_GENERATESOURCECODE)) {
IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
IProcess process = service.getProcessFromProcessItem(item);
IProcessor processor = ProcessorUtilities.getProcessor(process, null, process.getContextManager().getDefaultContext());
// hidePasswordInSourceCode4Doc(process);
try {
processor.cleanBeforeGenerate(TalendProcessOptionConstants.CLEAN_JAVA_CODES | TalendProcessOptionConstants.CLEAN_CONTEXTS | TalendProcessOptionConstants.CLEAN_DATA_SETS);
processor.generateCode(false, true, false);
} catch (ProcessorException e) {
ExceptionHandler.process(e);
}
//$NON-NLS-1$
Element sourceCodeInfoElement = DocumentHelper.createElement("sourcecodes");
ITalendSynchronizer synchronizer = CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
// StringBuffer componentsCode = new StringBuffer();
try {
IFile codeFile = synchronizer.getFile(item);
if (codeFile == null) {
return;
}
//$NON-NLS-1$
String tempStr = "";
InputStream in = codeFile.getContents();
BufferedReader buffer = new BufferedReader(new InputStreamReader(in));
while ((tempStr = buffer.readLine()) != null) {
//$NON-NLS-1$
Element codeElement = DocumentHelper.createElement("code");
// componentsCode.append(tempStr).append("\n");
//$NON-NLS-1$
codeElement.addAttribute("content", tempStr);
sourceCodeInfoElement.add(codeElement);
}
buffer.close();
in.close();
} catch (Exception e) {
// TODO Auto-generated catch block
// e.printStackTrace();
ExceptionHandler.process(e);
}
element.add(sourceCodeInfoElement);
}
}
use of org.dom4j.Element in project tdi-studio-se by Talend.
the class HTMLDocGenerator method handleXMLFile.
/**
* Generates the xml file base on an instance of <code>ExportFileResource</code> and the temporary folder path.
*
* @param resource
* @param tempFolderPath
* @param version
*/
private void handleXMLFile(ExportFileResource resource, String tempFolderPath, String... version) throws Exception {
Item item = resource.getItem();
// Check if generate Job Extra / Stats&Logs Setting Info
if (item instanceof ProcessItem) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IMRProcessService.class)) {
IMRProcessService mrProcessService = (IMRProcessService) GlobalServiceRegister.getDefault().getService(IMRProcessService.class);
generateExtraSetting = !mrProcessService.isMapReduceItem(item);
generateStatsLogsSetting = generateExtraSetting;
} else if (isRouteProcess(item)) {
generateStatsLogsSetting = generateExtraSetting = !isRouteProcess(item);
}
} else if (item instanceof JobletProcessItem) {
generateStatsLogsSetting = false;
}
targetConnectionMap = new HashMap<String, List>();
sourceConnectionMap = new HashMap<String, List>();
getSourceAndTargetConnection(item);
Document document = DocumentHelper.createDocument();
Element projectElement = generateProjectInfo(document);
Element jobElement = generateJobInfo(item, projectElement, version);
// This two element see feature 4162
generateContextInfo(item, jobElement);
generateJobSettingInfo(item, jobElement);
List<List> allList = seperateNodes(item);
if (allList == null || allList.size() != 3) {
return;
}
List<INode> allComponentsList = allList.get(0);
List<INode> internalNodeComponentsList = allList.get(1);
List<INode> externalNodeComponentsList = allList.get(2);
if (allComponentsList.size() > 0) {
// Generates information for 'Component List' part in exported HTML file.
generateAllComponentsSummaryInfo(item, jobElement, allComponentsList);
}
//$NON-NLS-1$
Element internalNodeElement = jobElement.addElement("internalNodeComponents");
//$NON-NLS-1$
Element externalNodeElement = jobElement.addElement("externalNodeComponents");
if (internalNodeComponentsList.size() > 0) {
InternalNodeComponentHandler internalNodeComponentHandler = new InternalNodeComponentHandler(this.picFilePathMap, internalNodeElement, internalNodeComponentsList, this.sourceConnectionMap, this.targetConnectionMap, this.designerCoreService, this.repositoryConnectionItemMap, this.repositoryDBIdAndNameMap, externalNodeHTMLMap);
// Generates internal node components information.
internalNodeComponentHandler.generateComponentInfo();
}
if (externalNodeComponentsList.size() > 0) {
ExternalNodeComponentHandler externalNodeComponentHandler = new ExternalNodeComponentHandler(this.picFilePathMap, externalNodeElement, externalNodeComponentsList, this.sourceConnectionMap, this.targetConnectionMap, this.designerCoreService, this.repositoryConnectionItemMap, this.repositoryDBIdAndNameMap, externalNodeHTMLMap);
// Generates external node components(tMap etc.) information.
externalNodeComponentHandler.generateComponentInfo();
}
// Generates all connection information(include internal node and external node).
EList connectionList = null;
if (item instanceof ProcessItem) {
connectionList = ((ProcessItem) item).getProcess().getConnection();
} else if (item instanceof JobletProcessItem) {
connectionList = (((JobletProcessItem) item).getJobletProcess().getConnection());
}
if (connectionList != null && connectionList.size() != 0) {
generateConnectionsInfo(jobElement, connectionList);
}
//$NON-NLS-1$
String versionPath = "_";
if (version != null && version.length == 1) {
versionPath = versionPath + version[0];
} else {
versionPath = versionPath + item.getProperty().getVersion();
}
String filePath = tempFolderPath + File.separatorChar + item.getProperty().getLabel() + versionPath + IHTMLDocConstants.XML_FILE_SUFFIX;
// This element see feature 4382
if (item instanceof ProcessItem) {
generateSourceCodeInfo((ProcessItem) item, jobElement);
}
XMLHandler.generateXMLFile(tempFolderPath, filePath, document);
}
use of org.dom4j.Element in project tdi-studio-se by Talend.
the class HTMLDocGenerator method generateConnectionsInfo.
/**
* Generates connections information base on <code>jobElement</code>,<code>connectionList</code>
*
* @param jobElement
* @param connectionList
*/
private void generateConnectionsInfo(Element jobElement, EList connectionList) {
//$NON-NLS-1$
Element connectionsElement = jobElement.addElement("connections");
for (int j = 0; j < connectionList.size(); j++) {
ConnectionType type = (ConnectionType) connectionList.get(j);
//$NON-NLS-1$
Element connectionElement = connectionsElement.addElement("connection");
//$NON-NLS-1$
connectionElement.addAttribute("label", HTMLDocUtils.checkString(type.getLabel()));
//$NON-NLS-1$ //$NON-NLS-2$
connectionElement.addAttribute("lineStyle", HTMLDocUtils.checkString(type.getLineStyle() + ""));
//$NON-NLS-1$
connectionElement.addAttribute("metaname", HTMLDocUtils.checkString(type.getMetaname()));
//$NON-NLS-1$ //$NON-NLS-2$
connectionElement.addAttribute("offsetLabelX", HTMLDocUtils.checkString(type.getOffsetLabelX() + ""));
//$NON-NLS-1$ //$NON-NLS-2$
connectionElement.addAttribute("offsetLabelY", HTMLDocUtils.checkString(type.getOffsetLabelY() + ""));
//$NON-NLS-1$
connectionElement.addAttribute("source", HTMLDocUtils.checkString(type.getSource()));
//$NON-NLS-1$
connectionElement.addAttribute("target", HTMLDocUtils.checkString(type.getTarget()));
}
}
Aggregations