📄 wmldeck.java
字号:
package com.aplpi.wapreview;
import java.net.URL;
import java.util.Hashtable;
import java.util.Stack;
import java.util.Enumeration;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.io.PushbackInputStream;
import java.io.IOException;
/**
*
* see http://wapreview.sourceforge.net
*
* Copyright (C) 2000 Robert Fuller, Applepie Solutions Ltd.
* <robert.fuller@applepiesolutions.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* This class represents a WmlDeck containing WmlCards.
* The deck is constructed by the WmlDeckBuilder, based
* upon the content of a WML deck retrieved from a URL.
* The deck contains all the cards within the WML deck,
* and provides common resources which include:
*
* @author Copyright (c) 2000, Applepie Solutions Ltd.
* @author Written by Robert Fuller <robert.fuller@applepiesolutions.com>
*
* <ul>
* <li> Variable expansion
* <li> Template level events.
* </ul>
* @see WmlDeckBuilder
*/
public class WmlDeck implements WmlDeckInterface{
public int unknownCards = 0;
private Hashtable cards;
private Stack deck;
private Stack hrefs;
private Hashtable variables;
private String onenterforward;
private String onenterbackward;
private String ontimer;
public WmlCardInterface currentcard;
public WmlCard firstcard;
public String url;
private String sourcecode;
private URL sourceUrl = null;
private Stack tasks;
private Stack htasks;
private String targetCard = null;
public String awaitingtask = null;
/* variable substitiution state model */
private final static int st_outvar = 0;
private final static int st_beginvar = 1;
private final static int st_invar = 2;
private final static int st_esc = 3;
/* variable escaping */
public final static int V_NOESC = 0;
public final static int V_ESCAPE = 1;
public final static int V_UNESC = 2;
/**
* Constructs and initialises new deck, identifying the URL used
* as a source.
*
* @param U The source url for this deck.
*/
public WmlDeck(URL U){
sourceUrl = U;
String u = sourceUrl.toString();
int i;
// a '#' in the url means there is a target card
if((i=u.indexOf('#'))>-1){
int j;
if(((j=u.indexOf('?'))>i)||((j=u.length())>0)){
if(j>i+1){
targetCard=u.substring(i+1,j);
//System.err.println("target card is["+targetCard+"]");
}
}
}
this.init();
}
/**
* Constructs and initialises a new deck.
*/
public WmlDeck(){
this.init();
}
/**
* Initialise the new deck.
*/
private void init(){
cards = new Hashtable();
//history = new Stack();
deck = new Stack();
tasks = new Stack();
htasks = new Stack(); // temporary for during construction.
variables = new Hashtable();
hrefs = new Stack();
onenterforward = new String();
onenterbackward = new String();
ontimer = new String();
currentcard = new WmlTemplate(this);
}
/**
* Sets a variable which is shared among all the cards
* in the deck.
*
* @param varName The name of the variable
* @param varValue The value to assign to the named variable
*/
public String setVar(String varName, String varValue){
//System.err.println("setVar(\""+varName+"\",\""+varValue+"\");");
variables.put(varName, varValue);
return(varName);
}
/**
* Returns the value of the named variable.
*
* @param varName The name of the variable.
* parses, but ignores variable escaping $(foo:escape)
*/
public String getVar(String varName){
//System.err.println("getVar("+varName+")");
// remove surrounding ()'s
if(varName.startsWith("(")){
varName = varName.substring(1);
}
if(varName.endsWith(")")){
varName = varName.substring(0, varName.length()-1);
}
if(varName.indexOf(':')>0){
// ignore escaping for now
varName = varName.substring(0,varName.indexOf(':')-1);
}
String val = (String)variables.get(varName);
if(val == null){val = "";}
return val;
}
/**
* Returns the javascript representation of the ontimer
* event for this deck.
* This method is invoked by cards which do not have their
* own ontimer event specified.
*/
public String ontimer(){
return ontimer;
}
/**
* Sets the source wml for this deck
*/
public void wml(String source){
sourcecode = source;
}
/**
* Returns the source wml for this deck
*/
public String wml(){
return(sourcecode==null?"No source is available":sourcecode);
}
/**
* Returns the javascript representation of the onenterforward
* event for this deck.
* This method is invoked by cards which do not have their
* own ontimer event specified.
*/
public String onenterforward(){
return onenterforward;
}
/**
* Returns the javascript representation of the onenterbackward
* event for this deck.
* This method is invoked by cards which do not have their
* own ontimer event specified.
*/
public String onenterbackward(){
return onenterbackward;
}
/**
* Sets the javascript representation of the onenterforward
* event for this deck.
* This method may be invoked by the WmlDeckBuilder during
* construction of this deck.
*/
public void onenterforward(String s){
onenterforward = new String(s);
}
/**
* Sets the javascript representation of the onenterbackward
* event for this deck.
* This method may be invoked by the WmlDeckBuilder during
* construction of this deck.
*/
public void onenterbackward(String s){
onenterbackward = new String(s);
}
/**
* Sets the javascript representation of the ontimer
* event for this deck.
* This method may be invoked by the WmlDeckBuilder during
* construction of this deck.
*/
public void ontimer(String s){
ontimer=s;
}
/**
* Returns the named card. If the named card cannot be found,
* a new card indicating this situation is constructed and returned.
*
* @param cardName The name of the wanted card.
*/
public WmlCard getCard(String cardName){
// return an "unknown card" or the sought one.
WmlCard card = new WmlCard(this, "unknown");
card.cardData("<center><b>card "+cardName+" not found!</b></center>");
//if(cards.contains(cardName)){
WmlCard foundcard = (WmlCard)cards.get(cardName);
if(foundcard != null){
card = foundcard;
}
return card;
}
/**
* Add the specified card onto this Deck.
* An explicit typecast is to convert the card from
* an Object into a WmlCard in order to avoid
* circular dependencies between WmlCardInterface
* and WmlDeckInterface. This method simply invokes
* the addCard(WmlCard card) method after performing
* the typecast.
* This method may be invoked by the WmlDeckBuilder during
* construction of this deck.
*
* @param card The card to be added to the deck.
*/
public void addCard(Object card){
this.addCard((WmlCard)card);
}
/**
* Add the specified card onto this Deck.
* This method may be invoked by the WmlDeckBuilder during
* construction of this deck.
*
* @param card The card to be added to the deck.
*/
public void addCard(WmlCard card){
deck.push(card);
cards.put(card.name(), card);
currentcard = card;
if(firstcard==null){
firstcard=card;
}else if(targetCard!=null && targetCard.equals(card.name())){
// target card was known by #id in url...
firstcard=card;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -