You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by ds...@apache.org on 2003/04/23 19:44:17 UTC
cvs commit: jakarta-tapestry/examples/wap/src/org/apache/tapestry/wap/quiz Global.java Home.java Quiz.java Scores.java Visit.java
dsolis 2003/04/23 10:44:17
Modified: examples/wap/context/WEB-INF/hello Hello.page Home.page
examples/wap/context/WEB-INF/quiz Home.page quiz.application
Quiz.page Scores.page
Added: examples/wap/src/org/apache/tapestry/wap/hello Hello.java
Home.java
examples/wap/src/org/apache/tapestry/wap/quiz Global.java
Home.java Quiz.java Scores.java Visit.java
Log:
Package structure similar to other examples
Revision Changes Path
1.3 +2 -2 jakarta-tapestry/examples/wap/context/WEB-INF/hello/Hello.page
Index: Hello.page
===================================================================
RCS file: /home/cvs/jakarta-tapestry/examples/wap/context/WEB-INF/hello/Hello.page,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Hello.page 25 Mar 2003 05:01:55 -0000 1.2
+++ Hello.page 23 Apr 2003 17:44:16 -0000 1.3
@@ -4,6 +4,6 @@
"-//Apache Software Foundation//Tapestry Specification 1.4//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_1_4.dtd">
-<page-specification class="wap.hello.Hello">
+<page-specification class="org.apache.tapestry.wap.hello.Hello">
<property-specification name="username" type="java.lang.String" persistent="no" initial-value="null"/>
</page-specification>
1.2 +2 -2 jakarta-tapestry/examples/wap/context/WEB-INF/hello/Home.page
Index: Home.page
===================================================================
RCS file: /home/cvs/jakarta-tapestry/examples/wap/context/WEB-INF/hello/Home.page,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Home.page 25 Mar 2003 04:37:50 -0000 1.1
+++ Home.page 23 Apr 2003 17:44:16 -0000 1.2
@@ -4,6 +4,6 @@
"-//Apache Software Foundation//Tapestry Specification 1.4//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_1_4.dtd">
-<page-specification class="wap.hello.Home">
+<page-specification class="org.apache.tapestry.wap.hello.Home">
<property-specification name="username" type="java.lang.String" persistent="yes" initial-value="null"/>
</page-specification>
1.2 +4 -4 jakarta-tapestry/examples/wap/context/WEB-INF/quiz/Home.page
Index: Home.page
===================================================================
RCS file: /home/cvs/jakarta-tapestry/examples/wap/context/WEB-INF/quiz/Home.page,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Home.page 25 Mar 2003 04:37:50 -0000 1.1
+++ Home.page 23 Apr 2003 17:44:16 -0000 1.2
@@ -4,7 +4,7 @@
"-//Apache Software Foundation//Tapestry Specification 1.4//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_1_4.dtd">
-<page-specification class="wap.quiz.Home">
+<page-specification class="org.apache.tapestry.wap.quiz.Home">
<component id="username" type="wml:Postfield">
<binding name="value" expression="username"/>
@@ -13,7 +13,7 @@
<component id="level" type="wml:SelectionField">
<binding name="value" expression="level"/>
- <binding name="model" expression="@wap.quiz.Home@LEVEL_MODEL"/>
+ <binding name="model" expression="@org.apache.tapestry.wap.quiz.Home@LEVEL_MODEL"/>
<binding name="name" expression="components.selectLevel.name"/>
</component>
@@ -24,7 +24,7 @@
<component id="selectLevel" type="wml:PropertySelection">
<static-binding name="name">level</static-binding>
- <binding name="model" expression="@wap.quiz.Home@LEVEL_MODEL"/>
+ <binding name="model" expression="@org.apache.tapestry.wap.quiz.Home@LEVEL_MODEL"/>
</component>
<component id="go" type="wml:Go">
1.2 +3 -3 jakarta-tapestry/examples/wap/context/WEB-INF/quiz/quiz.application
Index: quiz.application
===================================================================
RCS file: /home/cvs/jakarta-tapestry/examples/wap/context/WEB-INF/quiz/quiz.application,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- quiz.application 25 Mar 2003 05:21:27 -0000 1.1
+++ quiz.application 23 Apr 2003 17:44:16 -0000 1.2
@@ -8,9 +8,9 @@
<property name="org.apache.tapestry.template-extension" value="wml"/>
- <property name="org.apache.tapestry.global-class" value="wap.quiz.Global"/>
+ <property name="org.apache.tapestry.global-class" value="org.apache.tapestry.wap.quiz.Global"/>
- <property name="org.apache.tapestry.visit-class" value="wap.quiz.Visit"/>
+ <property name="org.apache.tapestry.visit-class" value="org.apache.tapestry.wap.quiz.Visit"/>
<library id="wml" specification-path="/org/apache/tapestry/wml/WML.library"/>
1.2 +2 -2 jakarta-tapestry/examples/wap/context/WEB-INF/quiz/Quiz.page
Index: Quiz.page
===================================================================
RCS file: /home/cvs/jakarta-tapestry/examples/wap/context/WEB-INF/quiz/Quiz.page,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Quiz.page 25 Mar 2003 04:37:50 -0000 1.1
+++ Quiz.page 23 Apr 2003 17:44:16 -0000 1.2
@@ -4,7 +4,7 @@
"-//Apache Software Foundation//Tapestry Specification 1.4//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_1_4.dtd">
-<page-specification class="wap.quiz.Quiz">
+<page-specification class="org.apache.tapestry.wap.quiz.Quiz">
<property-specification name="question" type="java.util.Map" persistent="yes" initial-value="null"/>
1.2 +2 -2 jakarta-tapestry/examples/wap/context/WEB-INF/quiz/Scores.page
Index: Scores.page
===================================================================
RCS file: /home/cvs/jakarta-tapestry/examples/wap/context/WEB-INF/quiz/Scores.page,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Scores.page 25 Mar 2003 04:37:50 -0000 1.1
+++ Scores.page 23 Apr 2003 17:44:16 -0000 1.2
@@ -4,7 +4,7 @@
"-//Apache Software Foundation//Tapestry Specification 1.4//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_1_4.dtd">
-<page-specification class="wap.quiz.Scores">
+<page-specification class="org.apache.tapestry.wap.quiz.Scores">
<property-specification name="newHighscore" type="boolean" persistent="no" initial-value="false"/>
<property-specification name="highscores" type="java.util.List" persistent="no" initial-value="null"/>
1.1 jakarta-tapestry/examples/wap/src/org/apache/tapestry/wap/hello/Hello.java
Index: Hello.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation", "Tapestry"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* or "Tapestry", nor may "Apache" or "Tapestry" appear in their
* name, without prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE TAPESTRY CONTRIBUTOR COMMUNITY
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.tapestry.wap.hello;
import org.apache.tapestry.wml.Deck;
/**
* @version $Id: Hello.java,v 1.1 2003/04/23 17:44:16 dsolis Exp $
* @author David Solis
*
**/
public abstract class Hello extends Deck
{
public abstract String getUsername();
public abstract void setUsername(String username);
}
1.1 jakarta-tapestry/examples/wap/src/org/apache/tapestry/wap/hello/Home.java
Index: Home.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation", "Tapestry"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* or "Tapestry", nor may "Apache" or "Tapestry" appear in their
* name, without prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE TAPESTRY CONTRIBUTOR COMMUNITY
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.tapestry.wap.hello;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.wml.Deck;
/**
* @version $Id: Home.java,v 1.1 2003/04/23 17:44:16 dsolis Exp $
* @author David Solis
*
**/
public abstract class Home extends Deck {
public void submit(IRequestCycle cycle)
{
Hello helloDeck = (Hello) cycle.getPage("Hello");
helloDeck.setUsername(getUsername());
cycle.activate(helloDeck);
}
public abstract String getUsername();
public abstract void setUsername(String username);
}
1.1 jakarta-tapestry/examples/wap/src/org/apache/tapestry/wap/quiz/Global.java
Index: Global.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation", "Tapestry"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* or "Tapestry", nor may "Apache" or "Tapestry" appear in their
* name, without prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE TAPESTRY CONTRIBUTOR COMMUNITY
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.tapestry.wap.quiz;
import org.apache.tapestry.ApplicationServlet;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.IResourceLocation;
import org.apache.tapestry.engine.IPropertySource;
import org.apache.tapestry.request.RequestContext;
import org.apache.tapestry.resource.ContextResourceLocation;
import org.apache.tapestry.util.StringSplitter;
import javax.servlet.ServletContext;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.Serializable;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Global object for the Quiz application.
* This class has the following responsabilities:
* <ul>
* <li>Read questions from the specified files</li>
* <li>Provide questions by index</li>
* <li>Keep high scores in memory</li>
* </ul>
*
* @version $Id: Global.java,v 1.1 2003/04/23 17:44:16 dsolis Exp $
* @author David Solis
*
**/
public class Global implements Serializable
{
private boolean init = false;
private int points[];
private String names[];
private static final List easyQuestions = new ArrayList();
private static final List mediumQuestions = new ArrayList();
private static final List hardQuestions = new ArrayList();
public static final int EASY_QUESTIONS = 1;
public static final int MEDIUM_QUESTIONS = 2;
public static final int HARD_QUESTIONS = 3;
public static final String EASY_LEVEL = "easy";
public static final String MEDIUM_LEVEL = "medium";
public static final String HARD_LEVEL = "hard";
public static final String QUESTION_KEY = "question";
public static final String ANSWER_KEY = "answer";
public static final String CHOICES_KEY = "choices";
public List getHighscores()
{
List result = new ArrayList();
for (int i = 0; i < 9; i++)
{
String name = names[i];
if (!"nobody".equals(name))
{
Map map = new HashMap();
map.put("name", name);
map.put("score", new Integer(points[i]));
result.add(map);
}
}
return result;
}
/**
* Checks if score is high scores
**/
public boolean isHighscore(int score)
{
return (score >= points[9]);
}
/**
* Checks if score is a new high score
**/
public boolean isNewHighscore(int score)
{
return (score > points[9]);
}
/**
* Adds score/name to the highscore table,
* returns position in highscore table or -1 if no highscore
**/
public int addHighscore(int score, String name)
{
int i = -1;
if (isNewHighscore(score))
{
for (i = 0; i <= 9; i++)
{
if (score > points[i])
break;
}
for (int j = 9; j >= i + 1; j--)
{
points[j] = points[j - 1];
names[j] = names[j - 1];
}
points[i] = score;
names[i] = name;
}
return i;
}
/**
* "getQuestionSet" method returns a number representing the right difficulty setting.
*
* @param level an <code>String</code> value
* @return an <code>int</code> value
*/
public int getQuestionSet(String level)
{
if (HARD_LEVEL.equals(level))
return HARD_QUESTIONS;
if (MEDIUM_LEVEL.equals(level))
return MEDIUM_QUESTIONS;
return EASY_QUESTIONS;
}
/**
* "getQuestion" method returns a String that contains the question, the alternatives and the correct answer.
*
* @param questionToBeAsked an <code>int</code> value
* @param questionSet an <code>int</code> value
* @return a <code>String</code> value
*/
public Map getQuestion(int questionToBeAsked, int questionSet)
{
String line;
List list;
switch (questionSet)
{
case EASY_QUESTIONS:
list = easyQuestions;
break;
case MEDIUM_QUESTIONS:
list = mediumQuestions;
break;
default:
list = hardQuestions;
break;
}
line = (String) list.get(questionToBeAsked);
StringSplitter splitter = new StringSplitter(';');
String[] result = splitter.splitToArray(line);
HashMap map = new HashMap();
map.put(QUESTION_KEY, result[0]);
int answer = Integer.parseInt(result[1]) - 1;
map.put(ANSWER_KEY, new Integer(answer));
int length = result.length - 2;
String[] choices = new String[length];
System.arraycopy(result, 2, choices, 0, length);
map.put(CHOICES_KEY, choices);
return map;
}
/**
* "getNumberOfQuestions" method returns the number of questions (Strings) in the questions table that is used.
*
* @param questionSet an <code>int</code> value
* @return an <code>int</code> value
*/
public int getNumberOfQuestions(int questionSet)
{
switch (questionSet)
{
case EASY_QUESTIONS:
return easyQuestions.size();
case MEDIUM_QUESTIONS:
return mediumQuestions.size();
default:
return hardQuestions.size();
}
}
public void initialize(IRequestCycle cycle)
{
if (!init)
{
RequestContext requestContext = cycle.getRequestContext();
ApplicationServlet servlet = requestContext.getServlet();
ServletContext context = servlet.getServletContext();
IPropertySource propertySource = cycle.getEngine().getPropertySource();
IResourceLocation webInfLocation = new ContextResourceLocation(context, "/WEB-INF/");
IResourceLocation webInfAppLocation = webInfLocation.getRelativeLocation(servlet.getServletName() + "/");
readQuestions(easyQuestions, webInfAppLocation, propertySource.getPropertyValue("easyquestionsfile"));
readQuestions(mediumQuestions, webInfAppLocation, propertySource.getPropertyValue("mediumquestiosfile"));
readQuestions(hardQuestions, webInfAppLocation, propertySource.getPropertyValue("hardquestionsfile"));
points = new int[10];
names = new String[10];
for (int i = 0; i <= 9; i++)
{
points[i] = 0;
names[i] = "nobody";
}
init = true;
}
}
/**
* This method reads the questions from the appropriate file to the appropriate Vector.
*
* @param questions a <code>Vector</code> value
* @param questionsFile a <code>String</code> value
* @exception java.io.IOException if an error occurs
*/
private void readQuestions(List questions, String questionsFile) throws IOException
{
BufferedReader reader = null;
String line;
reader = new BufferedReader(new FileReader(questionsFile));
while ((line = reader.readLine()) != null)
{
if (line.trim().equals("")) break;
questions.add(line);
}
}
private void readQuestions(List questions, IResourceLocation location, String filename)
{
IResourceLocation result = location.getRelativeLocation(filename);
URL url = result.getResourceURL();
try
{
readQuestions(questions, url.getFile());
}
catch (IOException e)
{
e.printStackTrace(System.err);
}
}
}
1.1 jakarta-tapestry/examples/wap/src/org/apache/tapestry/wap/quiz/Home.java
Index: Home.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation", "Tapestry"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* or "Tapestry", nor may "Apache" or "Tapestry" appear in their
* name, without prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE TAPESTRY CONTRIBUTOR COMMUNITY
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.tapestry.wap.quiz;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.form.IPropertySelectionModel;
import org.apache.tapestry.form.StringPropertySelectionModel;
import org.apache.tapestry.wml.Deck;
/**
* Home deck for the Quiz application.
*
* Quiz application is a game that is run on a server that people can connect to using a WAP phone.
* The game is highly customizable. You can add your own questions to simple text files without
* any knowledge of programming.
*
* @version $Id: Home.java,v 1.1 2003/04/23 17:44:16 dsolis Exp $
* @author David Solis
*
**/
public abstract class Home extends Deck
{
public static final IPropertySelectionModel LEVEL_MODEL = new StringPropertySelectionModel
(new String[] { Global.EASY_LEVEL, Global.MEDIUM_LEVEL, Global.HARD_LEVEL });
public void start(IRequestCycle cycle)
{
Global global = (Global) getGlobal();
global.initialize(cycle);
Visit visit = (Visit) getVisit();
String level = getLevel();
int questionSet = global.getQuestionSet(level);
String username = getUsername();
if (username == null || "".equals(username))
username = "newcomer";
visit.initialize(username, level, questionSet, global.getNumberOfQuestions(questionSet));
Quiz quizDeck = (Quiz) cycle.getPage("Quiz");
quizDeck.setQuestionNumber(0);
quizDeck.fetch();
cycle.activate(quizDeck);
}
public abstract String getUsername();
public abstract void setUsername(String username);
public abstract String getLevel();
public abstract void setLevel(String level);
}
1.1 jakarta-tapestry/examples/wap/src/org/apache/tapestry/wap/quiz/Quiz.java
Index: Quiz.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation", "Tapestry"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* or "Tapestry", nor may "Apache" or "Tapestry" appear in their
* name, without prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE TAPESTRY CONTRIBUTOR COMMUNITY
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.tapestry.wap.quiz;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.form.IPropertySelectionModel;
import org.apache.tapestry.form.StringPropertySelectionModel;
import org.apache.tapestry.wml.Deck;
import java.util.Map;
/**
* Quiz deck for the Quiz application.
*
* @version $Id: Quiz.java,v 1.1 2003/04/23 17:44:16 dsolis Exp $
* @author David Solis
*
**/
public abstract class Quiz extends Deck
{
int questionNumber;
public void fetch()
{
Visit visit = (Visit) getVisit();
Global global = (Global) getGlobal();
Map question = global.getQuestion(getQuestionNumber(), visit.getQuestionSet());
setQuestion(question);
}
public IPropertySelectionModel getChoiceModel()
{
return new StringPropertySelectionModel((String[])getQuestion().get(Global.CHOICES_KEY));
}
public void process(IRequestCycle cycle)
{
Visit visit = (Visit) getVisit();
int rightAnswer = ((Integer)getQuestion().get(Global.ANSWER_KEY)).intValue();
if (getChoice() == rightAnswer)
{
int points = visit.getPoints();
points += visit.getQuestionSet();
visit.setPoints(points);
}
int questionNumber = getQuestionNumber() + 1;
if (questionNumber < visit.getNumberOfQuestions())
{
setQuestionNumber(questionNumber);
fetch();
}
else
{
Scores scoresDeck = (Scores)cycle.getPage("Scores");
Global global = (Global) getGlobal();
boolean isNewHighscore = global.addHighscore(visit.getPoints(), visit.getUsername()) != -1;
scoresDeck.setNewHighscore(isNewHighscore);
scoresDeck.setHighscores(global.getHighscores());
cycle.activate(scoresDeck);
}
}
protected void initialize()
{
questionNumber = 0;
}
public int getQuestionNumber()
{
return questionNumber;
}
public void setQuestionNumber(int questionNumber)
{
this.questionNumber = questionNumber;
fireObservedChange("questionNumber", questionNumber);
}
public abstract Map getQuestion();
public abstract void setQuestion(Map question);
public abstract int getChoice();
}
1.1 jakarta-tapestry/examples/wap/src/org/apache/tapestry/wap/quiz/Scores.java
Index: Scores.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation", "Tapestry"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* or "Tapestry", nor may "Apache" or "Tapestry" appear in their
* name, without prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE TAPESTRY CONTRIBUTOR COMMUNITY
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.tapestry.wap.quiz;
import org.apache.tapestry.wml.Deck;
import java.util.List;
/**
* Scores deck for the Quiz application.
*
* @version $Id: Scores.java,v 1.1 2003/04/23 17:44:16 dsolis Exp $
* @author David Solis
*
**/
public abstract class Scores extends Deck
{
public abstract List getHighscores();
public abstract void setHighscores(List value);
public abstract boolean isNewHighscore();
public abstract void setNewHighscore(boolean value);
}
1.1 jakarta-tapestry/examples/wap/src/org/apache/tapestry/wap/quiz/Visit.java
Index: Visit.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation", "Tapestry"
* must not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* or "Tapestry", nor may "Apache" or "Tapestry" appear in their
* name, without prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE TAPESTRY CONTRIBUTOR COMMUNITY
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.tapestry.wap.quiz;
import java.io.Serializable;
/**
* Visit object for the Quiz application.
*
* @version $Id: Visit.java,v 1.1 2003/04/23 17:44:17 dsolis Exp $
* @author David Solis
*
**/
public class Visit implements Serializable
{
private String username;
private String level;
private int points;
private int questionSet;
private int numberOfQuestions;
public void initialize(String username, String level, int questionSet, int numberOfQuestions)
{
this.username = username;
this.level = level;
this.questionSet = questionSet;
this.numberOfQuestions = numberOfQuestions;
points = 0;
}
public int getNumberOfQuestions()
{
return numberOfQuestions;
}
public void setNumberOfQuestions(int numberOfQuestions)
{
this.numberOfQuestions = numberOfQuestions;
}
public int getQuestionSet()
{
return questionSet;
}
public void setQuestionSet(int questionSet)
{
this.questionSet = questionSet;
}
public void incPoints()
{
points++;
}
public int getPoints()
{
return points;
}
public void setPoints(int points)
{
this.points = points;
}
public String getLevel()
{
return level;
}
public void setLevel(String level)
{
this.level = level;
}
public String getUsername()
{
return username;
}
public void setUsername(String user)
{
this.username = user;
}
}