Fields Summary |
---|
public static final String | QUOTED_PRINTABLECode name of the Quoted-Printable binary encoding. |
public static final String | BASE64Code name of the Base64 binary encoding. |
public static final String | PLAIN_TEXTCode name of plain text binary encoding. |
public static final String | UTF8Name of default character encoding. |
public static final char | DAILYRepeat rule daily frequency char representation. |
public static final char | WEEKLYRepeat rule weekly frequency char representation. |
public static final char | MONTHLYRepeat rule monthly frequency char representation. |
public static final char | YEARLYRepeat rule yearly frequency char representation. |
public static final char | DAY_IN_MONTHRepeat rule day-in-month char representation. |
public static final char | WEEK_IN_MONTHRepeat rule week-in-month char representation. |
public static final char | DAY_IN_YEARRepeat rule day-in-year char representation. |
public static final char | MONTH_IN_YEARRepeat rule month-in-year char representation. |
Methods Summary |
---|
public static boolean | contains(int[] a, int value)Checks to see if a sorted array of integers contains a given integer.
// binary chop search
int lowerBound = 0;
int upperBound = a.length - 1;
while (upperBound - lowerBound >= 0) {
int i = lowerBound + (upperBound - lowerBound) / 2;
int v = a[i];
if (v > value) {
// look between lowerBound and i
upperBound = i - 1;
} else if (v < value) {
// look between i and upperBound
lowerBound = i + 1;
} else {
return true;
}
}
return false;
|
public static java.lang.String | convertString(java.lang.String data, java.lang.String encoding, java.lang.String charset)Converts a string from the given UTF-8 plain text encoding to the
specified encoding.
if (encoding.equals(QUOTED_PRINTABLE)) {
byte[] b = QuotedPrintableEncoding.fromQuotedPrintable(data);
try {
return new String(b, charset);
} catch (UnsupportedEncodingException e) {
// should not happen if charset was returned from getCharSet()
return new String(b);
}
} else if (encoding.equals(BASE64)) {
byte[] b = Base64Encoding.fromBase64(data);
try {
return new String(b, charset);
} catch (UnsupportedEncodingException e) {
// should not happen if charset was returned from getCharSet()
return new String(b);
}
} else if (charset.equals(UTF8)) {
return data;
} else {
try {
return new String(data.getBytes(UTF8), charset);
} catch (UnsupportedEncodingException e) {
throw new Error(UTF8 + " encoding not available");
}
}
|
public static java.lang.String | getAttributeValue(java.lang.String[] attributes, java.lang.String key, java.lang.String defaultValue)Gets an attribute of the form (key)(value), if one exists in the supplied
attributes list.
for (int i = 0; i < attributes.length; i++) {
if (attributes[i].startsWith(key)) {
return attributes[i].substring(key.length());
}
}
return defaultValue;
|
public static java.lang.String | getCharSet(java.lang.String[] attributes)Gets the character set specified by the given property attributes.
The default is UTF-8, unless the attributes contain a CHARSET= entry.
String charset = getAttributeValue(attributes, "CHARSET=", UTF8);
try {
"".getBytes(charset);
return charset;
} catch (UnsupportedEncodingException e) {
// cannot use this encoding.
return UTF8;
}
|
public static java.lang.String | getEncoding(java.lang.String[] attributes)Gets the encoding used for a value with the given attributes.
for (int i = 0; i < attributes.length; i++) {
String s = attributes[i].toUpperCase();
if (s.equals("ENCODING=QUOTED-PRINTABLE")
|| s.equals("QUOTED-PRINTABLE")) {
return QUOTED_PRINTABLE;
}
if (s.equals("ENCODING=BASE64")
|| s.equals("BASE64")
|| s.equals("ENCODING=B")) {
return BASE64;
}
}
return PLAIN_TEXT;
|
public static java.lang.String | join(java.lang.String[] elements, java.lang.String separator)Joins the elements of a string array together into a single string.
StringBuffer sb = new StringBuffer();
for (int i = 0; i < elements.length; i++) {
if (i > 0) {
sb.append(separator);
}
sb.append(elements[i]);
}
return sb.toString();
|
public static byte[] | parseBinary(java.lang.String[] attributes, java.lang.String data)Interpret a vCard or vCalendar data element as a byte array, taking
into account any encoding parameters specified in the attribute array.
String encoding = getEncoding(attributes);
if (encoding.equals(QUOTED_PRINTABLE)) {
return QuotedPrintableEncoding.fromQuotedPrintable(data);
} else if (encoding.equals(BASE64)) {
return Base64Encoding.fromBase64(data);
} else {
return data.getBytes();
}
|
public static com.sun.kvem.midp.pim.formats.FormatSupport$DataElement | parseObjectLine(java.lang.String line)Extracts data from a vCard or vCalendar line.
// break the line into property name, attributes and data
int i = line.indexOf(':");
if (i == -1 || i == 0) {
// every line in a vCalendar object must have a colon delimiter
throw new UnsupportedPIMFormatException(
"Invalid line: '" + line + "'");
}
DataElement element = new DataElement();
element.data = line.substring(i + 1).trim();
String prefix = line.substring(0, i).trim();
i = prefix.indexOf(';");
if (i == -1) {
element.propertyName = prefix.toUpperCase();
element.attributes = new String[0];
} else {
element.propertyName = prefix.substring(0, i).toUpperCase();
element.attributes = FormatSupport.split(prefix, ';", i + 1);
for (int j = 0; j < element.attributes.length; j++) {
element.attributes[j] = element.attributes[j].toUpperCase();
}
}
// propertyName could contain a group name. (e.g. HOME.FN:)
// we don't have to do anything with the group name - there is
// really nothing to do with it - but we do have to process it.
// remove a group name, if one exists:
i = element.propertyName.lastIndexOf('.");
if (i != -1) {
element.propertyName = element.propertyName.substring(i + 1);
}
return element;
|
public static java.lang.String | parseString(java.lang.String[] attributes, java.lang.String data)Interpret a vCard or vCalendar data element as a string, taking
into account any encoding parameters specified in the attribute array.
String charset = getCharSet(attributes);
String encoding = getEncoding(attributes);
return convertString(data, encoding, charset);
|
public static java.lang.String[] | parseStringArray(java.lang.String[] attributes, java.lang.String data)Interpret a vCard or vCalendar data element as a string array, taking
into account any encoding parameters specified in the attribute array.
String charset = getCharSet(attributes);
String encoding = getEncoding(attributes);
String[] elements = split(data, ';", 0, false);
for (int i = 0; i < elements.length; i++) {
elements[i] = convertString(elements[i], encoding, charset);
// treat empty elements as null
if ("".equals(elements[i])) {
elements[i] = null;
}
}
return elements;
|
public static void | sort(int[] a)Sorts an array of integers.
// insertion sort
for (int j = 1; j < a.length; j++) {
int v = a[j];
int i = j - 1;
while (i >= 0 && a[i] > v) {
a[i + 1] = a[i];
i--;
}
a[i + 1] = v;
}
|
public static java.lang.String[] | split(java.lang.String data, char separatorChar, int startingPoint, boolean skipFirstIfEmpty)Parses a separated list of strings into a string array.
An escaped separator (backslash followed by separatorChar) is not
treated as a separator.
if (startingPoint == data.length()) {
return new String[0];
}
// support for empty category name:
// if data starts with separator, just skip it
if (skipFirstIfEmpty && data.startsWith("" + separatorChar)) {
startingPoint++;
}
// tokenize elements
Vector elementList = new Vector();
int startSearchAt = startingPoint;
int startOfElement = startingPoint;
for (int i; (i = data.indexOf(separatorChar, startSearchAt)) != -1; ) {
if (i != 0 && data.charAt(i - 1) == '\\") {
// escaped separator. don't treat it as a real separator
startSearchAt = i + 1;
} else {
String element = data.substring(startOfElement, i);
elementList.addElement(element);
startSearchAt = startOfElement = i + 1;
}
}
// there is no separator found
if (elementList.size() == 0) {
return new String[] { data.substring(startOfElement) };
}
// add the last element
elementList.addElement(data.substring(startOfElement));
// convert Vector to array
int size = elementList.size();
String[] elements = new String[size];
for (int i = 0; i < size; i++) {
elements[i] = (String) elementList.elementAt(i);
}
return elements;
|
public static java.lang.String[] | split(java.lang.String data, char separatorChar, int startingPoint)Parses a separated list of strings into a string array.
An escaped separator (backslash followed by separatorChar) is not
treated as a separator.
return split(data, separatorChar, startingPoint, true);
|