<commit_before>/*
  Copyright 2010-2017 BusinessCode GmbH, Germany

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/
/**
 * <p>
 * Export package is the API to the WYSIWYG and detail exports of BCD-UI
 * WYSIWYG can be pdf, excel or image
 * </p>
 * @namespace bcdui.component.exports
 */
bcdui.util.namespace("bcdui.component.exports",
/** @lends bcdui.component.exports */
{
  /**
   * @private
   */
  _html2PdfServletUrl: bcdui.contextPath + "/bcdui/servlets/Html2PdfServlet",
  /**
   * @private
   */
  _html2ExcelServletUrl: bcdui.contextPath + "/bcdui/servlets/Html2ExcelServlet",

  /**
   * Produces a WYSIWYG pdf export of a windows.document subtree, needs pdf extension, part of EnterpriseEdition
   * @param {Object} args The parameter map contains the following properties:
   * @param {(string|HTMLElement)}  args.rootElement                  - The id of or the root element itself
   * @param {string}                [args.fileName=report.pdf]         - The name of the returned pdf
   * @param {string[]|string}       [args.css]                        - An array or space separated list of URLs containing CSS files to be used, relative the the current page.
   * This allows using different styling on export than on the page. You can also use an bcdPdfStyle for inline style only to be applied on export.
   * Absolute paths starting with '/' are relative to the context path. Use more specific rule precedence. (css precedence based on later declaration is not supported).
   * Local css are being cached.
   * @param {boolean}               [args.orientationLandscape=false] - Set this flag to true to make the PDF appear in landscape page orientation
   * @param {string}                [args.dimension=A4]               - Physical dimension of the output like 'A5' or 'LETTER', default is A4.
   *
   * @example
   *   bcdui.component.exports.exportWysiwygAsPdf( { rootElement: "myReportDiv", css: ["/bcdui/theme/css/allStyles.css", "my.css"] } );
   */
  exportWysiwygAsPdf: function( args )
  {
    args.mode = "PdfOrImage";
    args.servletBaseUrl = args.servletBaseUrl || bcdui.component.exports._html2PdfServletUrl;
    args.fileName = args.fileName || "report.pdf";
    new bcdui.component.exports.PDFExport( args ).execute();
  },
  
  /**
   * generates a timestamp string
   * @private
  */
  _getExportTimeStamp: function() {
    return bcdui.util.datetime.formatDateTime(new Date).replace(/-/g, "").replace(/:/g, "").substring(0, 13);
  },
  
  /**
   * generates a fileName based on navpath title information
   * @private
  */
  _getFileNameFromNavPath: function() {
    var root = bcdui.wkModels.bcdNavPath.query("/*");
    var fileName = null;
    if (root && root.getAttribute("targetId") != null) {
      fileName = root.getAttribute("title");
    }
    return fileName ? fileName.replace(/(?:^|\s)\w/g, function(match) {return match.toUpperCase();}).replace(/\s/g, "") : null;
  },

  /**
   * Produces a WYSIWYG pdf export of a windows.document subtree
   * @param {Object} args The parameter map contains the following properties:
   * @param {(string|HTMLElement)}  args.rootElement                  - The id of or the root element itself
   * @param {string}                [args.fileName=export(_timestamp).xsl] - The name of the returned Excel document
   * @param {string[]|string}       [args.css]                        - An array or space separated list of URLs containing CSS files to be used, relative the the current page.
   * This allows using different styling on export than on the page. You can also use an bcdPdfStyle for inline style only to be applied on export.
   * Absolute paths starting with '/' are relative to the context path. Use more specific rule precedence. (css precedence based on later declaration is not supported).
   * Local css are being cached.
   */
  exportWysiwygAsExcel: function( args )
  {
    args.mode = "Excel";
    args.servletBaseUrl = args.servletBaseUrl || bcdui.component.exports._html2ExcelServletUrl;

    if (! args.fileName) {

      // use navPath title if available and no fileName is given
      // also - when using navPath - prepend navPath html for export  
      var root = bcdui.wkModels.bcdNavPath.query("/*");
      if (root && root.getAttribute("targetId") != null) {
        var navPathTarget = root.getAttribute("targetId");
        var oldRoot = args.rootElement;
        args.rootElement = [];
        if (navPathTarget) {
          args.rootElement.push(navPathTarget);
          args.rootElement.push(jQuery("<table><tr></tr></table>").get(0));
        }
        if (typeof oldRoot == "string")      // html id
          args.rootElement.push(oldRoot);
        else if (jQuery(oldRoot).length > 0) // html element
          args.rootElement.push(oldRoot);
        else if (oldRoot.length > 0)         // array
          args.rootElement.concat(oldRoot);

        var fileName = bcdui.component.exports._getFileNameFromNavPath();
        if (fileName)<commit_msg>wysiwygExport, navPath header line should use only pure text<commit_after>/*
  Copyright 2010-2017 BusinessCode GmbH, Germany

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/
/**
 * <p>
 * Export package is the API to the WYSIWYG and detail exports of BCD-UI
 * WYSIWYG can be pdf, excel or image
 * </p>
 * @namespace bcdui.component.exports
 */
bcdui.util.namespace("bcdui.component.exports",
/** @lends bcdui.component.exports */
{
  /**
   * @private
   */
  _html2PdfServletUrl: bcdui.contextPath + "/bcdui/servlets/Html2PdfServlet",
  /**
   * @private
   */
  _html2ExcelServletUrl: bcdui.contextPath + "/bcdui/servlets/Html2ExcelServlet",

  /**
   * Produces a WYSIWYG pdf export of a windows.document subtree, needs pdf extension, part of EnterpriseEdition
   * @param {Object} args The parameter map contains the following properties:
   * @param {(string|HTMLElement)}  args.rootElement                  - The id of or the root element itself
   * @param {string}                [args.fileName=report.pdf]         - The name of the returned pdf
   * @param {string[]|string}       [args.css]                        - An array or space separated list of URLs containing CSS files to be used, relative the the current page.
   * This allows using different styling on export than on the page. You can also use an bcdPdfStyle for inline style only to be applied on export.
   * Absolute paths starting with '/' are relative to the context path. Use more specific rule precedence. (css precedence based on later declaration is not supported).
   * Local css are being cached.
   * @param {boolean}               [args.orientationLandscape=false] - Set this flag to true to make the PDF appear in landscape page orientation
   * @param {string}                [args.dimension=A4]               - Physical dimension of the output like 'A5' or 'LETTER', default is A4.
   *
   * @example
   *   bcdui.component.exports.exportWysiwygAsPdf( { rootElement: "myReportDiv", css: ["/bcdui/theme/css/allStyles.css", "my.css"] } );
   */
  exportWysiwygAsPdf: function( args )
  {
    args.mode = "PdfOrImage";
    args.servletBaseUrl = args.servletBaseUrl || bcdui.component.exports._html2PdfServletUrl;
    args.fileName = args.fileName || "report.pdf";
    new bcdui.component.exports.PDFExport( args ).execute();
  },
  
  /**
   * generates a timestamp string
   * @private
  */
  _getExportTimeStamp: function() {
    return bcdui.util.datetime.formatDateTime(new Date).replace(/-/g, "").replace(/:/g, "").substring(0, 13);
  },
  
  /**
   * generates a fileName based on navpath title information
   * @private
  */
  _getFileNameFromNavPath: function() {
    var root = bcdui.wkModels.bcdNavPath.query("/*");
    var fileName = null;
    if (root && root.getAttribute("targetId") != null) {
      fileName = root.getAttribute("title");
    }
    return fileName ? fileName.replace(/(?:^|\s)\w/g, function(match) {return match.toUpperCase();}).replace(/\s/g, "") : null;
  },

  /**
   * Produces a WYSIWYG pdf export of a windows.document subtree
   * @param {Object} args The parameter map contains the following properties:
   * @param {(string|HTMLElement)}  args.rootElement                  - The id of or the root element itself
   * @param {string}                [args.fileName=export(_timestamp).xsl] - The name of the returned Excel document
   * @param {string[]|string}       [args.css]                        - An array or space separated list of URLs containing CSS files to be used, relative the the current page.
   * This allows using different styling on export than on the page. You can also use an bcdPdfStyle for inline style only to be applied on export.
   * Absolute paths starting with '/' are relative to the context path. Use more specific rule precedence. (css precedence based on later declaration is not supported).
   * Local css are being cached.
   */
  exportWysiwygAsExcel: function( args )
  {
    args.mode = "Excel";
    args.servletBaseUrl = args.servletBaseUrl || bcdui.component.exports._html2ExcelServletUrl;

    if (! args.fileName) {

      // use navPath title if available and no fileName is given
      // also - when using navPath - prepend navPath html for export  
      var root = bcdui.wkModels.bcdNavPath.query("/*");
      if (root && root.getAttribute("targetId") != null) {
        var navPathTarget = root.getAttribute("targetId");
        var oldRoot = args.rootElement;
        args.rootElement = [];
        if (navPathTarget)
          args.rootElement.push(jQuery("<table><tr><td>" + jQuery("#" + navPathTarget).text() + "</td></tr><tr></tr></table>").get(0));
        if (typeof oldRoot == "string")      // html id
          args.rootElement.push(oldRoot);
        else if (jQuery(oldRoot).length > 0) // html element
          args.rootElement.push(oldRoot);
        else if (oldRoot.length > 0)         // array
          args.rootElement.concat(oldRoot);

        var fileName = bcdui.component.exports._getFileNameFromNavPath();
        if (fileName)
{'fraction_non_alphanumeric': 0.10728910728910729, 'fraction_numerical': 0.004914004914004914, 'mean_word_length': 2.943308216720488, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5519756', 'n_tokens_mistral': 3185, 'n_tokens_neox': 3121, 'n_words': 1063}