Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
58 changed files
with
3,531 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="src" output="test-classes" path="test"/> | ||
<classpathentry kind="con" path="com.google.appengine.eclipse.core.GAE_CONTAINER"/> | ||
<classpathentry kind="con" path="com.google.gwt.eclipse.core.GWT_CONTAINER"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
<classpathentry kind="output" path="war/WEB-INF/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,2 @@ | ||
*.class | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
gwt-unitCache | ||
test-classes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>shifts-solver</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.wst.common.project.facet.core.builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>com.google.gdt.eclipse.core.webAppProjectValidator</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>com.google.appengine.eclipse.core.gaeProjectChangeNotifier</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>com.google.appengine.eclipse.core.projectValidator</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>com.google.gwt.eclipse.core.gwtProjectValidator</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>com.google.appengine.eclipse.core.enhancerbuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>com.google.appengine.eclipse.core.gaeNature</nature> | ||
<nature>com.google.gwt.eclipse.core.gwtNature</nature> | ||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
eclipse.preferences.version=1 | ||
filesCopiedToWebInfLib=appengine-api-1.0-sdk-1.9.26.jar|appengine-api-labs.jar|appengine-endpoints-deps.jar|appengine-endpoints.jar|appengine-jsr107cache-1.9.26.jar|asm-4.0.jar|datanucleus-api-jdo-3.1.3.jar|datanucleus-api-jpa-3.1.3.jar|datanucleus-appengine-2.1.2.jar|datanucleus-core-3.1.3.jar|geronimo-jpa_2.0_spec-1.0.jar|jdo-api-3.0.1.jar|jsr107cache-1.1.jar|jta-1.1.jar | ||
gaeDatanucleusVersion=v2 | ||
gaeHrdEnabled=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
eclipse.preferences.version=1 | ||
warSrcDir=war | ||
warSrcDirIsOutput=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eclipse.preferences.version=1 | ||
filesCopiedToWebInfLib=gwt-servlet.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<faceted-project> | ||
<installed facet="java" version="1.7"/> | ||
</faceted-project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig"> | ||
|
||
<persistence-manager-factory name="transactions-optional"> | ||
<property name="javax.jdo.PersistenceManagerFactoryClass" | ||
value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory"/> | ||
<property name="javax.jdo.option.ConnectionURL" value="appengine"/> | ||
<property name="javax.jdo.option.NontransactionalRead" value="true"/> | ||
<property name="javax.jdo.option.NontransactionalWrite" value="true"/> | ||
<property name="javax.jdo.option.RetainValues" value="true"/> | ||
<property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/> | ||
<property name="datanucleus.appengine.singletonPMFForName" value="true"/> | ||
</persistence-manager-factory> | ||
</jdoconfig> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<persistence xmlns="http://java.sun.com/xml/ns/persistence" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence | ||
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"> | ||
|
||
<persistence-unit name="transactions-optional"> | ||
<provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider> | ||
<properties> | ||
<property name="datanucleus.NontransactionalRead" value="true"/> | ||
<property name="datanucleus.NontransactionalWrite" value="true"/> | ||
<property name="datanucleus.ConnectionURL" value="appengine"/> | ||
</properties> | ||
</persistence-unit> | ||
</persistence> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
When updating your version of GWT, you should also update this DTD reference, | ||
so that your app can take advantage of the latest GWT module capabilities. | ||
--> | ||
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.1//EN" | ||
"http://google-web-toolkit.googlecode.com/svn/tags/2.5.1/distro-source/core/src/gwt-module.dtd"> | ||
<module rename-to='shifts_solver'> | ||
<!-- Inherit the core Web Toolkit stuff. --> | ||
<inherits name='com.google.gwt.user.User'/> | ||
|
||
<!-- Inherit the default GWT style sheet. You can change --> | ||
<!-- the theme of your GWT application by uncommenting --> | ||
<!-- any one of the following lines. --> | ||
<inherits name='com.google.gwt.user.theme.clean.Clean'/> | ||
<!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> --> | ||
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> --> | ||
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> --> | ||
|
||
<!-- Other module inherits --> | ||
|
||
<!-- Specify the app entry point class. --> | ||
<entry-point class='com.mindforger.shiftsolver.client.Shifts_solver'/> | ||
|
||
<!-- Specify the paths for translatable code --> | ||
<source path='client'/> | ||
<source path='shared'/> | ||
|
||
</module> |
12 changes: 12 additions & 0 deletions
12
src/com/mindforger/shiftsolver/client/GreetingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.mindforger.shiftsolver.client; | ||
|
||
import com.google.gwt.user.client.rpc.RemoteService; | ||
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; | ||
|
||
/** | ||
* The client side stub for the RPC service. | ||
*/ | ||
@RemoteServiceRelativePath("greet") | ||
public interface GreetingService extends RemoteService { | ||
String greetServer(String name) throws IllegalArgumentException; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/com/mindforger/shiftsolver/client/GreetingServiceAsync.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.mindforger.shiftsolver.client; | ||
|
||
import com.google.gwt.user.client.rpc.AsyncCallback; | ||
|
||
/** | ||
* The async counterpart of <code>GreetingService</code>. | ||
*/ | ||
public interface GreetingServiceAsync { | ||
void greetServer(String input, AsyncCallback<String> callback) | ||
throws IllegalArgumentException; | ||
} |
152 changes: 152 additions & 0 deletions
152
src/com/mindforger/shiftsolver/client/Shifts_solver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package com.mindforger.shiftsolver.client; | ||
|
||
import com.mindforger.shiftsolver.shared.FieldVerifier; | ||
import com.google.gwt.core.client.EntryPoint; | ||
import com.google.gwt.core.client.GWT; | ||
import com.google.gwt.event.dom.client.ClickEvent; | ||
import com.google.gwt.event.dom.client.ClickHandler; | ||
import com.google.gwt.event.dom.client.KeyCodes; | ||
import com.google.gwt.event.dom.client.KeyUpEvent; | ||
import com.google.gwt.event.dom.client.KeyUpHandler; | ||
import com.google.gwt.user.client.rpc.AsyncCallback; | ||
import com.google.gwt.user.client.ui.Button; | ||
import com.google.gwt.user.client.ui.DialogBox; | ||
import com.google.gwt.user.client.ui.HTML; | ||
import com.google.gwt.user.client.ui.Label; | ||
import com.google.gwt.user.client.ui.RootPanel; | ||
import com.google.gwt.user.client.ui.TextBox; | ||
import com.google.gwt.user.client.ui.VerticalPanel; | ||
|
||
/** | ||
* Entry point classes define <code>onModuleLoad()</code>. | ||
*/ | ||
public class Shifts_solver implements EntryPoint { | ||
/** | ||
* The message displayed to the user when the server cannot be reached or | ||
* returns an error. | ||
*/ | ||
private static final String SERVER_ERROR = "An error occurred while " | ||
+ "attempting to contact the server. Please check your network " | ||
+ "connection and try again."; | ||
|
||
/** | ||
* Create a remote service proxy to talk to the server-side Greeting service. | ||
*/ | ||
private final GreetingServiceAsync greetingService = GWT | ||
.create(GreetingService.class); | ||
|
||
/** | ||
* This is the entry point method. | ||
*/ | ||
public void onModuleLoad() { | ||
final Button sendButton = new Button("Send"); | ||
final TextBox nameField = new TextBox(); | ||
nameField.setText("GWT User"); | ||
final Label errorLabel = new Label(); | ||
|
||
// We can add style names to widgets | ||
sendButton.addStyleName("sendButton"); | ||
|
||
// Add the nameField and sendButton to the RootPanel | ||
// Use RootPanel.get() to get the entire body element | ||
RootPanel.get("nameFieldContainer").add(nameField); | ||
RootPanel.get("sendButtonContainer").add(sendButton); | ||
RootPanel.get("errorLabelContainer").add(errorLabel); | ||
|
||
// Focus the cursor on the name field when the app loads | ||
nameField.setFocus(true); | ||
nameField.selectAll(); | ||
|
||
// Create the popup dialog box | ||
final DialogBox dialogBox = new DialogBox(); | ||
dialogBox.setText("Remote Procedure Call"); | ||
dialogBox.setAnimationEnabled(true); | ||
final Button closeButton = new Button("Close"); | ||
// We can set the id of a widget by accessing its Element | ||
closeButton.getElement().setId("closeButton"); | ||
final Label textToServerLabel = new Label(); | ||
final HTML serverResponseLabel = new HTML(); | ||
VerticalPanel dialogVPanel = new VerticalPanel(); | ||
dialogVPanel.addStyleName("dialogVPanel"); | ||
dialogVPanel.add(new HTML("<b>Sending name to the server:</b>")); | ||
dialogVPanel.add(textToServerLabel); | ||
dialogVPanel.add(new HTML("<br><b>Server replies:</b>")); | ||
dialogVPanel.add(serverResponseLabel); | ||
dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT); | ||
dialogVPanel.add(closeButton); | ||
dialogBox.setWidget(dialogVPanel); | ||
|
||
// Add a handler to close the DialogBox | ||
closeButton.addClickHandler(new ClickHandler() { | ||
public void onClick(ClickEvent event) { | ||
dialogBox.hide(); | ||
sendButton.setEnabled(true); | ||
sendButton.setFocus(true); | ||
} | ||
}); | ||
|
||
// Create a handler for the sendButton and nameField | ||
class MyHandler implements ClickHandler, KeyUpHandler { | ||
/** | ||
* Fired when the user clicks on the sendButton. | ||
*/ | ||
public void onClick(ClickEvent event) { | ||
sendNameToServer(); | ||
} | ||
|
||
/** | ||
* Fired when the user types in the nameField. | ||
*/ | ||
public void onKeyUp(KeyUpEvent event) { | ||
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { | ||
sendNameToServer(); | ||
} | ||
} | ||
|
||
/** | ||
* Send the name from the nameField to the server and wait for a response. | ||
*/ | ||
private void sendNameToServer() { | ||
// First, we validate the input. | ||
errorLabel.setText(""); | ||
String textToServer = nameField.getText(); | ||
if (!FieldVerifier.isValidName(textToServer)) { | ||
errorLabel.setText("Please enter at least four characters"); | ||
return; | ||
} | ||
|
||
// Then, we send the input to the server. | ||
sendButton.setEnabled(false); | ||
textToServerLabel.setText(textToServer); | ||
serverResponseLabel.setText(""); | ||
greetingService.greetServer(textToServer, | ||
new AsyncCallback<String>() { | ||
public void onFailure(Throwable caught) { | ||
// Show the RPC error message to the user | ||
dialogBox | ||
.setText("Remote Procedure Call - Failure"); | ||
serverResponseLabel | ||
.addStyleName("serverResponseLabelError"); | ||
serverResponseLabel.setHTML(SERVER_ERROR); | ||
dialogBox.center(); | ||
closeButton.setFocus(true); | ||
} | ||
|
||
public void onSuccess(String result) { | ||
dialogBox.setText("Remote Procedure Call"); | ||
serverResponseLabel | ||
.removeStyleName("serverResponseLabelError"); | ||
serverResponseLabel.setHTML(result); | ||
dialogBox.center(); | ||
closeButton.setFocus(true); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
// Add a handler to send the name to the server | ||
MyHandler handler = new MyHandler(); | ||
sendButton.addClickHandler(handler); | ||
nameField.addKeyUpHandler(handler); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/com/mindforger/shiftsolver/server/GreetingServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.mindforger.shiftsolver.server; | ||
|
||
import com.mindforger.shiftsolver.client.GreetingService; | ||
import com.mindforger.shiftsolver.shared.FieldVerifier; | ||
import com.google.gwt.user.server.rpc.RemoteServiceServlet; | ||
|
||
/** | ||
* The server side implementation of the RPC service. | ||
*/ | ||
@SuppressWarnings("serial") | ||
public class GreetingServiceImpl extends RemoteServiceServlet implements | ||
GreetingService { | ||
|
||
public String greetServer(String input) throws IllegalArgumentException { | ||
// Verify that the input is valid. | ||
if (!FieldVerifier.isValidName(input)) { | ||
// If the input is not valid, throw an IllegalArgumentException back to | ||
// the client. | ||
throw new IllegalArgumentException( | ||
"Name must be at least 4 characters long"); | ||
} | ||
|
||
String serverInfo = getServletContext().getServerInfo(); | ||
String userAgent = getThreadLocalRequest().getHeader("User-Agent"); | ||
|
||
// Escape data from the client to avoid cross-site script vulnerabilities. | ||
input = escapeHtml(input); | ||
userAgent = escapeHtml(userAgent); | ||
|
||
return "Hello, " + input + "!<br><br>I am running " + serverInfo | ||
+ ".<br><br>It looks like you are using:<br>" + userAgent; | ||
} | ||
|
||
/** | ||
* Escape an html string. Escaping data received from the client helps to | ||
* prevent cross-site script vulnerabilities. | ||
* | ||
* @param html the html string to escape | ||
* @return the escaped string | ||
*/ | ||
private String escapeHtml(String html) { | ||
if (html == null) { | ||
return null; | ||
} | ||
return html.replaceAll("&", "&").replaceAll("<", "<") | ||
.replaceAll(">", ">"); | ||
} | ||
} |
Oops, something went wrong.