2 * Copyright (c) 2016 highstreet technologies GmbH and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
11 'app/core/core.services',
12 'common/config/env.module',
13 'app/mwtnCommons/bower_components/angular-ui-grid/ui-grid.min',
14 'app/mwtnCommons/bower_components/chart.js/dist/Chart',
15 'app/mwtnCommons/bower_components/angular-chart.js/dist/angular-chart',
16 'app/mwtnCommons/bower_components/angular-clipboard/angular-clipboard',
18 'app/mwtnCommons/bower_components/json-formatter/dist/json-formatter.min'],
20 var mwtnCommonsApp = angular.module('app.mwtnCommons', ['app.core','chart.js', 'ui.router.state', 'ui.grid', 'ui.bootstrap', 'jsonFormatter', 'config', 'pascalprecht.translate', 'angular-clipboard']);
22 mwtnCommonsApp.config(function($stateProvider, $compileProvider, $controllerProvider, $provide, NavHelperProvider, $httpProvider, $translateProvider, $translatePartialLoaderProvider) {
23 mwtnCommonsApp.register = {
24 controller : $controllerProvider.register,
25 directive : $compileProvider.directive,
26 factory : $provide.factory,
27 service : $provide.service
30 $translatePartialLoaderProvider.addPart('app/mwtnCommons/locale/locale');
32 var access = routingConfig.accessLevels;
36 mwtnCommonsApp.directive('htHeader', [ '$injector' ,function ($injector) {
38 template: '<div class="ht-header"><div class="ht-header-right"><alarm-status ng-if="mwtnFaultExists"></alarm-status><help ng-if="helpExists" link="{{helpLink}}" ></help></div></div>',
39 controller: ['$scope', function ($scope) {
40 $scope.helpExists = $injector.has('helpDirective');
41 $scope.mwtnFaultExists = $injector.has('alarmStatusDirective');
52 return mwtnCommonsApp;
57 Copyright 2011-2013 Abdulla Abdurakhmanov
58 Original sources are available at https://code.google.com/p/x2js/
60 Licensed under the Apache License, Version 2.0 (the "License");
61 you may not use this file except in compliance with the License.
62 You may obtain a copy of the License at
64 http://www.apache.org/licenses/LICENSE-2.0
66 Unless required by applicable law or agreed to in writing, software
67 distributed under the License is distributed on an "AS IS" BASIS,
68 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
69 See the License for the specific language governing permissions and
70 limitations under the License.
73 function X2JS(config) {
76 var VERSION = "1.1.5";
78 config = config || {};
80 initRequiredPolyfills();
82 function initConfigDefaults() {
83 if(config.escapeMode === undefined) {
84 config.escapeMode = true;
86 config.attributePrefix = config.attributePrefix || "_";
87 config.arrayAccessForm = config.arrayAccessForm || "none";
88 config.emptyNodeForm = config.emptyNodeForm || "text";
89 if(config.enableToStringFunc === undefined) {
90 config.enableToStringFunc = true;
92 config.arrayAccessFormPaths = config.arrayAccessFormPaths || [];
93 if(config.skipEmptyTextNodesForObj === undefined) {
94 config.skipEmptyTextNodesForObj = true;
96 if(config.stripWhitespaces === undefined) {
97 config.stripWhitespaces = true;
99 config.datetimeAccessFormPaths = config.datetimeAccessFormPaths || [];
105 CDATA_SECTION_NODE : 4,
110 function initRequiredPolyfills() {
111 function pad(number) {
112 var r = String(number);
113 if ( r.length === 1 ) {
119 if(typeof String.prototype.trim !== 'function') {
120 String.prototype.trim = function() {
121 return this.replace(/^\s+|^\n+|(\s|\n)+$/g, '');
124 if(typeof Date.prototype.toISOString !== 'function') {
125 // Implementation from http://stackoverflow.com/questions/2573521/how-do-i-output-an-iso-8601-formatted-string-in-javascript
126 Date.prototype.toISOString = function() {
127 return this.getUTCFullYear()
128 + '-' + pad( this.getUTCMonth() + 1 )
129 + '-' + pad( this.getUTCDate() )
130 + 'T' + pad( this.getUTCHours() )
131 + ':' + pad( this.getUTCMinutes() )
132 + ':' + pad( this.getUTCSeconds() )
133 + '.' + String( (this.getUTCMilliseconds()/1000).toFixed(3) ).slice( 2, 5 )
139 function getNodeLocalName( node ) {
140 var nodeLocalName = node.localName;
141 if(nodeLocalName == null) // Yeah, this is IE!!
142 nodeLocalName = node.baseName;
143 if(nodeLocalName == null || nodeLocalName=="") // =="" is IE too
144 nodeLocalName = node.nodeName;
145 return nodeLocalName;
148 function getNodePrefix(node) {
152 function escapeXmlChars(str) {
153 if(typeof(str) == "string")
154 return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g, '/');
159 function unescapeXmlChars(str) {
160 return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, "'").replace(///g, '\/');
163 function toArrayAccessForm(obj, childName, path) {
164 switch(config.arrayAccessForm) {
166 if(!(obj[childName] instanceof Array))
167 obj[childName+"_asArray"] = [obj[childName]];
169 obj[childName+"_asArray"] = obj[childName];
175 if(!(obj[childName] instanceof Array) && config.arrayAccessFormPaths.length > 0) {
177 for(; idx < config.arrayAccessFormPaths.length; idx++) {
178 var arrayPath = config.arrayAccessFormPaths[idx];
179 if( typeof arrayPath === "string" ) {
180 if(arrayPath == path)
184 if( arrayPath instanceof RegExp) {
185 if(arrayPath.test(path))
189 if( typeof arrayPath === "function") {
190 if(arrayPath(obj, childName, path))
194 if(idx!=config.arrayAccessFormPaths.length) {
195 obj[childName] = [obj[childName]];
200 function fromXmlDateTime(prop) {
201 // Implementation based up on http://stackoverflow.com/questions/8178598/xml-datetime-to-javascript-date-object
202 // Improved to support full spec and optional parts
203 var bits = prop.split(/[-T:+Z]/g);
205 var d = new Date(bits[0], bits[1]-1, bits[2]);
206 var secondBits = bits[5].split("\.");
207 d.setHours(bits[3], bits[4], secondBits[0]);
208 if(secondBits.length>1)
209 d.setMilliseconds(secondBits[1]);
211 // Get supplied time zone offset in minutes
212 if(bits[6] && bits[7]) {
213 var offsetMinutes = bits[6] * 60 + Number(bits[7]);
214 var sign = /\d\d-\d\d:\d\d$/.test(prop)? '-' : '+';
217 offsetMinutes = 0 + (sign == '-'? -1 * offsetMinutes : offsetMinutes);
219 // Apply offset and local timezone
220 d.setMinutes(d.getMinutes() - offsetMinutes - d.getTimezoneOffset())
223 if(prop.indexOf("Z", prop.length - 1) !== -1) {
224 d = new Date(Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds()));
227 // d is now a local time equivalent to the supplied time
231 function checkFromXmlDateTimePaths(value, childName, fullPath) {
232 if(config.datetimeAccessFormPaths.length > 0) {
233 var path = fullPath.split("\.#")[0];
235 for(; idx < config.datetimeAccessFormPaths.length; idx++) {
236 var dtPath = config.datetimeAccessFormPaths[idx];
237 if( typeof dtPath === "string" ) {
242 if( dtPath instanceof RegExp) {
243 if(dtPath.test(path))
247 if( typeof dtPath === "function") {
248 if(dtPath(obj, childName, path))
252 if(idx!=config.datetimeAccessFormPaths.length) {
253 return fromXmlDateTime(value);
262 function parseDOMChildren( node, path ) {
263 if(node.nodeType == DOMNodeTypes.DOCUMENT_NODE) {
264 var result = new Object;
265 var nodeChildren = node.childNodes;
266 // Alternative for firstElementChild which is not supported in some environments
267 for(var cidx=0; cidx <nodeChildren.length; cidx++) {
268 var child = nodeChildren.item(cidx);
269 if(child.nodeType == DOMNodeTypes.ELEMENT_NODE) {
270 var childName = getNodeLocalName(child);
271 result[childName] = parseDOMChildren(child, childName);
277 if(node.nodeType == DOMNodeTypes.ELEMENT_NODE) {
278 var result = new Object;
281 var nodeChildren = node.childNodes;
284 for(var cidx=0; cidx <nodeChildren.length; cidx++) {
285 var child = nodeChildren.item(cidx); // nodeChildren[cidx];
286 var childName = getNodeLocalName(child);
288 if(child.nodeType!= DOMNodeTypes.COMMENT_NODE) {
290 if(result[childName] == null) {
291 result[childName] = parseDOMChildren(child, path+"."+childName);
292 toArrayAccessForm(result, childName, path+"."+childName);
295 if(result[childName] != null) {
296 if( !(result[childName] instanceof Array)) {
297 result[childName] = [result[childName]];
298 toArrayAccessForm(result, childName, path+"."+childName);
301 (result[childName])[result[childName].length] = parseDOMChildren(child, path+"."+childName);
307 for(var aidx=0; aidx <node.attributes.length; aidx++) {
308 var attr = node.attributes.item(aidx); // [aidx];
310 result[config.attributePrefix+attr.name]=attr.value;
313 // Node namespace prefix
314 var nodePrefix = getNodePrefix(node);
315 if(nodePrefix!=null && nodePrefix!="") {
317 result.__prefix=nodePrefix;
320 if(result["#text"]!=null) {
321 result.__text = result["#text"];
322 if(result.__text instanceof Array) {
323 result.__text = result.__text.join("\n");
325 if(config.escapeMode)
326 result.__text = unescapeXmlChars(result.__text);
327 if(config.stripWhitespaces)
328 result.__text = result.__text.trim();
329 delete result["#text"];
330 if(config.arrayAccessForm=="property")
331 delete result["#text_asArray"];
332 result.__text = checkFromXmlDateTimePaths(result.__text, childName, path+"."+childName);
334 if(result["#cdata-section"]!=null) {
335 result.__cdata = result["#cdata-section"];
336 delete result["#cdata-section"];
337 if(config.arrayAccessForm=="property")
338 delete result["#cdata-section_asArray"];
341 if( result.__cnt == 1 && result.__text!=null ) {
342 result = result.__text;
345 if( result.__cnt == 0 && config.emptyNodeForm=="text" ) {
349 if ( result.__cnt > 1 && result.__text!=null && config.skipEmptyTextNodesForObj) {
350 if( (config.stripWhitespaces && result.__text=="") || (result.__text.trim()=="")) {
351 delete result.__text;
356 if( config.enableToStringFunc && (result.__text!=null || result.__cdata!=null )) {
357 result.toString = function() {
358 return (this.__text!=null? this.__text:'')+( this.__cdata!=null ? this.__cdata:'');
365 if(node.nodeType == DOMNodeTypes.TEXT_NODE || node.nodeType == DOMNodeTypes.CDATA_SECTION_NODE) {
366 return node.nodeValue;
370 function startTag(jsonObj, element, attrList, closed) {
371 var resultStr = "<"+ ( (jsonObj!=null && jsonObj.__prefix!=null)? (jsonObj.__prefix+":"):"") + element;
373 for(var aidx = 0; aidx < attrList.length; aidx++) {
374 var attrName = attrList[aidx];
375 var attrVal = jsonObj[attrName];
376 if(config.escapeMode)
377 attrVal=escapeXmlChars(attrVal);
378 resultStr+=" "+attrName.substr(config.attributePrefix.length)+"='"+attrVal+"'";
388 function endTag(jsonObj,elementName) {
389 return "</"+ (jsonObj.__prefix!=null? (jsonObj.__prefix+":"):"")+elementName+">";
392 function endsWith(str, suffix) {
393 return str.indexOf(suffix, str.length - suffix.length) !== -1;
396 function jsonXmlSpecialElem ( jsonObj, jsonObjField ) {
397 if((config.arrayAccessForm=="property" && endsWith(jsonObjField.toString(),("_asArray")))
398 || jsonObjField.toString().indexOf(config.attributePrefix)==0
399 || jsonObjField.toString().indexOf("__")==0
400 || (jsonObj[jsonObjField] instanceof Function) )
406 function jsonXmlElemCount ( jsonObj ) {
408 if(jsonObj instanceof Object ) {
409 for( var it in jsonObj ) {
410 if(jsonXmlSpecialElem ( jsonObj, it) )
418 function parseJSONAttributes ( jsonObj ) {
420 if(jsonObj instanceof Object ) {
421 for( var ait in jsonObj ) {
422 if(ait.toString().indexOf("__")== -1 && ait.toString().indexOf(config.attributePrefix)==0) {
430 function parseJSONTextAttrs ( jsonTxtObj ) {
433 if(jsonTxtObj.__cdata!=null) {
434 result+="<![CDATA["+jsonTxtObj.__cdata+"]]>";
437 if(jsonTxtObj.__text!=null) {
438 if(config.escapeMode)
439 result+=escapeXmlChars(jsonTxtObj.__text);
441 result+=jsonTxtObj.__text;
446 function parseJSONTextObject ( jsonTxtObj ) {
449 if( jsonTxtObj instanceof Object ) {
450 result+=parseJSONTextAttrs ( jsonTxtObj );
453 if(jsonTxtObj!=null) {
454 if(config.escapeMode)
455 result+=escapeXmlChars(jsonTxtObj);
463 function parseJSONArray ( jsonArrRoot, jsonArrObj, attrList ) {
465 if(jsonArrRoot.length == 0) {
466 result+=startTag(jsonArrRoot, jsonArrObj, attrList, true);
469 for(var arIdx = 0; arIdx < jsonArrRoot.length; arIdx++) {
470 result+=startTag(jsonArrRoot[arIdx], jsonArrObj, parseJSONAttributes(jsonArrRoot[arIdx]), false);
471 result+=parseJSONObject(jsonArrRoot[arIdx]);
472 result+=endTag(jsonArrRoot[arIdx],jsonArrObj);
478 function parseJSONObject ( jsonObj ) {
481 var elementsCnt = jsonXmlElemCount ( jsonObj );
483 if(elementsCnt > 0) {
484 for( var it in jsonObj ) {
486 if(jsonXmlSpecialElem ( jsonObj, it) )
489 var subObj = jsonObj[it];
491 var attrList = parseJSONAttributes( subObj )
493 if(subObj == null || subObj == undefined) {
494 result+=startTag(subObj, it, attrList, true);
497 if(subObj instanceof Object) {
499 if(subObj instanceof Array) {
500 result+=parseJSONArray( subObj, it, attrList );
502 else if(subObj instanceof Date) {
503 result+=startTag(subObj, it, attrList, false);
504 result+=subObj.toISOString();
505 result+=endTag(subObj,it);
508 var subObjElementsCnt = jsonXmlElemCount ( subObj );
509 if(subObjElementsCnt > 0 || subObj.__text!=null || subObj.__cdata!=null) {
510 result+=startTag(subObj, it, attrList, false);
511 result+=parseJSONObject(subObj);
512 result+=endTag(subObj,it);
515 result+=startTag(subObj, it, attrList, true);
520 result+=startTag(subObj, it, attrList, false);
521 result+=parseJSONTextObject(subObj);
522 result+=endTag(subObj,it);
526 result+=parseJSONTextObject(jsonObj);
531 this.parseXmlString = function(xmlDocStr) {
532 var isIEParser = window.ActiveXObject || "ActiveXObject" in window;
533 if (xmlDocStr === undefined) {
537 if (window.DOMParser) {
538 var parser=new window.DOMParser();
539 var parsererrorNS = null;
543 parsererrorNS = parser.parseFromString("INVALID", "text/xml").childNodes[0].namespaceURI;
546 parsererrorNS = null;
550 xmlDoc = parser.parseFromString( xmlDocStr, "text/xml" );
551 if( parsererrorNS!= null && xmlDoc.getElementsByTagNameNS(parsererrorNS, "parsererror").length > 0) {
552 //throw new Error('Error parsing XML: '+xmlDocStr);
562 if(xmlDocStr.indexOf("<?")==0) {
563 xmlDocStr = xmlDocStr.substr( xmlDocStr.indexOf("?>") + 2 );
565 xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
566 xmlDoc.async="false";
567 xmlDoc.loadXML(xmlDocStr);
572 this.asArray = function(prop) {
573 if(prop instanceof Array)
579 this.toXmlDateTime = function(dt) {
580 if(dt instanceof Date)
581 return dt.toISOString();
583 if(typeof(dt) === 'number' )
584 return new Date(dt).toISOString();
589 this.asDateTime = function(prop) {
590 if(typeof(prop) == "string") {
591 return fromXmlDateTime(prop);
597 this.xml2json = function (xmlDoc) {
598 return parseDOMChildren ( xmlDoc );
601 this.xml_str2json = function (xmlDocStr) {
602 var xmlDoc = this.parseXmlString(xmlDocStr);
604 return this.xml2json(xmlDoc);
609 this.json2xml_str = function (jsonObj) {
610 return parseJSONObject ( jsonObj );
613 this.json2xml = function (jsonObj) {
614 var xmlDocStr = this.json2xml_str (jsonObj);
615 return this.parseXmlString(xmlDocStr);
618 this.getVersion = function () {