add support XML

This commit is contained in:
Namhyeon Go 2020-11-05 12:04:50 +09:00
parent ff279ba2de
commit 84ae151055
4 changed files with 84 additions and 13 deletions

View File

@ -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;

16
lib/config.js Normal file
View File

@ -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;

60
lib/xml.js Normal file
View File

@ -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;

View File

@ -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;