📄 xsdabstractdatetimetype.java
字号:
//parse [ss]
timeZone[mm]=parseInt(buffer, stop, stop+2);
if ( stop+2!=end ) {
throw new RuntimeException("Error in parsing time zone");
}
}
else {
throw new RuntimeException("Error in parsing time zone");
}
}
/**
* Computes index of given char within StringBuffer
*
* @param start
* @param end
* @param ch character to look for in StringBuffer
* @return index of ch within StringBuffer
*/
protected int indexOf (String buffer, int start, int end, char ch) {
for ( int i=start;i<end;i++ ) {
if ( buffer.charAt(i) == ch ) {
return i;
}
}
return -1;
}
// check whether the character is in the range 0x30 ~ 0x39
public static final boolean isDigit(char ch) {
return ch >= '0' && ch <= '9';
}
// if the character is in the range 0x30 ~ 0x39, return its int value (0~9),
// otherwise, return -1
public static final int getDigit(char ch) {
return isDigit(ch) ? ch - '0' : -1;
}
/**
* Return index of UTC char: 'Z', '+', '-'
*
* @param start
* @param end
* @return index of the UTC character that was found
*/
protected int findUTCSign (String buffer, int start, int end) {
int c;
for ( int i=start;i<end;i++ ) {
c=buffer.charAt(i);
if ( c == 'Z' || c=='+' || c=='-' ) {
return i;
}
}
return -1;
}
/**
* Given start and end position, parses string value
*
* @param value string to parse
* @param start Start position
* @param end end position
* @return return integer representation of characters
*/
protected int parseInt (String buffer, int start, int end)
throws NumberFormatException{
//REVISIT: more testing on this parsing needs to be done.
int radix=10;
int result = 0;
int digit=0;
int limit = -Integer.MAX_VALUE;
int multmin = limit / radix;
int i = start;
do {
digit = getDigit(buffer.charAt(i));
if ( digit < 0 ) throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
if ( result < multmin ) throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
result *= radix;
if ( result < limit + digit ) throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
result -= digit;
}while ( ++i < end );
return -result;
}
// parse Year differently to support negative value.
protected int parseIntYear (String buffer, int end){
int radix=10;
int result = 0;
boolean negative = false;
int i=0;
int limit;
int multmin;
int digit=0;
if (buffer.charAt(0) == '-'){
negative = true;
limit = Integer.MIN_VALUE;
i++;
}
else{
limit = -Integer.MAX_VALUE;
}
multmin = limit / radix;
while (i < end)
{
digit = getDigit(buffer.charAt(i++));
if (digit < 0) throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
if (result < multmin) throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
result *= radix;
if (result < limit + digit) throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
result -= digit;
}
if (negative)
{
if (i > 1) return result;
else throw new NumberFormatException("'"+buffer.toString()+"' has wrong format");
}
return -result;
}
public String dateToString(int[] date) {
StringBuffer message = new StringBuffer(25);
append(message, date[CY], 4);
message.append('-');
append(message, date[M], 2);
message.append('-');
append(message, date[D], 2);
message.append('T');
append(message, date[h], 2);
message.append(':');
append(message, date[m], 2);
message.append(':');
append(message, date[s], 2);
message.append('.');
appendFractionalTime(message, date[ms], date[msscale]);
append(message, (char)date[utc], 0);
return message.toString();
}
/** Append the fraction time part of a date/time vector to
* a string buffer.
*/
public static void appendFractionalTime(StringBuffer buff, int fsec, int scale) {
String msString = Integer.toString(fsec);
int pad = scale - msString.length();
while (pad > 0) {
buff.append('0');
pad--;
}
int trunc = msString.length();
while (trunc > 0 && msString.charAt(trunc-1) == '0') trunc --;
buff.append(msString.substring(0, trunc));
}
protected void append(StringBuffer message, int value, int nch) {
if (value < 0) {
message.append('-');
value = -value;
}
if (nch == 4) {
if (value < 10)
message.append("000");
else if (value < 100)
message.append("00");
else if (value < 1000)
message.append("0");
message.append(value);
}
else if (nch == 2) {
if (value < 10)
message.append('0');
message.append(value);
}
else {
if (value != 0)
message.append((char)value);
}
}
// --------------------------------------------------------------------
// End of code is adapated from Xerces 2.6.0 AbstractDateTimeDV.
// --------------------------------------------------------------------
/**
* Return a minimal datatype for this object. Used to handle
* cases where a single java object can represent multiple
* specific types and where we want narrow the type used.
* For example, a BigDecimal may narrow to a simple xsd:int.
* Currently only used to narrow gener XSDDateTime objects
* to the minimal XSD date/time type.
*/
public RDFDatatype getNarrowedDatatype(Object value) {
if (value instanceof XSDDateTime) {
return ((XSDDateTime)value).getNarrowedDatatype();
} else {
return this;
}
}
}
/*
(c) Copyright 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -