Questetra-Addon-XML Extract Configs

Extracts the configs of the automatic step. The Addon-XML file (for Questetra BPMS automatic task) is parsed and information such as summary, last-modified, config etc. are extracted (XML escape is not decoded). And simple HTML code is generated.

2019-08-22 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/questetra-addon-xml-extract-configs/

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) 2019, 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 ) {
  throw new Error( "\n AutomatedTask UnexpectedFilesError:" + 
                   " Files {A} not found \n" );
}

if (myFiles.size() > 1) {
  throw new Error( "\n AutomatedTask UnexpectedFilesError:" + 
                   " Number of Files {A} must be single: " + myFiles.size() + " files \n" );
}
var myFileText = '';
var myLineCounter = 0;
fileRepository.readFile(myFiles.get(0), "UTF-8", function(line) {
    myFileText += line + '\n';
    myLineCounter++;
});
engine.log( " AutomatedTask FileLoaded: Number of lines " + myLineCounter );


//// == Calculating / 演算 ==
/// parse XML (ECMAScript for XML (E4X))
myFileText = myFileText
//  .replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, "")
  .replace(/<\?xml[^>]*\?>/, "") // E4X bug 336551
  .trim(); // Removes space, tab, no-break space, LF and CR from both ends of a string
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] = "";
  }
}

/// Generates HTML
var myHtml = '';

/// Addon Name
myHtml += '<!-- wp:shortcode -->\n';
myHtml += '[su_box title="' + myLabel;
if( myLabel !== myDefaultLabel ){
  myHtml += ' (' + myDefaultLabel +  ')';
}
myHtml += '" style="soft" box_color="#ff99ff" title_color="#000000" radius="0"]\n';
myHtml += '<!-- /wp:shortcode -->\n';
myHtml += '\n';

myHtml += '<!-- wp:paragraph -->\n';
myHtml += '<p>' + mySummary + '</p>\n';
myHtml += '<!-- /wp:paragraph -->\n';
myHtml += '\n';

myHtml += '<!-- wp:shortcode -->\n';
myHtml +=  '[/su_box';
myHtml +=  ']\n';
myHtml += '<!-- /wp:shortcode -->\n';
myHtml += '\n';

myHtml += '<!-- wp:paragraph {"align":"right"} -->\n';
myHtml += '<p style="text-align:right">' + myLastModified + ' ' + myLicense + '<br>\n';
myHtml += '<a href="' + myHelpPageUrl + '">' + myHelpPageUrl + '</a></p>\n' ;
myHtml += '<!-- /wp:paragraph -->\n';
myHtml += '\n';

/// Config
myHtml += '<!-- wp:shortcode -->\n';
myHtml += '[su_spoiler title="Configs" open="yes" style="modern-light"';
myHtml += ' icon="plus-square-1" anchor="configs"]\n';
myHtml += '<!-- /wp:shortcode -->\n';
myHtml += '\n';

myHtml += '<!-- wp:html -->\n';
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 if( xmlObj.configs.config[i].attribute("form-type").toString() == "QUSER" ){
    myHtml += '<i class="fal fa-user fa-lg"></i></span> ';
  }else if( xmlObj.configs.config[i].attribute("form-type").toString() == "OAUTH2" ){
    myHtml += '<i class="fal fa-badge-check 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>\n';
}
myHtml += '</ul>\n';
myHtml += '<!-- /wp:html -->\n';
myHtml += '\n';

myHtml += '<!-- wp:shortcode -->\n';
myHtml += '[/su_spoiler';
myHtml += ']\n';
myHtml += '<!-- /wp:shortcode -->\n';
myHtml += '\n';

/// Script
myHtml += '<!-- wp:shortcode -->\n';
myHtml += '[su_spoiler title="Script" style="modern-light"';
myHtml += ' icon="plus-square-1" anchor="script"]\n';
myHtml += '<!-- /wp:shortcode -->\n';
myHtml += '\n';

myHtml += '<!-- wp:code -->\n';
myHtml += '<pre class="wp-block-code"><code>';
myHtml += myScript.replace(/&/g, '&amp;')
            .replace(/\[/g, '&#91;')
            .replace(/\]/g, '&#93;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;');
myHtml += '</code></pre>\n';
myHtml += '<!-- /wp:code -->\n';
myHtml += '\n';

myHtml += '<!-- wp:shortcode -->\n';
myHtml += '[/su_spoiler';
myHtml += ']\n';
myHtml += '<!-- /wp:shortcode -->\n';
myHtml += '\n';

/// Icon
myHtml += '<!-- wp:image {"align":"right","ampNoLoading":true} -->\n';
myHtml += '<div data-amp-noloading="true" ';
myHtml += 'class="wp-block-image"><figure class="alignright">';
myHtml += '<img src="data:image;base64,';
myHtml += myIcon;
myHtml += '"></figure></div>\n';
myHtml += '<!-- /wp:image -->\n';
myHtml += '\n';

/// SU Divider
myHtml += '<!-- wp:shortcode -->\n';
myHtml += '[su_divider top="no" style="dashed"';
myHtml += ' divider_color="#009900" size="8" margin="30"]\n';
myHtml += '<!-- /wp:shortcode -->\n';
myHtml += '\n';

/// Download etc
myHtml += '<!-- wp:heading {"level":3} -->\n';
myHtml += '<h3><i class="fal fa-cloud-download-alt"></i> Download</h3>\n';
myHtml += '<!-- /wp:heading -->\n';
myHtml += '\n';

myHtml += '<!-- wp:list -->\n';
myHtml += '<ul><li>example1.xml</li></ul>\n';
myHtml += '<!-- /wp:list -->\n';
myHtml += '\n';

myHtml += '<!-- wp:heading {"level":3} -->\n';
myHtml += '<h3><i class="fal fa-images"></i> Capture</h3>\n';
myHtml += '<!-- /wp:heading -->\n';
myHtml += '\n';

myHtml += '<!-- wp:heading {"level":3} -->\n';
myHtml += '<h3><i class="fal fa-lightbulb-exclamation"></i> Notes</h3>\n';
myHtml += '<!-- /wp:heading -->\n';
myHtml += '\n';

myHtml += '<!-- wp:list {"ordered":true} -->\n';
myHtml += '<ol><li>(addon note 1)</li></ol>\n';
myHtml += '<!-- /wp:list -->\n';
myHtml += '\n';

myHtml += '<!-- wp:heading {"level":3} -->\n';
myHtml += '<h3><i class="fal fa-balance-scale"></i> See also</h3>\n';
myHtml += '<!-- /wp:heading -->\n';
myHtml += '\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

Capture

See also

1 thought on “Questetra-Addon-XML Extract Configs”

  1. Pingback: Questetra-Addon-XML Generate Digest-HTML – Questetra Support

Leave a Reply

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

%d bloggers like this: