Questetra-Addon-XML Generate Digest-HTML
Generates HTML code. The Addon-XML file for Questetra BPMS is parsed and information such as summary, last-modified, config etc. is extracted according to the locale (XML escape is not decoded). After that, simple HTML code for WordPress is generated.
https://support.questetra.com/addons/questetra-addon-xml-generate-digest-html/
2018-11-30 (C) Questetra, Inc. (MIT License)
Configs
  • A: Select FILES DATA for Addon-XML (Multiple not supported) *
  • B: Set LocaleCode for Extraction (e.g. “de”, “”) #{EL}
  • C0: Select STRING DATA for DefaultLang Label (update)
  • C: Select STRING DATA for Label (update)
  • D: Select STRING DATA for Summary (update)
  • E: Select STRING DATA for HelpPageUrl (update)
  • F: Select STRING DATA for LastModified (update)
  • G: Select STRING DATA for EngineType (update)
  • H: Select STRING DATA for Script (update)
  • I: Select STRING DATA for Digest HTML (update)
  • J: Select STRING DATA for License (update)
Script
// (c) 2018, Questetra, Inc. (the MIT License)
// Rhino engine (engine type: 0) to use E4X

//////// START "main()" ////////
main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
var dataIdA = configs.get( "conf_DataIdA" ) + "";
var localeCode = configs.get( "conf_LocaleCode" ) + "";
var dataIdC0 = configs.get( "conf_DataIdC0" ) + "";
var dataIdC = configs.get( "conf_DataIdC" ) + "";
var dataIdD = configs.get( "conf_DataIdD" ) + "";
var dataIdE = configs.get( "conf_DataIdE" ) + "";
var dataIdF = configs.get( "conf_DataIdF" ) + "";
var dataIdG = configs.get( "conf_DataIdG" ) + "";
var dataIdH = configs.get( "conf_DataIdH" ) + "";
var dataIdI = configs.get( "conf_DataIdI" ) + "";
var dataIdJ = configs.get( "conf_DataIdJ" ) + "";
// 'java.lang.String' (String Obj) to javascript primitive 'string'


//// == Data Retrieving / ワークフローデータの参照 ==
var myFiles = engine.findDataByNumber( dataIdA ); 
// java.util.ArrayList
if (myFiles === null || myFiles.size() != 1) {
  throw new Error( 'Attachment of multiple files can not be supported.' );
}
var myFileText = '';
var myLineCounter = 0;
fileRepository.readFile(myFiles.get(0), "UTF-8", function(line) {
    myFileText += line + '\n';
    myLineCounter++;
});
engine.log( "#Line of Text-File: " + myLineCounter );
// engine.log( myFileText ); // debug


//// == Calculating / 演算 ==
// parse XML (ECMAScript for XML (E4X))
myFileText = myFileText
  .replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, ""); 
// E4X bug 336551
var xmlObj = new XML( myFileText );
var i = 0;

var myDefaultLabel = "";
for (i = 0; i < xmlObj.label.length(); i++){
  if( xmlObj.label[i].attribute("locale").toString() == "" ){
    myDefaultLabel = xmlObj.label[i].toString();
    break;
  }
}

var myLabel = xmlObj.label.(@locale == localeCode).toString();
if( myLabel === ""){
  engine.log( "Label '" + localeCode + "' is not defined." );
  for (i = 0; i < xmlObj.label.length(); i++){
    if( xmlObj.label[i].attribute("locale").toString() == "" ){
      myLabel = xmlObj.label[i].toString();
      engine.log( "- default is applied: " + myLabel );
      break;
    }
  }
}
var mySummary = xmlObj.summary.(@locale == localeCode).toString();
if( mySummary === ""){
  engine.log( "Summary '" + localeCode + "' is not defined." );
  for (i = 0; i < xmlObj.summary.length(); i++){
    if( xmlObj.summary[i].attribute("locale").toString() == "" ){
      mySummary = xmlObj.summary[i].toString();
      engine.log( "- default is applied: " + mySummary );
      break;
    }
  }
}
var myHelpPageUrl = xmlObj["help-page-url"].(@locale == localeCode).toString();
if( myHelpPageUrl === ""){
  engine.log( "HelpPageUrl '" + localeCode + "' is not defined." );
  for (i = 0; i < xmlObj["help-page-url"].length(); i++){
    if( xmlObj["help-page-url"][i].attribute("locale").toString() == "" ){
      myHelpPageUrl = xmlObj["help-page-url"][i].toString();
      engine.log( "- default is applied: " + myHelpPageUrl );
      break;
    }
  }
}
var myLastModified = xmlObj["last-modified"].toString();
var myEngineType   = xmlObj["engine-type"].toString();
var myScript       = xmlObj.script.toString();
var myLicense      = xmlObj.license.toString();
var myIcon         = xmlObj.icon.toString();

var myConfigs = [];
var myConfigsRequired = [];
var myConfigsEl = [];
for(i = 0; i < xmlObj.configs.config.length(); i++ ){
  myConfigs[i] = xmlObj.configs.config[i].label.(@locale == localeCode).toString();
  if( myConfigs[i] === "" ){
    engine.log( "config[" + i + "].label '" + localeCode + "' is not defined." );
    for(var j = 0; j < xmlObj.configs.config[i].label.length(); j++){
      if( xmlObj.configs.config[i].label[j].attribute("locale").toString() == "" ){
        myConfigs[i] = xmlObj.configs.config[i].label[j].toString();
        engine.log( "- default is applied: " + myConfigs[i] );
        break;
      }
    }
  }

  if( xmlObj.configs.config[i].attribute("required").toString() == "true" ){
    myConfigsRequired[i] = "required";
  }else{
    myConfigsRequired[i] = "";
  }

  if( xmlObj.configs.config[i].attribute("el-enabled").toString() == "true" ){
    myConfigsEl[i] = "el";
  }else{
    myConfigsEl[i] = "";
  }
}

var myHtml = '';
myHtml += '[su_box title="' + myLabel;
if( myLabel !== myDefaultLabel ){
  myHtml += ' (' + myDefaultLabel +  ')';
}
myHtml += '" style="soft" box_color="#ff99ff" title_color="#000000" radius="0"]';
myHtml += mySummary + '<br><a href="' + myHelpPageUrl + '" target="_Blank">';
myHtml += myHelpPageUrl + '</a><br><span style="float: right;">';
myHtml += myLastModified + ' ' + myLicense + '</span>[/su_box]';
myHtml += '\n\n';

myHtml += '[su_spoiler title="Configs" open="yes" style="modern-light"';
myHtml += ' icon="plus-square-1" anchor="source"]';
myHtml += '<ul class="fa-ul">\n';
for(i = 0; i < xmlObj.configs.config.length(); i++ ){
  myHtml += '<li><span class="fa-li">';
  if( xmlObj.configs.config[i].attribute("form-type").toString() == "SELECT" ){
    myHtml += '<i class="fal fa-caret-square-down fa-lg"></i></span> ';
  }else{
    myHtml += '<i class="fal fa-pen-square fa-lg"></i></span> ';
  }
  myHtml += myConfigs[i];
  if( myConfigsRequired[i] === "required" ){
    myHtml += '<span style="color:#990000;"> *</span>';
  }
  if( myConfigsEl[i] === "el" ){
    myHtml += '<span style="color:#000099;"> <sup style="font-style:italic;">#{EL}</sup></span>';
  }
  myHtml += '</li>';
  myHtml += '\n';
}
myHtml += '</ul>[/su_spoiler]';
myHtml += '\n\n';

myHtml += '[su_spoiler title="Script" style="modern-light"';
myHtml += ' icon="plus-square-1" anchor="source"]';
myHtml += '<pre><code class="JavaScript">';

myHtml += myScript.replace(/&/g, '&amp;')
  .replace(/\[/g, '&#91;').replace(/\]/g, '&#93;')
  .replace(/</g, '&lt;').replace(/>/g, '&gt;');

myHtml += '</code></pre>[/su_spoiler';
myHtml += ']\n\n';

myHtml += '<div align="right"><img src="data:image;base64,';
myHtml += myIcon;
myHtml += '"></div>';
myHtml += '\n\n';

myHtml += '[su_divider top="no" style="dashed"';
myHtml += ' divider_color="#009900" size="8" margin="30"';
myHtml += ']\n\n';

myHtml += '<h3><i class="fal fa-cloud-download-alt"></i> Download</h3>\n';
myHtml += '<a href="●●●">●●●</a>';
myHtml += '\n\n';

myHtml += '<h3><i class="fal fa-images"></i> Capture</h3>\n';
myHtml += '[su_lightbox type="image" src="●●●"';
myHtml += ']●●●[/su_lightbox';
myHtml += ']\n\n';

myHtml += '<h3><i class="fal fa-lightbulb-exclamation"></i> Notes</h3>\n';
myHtml += '<ol>\n';
myHtml += ' 	<li>●●●</li>\n';
myHtml += ' 	<li>●●●</li>\n';
myHtml += ' 	<li>●●●</li>\n';
myHtml += '</ol>';
myHtml += '\n\n';

myHtml += '<h3><i class="fal fa-balance-scale"></i> See also</h3>\n';
myHtml += '●ワークフローサンプル記事●\n\n\n';
myHtml += '●関連するブログ記事:pinback対応のWordpress記事はURLのみ●\n\n\n';
myHtml += '●類似AddonXML:pinback対応のWordpress記事はURLのみ●\n\n\n';


//// == Data Updating / ワークフローデータへの代入 ==
if( dataIdC0 !== "" ){
  engine.setDataByNumber( dataIdC0, myDefaultLabel );
}
if( dataIdC !== "" ){
  engine.setDataByNumber( dataIdC, myLabel );
}
if( dataIdD !== "" ){
  engine.setDataByNumber( dataIdD, mySummary );
}
if( dataIdE !== "" ){
  engine.setDataByNumber( dataIdE, myHelpPageUrl );
}
if( dataIdF !== "" ){
  engine.setDataByNumber( dataIdF, myLastModified );
}
if( dataIdG !== "" ){
  engine.setDataByNumber( dataIdG, myEngineType );
}
if( dataIdH !== "" ){
  engine.setDataByNumber( dataIdH, myScript );
}
if( dataIdI !== "" ){
  engine.setDataByNumber( dataIdI, myHtml );
}
if( dataIdJ !== "" ){
  engine.setDataByNumber( dataIdJ, myLicense );
}

} //////// END "main()" ////////

// Methods of the XML object (E4X)
// - https://wso2.com/project/mashup/0.2/docs/e4xquickstart.html
// - Objects marked with a * are also available on XML List objects.
// appendChild(child), attribute(attributeName) *, attributes() *,
// child(propertyName) *, childIndex(), children() *,
// comments() *, contains(value) *, copy() *, descendants([name]) *,
// elements([name]) *, hasComplexContent() *, hasSimpleContent() *,
// inScopeNamespaces(), insertChildAfter(child1, child2),
// insertChildBefore(child1, child2), length() *, localName(), name(),
// namespace([prefix]), namespaceDeclarations(), nodeKind(),
// normalize() *, parent() *, processingInstructions([name]) *,
// prependChild(value), removeNamespace(namespace),
// replace(propertyName, value), setChildren(value), 
// setLocalName(name), setName(name), setNamespace(ns)
// text() *, toString() *, toXMLString() *, valueOf() *

Download

Questetra-Addon-XML-Generate-Digest-HTML.xml

Capture

See also

Converter (TextFile to String)

1 thought on “Questetra-Addon-XML Generate Digest-HTML”

  1. Pingback: Converter (TextFile to String) – Questetra Support

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.