Example usage for org.dom4j Element addCDATA

List of usage examples for org.dom4j Element addCDATA

Introduction

In this page you can find the example usage for org.dom4j Element addCDATA.

Prototype

Element addCDATA(String cdata);

Source Link

Document

Adds a new CDATA node with the given text to this element.

Usage

From source file:org.pentaho.actionsequence.dom.ActionSequenceInput.java

License:Open Source License

/**
 * Sets the input default value.//from   ww  w.  j  a  v a2s  . c  o  m
 * 
 * @param defValue
 *          the default value
 */
public void setDefaultValue(String defValue) {
    Element defValElement = ioElement.element(ActionSequenceDocument.DEFAULT_VAL_NAME);
    ioElement.elements(ActionSequenceDocument.RESULTSET_DEFAULT_COLUMNS).clear();
    if (defValue == null) {
        if (defValElement != null) {
            defValElement.detach();
            ActionSequenceDocument.fireIoChanged(this);
        }
    } else {
        if (defValElement == null) {
            defValElement = ioElement.addElement(ActionSequenceDocument.DEFAULT_VAL_NAME);
        } else {
            defValElement.clearContent();
        }
        defValElement.addAttribute(TYPE_NAME, null);
        if (defValue.length() > 0) {
            defValElement.addCDATA(defValue);
        }
        ActionSequenceDocument.fireIoChanged(this);
    }
}

From source file:org.pentaho.common.ui.services.SolutionRepoService.java

License:Open Source License

/**
 * Saves state into the solution repository
 *///from   w  w  w.  j av a2 s . c o  m
protected StateMessage saveState(String filepath, String state, boolean stateIsXml, String type,
        Boolean replace, String title, String description) throws Exception {

    StateMessage result = new StateMessage();

    result.setStatus(StateMessage.STATUS_FAILED);
    if (StringUtils.isEmpty(filepath)) {
        result.setMessage(Messages.getErrorString("SolutionRepo.ERROR_0001_NO_FILEPATH")); //$NON-NLS-1$
        return result;
    }
    if (StringUtils.isEmpty(state)) {
        result.setMessage(Messages.getErrorString("SolutionRepo.ERROR_0002_NO_STATE")); //$NON-NLS-1$
        return result;
    }
    if (StringUtils.isEmpty(type)) {
        result.setMessage(Messages.getErrorString("SolutionRepo.ERROR_0007_NO_TYPE")); //$NON-NLS-1$
        return result;
    }
    if (replace == null) {
        replace = Boolean.FALSE;
        //      return result;
    }

    // make sure the path is good
    ActionInfo info = ActionInfo.parseActionString(filepath);
    if (info == null) {
        result.setMessage(
                Messages.getErrorString("SolutionUrlContentGenerator.ERROR_0005_BAD_FILEPATH", filepath)); //$NON-NLS-1$
        return result;
    }

    IPentahoSession userSession = PentahoSessionHolder.getSession();
    ISolutionRepository repo = PentahoSystem.get(ISolutionRepository.class, userSession);

    // create the state file to save
    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement("state-file"); //$NON-NLS-1$
    Element documentation = root.addElement("documentation"); //$NON-NLS-1$
    documentation.addElement("author").addCDATA(userSession.getName()); //$NON-NLS-1$

    if (stateIsXml) {
        Element stateElement = root.addElement("state-xml"); //$NON-NLS-1$
        Document stateDoc = null;
        try {
            stateDoc = DocumentHelper.parseText(state);
        } catch (Exception e) {
            result.setMessage(Messages.getErrorString("SolutionRepo.ERROR_0009_BAD_STATE", state)); //$NON-NLS-1$
            return result;
        }
        Node stateRoot = stateDoc.getRootElement();
        stateRoot = stateRoot.detach();
        stateElement.add(stateRoot);
    } else {
        Element stateElement = root.addElement("state-text"); //$NON-NLS-1$
        stateElement.addCDATA(state);
    }

    documentation.addElement("title").addCDATA(title); //$NON-NLS-1$
    documentation.addElement("description").addCDATA(description); //$NON-NLS-1$

    String fileName = info.getActionName();
    if (!fileName.endsWith('.' + type)) {
        fileName = fileName + '.' + type;
    }

    // see if we can find a content generator to get the file icon
    IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, userSession);
    if (pluginManager != null) {
        //      IContentInfo contentInfo = pluginManager.getContentInfoFromExtension(type, userSession);
        IContentInfo contentInfo = pluginManager.getContentTypeInfo(type);
        if (contentInfo != null) {
            String icon = contentInfo.getIconUrl();
            documentation.addElement("icon").addCDATA(icon); //$NON-NLS-1$
        }
    }

    String basePath = PentahoSystem.getApplicationContext().getSolutionRootPath();
    if (!basePath.endsWith("" + ISolutionRepository.SEPARATOR)) { //$NON-NLS-1$
        basePath = basePath + ISolutionRepository.SEPARATOR;
    }
    // save the file
    int ret = repo.addSolutionFile(basePath, info.getSolutionName() + '/' + info.getPath(), fileName,
            doc.asXML().getBytes(), replace);

    if (ret == ISolutionRepository.FILE_EXISTS) {
        result.setMessage(Messages.getErrorString("SolutionRepo.ERROR_0004_CANNOT_REPLACE")); //$NON-NLS-1$
        return result;
    } else if (ret == ISolutionRepository.FILE_ADD_INVALID_USER_CREDENTIALS) {
        result.setMessage(Messages.getErrorString("SolutionRepo.ERROR_0005_CREDENTIALS")); //$NON-NLS-1$
        return result;
    } else if (ret != ISolutionRepository.FILE_ADD_SUCCESSFUL) {
        result.setMessage(Messages.getErrorString("SolutionRepo.ERROR_0006_SAVE_FAILED")); //$NON-NLS-1$
        return result;
    }

    result.setStatus(StateMessage.STATUS_SUCCESS);
    result.setMessage(Messages.getString("SolutionRepo.USER_FILE_SAVE")); //$NON-NLS-1$
    return result;
}

From source file:org.pentaho.jfreereport.wizard.utility.report.ReportGenerationUtility.java

License:Open Source License

public static void createCalculatedColumnExpression(ReportSpec reportSpec, Element functionNode, Field f) {
    Element expression = functionNode.addElement("expression"); //$NON-NLS-1$
    expression.addAttribute("class", "org.jfree.report.modules.misc.beanshell.BSHExpression"); //$NON-NLS-1$ //$NON-NLS-2$
    expression.addAttribute(NAME_ATTRIBUTE_NAME, f.getName() + "_calc_column_expression"); //$NON-NLS-1$
    Element properties = expression.addElement("properties"); //$NON-NLS-1$
    Element property = properties.addElement(PROPERTY_ELEMENT_NAME);
    property.addAttribute(NAME_ATTRIBUTE_NAME, "expression"); //$NON-NLS-1$
    StringBuffer nameArrayStrBuf = new StringBuffer();
    nameArrayStrBuf.append("{"); //$NON-NLS-1$
    for (int i = 0; i < f.getCalculatedColumnsCount(); i++) {
        String column = f.getCalculatedColumns()[i];
        nameArrayStrBuf.append("\"" + column + "\""); //$NON-NLS-1$//$NON-NLS-2$
        if (i < f.getCalculatedColumnsCount() - 1) {
            nameArrayStrBuf.append(", "); //$NON-NLS-1$
        }/*from   w  ww.  j  ava  2 s . c  om*/
    }
    nameArrayStrBuf.append("}"); //$NON-NLS-1$
    if ("sum".equals(f.getCalculatedColumnFunction())) { //$NON-NLS-1$
        String calcString = "calc += ((Number)value).doubleValue();"; //$NON-NLS-1$
        String text = "Object getValue() { " + "String[] names = " //$NON-NLS-1$ //$NON-NLS-2$
                + nameArrayStrBuf.toString() + ";" //$NON-NLS-1$
                +
                // "double calc = ((Number)dataRow.get(names[0])).doubleValue(); " +
                "double calc = 0; " + "try { " + "  for (int x=0;x < names.length; x++) { " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + "    Object value = dataRow.get(names[x]); " //$NON-NLS-1$
                + "    if (value != null && value instanceof Number) { " + calcString + "    } " + "  }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + "  return new Double(calc);" + "} catch (Exception e) { " + "  e.prinStackTrace();" + "}" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
                + "}"; //$NON-NLS-1$
        property.addCDATA(text);
    } else if ("diff".equals(f.getCalculatedColumnFunction())) { //$NON-NLS-1$
        String calcString = "calc -= ((Number)value).doubleValue();"; //$NON-NLS-1$
        String text = "Object getValue() { " + "String[] names = " + nameArrayStrBuf.toString() + ";" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + "double calc = ((Number)dataRow.get(names[0])).doubleValue(); " + "try { " //$NON-NLS-1$ //$NON-NLS-2$
                + "  for (int x=1;x < names.length; x++) { " + "    Object value = dataRow.get(names[x]); " //$NON-NLS-1$ //$NON-NLS-2$
                + "    if (value != null && value instanceof Number) { " + calcString + "    } " + "  }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + "  return new Double(calc);" + "} catch (Exception e) { " + "  e.prinStackTrace();" + "}" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
                + "}"; //$NON-NLS-1$
        property.addCDATA(text);
    } else if ("absdiff".equals(f.getCalculatedColumnFunction())) { //$NON-NLS-1$
        String calcString = "calc -= ((Number)value).doubleValue();"; //$NON-NLS-1$
        String text = "Object getValue() { " + "String[] names = " + nameArrayStrBuf.toString() + ";" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + "double calc = ((Number)dataRow.get(names[0])).doubleValue(); " + "try { " //$NON-NLS-1$ //$NON-NLS-2$
                + "  for (int x=1;x < names.length; x++) { " + "    Object value = dataRow.get(names[x]); " //$NON-NLS-1$ //$NON-NLS-2$
                + "    if (value != null && value instanceof Number) { " + calcString + "    } " + "  }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + "  return new Double(Math.abs(calc));" + "} catch (Exception e) { " + "  e.prinStackTrace();" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                + "}" + "}"; //$NON-NLS-1$ //$NON-NLS-2$
        property.addCDATA(text);
    } else if ("mult".equals(f.getCalculatedColumnFunction())) { //$NON-NLS-1$
        String calcString = "calc *= ((Number)value).doubleValue();"; //$NON-NLS-1$
        String text = "Object getValue() { " + "String[] names = " + nameArrayStrBuf.toString() + ";" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + "double calc = ((Number)dataRow.get(names[0])).doubleValue(); " + "try { " //$NON-NLS-1$ //$NON-NLS-2$
                + "  for (int x=1;x < names.length; x++) { " + "    Object value = dataRow.get(names[x]); " //$NON-NLS-1$ //$NON-NLS-2$
                + "    if (value != null && value instanceof Number) { " + calcString + "    } " + "  }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + "  return new Double(calc);" + "} catch (Exception e) { " + "  e.prinStackTrace();" + "}" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
                + "}"; //$NON-NLS-1$
        property.addCDATA(text);
    } else if ("avg".equals(f.getCalculatedColumnFunction())) { //$NON-NLS-1$
        String calcString = "calc += ((Number)value).doubleValue();"; //$NON-NLS-1$
        String text = "Object getValue() { " + "String[] names = " + nameArrayStrBuf.toString() + ";" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                + "int numSum = 0;" //$NON-NLS-1$
                + "double calc = 0; " + "try { " + "  for (int x=0;x < names.length; x++) { " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + "    Object value = dataRow.get(names[x]); " //$NON-NLS-1$
                + "    if (value != null && value instanceof Number) { " + "      numSum++;" + calcString //$NON-NLS-1$//$NON-NLS-2$
                + "    } " //$NON-NLS-1$
                + "  }" + "  return new Double(calc / numSum);" + "} catch (Exception e) { " //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                + "  e.prinStackTrace();" + "}" //$NON-NLS-1$ //$NON-NLS-2$
                + "}"; //$NON-NLS-1$
        property.addCDATA(text);
    } else if ("min".equals(f.getCalculatedColumnFunction())) { //$NON-NLS-1$
        String text = "Object getValue() { " + "String[] names = " + nameArrayStrBuf.toString() + ";" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + "double min = Double.MAX_VALUE;" + "try { " + "  for (int x=0;x < names.length; x++) { " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + "    Object value = dataRow.get(names[x]); " //$NON-NLS-1$
                + "    if (value != null && value instanceof Number) { " //$NON-NLS-1$
                + "      min = Math.min(min, ((Number)value).doubleValue());" + "    } " + "  }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + "  return new Double(min);" + "} catch (Exception e) { " + "  e.prinStackTrace();" + "}" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
                + "}"; //$NON-NLS-1$
        property.addCDATA(text);
    } else if ("max".equals(f.getCalculatedColumnFunction())) { //$NON-NLS-1$
        String text = "Object getValue() { " + "String[] names = " + nameArrayStrBuf.toString() + ";" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + "double max = Double.MIN_VALUE;" + "try { " + "  for (int x=0;x < names.length; x++) { " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + "    Object value = dataRow.get(names[x]); " //$NON-NLS-1$
                + "    if (value != null && value instanceof Number) { " //$NON-NLS-1$
                + "      max = Math.max(max, ((Number)value).doubleValue());" + "    } " + "  }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                + "  return new Double(max);" + "} catch (Exception e) { " + "  e.prinStackTrace();" + "}" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
                + "}"; //$NON-NLS-1$
        property.addCDATA(text);
    }
}

From source file:org.pentaho.pac.server.config.HibernateConfigXml.java

License:Open Source License

private void setValue(String xPath, String value, boolean useCData) {
    Element element = (Element) document.selectSingleNode(xPath);
    if (element == null) {
        element = DocumentHelper.makeElement(document, xPath);
    }/*  w  ww.  j  a v  a 2s  .  c o  m*/
    if (useCData) {
        element.clearContent();
        element.addCDATA(value);
    } else {
        element.setText(value);
    }
}

From source file:org.pentaho.platform.engine.services.SoapHelper.java

License:Open Source License

private static Element createSoapElement(String name, String value) {
    Element element = new DefaultElement(name);
    element.addCDATA(value);
    return element;
}

From source file:org.pentaho.platform.engine.services.SoapHelper.java

License:Open Source License

private static Element createSoapElement(String name, List value) {
    Element element = new DefaultElement(name);
    element.addCDATA(value.toString());
    return element;
}

From source file:org.pentaho.platform.engine.services.SoapHelper.java

License:Open Source License

private static Element createSoapFaultElement(List messages) {
    Element faultElement = new DefaultElement("SOAP-ENV:Fault");

    // TODO mlowery begin hack: copied in getFirstError code from MessageFormatter
    // to avoid needing an IPentahoSession
    String message = null;//from   w ww .  j a  va2 s . co  m
    String errorStart = PentahoMessenger.getUserString("ERROR"); //$NON-NLS-1$
    int pos = errorStart.indexOf('{');
    if (pos != -1) {
        errorStart = errorStart.substring(0, pos);
    }
    Iterator msgIterator = messages.iterator();
    while (msgIterator.hasNext()) {
        String msg = (String) msgIterator.next();
        if (msg.indexOf(errorStart) == 0) {
            message = msg;
        }
    }
    // TODO mlowery end hack

    if (message == null) {
        message = Messages.getInstance().getErrorString("SoapHelper.ERROR_0001_UNKNOWN_ERROR"); //$NON-NLS-1$
    }

    // Envelope envelope = new Envelope();
    // Fault fault = new Fault( );
    // TODO: Generate the following message using the envelope and fault objects

    // TODO determine if this is a reciever or a sender problem by examining
    // the error code
    boolean senderFault = (message.indexOf("SolutionEngine.ERROR_0002") != -1) || //$NON-NLS-1$ // solution not specifed
            (message.indexOf("SolutionEngine.ERROR_0003") != -1) || //$NON-NLS-1$ // Path not specifeid
            (message.indexOf("SolutionEngine.ERROR_0004") != -1) || //$NON-NLS-1$ // Action not specified
            (message.indexOf("SolutionEngine.ERROR_0005") != -1); //$NON-NLS-1$ // Action not found
    // send the error code
    // TODO parse out the error code
    faultElement.addElement("SOAP-ENV:Fault").addElement("SOAP-ENV:Subcode").addElement("SOAP-ENV:Value") //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            .addCDATA(message);
    if (senderFault) {
        faultElement.addElement("SOAP-ENV:faultactor").setText("SOAP-ENV:Client"); //$NON-NLS-1$ //$NON-NLS-2$ 
    } else {
        faultElement.addElement("SOAP-ENV:faultactor").setText("SOAP-ENV:Server"); //$NON-NLS-1$ //$NON-NLS-2$ 
    }

    Element faultTextElement = faultElement.addElement("SOAP-ENV:faultstring").addElement("SOAP-ENV:Text");
    faultTextElement.addAttribute("xml:lang", LocaleHelper.getDefaultLocale().toString());
    faultTextElement.addCDATA(message);

    Element detailElement = faultElement.addElement("SOAP-ENV:Detail");
    Iterator messageIterator = messages.iterator();
    while (messageIterator.hasNext()) {
        detailElement.addElement("message").addAttribute("name", "trace")
                .addCDATA((String) messageIterator.next());
    }
    return faultElement;
}

From source file:org.snipsnap.snip.storage.SnipDataSerializer.java

License:Open Source License

/**
 * Add an element whose content is put into a cdata section
 * @param elementName the element to be created
 * @param content the content as a string
 * @return the newly created element//from   w ww  .  j  a v a 2 s.c om
 */
private Element addCDATAContent(String elementName, String content) {
    Element element = DocumentHelper.createElement(elementName);
    if (null == content || "".equals(content)) {
        return element;
    }
    element.addCDATA(content);
    return element;
}

From source file:org.talend.designer.documentation.generation.HTMLDocGenerator.java

License:Open Source License

/**
 * Generates job(process) information in XML base on <code>ProcessItem</code> and project element.
 * /*from w w w. ja va  2s  .c om*/
 * @param item <code>ProcessItem</code>
 * @param projectElement <code>Element</code>
 * @param version
 * @return an instance of <code>Element</code>
 */
private Element generateJobInfo(Item item, Element projectElement, String... version) {

    picFilePathMap = new HashMap<String, String>();
    // IProcess process = CorePlugin.getDefault().getDesignerCoreService().getProcessFromProcessItem(processItem);

    Property property = item.getProperty();
    String jobName = property.getLabel();
    String jobVersion = property.getVersion();
    Element jobElement = projectElement.addElement("job"); //$NON-NLS-1$
    jobElement.addAttribute("name", HTMLDocUtils.checkString(jobName)); //$NON-NLS-1$

    jobElement.addAttribute("author", HTMLDocUtils.checkString(property.getAuthor().toString())); //$NON-NLS-1$

    if (version != null && version.length == 1) {
        jobVersion = version[0];
    }
    if (isRouteProcess(item)) {
        jobElement.addAttribute("type", "route");//$NON-NLS-1$//$NON-NLS-2$
        ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault()
                .getService(ICamelDesignerCoreService.class);
        camelService.appendRouteInfo2Doc(item, jobElement);
    }
    if (generateExtraSetting) {
        jobElement.addAttribute("i18n.job.extract.settings.type", "i18n.job.extract.settings");//$NON-NLS-1$//$NON-NLS-2$
    }
    if (generateStatsLogsSetting) {
        jobElement.addAttribute("i18n.job.stats.logs.type", "i18n.job.stats.logs");//$NON-NLS-1$//$NON-NLS-2$
    }
    jobElement.addAttribute("version", HTMLDocUtils.checkString(jobVersion)); //$NON-NLS-1$
    jobElement.addAttribute("purpose", HTMLDocUtils.checkString(property.getPurpose())); //$NON-NLS-1$
    jobElement.addAttribute("status", HTMLDocUtils.checkString(property.getStatusCode())); //$NON-NLS-1$

    //        jobElement.addAttribute("description", HTMLDocUtils.checkString(property.getDescription())); //$NON-NLS-1$

    jobElement.addAttribute("creation", HTMLDocUtils.checkDate(property.getCreationDate())); //$NON-NLS-1$
    jobElement.addAttribute("modification", HTMLDocUtils.checkDate(property.getModificationDate())); //$NON-NLS-1$

    Element descr = jobElement.addElement("description"); //$NON-NLS-1$
    // bug 22608
    String jobDescriptionStr = HTMLDocUtils.checkString(property.getDescription()).replaceAll("\\r\\n", //$NON-NLS-1$
            "<br/>"); //$NON-NLS-1$
    StringBuffer sb = new StringBuffer();
    if (jobDescriptionStr != null) {
        String[] jobDescriptions = jobDescriptionStr.split("<br/>"); //$NON-NLS-1$
        for (String str : jobDescriptions) {
            String ss = str;
            if (str != null && str.length() > 120) {
                while (ss.length() > 120) {
                    int k = ss.length() / 120;
                    for (int i = 0; i < k; i++) {
                        sb.append(ss.substring(0, 120) + "<br/>"); //$NON-NLS-1$
                        ss = ss.substring(120, ss.length());
                    }
                }
                sb.append(ss);
            } else {
                sb.append(str + "<br/>"); //$NON-NLS-1$
            }
        }
    }
    descr.addCDATA(sb.toString());

    String picName = jobName + "_" + jobVersion + IHTMLDocConstants.JOB_PREVIEW_PIC_SUFFIX; //$NON-NLS-1$
    IPath filePath = null;
    if (item instanceof ProcessItem) {
        filePath = DocumentationPathProvider.getPathFileName(item,
                RepositoryConstants.IMG_DIRECTORY_OF_JOB_OUTLINE, picName);
    } else if (item instanceof JobletProcessItem) {
        filePath = DocumentationPathProvider.getPathFileName(item,
                RepositoryConstants.IMG_DIRECTORY_OF_JOBLET_OUTLINE, picName);
    }
    Element previewElement = jobElement.addElement("preview"); //$NON-NLS-1$
    previewElement.addAttribute("picture", IHTMLDocConstants.PICTUREFOLDERPATH + picName); //$NON-NLS-1$

    // if (filePath == null) {
    //            previewElement.addAttribute("picture", ""); //$NON-NLS-1$ //$NON-NLS-2$
    // } else {
    // String filePathStr = filePath.toOSString();
    // File file = new File(filePathStr);
    // if (file.exists()) {
    //                previewElement.addAttribute("picture", IHTMLDocConstants.PICTUREFOLDERPATH + picName); //$NON-NLS-1$
    // picFilePathMap.put(picName, filePathStr);
    // }
    // }
    return jobElement;
}

From source file:org.talend.designer.documentation.generation.HTMLDocGenerator.java

License:Open Source License

/**
 * Generates project element information in XML file.
 * //from  ww  w .j a  va2s  .c om
 * @param document <code>Document</code>
 * @return an instance of <code>Element</code>
 */
protected Element generateProjectInfo(Document document) {
    Element projectElement = document.addElement("project"); //$NON-NLS-1$
    generateMessages(projectElement);
    projectElement.addAttribute("name", getProject().getLabel()); //$NON-NLS-1$
    projectElement.addAttribute("logo", //$NON-NLS-1$
            IHTMLDocConstants.PICTUREFOLDERPATH + IHTMLDocConstants.TALEND_LOGO_FILE_NAME);
    projectElement.addAttribute("title", IHTMLDocConstants.TITLE_GEN + getFullProductName()); //$NON-NLS-1$
    projectElement.addAttribute("link", IHTMLDocConstants.WEBSITE_LINK); //$NON-NLS-1$
    projectElement.addAttribute("language", getProject().getLanguage().getName()); //$NON-NLS-1$
    //        projectElement.addAttribute("description", getProject().getDescription()); //$NON-NLS-1$
    projectElement.addAttribute("generatedDate", DateFormat.getDateTimeInstance().format(new Date())); //$NON-NLS-1$
    projectElement.addAttribute("versionName", getProductVersionName()); //$NON-NLS-1$
    projectElement.addAttribute("version", VersionUtils.getVersion()); //$NON-NLS-1$
    projectElement.addAttribute("docType", getDocTypeAttribute()); //$NON-NLS-1$
    String company = CorePlugin.getDefault().getPreferenceStore()
            .getString(ITalendCorePrefConstants.DOC_COMPANY_NAME);
    if (company != null) {
        projectElement.addAttribute("company", company); //$NON-NLS-1$
    }

    Element proDesc = projectElement.addElement("pro-description"); //$NON-NLS-1$
    if (getProject().getDescription() != null) { // for bug 16854, project description can be null.
        proDesc.addCDATA(getProject().getDescription().replaceAll("\\r\\n", "<br/>")); //$NON-NLS-1$ //$NON-NLS-2$
    }
    return projectElement;
}