📄 currentdeck.java
字号:
/*
* j2wap is distributed under the terms of the GNU Public License
*
* j2wap was written by:
*
* Scott Campbell
* Michael Nordling
* Karl Maftoum
* Julian Bright
*
* This was a final project for Comp.Engineering at the University of Canberra, Australia
*
* Now released as Open Source software. 28 November 2000
*
* Email: k_maftoum@hotmail.com for more info
*
* Use entirely at your own risk.
*/
package wae;
import java.io.IOException;
/**
* Title: CurrentDeck
* Description: The Current deck class our view of an WML deck. It contains
* a reference to an instance of DeckElement, which encapsulates a
* binary encoded WML deck.
*
* CurrentDeck also provides functionality to extract a deck's
* version number, public identifier, charset and string table.
* It also keeps track of the deck's URL and whether it has a
* <code>template</code> element.
* Company: J2wap.com
* @author Scott Campbell.
* @version 1.1
*/
public class CurrentDeck extends WbxmlUtility
{
// Private attributes
/** Flags if a TEMPLATE element has been found in the deck. */
private boolean c_bolHasTemplate;
/** Holds the version number of the deck. */
private int c_intVersion;
/** Holds the public identifier of the deck. */
private int c_intPublicIdentifierId;
/** Holds the charset of the deck. */
private int c_intCharSet;
/** Holds all strings contained in the deck's string table. */
private char c_arrStringTable[];
/** Holds the base part of the deck's URL. */
private String c_strDeckBaseURL = new String ();
/** Holds the tail of the deck's URL. */
private String c_strDeckURLTail = new String ();
/** Holds the fragment ID of the deck's URL. */
private String c_strFragmentID;
/** Object holding the deck. */
private DeckElement c_clsDeckBytecode;
/**
* Get a new deck, extract string table, and parse deck elements.
* This method parses all deck elements preceeding card elements.
* @param in_clsDeckByteCode Deck's bytecode.
* @param in_clsDeckURL The decks's absolute URL.
*/
public void getDeck (byte in_clsDeckByteCode[], String in_clsDeckURL) throws IOException
{
c_clsDeckBytecode = new DeckElement (in_clsDeckByteCode);
c_bolHasTemplate = false;
// Get version and public identifier.
c_intVersion = nextByte ();
c_intPublicIdentifierId = readMultiByteInteger ();
setDeckURL(in_clsDeckURL);
// skip charset
c_intCharSet = readMultiByteInteger ();
// Get string table size and read in string table.
int intStrTabSize = readMultiByteInteger ();
this.c_arrStringTable = new char [intStrTabSize];
for (int i = 0; i < intStrTabSize; i++)
c_arrStringTable [i] = (char) nextByte ();
// Set the WML start (<WML>) marker in the bytecode.
this.c_clsDeckBytecode.setWmlStartPos ();
} // getDeck
/**
* Read an inline string starting at the next byte in the deck's bytecode
* array.
* @return The inline string read from the deck's bytecode.
*/
public String readInlineString () throws IOException, J2WapException
{
StringBuffer clsStrBuf = new StringBuffer ();
while (true)
{
// Read the next byte
byte bytCurrentByte = c_clsDeckBytecode.nextByte ();
// If valid byte, then append to string buffer
if (bytCurrentByte == 0xFF)
{
J2WapException clsExep = new J2WapException (
"Error: End of file " + "encountered while reading inline string.");
throw (clsExep);
} // if
else if (bytCurrentByte == 0)
return clsStrBuf.toString ();
else clsStrBuf.append ((char) bytCurrentByte);
} // while
} // readInlineString
/**
* Read a string from the string table.<p>
* This method will probably need to be used by the class
* that parses the deck and divides the deck into cards.
* @return String that was read from the string table.
*/
public String readStringFromStringTable () throws IOException
{
// Get the start and end positions of the string in the string table.
int intPos = readMultiByteInteger ();
int intEnd = intPos;
// Find last character of string.
while (c_arrStringTable [intEnd] != 0)
intEnd++;
return new String (c_arrStringTable, intPos, intEnd-intPos);
} // readStringFromStringTable
/**
* Reads the next byte in the deck's bytecode array.
* @return The next byte in the deck's byte code array.
*/
public byte nextByte()
{
return c_clsDeckBytecode.nextByte ();
} // nextByte
/**
* Reads a multi byte integer from the deck's bytecode.
* @return The multibyte (mb_u_int32) integer read.
*/
public int readMultiByteInteger () throws IOException
{
int intResult = 0;
byte bytTemp;
do
{
bytTemp = c_clsDeckBytecode.nextByte ();
intResult = (intResult << 7) | (bytTemp & c_LowByteMask);
}
while (moreBytesInMBInt (bytTemp));
return intResult;
} // readMultiByteInteger
/**
* Get the position of the nextbyte to be read from the bytecode array.
* @return Position of the nextbyte.
*/
public int posOfNextByte ()
{
return (c_clsDeckBytecode.nextPos ());
} // posOfNextByte
/**
* Sets the next position indicator in the bytecode array to the value
* of "in_intPos". A subsequent call to the "nextByte ()" will return the
* byte at the "in_intPost" position in the bytecode array.
* @param in_intPos The index of the next byte that will be returned by a
* call to <code>nextByte()</code>.
*/
public void setPosOfNextBytecode (int in_intPos)
{
c_clsDeckBytecode.setNextPos(in_intPos);
} // setPosOfNextBytecode
/**
* Marks the position of the <code>template</code> tag in the bytecode.
*/
public void setTemplateStartPos ()
{
c_clsDeckBytecode.setTemplateStartPos ();
c_bolHasTemplate = true;
} // setTemplateStartPos
/**
* Resets the next position indicator in the bytecode array so that a
* subsequent call the "nextByte ()" will return <code>WML</code> tag.
*/
public void ResetToWmlStartPos ()
{
c_clsDeckBytecode.ResetToWmlStartPos ();
} // ResetToWmlStartPos
/**
* Resets the next position indicator in the bytecode array so that a
* subsequent call the "nextByte ()" will return <code>template</code> tag.
*/
public void ResetToTemplateStartPos ()
{
c_clsDeckBytecode.ResetToTemplateStartPos ();
} // ResetToTemplateStartPos
/**
* Determine the string representation of a byte element.
* @param in_bytId The element as a byte.
* @return The element's start tag as a string.
*/
public String resolveElementTag (byte in_bytId) throws J2WapException
{
switch (in_bytId)
{
case (byte) 0x1C: return WmlTags.START_TAG_A;
case (byte) 0x1D: return WmlTags.START_TAG_TD;
case (byte) 0x1E: return WmlTags.START_TAG_TR;
case (byte) 0x1F: return WmlTags.START_TAG_TABLE;
case (byte) 0x20: return WmlTags.START_TAG_P;
case (byte) 0x21: return WmlTags.START_TAG_POSTFIELD;
case (byte) 0x22: return WmlTags.START_TAG_ANCHOR;
case (byte) 0x23: return WmlTags.START_TAG_ACCESS;
case (byte) 0x24: return WmlTags.START_TAG_B;
case (byte) 0x25: return WmlTags.START_TAG_BIG;
case (byte) 0x26: return WmlTags.START_TAG_BR;
case (byte) 0x27: return WmlTags.START_TAG_CARD;
case (byte) 0x28: return WmlTags.START_TAG_DO;
case (byte) 0x29: return WmlTags.START_TAG_EM;
case (byte) 0x2A: return WmlTags.START_TAG_FIELDSET;
case (byte) 0x2B: return WmlTags.START_TAG_GO;
case (byte) 0x2C: return WmlTags.START_TAG_HEAD;
case (byte) 0x2D: return WmlTags.START_TAG_I;
case (byte) 0x2E: return WmlTags.START_TAG_IMG;
case (byte) 0x2F: return WmlTags.START_TAG_INPUT;
case (byte) 0x30: return WmlTags.START_TAG_META;
case (byte) 0x31: return WmlTags.START_TAG_NOOP;
case (byte) 0x32: return WmlTags.START_TAG_PREV;
case (byte) 0x33: return WmlTags.START_TAG_ONEVENT;
case (byte) 0x34: return WmlTags.START_TAG_OPTGROUP;
case (byte) 0x35: return WmlTags.START_TAG_OPTION;
case (byte) 0x36: return WmlTags.START_TAG_REFRESH;
case (byte) 0x37: return WmlTags.START_TAG_SELECT;
case (byte) 0x38: return WmlTags.START_TAG_SMALL;
case (byte) 0x39: return WmlTags.START_TAG_STRONG;
// No 0x3A tag.
case (byte) 0x3B: return WmlTags.START_TAG_TEMPLATE;
case (byte) 0x3C: return WmlTags.START_TAG_TIMER;
case (byte) 0x3D: return WmlTags.START_TAG_U;
case (byte) 0x3E: return WmlTags.START_TAG_SETVAR;
case (byte) 0x3F: return WmlTags.START_TAG_WML;
default: // Illegal tag. Raise an exception.
J2WapException clsExcep = new J2WapException (
"Error: Illegal tag (" + in_bytId + ").");
throw (clsExcep);
} // switch
} // resolveElementTag
/**
* Determine the string representation of a byte element's end tag. Note
* that this end tag is not a WML tag. These end tags are used to simplify
* the work that the user interface must do to render the card.
* @param in_bytId The element as a byte.
* @return The element's end tag as a string.
*/
public String resolveEndTag (byte in_bytId) throws J2WapException
{
switch (in_bytId)
{
case (byte) 0x1C: return WmlTags.END_TAG_A;
case (byte) 0x1D: return WmlTags.END_TAG_TD;
case (byte) 0x1E: return WmlTags.END_TAG_TR;
case (byte) 0x1F: return WmlTags.END_TAG_TABLE;
case (byte) 0x20: return WmlTags.END_TAG_P;
case (byte) 0x21: return WmlTags.END_TAG_POSTFIELD;
case (byte) 0x22: return WmlTags.END_TAG_ANCHOR;
case (byte) 0x23: return WmlTags.END_TAG_ACCESS;
case (byte) 0x24: return WmlTags.END_TAG_B;
case (byte) 0x25: return WmlTags.END_TAG_BIG;
case (byte) 0x26: return WmlTags.END_TAG_BR;
case (byte) 0x27: return WmlTags.END_TAG_CARD;
case (byte) 0x28: return WmlTags.END_TAG_DO;
case (byte) 0x29: return WmlTags.END_TAG_EM;
case (byte) 0x2A: return WmlTags.END_TAG_FIELDSET;
case (byte) 0x2B: return WmlTags.END_TAG_GO;
case (byte) 0x2C: return WmlTags.END_TAG_HEAD;
case (byte) 0x2D: return WmlTags.END_TAG_I;
case (byte) 0x2E: return WmlTags.END_TAG_IMG;
case (byte) 0x2F: return WmlTags.END_TAG_INPUT;
case (byte) 0x30: return WmlTags.END_TAG_META;
case (byte) 0x31: return WmlTags.END_TAG_NOOP;
case (byte) 0x32: return WmlTags.END_TAG_PREV;
case (byte) 0x33: return WmlTags.END_TAG_ONEVENT;
case (byte) 0x34: return WmlTags.END_TAG_OPTGROUP;
case (byte) 0x35: return WmlTags.END_TAG_OPTION;
case (byte) 0x36: return WmlTags.END_TAG_REFRESH;
case (byte) 0x37: return WmlTags.END_TAG_SELECT;
case (byte) 0x38: return WmlTags.END_TAG_SMALL;
case (byte) 0x39: return WmlTags.END_TAG_STRONG;
// No 0x3A tag.
case (byte) 0x3B: return WmlTags.END_TAG_TEMPLATE;
case (byte) 0x3C: return WmlTags.END_TAG_TIMER;
case (byte) 0x3D: return WmlTags.END_TAG_U;
case (byte) 0x3E: return WmlTags.END_TAG_SETVAR;
case (byte) 0x3F: return WmlTags.END_TAG_WML;
default: // Illegal attribrute start token. Raise an exception.
J2WapException clsExcep = new J2WapException (
"Error: Illegal attribrute start token (" + in_bytId + ").");
throw (clsExcep);
} // switch
} // resolveEndTag
/**
* Determine the string representation of an byte attribute start token.
* @param in_bytId The attribute start token as a byte.
* @return The attribute start token as a string.
*/
public String resolveAttrStartToken (byte in_bytId) throws J2WapException
{
switch (in_bytId)
{
case (byte) 0x05: return "accept-charset";
case (byte) 0x06: return "align=bottom";
case (byte) 0x07: return "align=center";
case (byte) 0x08: return "align=left";
case (byte) 0x09: return "align=middle";
case (byte) 0x0A: return "align=right";
case (byte) 0x0B: return "align=top";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -