Skip to content

Commit

Permalink
Add Globalization Plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew Walters committed Sep 22, 2011
1 parent 651283a commit cdf1e95
Show file tree
Hide file tree
Showing 223 changed files with 2,610 additions and 0 deletions.
531 changes: 531 additions & 0 deletions BlackBerry/Globalization/Globalization.java

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions BlackBerry/Globalization/GlobalizationError.java
@@ -0,0 +1,83 @@
/*
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
* Copyright (c) 2011, IBM Corporation
*/
package com.phonegap.plugins.globalization;

/**
* User initiated exception. Exception class representing defined
* Globalization error codes.
*
* Globalization error codes:
* GlobalizationError.UNKNOWN_ERROR = 0;
* GlobalizationError.FORMATTING_ERROR = 1;
* GlobalizationError.PARSING_ERROR = 2;
* GlobalizationError.PATTERN_ERROR = 3;
*/
public class GlobalizationError extends Exception {

private static final long serialVersionUID = 1L;
public static final String UNKNOWN_ERROR = "UNKNOWN_ERROR";
public static final String FORMATTING_ERROR = "FORMATTING_ERROR";
public static final String PARSING_ERROR = "PARSING_ERROR";
public static final String PATTERN_ERROR = "PATTERN_ERROR";

int error = 0; // default unknown error thrown

/**
* Default constructor
*/
public GlobalizationError() {
}

/**
* Create an exception returning an error code
*
* @param s
*/
public GlobalizationError(String s) {
if (s.equalsIgnoreCase(FORMATTING_ERROR)) {
error = 1;
} else if (s.equalsIgnoreCase(PARSING_ERROR)) {
error = 2;
} else if (s.equalsIgnoreCase(PATTERN_ERROR)) {
error = 3;
}
}

/**
* get error string based on error code
*
* @param String msg
*/
public String getErrorString() {
String msg = "";
switch (error) {
case 0:
msg = UNKNOWN_ERROR;
break;
case 1:
msg = FORMATTING_ERROR;
break;
case 2:
msg = PARSING_ERROR;
break;
case 3:
msg = PATTERN_ERROR;
break;
}
return msg;
}

/**
* get error code
*
* @param String msg
*/
public int getErrorCode() {
return error;
}

}
20 changes: 20 additions & 0 deletions BlackBerry/Globalization/LICENSE
@@ -0,0 +1,20 @@
The MIT License

Copyright (c) 2011 IBM

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46 changes: 46 additions & 0 deletions BlackBerry/Globalization/README.md
@@ -0,0 +1,46 @@
# PhoneGap Globalization Plugin #
by IBM

## Adding the Plugin to your project ##

Using this plugin requires [BlackBerry-WebWorks PhoneGap](http://github.com/phonegap/phonegap-blackberry-webworks).

1. To install the plugin, copy globalization.js to your project and include a reference to it in your html file after phonegap.js.

&lt;script type="text/javascript" charset="utf-8" src="phonegap.js"&gt;&lt;/script&gt;<br/>
&lt;script type="text/javascript" charset="utf-8" src="globalization.js"&gt;&lt;/script&gt;

2. Copy the resourceBundles folder and all of its contents to your projects resources folder. The resourceBundles folder contains additional localization information that is not available from the BlackBerry operating system. If you do not need to support all the locales you may selectively remove them so they are not included in your application.

3. Add the plugin source to your phonegap.jar in your projects ext folder. The phonegap.jar file is a jar of source code. Open phonegap.jar with your favorite archive manager or use the jar command to create a directory called "src/com/phonegap/plugins/globalization" and copy Globalization.java, GlobalizationError.java, Resources.java and Util.java into it.

4. In your projects plugins.xml file add the following line:

&lt;plugin name="Globalization" value="com.phonegap.plugins.globalization.Globalization"/&gt;


## RELEASE NOTES ##

### 20110915 ###
* Initial release
* See the .js file for API docs
* A globalization.tests.js file is provide to run with qunit as part of Mobile-Spec [Github](http://github.com/phonegap/mobile-spec)

## BUGS AND CONTRIBUTIONS ##

Patches welcome! Send a pull request. Requires a [CLA](https://files.pbworks.com/download/qH1OfztZ1d/phonegap/31724031/NitobiPhoneGapCLA.pdf).

Post issues in the [PhoneGap Google Groups](http://groups.google.com/group/phonegap), include in the subject heading - "GlobalizationPlugin" or on [Github](http://github.com/phonegap/phonegap-plugins/issues)
(preferred)

## LICENSE ##

The MIT License

Copyright (c) 2011 IBM

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
86 changes: 86 additions & 0 deletions BlackBerry/Globalization/Resources.java
@@ -0,0 +1,86 @@
/*
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
* Copyright (c) 2011, IBM Corporation
*/
package com.phonegap.plugins.globalization;

public class Resources {
// Globalization Plugin Actions
public static final String GETLOCALENAME = "getLocaleName";
public static final String DATETOSTRING = "dateToString";
public static final String STRINGTODATE = "stringToDate";
public static final String GETDATEPATTERN = "getDatePattern";
public static final String GETDATENAMES = "getDateNames";
public static final String ISDAYLIGHTSAVINGSTIME = "isDayLightSavingsTime";
public static final String GETFIRSTDAYOFWEEK = "getFirstDayOfWeek";
public static final String NUMBERTOSTRING = "numberToString";
public static final String STRINGTONUMBER = "stringToNumber";
public static final String GETNUMBERPATTERN = "getNumberPattern";
public static final String GETCURRENCYPATTERN = "getCurrencyPattern";

// Globalization Option Parameters
public static final String OPTIONS = "options";
public static final String FORMATLENGTH = "formatLength";
public static final String MEDIUM = "medium";
public static final String LONG = "long";
public static final String FULL = "full";
public static final String SELECTOR = "selector";
public static final String DATE = "date";
public static final String TIME = "time";
public static final String DATESTRING = "dateString";
public static final String TYPE = "type";
public static final String ITEM = "item";
public static final String NARROW = "narrow";
public static final String WIDE = "wide";
public static final String MONTHS = "months";
public static final String DAYS = "days";
public static final String SPACE = " ";
public static final String DATEDELIMITER = "-";
public static final String TIMEDELIMITER = ":";
public static final String[] AM_PMFORMATS = {"a","aa"};
public static final String NUMBER = "number";
public static final String NUMBERSTRING = "numberString";
public static final String PERCENT = "percent";
public static final String CURRENCY = "currency";
public static final String CURRENCYCODE = "currencyCode";

// JSON File: JSONObject
public static final String JSON_CURRENCY = "currency";
public static final String JSON_LOCALE = "locale";
public static final String JSON_NAME = "name";

// JSON File: parameters
// locale:
public static final String JSON_PATTERN = "pattern";
public static final String JSON_DECIMAL = "decimal";
public static final String JSON_FRACTION = "fraction";
public static final String JSON_ROUNDING = "rounding";
public static final String JSON_GROUPING = "grouping";
public static final String JSON_NEGATIVE = "negative";
public static final String JSON_FIRISTDAYOFWEEK = "firstDayOfWeek";
public static final String JSON_POSITIVE = "positive";
public static final String JSON_PERCENTSYMBOL = "percentSymbol";
public static final String JSON_CURRENCYSYMBOL = "currencySymbol";
public static final String JSON_DECIMALSYMBOL = "decimalSymbol";
public static final String JSON_DISPLAYNAME = "displayName";

// currency
public static final String JSON_CURRENCYCODE = "currencyCode";
public static final String JSON_CURRENCYPATTERN = "currencyPattern";
public static final String JSON_CURRENCYDECIMAL = "currencyDecimal";
public static final String JSON_CURRENCYFRACTION = "currencyFraction";
public static final String JSON_CURRENCYGROUPING = "currencyGrouping";
public static final String JSON_CURRENCYROUNDING = "currencyRounding";

// class paths:
public static final String LOCALEINFOPATH = "/resources/resourceBundles/";
public static final String LOCALEINFOPATHEND = ".js.gz";

// locale resource key identifiers
public static final int LOCALENAME = 0;

// Persistent Store ID:
public static final long PERSISTENTSTORE_ID = 0x10001;
}

0 comments on commit cdf1e95

Please sign in to comment.