husted 2004/03/26 19:58:02
Modified: chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader
CommandAction.java
Added: chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader
ViewContext.java
chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/commands
LocaleCommand.java MailReader.java
MailReaderBase.java
Log:
Add test and code for LocaleCommand
Revision Changes Path
1.2 +2 -2
jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/CommandAction.java
Index: CommandAction.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/CommandAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CommandAction.java 25 Mar 2004 12:39:27 -0000 1.1
+++ CommandAction.java 27 Mar 2004 03:58:02 -0000 1.2
@@ -10,9 +10,9 @@
/**
* <p>
- * Create ActionContextBase pass to Command corresponding to the ActionForm name.
+ * Create ActionHelperBase pass to Command corresponding to the ActionForm name.
* On return, analyze Context, returning values in servlet contexts as
- * appropriate. The ActionContextBase is also exposed in the request under
+ * appropriate. The ActionHelperBase is also exposed in the request under
* the key "context".
* </p>
* <p>
1.1
jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/ViewContext.java
Index: ViewContext.java
===================================================================
package org.apache.commons.chain.mailreader;
import org.apache.commons.chain.Context;
import java.util.Locale;
/**
* Application interface for the Struts framework.
*/
public interface ViewContext extends Context {
public static String PN_LOCALE = "locale";
public boolean isLocale();
public void setLocale(Locale locale);
public Locale getLocale();
public static String PN_INPUT = "input";
public boolean isInput();
public void setInput(Context context);
public Context getInput();
}
1.1
jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/commands/LocaleCommand.java
Index: LocaleCommand.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/commands/LocaleCommand.java,v
1.1 2004/03/27 03:58:02 husted Exp $
* $Revision: 1.1 $
* $Date: 2004/03/27 03:58:02 $
*
* Copyright 2000-2004 Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.chain.mailreader.commands;
import org.apache.commons.chain.Command;
import org.apache.commons.chain.Context;
import java.util.Locale;
/**
* Change Locale according to input values, country and language.
*/
public class LocaleCommand implements Command {
static boolean isBlank(String string) {
return ((string==null) || (string.trim().length()==0));
}
public boolean execute(Context context) {
MailReader app = (MailReader) context;
Context input = app.getInput();
String country = (String) input.get(MailReader.PN_COUNTRY);
String language = (String) input.get(MailReader.PN_LANGUAGE);
Locale locale = Locale.getDefault();
if ((!isBlank(language)) && (!isBlank(country))) {
locale = new Locale(language, country);
}
else if (!isBlank(language)) {
locale = new Locale(language, "");
}
app.setLocale(locale);
return false;
}
}
1.1
jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/commands/MailReader.java
Index: MailReader.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/commands/MailReader.java,v
1.1 2004/03/27 03:58:02 husted Exp $
* $Revision: 1.1 $
* $Date: 2004/03/27 03:58:02 $
*
* Copyright 2000-2004 Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.chain.mailreader.commands;
import org.apache.commons.chain.Context;
import org.apache.commons.chain.mailreader.ViewContext;
import java.util.Locale;
/**
* Application interface for MailReader Commands.
*/
public interface MailReader extends ViewContext {
static String PN_COUNTRY = "country";
static String PN_LANGUAGE = "language";
}
1.1
jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/commands/MailReaderBase.java
Index: MailReaderBase.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/chain/apps/mailreader/src/java/org/apache/commons/chain/mailreader/commands/MailReaderBase.java,v
1.1 2004/03/27 03:58:02 husted Exp $
* $Revision: 1.1 $
* $Date: 2004/03/27 03:58:02 $
*
* Copyright 2000-2004 Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.chain.mailreader.commands;
import org.apache.commons.chain.impl.ContextBase;
import org.apache.commons.chain.Context;
import java.util.Locale;
/**
* Implements MailReader API for a Struts application.
*/
public class MailReaderBase extends ContextBase implements MailReader {
public MailReaderBase() {
super();
}
public MailReaderBase(Locale locale, Context input) {
super();
this.locale = locale;
this.input = input;
}
private boolean isLocale = false;
private Locale locale;
public Locale getLocale() {
return locale;
}
public void setLocale(Locale locale) {
this.locale = locale;
setIsLocale(true);
}
public boolean isLocale() {
return isLocale;
}
public void setIsLocale(boolean locale) {
isLocale = locale;
}
private boolean isInput = false;
private Context input;
public Context getInput() {
return input;
}
public void setInput(Context input) {
this.input = input;
setIsInput(true);
}
public boolean isInput() {
return isInput;
}
public void setIsInput(boolean input) {
isInput = input;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]