📄 parser.java
字号:
* be returned.
*/
public void readRestOfAttr (StringBuffer in_clsSBufAttr,
boolean in_bolGetValue)
throws IOException, NullPointerException, J2WapException
{
// Get all/rest of the attribute value
byte bytId = nextByte ();
while (isAttributeValueString (bytId) || bytId == Wbxml.ENTITY
|| bytId == Wbxml.STR_I || bytId == Wbxml.STR_T
|| (bytId >= Wbxml.EXT_I_0 && bytId <= Wbxml.EXT_I_2)
|| (bytId >= Wbxml.EXT_T_0 && bytId <= Wbxml.EXT_T_2))
{
switch (bytId)
{
case Wbxml.ENTITY:
in_clsSBufAttr.append ((char) readMultiByteInteger ());
break;
case Wbxml.STR_I:
in_clsSBufAttr.append (readInlineString ());
break;
case Wbxml.EXT_I_0: case Wbxml.EXT_I_1: case Wbxml.EXT_I_2:
case Wbxml.EXT_T_0: case Wbxml.EXT_T_1: case Wbxml.EXT_T_2:
case Wbxml.EXT_0: case Wbxml.EXT_1: case Wbxml.EXT_2:
case Wbxml.OPAQUE:
if (in_bolGetValue)
in_clsSBufAttr.append (handleExtensions (bytId));
else // Get the string that the extension token is referring to.
in_clsSBufAttr.append (resolveExtension (bytId));
break;
case Wbxml.STR_T:
in_clsSBufAttr.append (readStringFromStringTable ());
break;
default:
in_clsSBufAttr.append (c_clsDeck.resolveAttrValueToken (bytId));
} // switch
bytId = nextByte ();
} // while
/* Reset the next byte to be returned by "nextByte ()" to be the byte
* that we are now looking at. This is neccessary because this byte is
* the attribute start token of the next attribute.
*/
c_clsDeck.setPosOfNextBytecode (c_clsDeck.posOfNextByte () -1);
} //readRestOfAttr
/**
* Create a go event.
* @param in_bolOnevent True if <code>go</code> is in a <code>onevent</code>
* @param in_bolHasContent True if <code>go</code> has content.
* @return Event ID of the <code>go</code> element.
*/
public int readGoEvent (boolean in_bolOnevent,
boolean in_bolHasContent)
throws IOException, NullPointerException, J2WapException
{
boolean bolSendRef = false; // Default value is false.
int intGoId = WmlTags.NO_EVENT;
String clsStrAttr = null;
String clsStrHref = null;
String clsStrSendReferer = null;
String clsStrMethod = null;
String clsStrEncType = null;
c_bolLastGoHasVars = false;
// Get the attribute start token of the first attribute.
byte bytId = nextByte ();
while (bytId != Wbxml.END)
{
// Get a string representation of the attribute.
clsStrAttr = readAttribute (bytId);
if (parsingDesiredCardOrTemplate ())
{
// We now have a string containing the attribute start and the
// attribute end, delimitted by "=". So now extract the attribute start.
int intDelim = clsStrAttr.indexOf ('=');
String clsStrAttrStart = clsStrAttr.substring (0, intDelim);
String clsStrAttrValue =
clsStrAttr.substring (intDelim+2, clsStrAttr.length()-1);
// Now Determine which attribute it is and copy it to
// the appropiate variable.
if (clsStrAttrStart.equals ("href"))
clsStrHref = clsStrAttrValue;
else if (clsStrAttrStart.equals ("sendreferer"))
bolSendRef = (clsStrAttrValue.equals("TRUE") ||
clsStrAttrValue.equals("true"));
else if (clsStrAttrStart.equals ("method"))
clsStrMethod = clsStrAttrValue;
else if (clsStrAttrStart.equals ("enctype"))
clsStrEncType = clsStrAttrValue;
} // if
// Get the attribute start token of the next attribute.
bytId = nextByte ();
} // while
if (parsingDesiredCardOrTemplate ())
{
// Register the Go event.
intGoId = c_clsEventManagement.registerGo(clsStrHref, bolSendRef,
clsStrMethod, clsStrEncType);
/* Now add the start tag, event id and end tag to vector
* if the desired card is being parsed.
*/
if (!in_bolOnevent && shouldResigterEvent ())
{
conditionalAddToVector(WmlTags.START_TAG_GO);
conditionalAddToVector(new Integer(intGoId).toString());
conditionalAddToVector(c_clsDeck.resolveEndTag (WmlTags.GO));
} // if
} // if
if (in_bolHasContent)
readEventContents (intGoId, WmlTags.GO);
// Clean up.
clsStrAttr = null;
clsStrHref = null;
clsStrSendReferer = null;
clsStrMethod = null;
clsStrEncType = null;
return intGoId;
} // readGoEvent
/**
* Process a <code>prev</code> or <code>refresh</code> event.
* @param in_bolOnevent True if <code>go</code> is in a <code>onevent</code>
* @param in_bolHasContent True if <code>go</code> has content.
* @return Event ID of the <code>prev</code>
*/
public int readPrevOrResfreshEvent (byte in_bytEventElem,
boolean in_bolOnevent)
throws IOException, NullPointerException, J2WapException
{
int intEventId = WmlTags.NO_EVENT;
String strEndTag = null;
if (parsingDesiredCard ())
{
// Register the event.
if (in_bytEventElem == WmlTags.PREV)
{
intEventId = c_clsEventManagement.registerPrev();
// Now add to vector if the desired card is being parsed.
if (!in_bolOnevent)
{
conditionalAddToVector(WmlTags.START_TAG_PREV);
conditionalAddToVector(new Integer(intEventId).toString());
conditionalAddToVector(c_clsDeck.resolveEndTag (in_bytEventElem));
} // if
}
else if (in_bytEventElem == WmlTags.REFRESH)
{
intEventId = c_clsEventManagement.registerRefresh();
// Now add to vector if the desired card is being parsed.
if (!in_bolOnevent)
{
conditionalAddToVector(WmlTags.START_TAG_REFRESH + intEventId);
conditionalAddToVector(new Integer(intEventId).toString());
conditionalAddToVector(c_clsDeck.resolveEndTag (in_bytEventElem));
} // if
} // if-else
} // if
// Clean up.
strEndTag = null;
return intEventId;
} // readPrevOrResfreshEvent
/**
* Get the contents of an event element and add them to the event instance.
* <code>prev</code>, <code>refresh</code> contain zero no content.
* <code>go</code> contain zero or more <code>postfield</code> and
* <code>setvar</code> elements.
* @param in_intEventId ID of the event.
* @param in_byteEventType Type of event.
*/
public void readEventContents (int in_intEventId,
byte in_byteEventType)
throws IOException, NullPointerException, J2WapException
{
// Get the next byte.
byte bytId = (byte) (nextByte() & Wbxml.ELEMENT_TAG_ID);
byte bytAttStart;
boolean bolFoundNm;
boolean bolFoundVal;
String strName;
String strValue;
StringBuffer strBName = new StringBuffer ();
StringBuffer strBVal = new StringBuffer ();
while (bytId != Wbxml.END)
{
bolFoundNm = false;
bolFoundVal = false;
strBName.delete (0, strBName.length ());
strBVal.delete (0, strBName.length ());
if ((bytId == WmlTags.SETVAR) || (bytId == WmlTags.POSTFIELD))
{
// Process all attributes of the <setvar> or <postfield>.
bytAttStart = nextByte();
while (bytAttStart != Wbxml.END)
{
// Get the name and value attributes.
if (bytAttStart == WmlTags.BYTE_ATTR_NAME)
{
readRestOfAttr(strBName, false);
bolFoundNm = true;
}
else if (bytAttStart == WmlTags.BYTE_ATTR_VALUE)
{
readRestOfAttr(strBVal, false);
bolFoundVal = true;
}
else
{
// Invalid contents. Raise exception.
J2WapException clsExep =
new J2WapException ("Invalid event attribute.");
throw (clsExep);
} // if-else
bytAttStart = nextByte();
} // while
if (bolFoundNm && bolFoundVal)
{
if (in_byteEventType == WmlTags.GO)
c_bolLastGoHasVars = true;
// Add the element to the event instance.
if (bytId == WmlTags.SETVAR)
c_clsEventManagement.setVariable(
in_intEventId, strBName.toString(), strBVal.toString());
else if ( bytId == WmlTags.POSTFIELD &&
in_byteEventType == WmlTags.GO ) // Only <go> has postfields.
c_clsEventManagement.setPostfield(
in_intEventId, strBName.toString(), strBVal.toString());
} // if
} // if
else
{
// Invalid contents. Raise exception.
J2WapException clsExep = new J2WapException ("Invalid event contents.");
throw (clsExep);
} // if-else
bytId = (byte) (nextByte() & Wbxml.ELEMENT_TAG_ID);
} // while
// Clean up.
strName = null;
strValue = null;
} // readEventContents
/**
* Reads the next byte from the card.
* @return nextbyte fromthe deck's bytecode array.
*/
public byte nextByte () throws IOException
{
byte bytResult;
bytResult = c_clsDeck.nextByte();
if (bytResult == Wbxml.INVALID_BYTE)
return Wbxml.END;
return bytResult;
} // nextByte
/**
* Read the next inline string from the deck being parsed.
* @return Inline string from the bytecode array.
*/
public String readInlineString ()
throws IOException, NullPointerException, J2WapException
{
return c_clsDeck.readInlineString ();
} // readInlineString
/**
* Read the next multi-byte integer from the deck being parsed.
*/
public int readMultiByteInteger () throws IOException, NullPointerException
{
return c_clsDeck.readMultiByteInteger ();
} // readMultiByteInteger
/**
* Read a string from the string table.<p>
*/
String readStringFromStringTable () throws IOException, NullPointerException
{
return c_clsDeck.readStringFromStringTable();
} // readStringFromStringTable
/**
* Add the object to the card vector only if we are currently parsing the
* card that is to be drawn.<p>
*/
abstract void conditionalAddToVector (Object in_clsObject)
throws IOException, NullPointerException;
/**
* Record the end of an element. Check if the end tag relates to the deck
* element being parsed, if so flag to stop parsing of the bytecode.<p>
*/
protected void closeElement ()
{
c_intOpenElements--;
if (c_intOpenElements == 0)
c_bolFinishedParsing = true;
} // closeElement
/**
* Pop the top element of the c_clsStackEndTags stack.<p>
*/
protected String popEndTag() throws J2WapException
{
try
{
return (String) (c_clsStackEndTags.pop ());
}
catch (java.util.EmptyStackException z)
{
// There are unclosed elements. Rais an exception.
J2WapException clsExcep = new J2WapException (
"Error: Open elements exist in deck after parsing has completed.");
throw (clsExcep);
} // catch
} // popEndTag
/** Read attributes of an element.
* There are some attribute start tokens that include part or
* all of the attribute value as well. For example:
* type="accept" (0x38)
* href="http://" (0x4b)
*
* In the first example, the attribute start token also includes
* the whole attribute value.
*
* In the second example, the attribute start token also includes
* part of the attribute value. This means that there is a byte or
* bytes following, which contain the rest of the attribute value.
* @param in_bytElement byte representation of the element.
*/
public int readAttributes (byte in_bytElement)
throws IOException, NullPointerException, J2WapException
{
int intTemp;
switch (in_bytElement)
{
case WmlTags.BYTE_A_TAG:
readGoEventForA (); // The "href" attribute specifies a go event.
break;
case WmlTags.BYTE_START_CARD: // this should probably be called from readElement().
return readCardOrTemplateAttrs (true);
case WmlTags.BYTE_DO_TAG:
readDoAttributes ();
break;
default:
byte bytId = nextByte ();
while (bytId != Wbxml.END)
{
// Get a string representation of the attribute and add it to the
// vector if the desired card is being parsed.
conditionalAddToVector(readAttribute (bytId));
bytId = nextByte ();
} // while
// Have all the attributes. Add the end of attributes flag to vector.
conditionalAddToVector(WmlTags.ENDATTRIBS);
} // switch
return WmlTags.NO_EVENT;
} // readAttributes
/**
* Dummy: Declared here so that CardParser can redeclare it.
*/
protected void readGoEventForA ()
throws IOException, NullPointerException, J2WapException
{
boolean bytDummy = false;
} // readGoEventForA
abstract protected boolean parsingDesiredCard ();
abstract protected boolean parsingDesiredCardOrTemplate ();
abstract protected void readDoAttributes ()
throws IOException, NullPointerException, J2WapException;
abstract protected int parse( String in_clsCardId,
Vector in_clsVecstack,
Vector c_VecDosInCard,
boolean in_bolNavDirecFlag)
throws IOException, NullPointerException, J2WapException;
abstract protected boolean shouldResigterEvent ();
} // class Parser
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -