Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xsd-schema-validator

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xsd-schema-validator - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

CHANGELOG.md

150

lib/validator.js

@@ -5,2 +5,4 @@ var fs = require('fs');

var which = require('which');
var spawn = require('child_process').spawn;

@@ -10,4 +12,2 @@

var JAVA_HOME = process.env.JAVA_HOME;
var BASE_DIR = path.resolve(__dirname + '/../');

@@ -17,24 +17,73 @@

// Assume jvm/jdk are on the PATH if JAVA_HOME is not set
var JAVA = JAVA_HOME ? JAVA_HOME + '/bin/java' : 'java';
var JAVAC = JAVA_HOME ? JAVA_HOME + '/bin/javac' : 'javac';
function withJava(executable, callback, debug) {
if (debug) {
console.log('Locating %s, JAVA_HOME=%s', executable, process.env.JAVA_HOME);
}
function withValidator(callback) {
var options = process.env.JAVA_HOME
? { path: process.env.JAVA_HOME + '/bin' }
: {};
return which(executable, options, callback);
}
function onceOnly(callback) {
var called = false;
return function() {
if (called) {
return;
}
called = true;
callback.apply(null, arguments);
};
}
function withValidator(callback, debug) {
callback = onceOnly(callback);
if (fs.existsSync(VALIDATOR + '.class')) {
callback();
} else {
if (JAVA_HOME && !fs.existsSync(JAVAC) && !fs.existsSync(JAVAC + '.exe')) {
callback(new Error('JDK required at JAVA_HOME or in path to compile helper'));
} else {
spawn(JAVAC, [ 'support/XMLValidator.java' ], { cwd: BASE_DIR })
.on('exit', function(exitCode) {
if (exitCode !== 0) {
callback(new Error('Failed to compile helper. Is javac on the PATH?'));
} else {
callback();
}
});
if (debug) {
console.log('Using existing helper');
}
return callback();
}
if (debug) {
console.log('Compiling helper');
}
return withJava('javac', function(err, javac) {
if (err) {
return callback(
new Error('Java SDK required at JAVA_HOME or in path to compile validation helper')
);
}
if (debug) {
console.log('Found javac: %s', javac);
}
spawn(javac, [ 'support/XMLValidator.java' ], { cwd: BASE_DIR })
.on('error', callback)
.on('exit', function(exitCode) {
if (exitCode !== 0) {
return callback(
new Error('Failed to compile helper (exitCode=' + exitCode + ')')
);
}
if (debug) {
console.log('Helper compiled');
}
return callback();
});
}, debug);
}

@@ -54,3 +103,3 @@

this.cwd = options.cwd || process.cwd();
this.cwd = options.cwd;
this.debug = !!options.debug;

@@ -68,2 +117,4 @@ }

callback = onceOnly(callback);
var cwd = this.cwd,

@@ -110,9 +161,5 @@ debug = this.debug;

withValidator(function(err) {
function runValidation(java, callback) {
if (err) {
return callback(err);
}
var validator = spawn(JAVA, [
var validator = spawn(java, [
'-Dfile.encoding=UTF-8',

@@ -122,3 +169,3 @@ '-classpath',

'support.XMLValidator',
input.file ? '-file=' + xml.file : '-stdin',
input.file ? '-file=' + input.file : '-stdin',
'-schema=' + schema

@@ -168,2 +215,6 @@ ], { cwd: cwd });

validator.on('error', function(err) {
callback(err);
});
validator.on('exit', function(exitCode) {

@@ -199,9 +250,40 @@ code = exitCode;

stdin.end();
});
}
withValidator(function(err) {
if (err) {
return callback(err);
}
withJava('java', function(err, java) {
if (err) {
return callback(
new Error('Java JRE required at JAVA_HOME or in path to perform validation')
);
}
if (debug) {
console.log('Found java: %s', java);
}
return runValidation(java, callback);
}, debug);
}, debug);
};
module.exports = Validator;
module.exports.Validator = Validator;
/**
* Ensures that the validator is setup to perform actual validation.
*
* @param {Function} callback
*/
module.exports.setup = function(callback) {
var debug = /xsd-schema-validator/.test(process.env.LOG_DEBUG || '');
withValidator(callback, debug);
};
/**
* Validate xml based on the given schema.

@@ -211,7 +293,13 @@ *

* @param {String} schema
*
* @param {Function} callback
*/
module.exports.validateXML = function(xml, schema, callback) {
return new Validator().validateXML(xml, schema, callback);
var cwd = process.cwd();
var debug = /xsd-schema-validator/.test(process.env.LOG_DEBUG || '');
return new Validator({
cwd: cwd,
debug: debug
}).validateXML(xml, schema, callback);
};
{
"name": "xsd-schema-validator",
"version": "0.6.0",
"version": "0.7.0",
"description": "A (XSD) schema validator for nodejs",

@@ -9,3 +9,4 @@ "main": "lib/validator.js",

"lint": "eslint .",
"test": "mocha"
"test": "mocha",
"postinstall": "node ./lib/post-install.js"
},

@@ -23,11 +24,14 @@ "repository": {

],
"author": "Nikku",
"author": "Nico Rehwaldt <https://github.com/nikku>",
"license": "MIT",
"devDependencies": {
"chai": "^4.1.2",
"eslint": "^4.16.0",
"eslint-plugin-mocha": "^4.11.0",
"eslint": "^7.24.0",
"eslint-plugin-bpmn-io": "^0.12.0",
"mocha": "^5.0.0",
"npm-run-all": "^4.1.2"
},
"dependencies": {
"which": "^2.0.2"
}
}
# xsd-schema-validator
[![Build Status](https://travis-ci.org/nikku/node-xsd-schema-validator.svg?branch=master)](https://travis-ci.org/nikku/node-xsd-schema-validator)
[![CI](https://github.com/nikku/node-xsd-schema-validator/workflows/CI/badge.svg)](https://github.com/nikku/node-xsd-schema-validator/actions?query=workflow%3ACI)
A (XSD) schema validator for [NodeJS](nodejs.org) that uses [Java](https://www.java.com) to perform the actual validation.
A (XSD) schema validator for [NodeJS](nodejs.org) that uses [Java](https://www.java.com) to perform the actual validation. [:arrow_right: Why?](#why)

@@ -10,11 +10,12 @@

This utility assumes that `javac` and `java` are on the path _or_ that
the `JAVA_HOME` environment exists and points to an installed JDK.
Under the hood, this utility uses Java to do the actual validation.
It assumes that `javac` and `java` are on the path. If a `JAVA_HOME` environment variable exists it uses that to locate an installed JDK.
On some platforms, i.e. [Mac OSX](http://www.mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/) you need to define `JAVA_HOME` manually.
## How to Use
## Installation
Install via [npm](http://npmjs.org):
Install the package via [npm](http://npmjs.org):

@@ -25,2 +26,5 @@ ```

## Usage
Use in your application:

@@ -42,3 +46,3 @@

You may validate readable streams, too:
You may validate readable streams:

@@ -51,3 +55,3 @@ ```javascript

...and files, too:
You may validate files, too:

@@ -58,3 +62,2 @@ ```javascript

## Why

@@ -61,0 +64,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc