From 84ae15105599f7ae4859b0863cc4643ad7ffa63e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B3=A0=EB=82=A8=ED=98=84?= Date: Thu, 5 Nov 2020 12:04:50 +0900 Subject: [PATCH] add support XML --- lib/base64.js | 17 ++++----------- lib/config.js | 16 ++++++++++++++ lib/xml.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ webloader.js | 4 ++++ 4 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 lib/config.js create mode 100644 lib/xml.js diff --git a/lib/base64.js b/lib/base64.js index 4349484..009d35a 100644 --- a/lib/base64.js +++ b/lib/base64.js @@ -2,21 +2,12 @@ // Base64 API //////////////////////////////////////////////////////////////////////// +var XML = require("lib/xml"); + exports.VERSIONINFO = "Base64 Module (base64.js) version 0.1"; exports.global = global; exports.require = require; -var createMSXMLObject = function() { - return CreateObject([ - "Msxml2.DOMDocument.6.0", - "Msxml2.DOMDocument.5.0", - "Msxml2.DOMDocument.4.0", - "Msxml2.DOMDocument.3.0", - "MSXML2.DOMDocument", - "MSXML.DOMDocument" - ]); -}; - var getStream_StringToBinary = function(dText) { var adTypeText = 2; var adTypeBinary = 1; @@ -45,7 +36,7 @@ var getStream_BinaryToString = function(dBinary) { }; exports.encode = function(sText) { - var oXML = createMSXMLObject(); + var oXML = XML.createXMLObject(); var oNode = oXML.createElement("base64"); oNode.dataType = "bin.base64"; oNode.nodeTypedValue = getStream_StringToBinary(sText); @@ -53,7 +44,7 @@ exports.encode = function(sText) { }; exports.decode = function(vCode) { - var oXML = createMSXMLObject(); + var oXML = XML.createXMLObject(); var oNode = oXML.createElement("base64"); oNode.dataType = "bin.base64"; oNode.text = vCode; diff --git a/lib/config.js b/lib/config.js new file mode 100644 index 0000000..f72cd32 --- /dev/null +++ b/lib/config.js @@ -0,0 +1,16 @@ +//////////////////////////////////////////////////////////////////////// +// Config API +//////////////////////////////////////////////////////////////////////// + +var XML = require("lib/xml"); +var configObject; + +var readConfig = function(path) { + if (typeof(configObject) === "undefined") { + configObject = XML.loadXMLFile("config.xml"); + } + + return configObject.select(path); +}; + +exports.readConfig = readConfig; diff --git a/lib/xml.js b/lib/xml.js new file mode 100644 index 0000000..dd42aac --- /dev/null +++ b/lib/xml.js @@ -0,0 +1,60 @@ +//////////////////////////////////////////////////////////////////////// +// XML API +//////////////////////////////////////////////////////////////////////// + +var FILE = require("lib/file"); + +var createXMLObject = function() { + return CreateObject([ + "Msxml2.DOMDocument.6.0", + "Msxml2.DOMDocument.5.0", + "Msxml2.DOMDocument.4.0", + "Msxml2.DOMDocument.3.0", + "MSXML2.DOMDocument", + "MSXML.DOMDocument" + ]); +}; + +var loadXMLFile = function(filename) { + var doc = createXMLObject(); + + if (FILE.fileExists(filename)) { + doc.loadXML(FILE.readFile(filename, "utf-8")); + } else { + console.log("The file does not exists"); + return; + } + + return { + select: function(path) { + var nodes = doc.selectNodes(path); + + return { + getObject: function() { + return doc; + }, + all: function() { + return nodes; + }, + first: function() { + if(nodes.length > 0) { + return nodes[0]; + } + }, + last: function() { + if(nodes.length > 0) { + return nodes[nodes.length - 1]; + } + }, + eq: function(i) { + if(nodes.length > i) { + return nodes[i]; + } + } + } + } + }; +}; + +exports.createXMLObject = createXMLObject; +exports.loadXMLFile = loadXMLFile; diff --git a/webloader.js b/webloader.js index c3dacfc..a64dbe4 100644 --- a/webloader.js +++ b/webloader.js @@ -1,6 +1,7 @@ //////////////////////////////////////////////////////////////////////// // Webloader //////////////////////////////////////////////////////////////////////// +var CONFIG = require("lib/config"); var FILE = require("lib/file"); var OldBrowser = require("lib/oldbrowser"); @@ -118,6 +119,9 @@ exports.main = function(args) { }); }); + // config test + console.info(CONFIG.readConfig("/Config/ApiUrl").first().text); + // hook drag event document.body.ondragstart = function() { return false;