Skip to content

Commit

Permalink
Merge pull request #1289 from BladeRunnerJS/v0.15.2-release
Browse files Browse the repository at this point in the history
V0.15.2 release
  • Loading branch information
thanhc committed Mar 19, 2015
2 parents fbd2ee0 + f7ccb2a commit b31cf7f
Show file tree
Hide file tree
Showing 48 changed files with 1,104 additions and 196 deletions.
1 change: 1 addition & 0 deletions brjs-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies {
compile dependency('utils')
compile dependency('jericho-html')
compile dependency('xalan')
compile dependency('jmimemagic')

/* woodstox deps */
compile dependency('woodstox-core-asl')
Expand Down
25 changes: 23 additions & 2 deletions brjs-core/src/main/java/org/bladerunnerjs/model/NodeImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
Expand All @@ -14,11 +16,13 @@
import org.apache.commons.io.filefilter.NameFileFilter;
import org.apache.commons.io.filefilter.NotFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;

import org.bladerunnerjs.memoization.MemoizedFile;
import org.bladerunnerjs.model.exception.ConfigException;
import org.bladerunnerjs.model.exception.InvalidSdkDirectoryException;
import org.bladerunnerjs.plugin.AssetLocationPlugin;
import org.bladerunnerjs.plugin.AssetPlugin;

import org.bladerunnerjs.plugin.proxy.VirtualProxyAssetLocationPlugin;
import org.bladerunnerjs.plugin.proxy.VirtualProxyAssetPlugin;
import org.bladerunnerjs.plugin.utility.PluginLoader;
Expand All @@ -32,6 +36,7 @@

import com.google.common.collect.ImmutableMap;

import net.sf.jmimemagic.*;

@SuppressWarnings("unused")
public class NodeImporter {
Expand All @@ -44,7 +49,7 @@ public static void importAppFromZip(ZipFile sourceAppZip, App targetApp, String
ZipUtility.unzip(sourceAppZip, temporaryUnzipDir );
File[] temporaryUnzipDirFiles = temporaryUnzipDir.listFiles();
if (temporaryUnzipDirFiles.length != 1) {
throw new IOException("Exepected to find 1 folder inside the provided zip, there was " + temporaryUnzipDirFiles.length);
throw new IOException("Expected to find 1 folder inside the provided zip, there was " + temporaryUnzipDirFiles.length);
}

App tmpBrjsSourceApp = tempBrjs.app( targetApp.getName() );
Expand Down Expand Up @@ -190,8 +195,24 @@ private static void findAndReplaceInAllTextFiles(BRJS brjs, File rootRenameDirec
private static void findAndReplaceInTextFiles(BRJS brjs, Collection<File> files, String sourceRequirePrefix, String targetRequirePrefix) throws IOException
{
for (File f : files) {
findAndReplaceInTextFile(brjs, f, sourceRequirePrefix, targetRequirePrefix);
if (f.length() != 0) {
if (checkFileMimeType(f).startsWith("text")) {
findAndReplaceInTextFile(brjs, f, sourceRequirePrefix, targetRequirePrefix);
}
}
}
}

private static String checkFileMimeType(File file) throws IOException {
byte[] data = Files.readAllBytes(Paths.get(file.getAbsolutePath()));
MagicMatch match = null;
try {
match = Magic.getMagicMatch(data);
} catch (MagicParseException | MagicMatchNotFoundException
| MagicException e) {
throw new IOException(e);
}
return match.getMimeType();
}

private static void findAndReplaceInTextFile(BRJS brjs, File file, String oldRequirePrefix, String newRequirePrefix) throws IOException
Expand Down
1 change: 0 additions & 1 deletion brjs-sdk/sdk/libs/javascript/br-formatting/.js-style

This file was deleted.

87 changes: 26 additions & 61 deletions brjs-sdk/sdk/libs/javascript/br-formatting/src/DateFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
* @module br/formatting/DateFormatter
*/

br.Core.thirdparty("momentjs");
var moment = require('momentjs');
var topiarist = require('topiarist');
var Formatter = require('br/formatting/Formatter');
var DateParsingUtil = require('br/parsing/DateParsingUtil');

/**
* @deprecated The functionality provided by this formatter can be achieved more reliably with {@link module:br/formatting/LocalisedDateFormatter}
* @class
* @alias module:br/formatting/DateFormatter
* @implements module:br/formatting/Formatter
Expand All @@ -15,18 +19,15 @@ br.Core.thirdparty("momentjs");
* <code>DateFormatter</code> is typically used with Presenter, but can be invoked programmatically
* as in the following examples which evaluate to "09-Sep-2001 01:46:40" and "2001Sep09" respectively:
* <p/>
* <code>br.formatting.DateFormatter.format(1e12, {inputFormat:"U"})</code><br/>
* <code>br.formatting.DateFormatter.format(1e12, {inputFormat:"U", outputFormat:"YMd"})</code>
* <code>new br.formatting.DateFormatter().format(1e12, {inputFormat:"U"})</code><br/>
* <code>new br.formatting.DateFormatter().format(1e12, {inputFormat:"U", outputFormat:"YMd"})</code>
* <p/>
*
* See {@link module:br/presenter/parser/DateParser} for the complementary parser.
*/
br.formatting.DateFormatter = function()
{
this.m_sFormatDefault = "DD-MM-YYYY HH:mm:ss";
};
function DateFormatter() {}

br.Core.implement(br.formatting.DateFormatter, br.formatting.Formatter);
topiarist.implement(DateFormatter, Formatter);

/**
* Formats a date by converting it from a specified input format to a new output format.
Expand All @@ -39,66 +40,37 @@ br.Core.implement(br.formatting.DateFormatter, br.formatting.Formatter);
* @return the output date.
* @type String
*/
br.formatting.DateFormatter.prototype.format = function(vValue, mAttributes) {
DateFormatter.prototype.format = function(vValue, mAttributes) {
if (vValue) {
var sInputFormat = mAttributes["inputFormat"];
var bAdjustForTimezone = mAttributes["adjustForTimezone"];
var oDate = this.parseDate(vValue, sInputFormat);
var oDate = DateParsingUtil.parse(vValue, mAttributes.inputFormat);
if (oDate) {
var sOutputFormat = mAttributes["outputFormat"];
vValue = this.formatDate(oDate, sOutputFormat, mAttributes.adjustForTimezone);
vValue = this.formatDate(oDate, mAttributes.outputFormat, mAttributes);
}
}
return vValue;
};

/**
* @private
* @deprecated
*/
br.formatting.DateFormatter.prototype.parseDate = function(vDate, sDateFormat, bEndOfUnit)
{
if (!vDate)
{
return null;
}
if (vDate instanceof Date)
{
sDateFormat = "javascript";
}
else if (!sDateFormat)
{
sDateFormat = this.getDateFormat(sDateFormat);
}

switch (sDateFormat) {
case "java":
var oDate = new Date();
oDate.setTime(Number(vDate));
return oDate;
case "javascript":
return vDate;
case "U":
return moment(vDate*1000).toDate();
default:
var oMoment = moment(String(vDate), sDateFormat);
if (bEndOfUnit === true && sDateFormat.toLowerCase().indexOf('d') === -1) {
oMoment.endOf(sDateFormat === 'YYYY' ? 'year' : 'month');
}
var sValidationString = oMoment.format(sDateFormat);
return (sValidationString.toLowerCase() == String(vDate).toLowerCase()) ? oMoment.toDate() : null;
}
DateFormatter.prototype.parseDate = function(vDate, sDateFormat) {
return DateParsingUtil.parse(vDate, sDateFormat);
};

/**
* @private
*/
br.formatting.DateFormatter.prototype.formatDate = function(oDate, sDateFormat, bAdjustForTimezone) {
if(bAdjustForTimezone)
DateFormatter.prototype.formatDate = function(oDate, sDateFormat, mAttributes) {
var oTranslator = require("br/I18n").getTranslator();
if(mAttributes && mAttributes.adjustForTimezone)
{

oDate = this._adjustDateForTimezone(oDate);
}
sDateFormat = this.getDateFormat(sDateFormat);
if (!sDateFormat)
{
sDateFormat = "DD-MM-YYYY HH:mm:ss";
}
switch (sDateFormat) {
case "java":
return String(oDate.getTime());
Expand All @@ -107,18 +79,16 @@ br.formatting.DateFormatter.prototype.formatDate = function(oDate, sDateFormat,
case "ISO":
return oDate.toISOString();
case "localize":
var oTranslator = require("br/I18n").getTranslator();
return oTranslator.formatDate(oDate);
default:
var oTranslator = require("br/I18n").getTranslator();
return oTranslator.formatDate(oDate, sDateFormat);
}
};

/**
* @private
*/
br.formatting.DateFormatter.prototype._adjustDateForTimezone = function(oDate) {
DateFormatter.prototype._adjustDateForTimezone = function(oDate) {
var oDateClone = new Date(oDate.getTime()),
d = new Date(),
timezoneOffsetInMinutes = -(d.getTimezoneOffset());
Expand All @@ -131,13 +101,8 @@ br.formatting.DateFormatter.prototype._adjustDateForTimezone = function(oDate) {
/**
* @private
*/
br.formatting.DateFormatter.prototype.getDateFormat = function(sDateFormat) {
return sDateFormat || this.m_sFormatDefault;
};

/**
* @private
*/
br.formatting.DateFormatter.prototype.toString = function() {
DateFormatter.prototype.toString = function() {
return "br.formatting.DateFormatter";
};

module.exports = DateFormatter;
17 changes: 11 additions & 6 deletions brjs-sdk/sdk/libs/javascript/br-formatting/src/DecimalFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
* @module br/formatting/DecimalFormatter
*/

var topiarist = require('topiarist');
var Formatter = require('br/formatting/Formatter');
var NumberUtil = require('br/util/Number');

/**
* @class
* @alias module:br/formatting/DecimalFormatter
Expand All @@ -19,10 +23,9 @@
* <p/>
* <code>br.formatting.DecimalFormatter.format(3.14159, {dp:3})</code>
*/
br.formatting.DecimalFormatter = function() {
};
function DecimalFormatter() {}

br.Core.implement(br.formatting.DecimalFormatter, br.formatting.Formatter);
topiarist.implement(DecimalFormatter, Formatter);

/**
* Formats the value to the specified number of decimal places.
Expand All @@ -46,13 +49,15 @@ br.Core.implement(br.formatting.DecimalFormatter, br.formatting.Formatter);
* @return the number, formatted to the specified precision.
* @type String
*/
br.formatting.DecimalFormatter.prototype.format = function(vValue, mAttributes) {
return br.util.Number.isNumber(vValue) ? br.util.Number.toFixed(vValue, mAttributes["dp"]) : vValue;
DecimalFormatter.prototype.format = function(vValue, mAttributes) {
return NumberUtil.isNumber(vValue) ? NumberUtil.toFixed(vValue, mAttributes["dp"]) : vValue;
};

/**
* @private
*/
br.formatting.DecimalFormatter.prototype.toString = function() {
DecimalFormatter.prototype.toString = function() {
return "br.formatting.DecimalFormatter";
};

module.exports = DecimalFormatter;
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Formatter.prototype.format = function(vValue, mAttributes) {
throw new Errors.UnimplementedInterfaceError("Formatter.format() has not been implemented.");
};

br.formatting.Formatter = Formatter;
module.exports = Formatter;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* @module br/formatting/KeyValueFormatter
*/

var topiarist = require('topiarist');
var Formatter = require('br/formatting/Formatter');

/**
* @class
* @alias module:br/formatting/KeyValueFormatter
Expand All @@ -14,10 +17,9 @@
* The <code>mAttributes</code> argument should have the map holding the mappings in it's
* <code>map</code> key.
*/
br.formatting.KeyValueFormatter = function() {
};
function KeyValueFormatter() {}

br.Core.implement(br.formatting.KeyValueFormatter, br.formatting.Formatter);
topiarist.implement(KeyValueFormatter, Formatter);

/**
* Substitutes a value with a mapped value if the a mapped value exists otherwise it returns the
Expand All @@ -27,14 +29,16 @@ br.Core.implement(br.formatting.KeyValueFormatter, br.formatting.Formatter);
* @param {Map} mAttributes the object which holds a map of key-value pairs in its "map" element.
* @return the found value for the passed key or the the key if the value was not found.
*/
br.formatting.KeyValueFormatter.prototype.format = function(vValue, mAttributes) {
KeyValueFormatter.prototype.format = function(vValue, mAttributes) {
var mKeyValues = mAttributes.map;
return mKeyValues[vValue] || vValue;
};

/**
* @private
*/
br.formatting.KeyValueFormatter.prototype.toString = function() {
KeyValueFormatter.prototype.toString = function() {
return "br.formatting.KeyValueFormatter";
};

module.exports = KeyValueFormatter;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
* @module br/formatting/LeadingZeroFormatter
*/

var topiarist = require('topiarist');
var Formatter = require('br/formatting/Formatter');
var NumberUtil = require('br/util/Number');

/**
* @class
* @alias module:br/formatting/LeadingZeroFormatter
Expand All @@ -15,10 +19,9 @@
* <p/>
* <code>br.formatting.LeadingZeroFormatter.format(89, {length:4})</code>
*/
br.formatting.LeadingZeroFormatter = function() {
};
function LeadingZeroFormatter() {}

br.Core.implement(br.formatting.LeadingZeroFormatter, br.formatting.Formatter);
topiarist.implement(LeadingZeroFormatter, Formatter);

/**
* Pads the integer part of a number with as many leading zeros needed to reach the specified size.
Expand All @@ -41,13 +44,15 @@ br.Core.implement(br.formatting.LeadingZeroFormatter, br.formatting.Formatter);
* @return the number, padded to the required length with leading zeros.
* @type String
*/
br.formatting.LeadingZeroFormatter.prototype.format = function(vValue, mAttributes){
return br.util.Number.pad(vValue, mAttributes["length"]);
}
LeadingZeroFormatter.prototype.format = function(vValue, mAttributes){
return NumberUtil.pad(vValue, mAttributes.length);
};

/**
* @private
*/
br.formatting.LeadingZeroFormatter.prototype.toString = function() {
LeadingZeroFormatter.prototype.toString = function() {
return "br.formatting.LeadingZeroFormatter";
};

module.exports = LeadingZeroFormatter;
Loading

0 comments on commit b31cf7f

Please sign in to comment.