Search in sources :

Example 86 with Element

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));
}
Also used : Element(org.dom4j.Element)

Example 87 with Element

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);
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ContextItem(org.talend.core.model.properties.ContextItem) EList(org.eclipse.emf.common.util.EList) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) Element(org.dom4j.Element) Point(org.eclipse.draw2d.geometry.Point) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 88 with Element

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);
    }
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) ProcessorException(org.talend.designer.runprocess.ProcessorException) IFile(org.eclipse.core.resources.IFile) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Element(org.dom4j.Element) BufferedReader(java.io.BufferedReader) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcessor(org.talend.designer.runprocess.IProcessor) IProcess(org.talend.core.model.process.IProcess) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) ProcessorException(org.talend.designer.runprocess.ProcessorException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 89 with Element

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);
}
Also used : INode(org.talend.core.model.process.INode) InternalNodeComponentHandler(org.talend.core.ui.documentation.generation.InternalNodeComponentHandler) IMRProcessService(org.talend.core.service.IMRProcessService) Element(org.dom4j.Element) Document(org.dom4j.Document) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) EList(org.eclipse.emf.common.util.EList) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ExternalNodeComponentHandler(org.talend.core.ui.documentation.generation.ExternalNodeComponentHandler) CSSRuleList(org.w3c.dom.css.CSSRuleList) ArrayList(java.util.ArrayList) List(java.util.List) NodeList(org.w3c.dom.NodeList) EList(org.eclipse.emf.common.util.EList)

Example 90 with Element

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()));
    }
}
Also used : ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) Element(org.dom4j.Element) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

Element (org.dom4j.Element)2207 Document (org.dom4j.Document)500 ArrayList (java.util.ArrayList)294 List (java.util.List)249 SAXReader (org.dom4j.io.SAXReader)196 Iterator (java.util.Iterator)163 IQ (org.xmpp.packet.IQ)142 HashMap (java.util.HashMap)135 IOException (java.io.IOException)114 File (java.io.File)101 Attribute (org.dom4j.Attribute)97 StringReader (java.io.StringReader)90 DefaultElement (org.dom4j.tree.DefaultElement)87 JID (org.xmpp.packet.JID)87 Test (org.junit.jupiter.api.Test)78 DocumentException (org.dom4j.DocumentException)74 QName (org.dom4j.QName)68 AnnotatedElement (java.lang.reflect.AnnotatedElement)64 Node (org.dom4j.Node)64 Test (org.junit.Test)64