META-INF.adf.jsLibs.NumberConverter.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of trinidad-impl Show documentation
Show all versions of trinidad-impl Show documentation
Private implementation of the Apache MyFaces Trinidad project
function TrNumberConverter(
a0,
a1,
a2,
a3,
a4,
a5,
a6,
a7,
a8,
a9,
a10,
a11,
a12,
a13,
a14)
{
this._pattern=a0;
this._type=a1;
this._locale=a2;
this._messages=a3;
this._currencyCode=a6;
this._currencySymbol=a7;
this._maxFractionDigits=a8;
this._maxIntegerDigits=a9;
this._minFractionDigits=a10;
this._minIntegerDigits=a11;
this._negativePrefix=a12;
this._negativeSuffix=a13;
this._roundingMode=a14;
if(a4!==undefined)
this._integerOnly=a4;
else
this._integerOnly=false;
if(a5!==undefined)
this._groupingUsed=a5;
else
this._groupingUsed=true;
this._initNumberFormat(a2,a6,a7,a12,a13);
this._class="TrNumberConverter";
TrNumberConverter.ROUND_UP="UP";
TrNumberConverter.ROUND_DOWN="DOWN";
TrNumberConverter.ROUND_CEILING="CEILING";
TrNumberConverter.ROUND_FLOOR="FLOOR";
TrNumberConverter.ROUND_HALF_UP="HALF_UP";
TrNumberConverter.ROUND_HALF_DOWN="HALF_DOWN";
TrNumberConverter.ROUND_HALF_EVEN="HALF_EVEN";
TrNumberConverter.ROUND_UNNECESSARY="UNNECESSARY";
}
TrNumberConverter.prototype=new TrConverter();
TrNumberConverter.prototype.setCurrencyCode=function(a15)
{
this._currencyCode=a15;
}
TrNumberConverter.prototype.getCurrencyCode=function()
{
return this._currencyCode;
}
TrNumberConverter.prototype.setCurrencySymbol=function(a16)
{
this._currencySymbol=a16;
}
TrNumberConverter.prototype.getCurrencySymbol=function()
{
return this._currencySymbol;
}
TrNumberConverter.prototype.setMaxFractionDigits=function(a17)
{
this._maxFractionDigits=a17;
}
TrNumberConverter.prototype.getMaxFractionDigits=function()
{
return this._maxFractionDigits;
}
TrNumberConverter.prototype.setMaxIntegerDigits=function(a18)
{
this._maxIntegerDigits=a18;
}
TrNumberConverter.prototype.getMaxIntegerDigits=function()
{
return this._maxIntegerDigits;
}
TrNumberConverter.prototype.setMinFractionDigits=function(a19)
{
this._minFractionDigits=a19;
}
TrNumberConverter.prototype.getMinFractionDigits=function()
{
return this._minFractionDigits;
}
TrNumberConverter.prototype.setMinIntegerDigits=function(a20)
{
this._minIntegerDigits=a20;
}
TrNumberConverter.prototype.getMinIntegerDigits=function()
{
return this._minIntegerDigits;
}
TrNumberConverter.prototype.setNegativePrefix=function(a21)
{
this._negativePrefix=a21;
}
TrNumberConverter.prototype.getNegativePrefix=function()
{
return this._negativePrefix;
}
TrNumberConverter.prototype.setNegativeSuffix=function(a22)
{
this._negativeSuffix=a22;
}
TrNumberConverter.prototype.getNegativeSuffix=function()
{
return this._negativeSuffix;
}
TrNumberConverter.prototype.setGroupingUsed=function(a23)
{
this._groupingUsed=a23;
}
TrNumberConverter.prototype.isGroupingUsed=function()
{
return this._groupingUsed;
}
TrNumberConverter.prototype.setIntegerOnly=function(a24)
{
this._integerOnly=a24;
}
TrNumberConverter.prototype.isIntegerOnly=function()
{
return this._integerOnly;
}
TrNumberConverter.prototype.setRoundingMode=function(a25)
{
this._roundingMode=a25;
}
TrNumberConverter.prototype.getRoundingMode=function()
{
return this._roundingMode;
}
TrNumberConverter.prototype.isJSDefaultRoundingMode=function()
{
return this._roundingMode==TrNumberConverter.ROUND_HALF_UP;
}
TrNumberConverter.prototype.getFormatHint=function()
{
if(this._messages&&this._messages["hintPattern"])
{
return TrMessageFactory.createCustomMessage(
this._messages["hintPattern"],
this._pattern);
}
else
{
if(this._pattern)
{
return TrMessageFactory.createMessage(
"org.apache.myfaces.trinidad.convert.NumberConverter.FORMAT_HINT",
this._pattern);
}
else
{
return null;
}
}
}
TrNumberConverter.prototype.getAsString=function(
a26,
a27
)
{
if(this._isConvertible())
{
if(this._type=="percent"||this._type=="currency")
{
return this._numberFormat.format(a26);
}
else
{
if(typeof a26==="string")
{
return this._numberFormat.format(parseFloat(a26));
}
else
{
var a28=(false)?a26.toFixed(this._numberFormat.getMaximumFractionDigits()):a26;
return this._numberFormat.format(parseFloat(a28));
}
}
}
else
{
return undefined;
}
}
TrNumberConverter.prototype.getAsObject=function(
a29,
a30
)
{
a29=TrFormatUtils.trim(a29);
if(this._isConvertible(a29))
{
if(a29==null)
return null;
if(a29.length==0)
return null
var a31;
var a32=getLocaleSymbols(this._locale);
var a33=false;
var a34=this._numberFormat.hasPrefixOrSuffix(a29);
try
{
if(a34)
{
var a35=this._numberFormat.removePrefixAndSuffix(a29);
a29=a35[0];
a33=a35[1];
}
var a36=a32.getGroupingSeparator();
if(a36=="\xa0")
{
var a37=new RegExp("\\ ","g");
a29=a29.replace(a37,"\xa0");
}
var a38=new RegExp("\\"+a36,"g");
a29=a29.replace(a38,"");
var a39=a32.getDecimalSeparator();
var a40=new RegExp("\\"+a39,"g");
a29=a29.replace(a40,".");
if(a34)
{
a29=this._numberFormat.addPrefixAndSuffix(a29,a33);
}
a29=this._numberFormat.parse(a29)+"";
}
catch(e)
{
try
{
var a41=TrNumberFormat.getNumberInstance();
a41.setMinimumIntegerDigits(this._minIntegerDigits);
a41.setMaximumIntegerDigits(this._maxIntegerDigits);
a41.setMinimumFractionDigits(this._minFractionDigits);
a41.setMaximumFractionDigits(this._maxFractionDigits);
a29=a41.parse(a29)+"";
}
catch(e)
{
var a42;
var a43=this._numberFormat.format(this._example);
var a44="org.apache.myfaces.trinidad.convert.NumberConverter.CONVERT_"+this._type.toUpperCase();
if(this._messages&&this._messages[this._type])
{
a42=_createCustomFacesMessage(TrMessageFactory.getSummaryString(a44),this._messages[this._type],a30,a29,a43);
}
else
{
a42=_createFacesMessage(a44,a30,a29,a43);
}
throw new TrConverterException(a42);
}
}
var a45=new RegExp("\\"+".","g");
a29=a29.replace(a45,getLocaleSymbols().getDecimalSeparator());
a31=_decimalParse(a29,
this._messages,
"org.apache.myfaces.trinidad.convert.NumberConverter",
null,
null,
null,
null,
a30,
!this.isIntegerOnly());
var a46=(this.isJSDefaultRoundingMode())?a31.toFixed(this._numberFormat.getMaximumFractionDigits()):a31;
a31=parseFloat(a46);
if(this._type=="percent")
{
a31=a31/100;
}
return a31;
}
else
{
return undefined;
}
}
TrNumberConverter.prototype._isConvertible=function(a47)
{
if(this._pattern!=null)
return false;
return TrFormatUtils.isNumberConvertible(a47);
}
TrNumberConverter.prototype._initNumberFormat=function(
a48,
a49,
a50,
a51,
a52)
{
var a53={
"currencyCode":a49,
"currencySymbol":a50,
"negativePrefix":a51,
"negativeSuffix":a52,
"isGroupingUsed":this.isGroupingUsed(),
"maxFractionDigits":this.getMaxFractionDigits(),
"maxIntegerDigits":this.getMaxIntegerDigits(),
"minFractionDigits":this.getMinFractionDigits(),
"minIntegerDigits":this.getMinIntegerDigits(),
"roundingMode":this.getRoundingMode()
};
if(this._type=="percent")
{
this._example=0.3423;
this._numberFormat=TrNumberFormat.getPercentInstance(a48,a53);
}
else if(this._type=="currency")
{
this._example=10250;
this._numberFormat=TrNumberFormat.getCurrencyInstance(a48,a53);
}
else if(this._type=="number")
{
this._numberFormat=TrNumberFormat.getNumberInstance(a48,a53);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy