📄 browsercore.java
字号:
* BrowserCore creates an instance of TemplateParser and parses the
* template.
* <li>Sets the CardParser and TemplateParser objects to null.
* <li>If errors were encountered while parsing the card or template, a WML
* deck with an error message is created and passed as a parameter to
* DisplayEngine.drawCard(). If there were no errors, the parsed card is
* passed as a parameter to DisplayEngine.drawCard().
* </ul>
*/
public synchronized void processEventsLoop(int intEventID)
throws IOException
{
// Private variables
/** The binary encoded WML deck. */
byte[] bytDeck = null;
/**
* Flags whether errors were encountered in the parsing of the card or
* template.
*/
boolean c_bolNoErrors;
/** Flags if the user has navigated to a URL yet. */
boolean bolFirstURL = true;
/** Reference to the event instance that is being processed. */
EventInstance clsEI;
/** Reference to the GO event instance that is being processed. */
GoEventInstance clsGoEI = null;
/** The parser that parses cards. */
CardParser clsCardParser;
/**
* Holds the previous URL that was navigated to. This is used for adding
* URLs to the history.
*/
String strPrevURL = null;
c_clsRTime.gc();
while (intEventID != 0)
{
c_bolNoErrors = true;
// Get the event instance that matched the returned event
clsEI = (EventInstance)
c_clsEventManagement.getEventInstance(intEventID, c_clsBrowserContext);
// And execute the event instance
switch (clsEI.getEventType())
{
case 1: // go
clsGoEI = (GoEventInstance)clsEI;
// Push the new card onto the history stack
if (strPrevURL != null && !strPrevURL.equals(""))
{
if (!strPrevURL.startsWith("http://"))
c_clsBrowserContext.pushCard("http://" + strPrevURL);
else
c_clsBrowserContext.pushCard(strPrevURL);
} // if
strPrevURL = null;
// See if we need to get a new deck
if (c_clsCurrentDeck == null)
{
c_clsCurrentDeck = new CurrentDeck();
c_clsNetLayer.c_clsCurrDeck = c_clsCurrentDeck;
} // if
String clsStrURL = clsGoEI.getURL();
/* Set "strPrevURL" so that when a GO is next executed, this URL
* will be pushed onto the history. If this is the first URL for the
* session, we want to add the URL entered by the user to the history.
*/
if (bolFirstURL)
{
strPrevURL = clsStrURL;
bolFirstURL = false;
}
else
strPrevURL = c_clsCurrentDeck.getAbsoluteURL();
if (c_clsCurrentDeck.requireNewDeck(
c_clsBrowserCore.subVars(clsStrURL)))
{
bytDeck = processNewDeck(
c_clsBrowserCore.subVars(c_clsCurrentDeck.getAbsoluteURL()),
clsGoEI);
} // if
// Kill Event Management now that we are a in new process
c_clsEventManagement = null;
c_clsEventManagement = new EventManagement();
clsCardParser = new CardParser();
clsCardParser.init(c_clsBrowserCore,
c_clsCurrentDeck,
c_clsEventManagement,
c_clsBrowserContext);
c_clsVecCard = new Vector(1,1);
// Parse the card. Try-catch used for exception processing.
try
{
intEventID = clsCardParser.parse(
c_clsCurrentDeck.getFragmentID(),
c_clsVecCard,
c_clsVecDosInCard,
WmlTags.ONENTER_FORWARDS);
}
catch (J2WapException e)
{
/*
* Convert the contents of the card vector to a single string so
* that it can be placed in one element of the card vector.
*/
String clsStrCard = c_clsVecCard.toString();
c_clsVecCard.removeAllElements();
c_clsVecCard.addElement("<card>");
c_clsVecCard.addElement("<p>");
c_clsVecCard.addElement(
"Malformed card. The following error was encountered: ");
c_clsVecCard.addElement(e.getMessage());
c_clsVecCard.addElement("</p>");
c_clsVecCard.addElement("*** Contents of parsed card:");
c_clsVecCard.addElement(clsStrCard);
// </card> is added later on.
c_bolNoErrors = false;
intEventID = WmlTags.NO_EVENT;
setOntimerId(0);
} // try-catch
/* If no intrinsic event was fired and the deck has a tempate,
* parse it.
*/
if (c_bolNoErrors && intEventID == WmlTags.NO_EVENT &&
c_clsCurrentDeck.hasTemplate())
{
try
{
TemplateParser clsTemlateParser = new TemplateParser ();
clsTemlateParser.init(c_clsBrowserCore,
c_clsCurrentDeck,
c_clsEventManagement,
c_clsBrowserContext);
intEventID = clsTemlateParser.parse(
c_clsCurrentDeck.getFragmentID(),
c_clsVecCard,
c_clsVecDosInCard,
WmlTags.ONENTER_FORWARDS);
clsTemlateParser = null;
}
catch (J2WapException e)
{
/* Convert the contents of the card vector to a single string so
* that it can be placed in one element of the card vector.
*/
String clsStrCard = c_clsVecCard.toString();
c_clsVecCard.removeAllElements();
c_clsVecCard.addElement("<card>");
c_clsVecCard.addElement("<p>");
c_clsVecCard.addElement(
"Malformed card. The following error was encountered: ");
c_clsVecCard.addElement(e.getMessage());
c_clsVecCard.addElement("</p>");
c_clsVecCard.addElement("*** Contents of parsed card:");
c_clsVecCard.addElement(clsStrCard);
// </card> is added later on.
c_bolNoErrors = false;
intEventID = WmlTags.NO_EVENT;
setOntimerId(0);
} // try-catch
} // if
// Add the end of card tag to the card vector.
c_clsVecCard.addElement(WmlTags.END_TAG_CARD);
// Garbage collection.
clsCardParser = null;
c_clsRTime.gc ();
// Now delete content from do vector
c_clsVecDosInCard.removeAllElements ();
/**
* Call draw card if we don't already have an event
* which is the event id of the ontimer event.
*/
if (intEventID == WmlTags.NO_EVENT)
intEventID = c_clsDisplayEngine.drawCard(c_clsVecCard,
c_clsEventManagement,
c_intOntimerId);
break;
case 2: // prev
/*
* Previous will simply pop off the history URL,
* And aregister that as the next go event
*/
clsEI = null;
if (c_clsBrowserCore.historyHasURLs())
{
strPrevURL = c_clsBrowserContext.popCard();
intEventID = c_clsEventManagement.registerGo(strPrevURL,
false,
"GET",
null);
// Stop the URL from being added to history when the GO is executed.
strPrevURL = null;
}
else if (c_clsVecCard == null)
{
intEventID = c_clsDisplayEngine.drawCard(c_clsBrowserCore.c_clsStartWml,
c_clsEventManagement,
c_intOntimerId);
}
else
{
intEventID = c_clsDisplayEngine.drawCard(c_clsVecCard,
c_clsEventManagement,
c_intOntimerId);
} // if-else
break;
case 3: // refresh
/**
* Refresh needs to redraw the card with the current vector
*/
clsEI = null;
intEventID = c_clsDisplayEngine.drawCard(c_clsVecCard,
c_clsEventManagement,
c_intOntimerId);
break;
case 4: // noop
/**
* We should NEVER actually terminate a function to perform
* a noop event - they should be ignored, and normal ui
* processing should continue.
*/
System.exit(-1);
break;
} // switch
// Call garbage collection after a major event
Runtime.getRuntime().gc();
} // While intEventID != 0
} // processEventsLoop
/**
* Get the WML deck from the WAP gateway and save the bytecode in the
* <code>CurrentDeck</code> object.
* @param in_clsDeckURL The absolute URL of the required WML deck.
* @param in_clsGoEvent The <code>GoEventInstance</code> that contains
* details of the GO.
* @return The WML deck's bytecode.
*/
private byte[] processNewDeck (String in_clsDeckURL,
GoEventInstance in_clsGoEvent)
throws IOException
{
String strPostfield =
subVars(in_clsGoEvent.getPostfieldStr(c_clsBrowserContext));
byte deckByteArr[] = c_clsNetLayer.doConnection(
c_clsGateway,
in_clsDeckURL,
in_clsGoEvent.getMethod(),
1,
strPostfield);
// Clear all variables in the browser context.
c_clsBrowserContext.clearVariables();
c_clsCurrentDeck.getDeck(deckByteArr, in_clsDeckURL);
return deckByteArr;
} // processNewDeck
} // class ProcessEvents
} // class BrowserCore
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -