📄 cardparser.java
字号:
{
/* 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 set 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 (c_bolFoundDesiredCard)
{
// Register the Go event.
int intGoId = c_clsEventManagement.registerGo(
clsStrHref, bolSendRef, clsStrMethod, clsStrEncType);
conditionalAddToVector("href=" + intGoId);
} // if
} // readGoEventForA
/**
* Check if the card is the card that is to be drawn.
* @param String in_strId ID of the card that has been found in the binary
* encoded WML deck.
*/
protected void checkCard (String in_strId)
throws IOException, NullPointerException, J2WapException
{
// Mark the current position, then look at the next two bytes to see if
// the card is the one that we are after. i.e. Check the id attribute.
int intCardPos = c_clsDeck.posOfNextByte ();
byte bytNextByte = nextByte ();
if (bytNextByte == WmlTags.BYTE_ID)
{
// Card Id is an inline string, so 0x03 (Inline string follows)
// byte will be next. Get past it to the id value.
bytNextByte = nextByte ();
// This is the "id" attribute name. Now see if this is the right card.
String clsStrCardId = readInlineString ();
if (in_strId.toLowerCase().equals (clsStrCardId.toLowerCase()))
c_bolFoundDesiredCard = true;
} // if
// Reset the next byte to be read in the bytecode to where it was
// before the the card's "id" value was read.
c_clsDeck.setPosOfNextBytecode (intCardPos);
} // CheckCard
/**
* Determine if the <anchor> element can be expressed as an <a> element,
* and if so add it to the stack as an <a> element.<p>
*/
public void addAnchorToVector ()
{
Object clsElem = null;
int intNumElems = c_clsTempAnchorVec.size ();
if ((c_intNumOfGoTagsInAnchor != 1) ||
(c_intNumOfNonGoTagsInAnchor != 0) || c_bolLastGoHasVars)
{
// Cannot express the <anchor> as an <a>. Add to vector as is.
for (int i=0; i<intNumElems; i++)
c_clsVecStack.addElement (c_clsTempAnchorVec.elementAt(i));
c_clsVecStack.addElement (WmlTags.END_TAG_ANCHOR);
} // if
else
{
int intGoEIdPos = 0; // Position of the href attribute.
// Add to vector as an <a> element.
for (int i=0; i<intNumElems; i++)
{
clsElem = c_clsTempAnchorVec.elementAt(i);
if (clsElem.equals (WmlTags.START_TAG_ANCHOR))
{
c_clsVecStack.addElement (WmlTags.START_TAG_A);
intGoEIdPos = c_clsVecStack.size ();
} // if
else if (clsElem.equals (WmlTags.START_TAG_GO))
{
// Skip to the GO's event ID and add it to the card vector.
c_clsVecStack.insertElementAt (
"href=" + c_clsTempAnchorVec.elementAt(++i), intGoEIdPos);
i++; // Get past the </go>.
}
else // Content. Add it to the card vector.
c_clsVecStack.addElement (c_clsTempAnchorVec.elementAt(i));
} // for
c_clsVecStack.addElement (WmlTags.END_TAG_A);
} // if-else
// Reset <anchor> counts and flag.
c_bolInAnchorElement = false;
c_intNumOfGoTagsInAnchor = 0;
c_intNumOfNonGoTagsInAnchor = 0;
c_clsTempAnchorVec.removeAllElements();
} // addAnchorToVector
/**
* Add the object to the card vector only if we are currently parsing the
* card that is to be drawn.
* @param in_clsObject Object to be conditionally added to the vector.
*/
public void conditionalAddToVector (Object in_clsObject)
throws IOException, NullPointerException
{
if (in_clsObject != null)
{
if (c_bolFoundDesiredCard && !c_clsStackEndTags.empty())
{
if (c_bolInAnchorElement)
c_clsTempAnchorVec.addElement (in_clsObject);
else
c_clsVecStack.addElement (in_clsObject);
} // if
} // if
} // conditionalAddToVector
/**
* Redefines method on <code>Parser</code>.
*
* Indicates whether the desired card has been found and it's contents are
* being parsed.
* @return True is the desired card's contents are being parsed.
*/
public boolean parsingDesiredCard ()
{
return c_bolFoundDesiredCard;
} // parsingDesiredCard
/**
* Redefines method on <code>Parser</code>.
*
* Indicates whether the desired card has been found and it's contents are
* being parsed.
* @return True is the desired card's contents are being parsed.
*/
public boolean parsingDesiredCardOrTemplate ()
{
return c_bolFoundDesiredCard;
} // parsingDesiredCardOrTemplate
/**
* Read attributes of a <do> element. When it encounters the "name" attribute
* it is added to "c_clsVecDosInCard". If "name" is not found, name defaults
* to the value of the "type" attribute.<p>
*/
public void readDoAttributes ()
throws IOException, NullPointerException, J2WapException
{
boolean bolFoundName = false;
byte bytId = nextByte ();
int intDelim;
String clsStrAttrStart = new String ();
String clsStrAttrVal = new String ();
String clsStrAttr = new String ();
String clsStrType = null;
while (bytId != Wbxml.END)
{
// Get a string representation of the attribute.
clsStrAttr = readAttribute (bytId);
// Extract the attribute start value for inspection.
intDelim = clsStrAttr.indexOf (ATTR_DELIM);
clsStrAttrStart = clsStrAttr.substring (0, intDelim);
if (c_bolFoundDesiredCard)
{
if (clsStrAttrStart.equals ("name"))
{
// Check if the do has already been defined in the card. If not add it.
bolFoundName = true;
clsStrAttrVal = clsStrAttr.substring (intDelim + ATTR_DELIM_LEN,
clsStrAttr.length()-1);
if (c_bolFoundDesiredCard && !c_clsVecDosInCard.contains (clsStrAttrVal))
c_clsVecDosInCard.addElement (clsStrAttrVal);
else
{
// Error. Card has more than one <do> with the same name.
J2WapException clsExep = new J2WapException ("Found <do> with the " +
"same name as another <do> in the same card");
throw (clsExep);
} // if-else
} // if
else if (clsStrAttrStart.equals ("type"))
clsStrType = clsStrAttr.substring (intDelim + ATTR_DELIM_LEN,
clsStrAttr.length()-1);
}
conditionalAddToVector (clsStrAttr);
bytId = nextByte ();
} // while
// If the "name" has not been found default it to the "type" attribute.
if (c_bolFoundDesiredCard && !bolFoundName && (clsStrType != null))
{
//if (c_bolFoundDesiredCard && !c_clsVecDosInCard.contains (clsStrType))
if (!c_clsVecDosInCard.contains (clsStrType))
{
c_clsVecDosInCard.addElement (clsStrType);
conditionalAddToVector ("name=" + clsStrType + "\"");
}
else
{
// Error. Card has more than one <do> with the same name.
J2WapException clsExep = new J2WapException ("Found <do> with the " +
"same name as another <do> in the same card");
throw (clsExep);
} // if-else
} // if
// Have all the attributes. Add the end of attributes flag to vector.
conditionalAddToVector(WmlTags.ENDATTRIBS);
} // readDoAttributes
/**
* Indicates if an event should be registered.
* @return TRUE if an event should be registered.
*/
protected boolean shouldResigterEvent ()
{
return c_bolFoundDesiredCard;
} // shouldResigterEvent
/**
* Parses the attributes of an OPTION element.
*/
private void readOptionAttrs ()
throws IOException, NullPointerException, J2WapException
{
int intAttrDelim;
int intEventId = 0;
String clsStrAttr = null;
String clsStrAttrValue = null;
byte bytId = nextByte ();
while (bytId != Wbxml.END)
{
if (bytId == WmlTags.BYTE_ONPICK)
{
// The rest of the attribute is the href. Use it to register the GO.
StringBuffer clsSBufHref = new StringBuffer();
readRestOfAttr (clsSBufHref, true);
intEventId = c_clsEventManagement.registerGo (clsSBufHref.toString(),
false, null, null);
conditionalAddToVector ("onpick=" + intEventId);
clsSBufHref = null; // clean up.
}
else
{
clsStrAttr = new String (readAttribute (bytId));
intAttrDelim = clsStrAttr.indexOf ("=");
clsStrAttrValue = clsStrAttr.substring(intAttrDelim+1,
clsStrAttr.length()-1);
conditionalAddToVector (clsStrAttr); // Add attribute to vector.
} // if-else
bytId = nextByte ();
} // while
// Have all the attributes. Add the end of attributes flag to vector.
conditionalAddToVector(WmlTags.ENDATTRIBS);
//clean up.
clsStrAttr = null;
clsStrAttrValue = null;
} // readOptionAttrs
} // class CardParser
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -