You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by ag...@apache.org on 2006/06/12 23:47:55 UTC
svn commit: r413748 - in
/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions:
CreateWebsiteAction.java UserBaseAction.java UserNewAction.java
YourProfileAction.java
Author: agilliland
Date: Mon Jun 12 14:47:54 2006
New Revision: 413748
URL: http://svn.apache.org/viewvc?rev=413748&view=rev
Log:
code reformatting.
Modified:
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/CreateWebsiteAction.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/UserBaseAction.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/UserNewAction.java
incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/YourProfileAction.java
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/CreateWebsiteAction.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/CreateWebsiteAction.java?rev=413748&r1=413747&r2=413748&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/CreateWebsiteAction.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/CreateWebsiteAction.java Mon Jun 12 14:47:54 2006
@@ -1,26 +1,27 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* 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. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
package org.apache.roller.ui.authoring.struts.actions;
+
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.CharSetUtils;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionError;
@@ -49,17 +50,17 @@
/**
* Allows user to create a new website.
- *
+ *
* @struts.action path="/roller-ui/authoring/createWebsite" parameter="method" name="createWebsiteForm"
* @struts.action-forward name="createWebsite.page" path=".CreateWebsite"
* @struts.action-forward name="createWebsiteDone.page" path=".CreateWebsiteDone"
*/
-public class CreateWebsiteAction extends DispatchAction
-{
- protected static String DEFAULT_ALLOWED_CHARS = "A-Za-z0-9";
-
- private static Log mLogger =
- LogFactory.getFactory().getInstance(CreateWebsiteAction.class);
+public class CreateWebsiteAction extends DispatchAction {
+
+ protected static String DEFAULT_ALLOWED_CHARS = "A-Za-z0-9";
+
+ private static Log mLogger = LogFactory.getLog(CreateWebsiteAction.class);
+
/** If method param is not specified, use HTTP verb to pick method to call */
public ActionForward unspecified(
@@ -67,85 +68,84 @@
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response)
- throws Exception
- {
- if (request.getMethod().equals("GET"))
- {
+ throws Exception {
+
+ if (request.getMethod().equals("GET")) {
return create(mapping, actionForm, request, response);
}
return save(mapping, actionForm, request, response);
}
+
public ActionForward cancel(
ActionMapping mapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response)
- throws Exception
- {
+ throws Exception {
+
return mapping.findForward("yourWebsites");
}
+
/** Present new website form to user */
public ActionForward create(
ActionMapping mapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response)
- throws Exception
- {
- ActionForward forward = mapping.findForward("createWebsite.page");
+ throws Exception {
+
+ ActionForward forward = mapping.findForward("createWebsite.page");
CreateWebsiteForm form = (CreateWebsiteForm)actionForm;
RollerSession rses = RollerSession.getRollerSession(request);
- UserData user = rses.getAuthenticatedUser();
+ UserData user = rses.getAuthenticatedUser();
form.setLocale(user.getLocale());
- form.setTimeZone(user.getTimeZone());
+ form.setTimeZone(user.getTimeZone());
form.setEmailAddress(user.getEmailAddress());
-
+
if (!RollerConfig.getBooleanProperty("groupblogging.enabled")) {
- Roller roller = RollerFactory.getRoller();
+ Roller roller = RollerFactory.getRoller();
List permissions = roller.getUserManager().getAllPermissions(user);
if (permissions.size() > 0) {
// sneaky user trying to get around 1 blog limit that applies
// only when group blogging is disabled
return mapping.findForward("access-denied");
- }
+ }
}
- request.setAttribute("model",
+ request.setAttribute("model",
new CreateWebsitePageModel(request, response, mapping, null));
return forward;
}
- /** Save new website created by user */
+
+ /** Save new website created by user */
public ActionForward save(
ActionMapping mapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response)
- throws Exception
- {
+ throws Exception {
+
CreateWebsiteForm form = (CreateWebsiteForm)actionForm;
ActionMessages msgs = new ActionMessages();
ActionMessages errors = validate(form, new ActionErrors());
- ActionForward forward = mapping.findForward("yourWebsites");
+ ActionForward forward = mapping.findForward("yourWebsites");
Roller roller = RollerFactory.getRoller();
WebsiteData website = null;
- if (!errors.isEmpty())
- {
+ if (!errors.isEmpty()) {
saveErrors(request, errors);
forward = mapping.findForward("createWebsite.page");
- }
- else try
- {
+ } else try {
RollerContext rollerContext = RollerContext.getRollerContext();
- UserData user =
- RollerSession.getRollerSession(request).getAuthenticatedUser();
- UserManager mgr = roller.getUserManager();
+ UserData user =
+ RollerSession.getRollerSession(request).getAuthenticatedUser();
+ UserManager mgr = roller.getUserManager();
- if (!RollerConfig.getBooleanProperty("groupblogging.enabled")) {
+ if (!RollerConfig.getBooleanProperty("groupblogging.enabled")) {
List permissions = roller.getUserManager().getAllPermissions(user);
if (permissions.size() > 0) {
// sneaky user trying to get around 1 blog limit that applies
@@ -183,118 +183,102 @@
msgs.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("createWebsite.created", form.getHandle()));
saveMessages(request, msgs);
- }
- catch (RollerException e)
- {
- errors.add(ActionErrors.GLOBAL_ERROR,
- new ActionError(e.getMessage()));
- saveErrors(request, errors);
+ } catch (RollerException e) {
+ errors.add(ActionErrors.GLOBAL_ERROR,
+ new ActionError(e.getMessage()));
+ saveErrors(request, errors);
mLogger.error("ERROR in createWebsite", e);
}
- request.setAttribute("model",
- new CreateWebsitePageModel(request, response, mapping, website));
+ request.setAttribute("model",
+ new CreateWebsitePageModel(request, response, mapping, website));
- return forward;
+ return forward;
}
-
+
+
private ActionMessages validate(CreateWebsiteForm form, ActionErrors messages)
- throws RollerException
- {
+ throws RollerException {
+
String allowed = RollerConfig.getProperty("username.allowedChars");
- if(allowed == null || allowed.trim().length() == 0) {
- allowed = DEFAULT_ALLOWED_CHARS;
- }
- String safe = CharSetUtils.keep(form.getHandle(), allowed);
-
- if (form.getHandle() == null || "".equals(form.getHandle().trim()))
- {
- messages.add( ActionErrors.GLOBAL_ERROR,
- new ActionError("createWeblog.error.missingHandle"));
+ if(allowed == null || allowed.trim().length() == 0) {
+ allowed = DEFAULT_ALLOWED_CHARS;
}
- else if (!safe.equals(form.getHandle()) )
- {
+ String safe = CharSetUtils.keep(form.getHandle(), allowed);
+
+ if (form.getHandle() == null || "".equals(form.getHandle().trim())) {
messages.add( ActionErrors.GLOBAL_ERROR,
- new ActionError("createWeblog.error.invalidHandle"));
- }
- if (form.getEmailAddress() == null || "".equals(form.getEmailAddress().trim()))
- {
+ new ActionError("createWeblog.error.missingHandle"));
+ } else if (!safe.equals(form.getHandle()) ) {
messages.add( ActionErrors.GLOBAL_ERROR,
- new ActionError("createWeblog.error.missingEmailAddress"));
+ new ActionError("createWeblog.error.invalidHandle"));
+ }
+ if (form.getEmailAddress() == null || "".equals(form.getEmailAddress().trim())) {
+ messages.add( ActionErrors.GLOBAL_ERROR,
+ new ActionError("createWeblog.error.missingEmailAddress"));
}
Roller roller = RollerFactory.getRoller();
- if (roller.getUserManager().getWebsiteByHandle(form.getHandle()) != null)
- {
- messages.add(ActionErrors.GLOBAL_ERROR,
+ if (roller.getUserManager().getWebsiteByHandle(form.getHandle()) != null) {
+ messages.add(ActionErrors.GLOBAL_ERROR,
new ActionError("createWeblog.error.handleExists"));
}
return messages;
}
-
- public static class CreateWebsitePageModel extends BasePageModel
- {
- private List themes;
+
+
+ public static class CreateWebsitePageModel extends BasePageModel {
+
+ private List themes;
private String contextURL = null;
private String weblogURL = null;
private String rssURL = null;
private WebsiteData website = null;
public CreateWebsitePageModel(HttpServletRequest request,
- HttpServletResponse response, ActionMapping mapping, WebsiteData wd)
- throws RollerException
- {
+ HttpServletResponse response, ActionMapping mapping, WebsiteData wd)
+ throws RollerException {
super("createWebsite.title", request, response, mapping);
RollerContext rollerContext = RollerContext.getRollerContext();
Roller roller = RollerFactory.getRoller();
ThemeManager themeMgr = roller.getThemeManager();
themes = themeMgr.getEnabledThemesList();
- if (wd != null)
- {
+ if (wd != null) {
contextURL = rollerContext.getAbsoluteContextUrl(request);
- weblogURL = contextURL + "/page/" + wd.getHandle();
- rssURL = contextURL + "/rss/" + wd.getHandle();
+ weblogURL = contextURL + "/page/" + wd.getHandle();
+ rssURL = contextURL + "/rss/" + wd.getHandle();
website = wd;
}
}
- public String getContextURL()
- {
+ public String getContextURL() {
return contextURL;
}
- public void setContextURL(String contextURL)
- {
+ public void setContextURL(String contextURL) {
this.contextURL = contextURL;
}
- public String getRssURL()
- {
+ public String getRssURL() {
return rssURL;
}
- public void setRssURL(String rssURL)
- {
+ public void setRssURL(String rssURL) {
this.rssURL = rssURL;
}
- public List getThemes()
- {
+ public List getThemes() {
return themes;
}
- public void setThemes(List themes)
- {
+ public void setThemes(List themes) {
this.themes = themes;
}
- public String getWeblogURL()
- {
+ public String getWeblogURL() {
return weblogURL;
}
- public void setWeblogURL(String weblogURL)
- {
+ public void setWeblogURL(String weblogURL) {
this.weblogURL = weblogURL;
}
- public WebsiteData getWebsite()
- {
+ public WebsiteData getWebsite() {
return website;
}
- public void setWebsite(WebsiteData website)
- {
+ public void setWebsite(WebsiteData website) {
this.website = website;
}
}
+
}
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/UserBaseAction.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/UserBaseAction.java?rev=413748&r1=413747&r2=413748&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/UserBaseAction.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/UserBaseAction.java Mon Jun 12 14:47:54 2006
@@ -1,20 +1,20 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* 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. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
package org.apache.roller.ui.authoring.struts.actions;
@@ -29,45 +29,40 @@
import org.apache.roller.ui.authoring.struts.formbeans.UserFormEx;
-/////////////////////////////////////////////////////////////////////////////
/**
* Base class for user actions.
*/
-public class UserBaseAction extends DispatchAction
-{
- private static Log mLogger =
- LogFactory.getFactory().getInstance(UserBaseAction.class);
+public class UserBaseAction extends DispatchAction {
+
+ private static Log mLogger = LogFactory.getLog(UserBaseAction.class);
+
+ protected static String DEFAULT_ALLOWED_CHARS = "A-Za-z0-9";
+
- protected static String DEFAULT_ALLOWED_CHARS = "A-Za-z0-9";
-
- //------------------------------------------------------------------------
/** Validate user form. TODO: replace with Struts validation. */
protected ActionMessages validate( UserFormEx form, ActionMessages errors ) {
-
- String allowed = RollerConfig.getProperty("username.allowedChars");
- if(allowed == null || allowed.trim().length() == 0) {
- allowed = DEFAULT_ALLOWED_CHARS;
- }
- String safe = CharSetUtils.keep(form.getUserName(), allowed);
-
- if ( "".equals(form.getUserName().trim()))
- {
- errors.add( ActionErrors.GLOBAL_ERROR,
- new ActionError("error.add.user.missingUserName"));
+
+ String allowed = RollerConfig.getProperty("username.allowedChars");
+ if(allowed == null || allowed.trim().length() == 0) {
+ allowed = DEFAULT_ALLOWED_CHARS;
}
- else if ( !safe.equals(form.getUserName()) )
- {
+ String safe = CharSetUtils.keep(form.getUserName(), allowed);
+
+ if ( "".equals(form.getUserName().trim())) {
+ errors.add( ActionErrors.GLOBAL_ERROR,
+ new ActionError("error.add.user.missingUserName"));
+ } else if ( !safe.equals(form.getUserName()) ) {
errors.add( ActionErrors.GLOBAL_ERROR,
- new ActionError("error.add.user.badUserName"));
+ new ActionError("error.add.user.badUserName"));
}
-
- if ( "".equals(form.getEmailAddress().trim()))
- {
+
+ if ( "".equals(form.getEmailAddress().trim())) {
errors.add( ActionErrors.GLOBAL_ERROR,
- new ActionError("error.add.user.missingEmailAddress"));
+ new ActionError("error.add.user.missingEmailAddress"));
}
return errors;
}
+
}
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/UserNewAction.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/UserNewAction.java?rev=413748&r1=413747&r2=413748&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/UserNewAction.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/UserNewAction.java Mon Jun 12 14:47:54 2006
@@ -1,20 +1,20 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* 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. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
package org.apache.roller.ui.authoring.struts.actions;
@@ -48,181 +48,161 @@
import org.apache.roller.ui.authoring.struts.formbeans.UserFormEx;
import org.apache.roller.util.StringUtils;
-/////////////////////////////////////////////////////////////////////////////
+
/**
* Actions for creating a new user.
- *
- * @struts.action name="userFormEx" path="/user"
+ *
+ * @struts.action name="userFormEx" path="/user"
* scope="session" parameter="method"
- *
+ *
* @struts.action-forward name="registerUser.page" path=".UserNew"
* @struts.action-forward name="welcome.page" path=".welcome"
*/
-public class UserNewAction extends UserBaseAction
-{
- private static Log mLogger =
- LogFactory.getFactory().getInstance(UserNewAction.class);
-
- //------------------------------------------------------------------------
+public class UserNewAction extends UserBaseAction {
+
+ private static Log mLogger = LogFactory.getLog(UserNewAction.class);
+
+
/** Process GET of new user page (allows admin to create a user) */
public ActionForward createUser(
- ActionMapping mapping,
- ActionForm actionForm,
- HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException
- {
+ ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException {
UserFormEx userForm = (UserFormEx)actionForm;
userForm.setAdminCreated(true);
return registerUser(mapping, actionForm, request, response);
}
+
public ActionForward cancel(
ActionMapping mapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response)
- throws Exception
- {
+ throws Exception {
return mapping.findForward("main");
}
- //------------------------------------------------------------------------
+
/** Process GET of user registration page (allows users to register themselves). */
public ActionForward registerUser(
- ActionMapping mapping,
- ActionForm actionForm,
- HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException
- {
+ ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException {
ActionForward forward = mapping.findForward("registerUser.page");
ActionErrors errors = new ActionErrors();
RollerRequest rreq = RollerRequest.getRollerRequest(request);
- try
- {
+ try {
UserFormEx userForm = (UserFormEx)actionForm;
userForm.setLocale(Locale.getDefault().toString());
userForm.setTimeZone(TimeZone.getDefault().getID());
userForm.setPasswordText(null);
- userForm.setPasswordConfirm(null);
+ userForm.setPasswordConfirm(null);
request.setAttribute("model", new BasePageModel(
"newUser.addNewUser", request, response, mapping));
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
errors.add(ActionErrors.GLOBAL_ERROR,
- new ActionError("error.editing.user", e.toString()));
+ new ActionError("error.editing.user", e.toString()));
mLogger.error("ERROR in newUser", e);
}
return forward;
}
-
- //-----------------------------------------------------------------------
+
+
/** Process POST of new user information. */
public ActionForward add(
- ActionMapping mapping,
- ActionForm actionForm,
- HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException
- {
+ ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException {
UserFormEx form = (UserFormEx)actionForm;
RollerRequest rreq = RollerRequest.getRollerRequest(request);
ServletContext ctx = rreq.getServletContext();
RollerContext rollerContext = RollerContext.getRollerContext();
-
- boolean reg_allowed =
+
+ boolean reg_allowed =
RollerRuntimeConfig.getBooleanProperty("users.registration.enabled");
-
- if ( !reg_allowed && !request.isUserInRole("admin"))
- {
+
+ if ( !reg_allowed && !request.isUserInRole("admin")) {
throw new ServletException("New users disabled!");
}
-
+
ActionMessages msgs = new ActionMessages();
ActionMessages errors = validate(form, new ActionErrors());
- if (!errors.isEmpty())
- {
+ if (!errors.isEmpty()) {
saveErrors(request, errors);
- }
- else try
- {
+ } else try {
// Add new user
- UserManager mgr = RollerFactory.getRoller().getUserManager();
-
+ UserManager mgr = RollerFactory.getRoller().getUserManager();
+
UserData ud = new UserData();
form.copyTo(ud, request.getLocale()); // doesn't copy password
ud.setId(null);
ud.setDateCreated(new java.util.Date());
ud.setEnabled(Boolean.TRUE);
-
+
// If user set both password and passwordConfirm then reset password
- if ( !StringUtils.isEmpty(form.getPasswordText())
- && !StringUtils.isEmpty(form.getPasswordConfirm()))
- {
- ud.resetPassword(RollerFactory.getRoller(),
- form.getPasswordText(), form.getPasswordConfirm());
+ if ( !StringUtils.isEmpty(form.getPasswordText())
+ && !StringUtils.isEmpty(form.getPasswordConfirm())) {
+ ud.resetPassword(RollerFactory.getRoller(),
+ form.getPasswordText(), form.getPasswordConfirm());
}
// save new user
mgr.addUser(ud);
RollerFactory.getRoller().flush();
- if (form.getAdminCreated())
- {
+ if (form.getAdminCreated()) {
// User created for admin, so return to new user page with empty form
- msgs.add(ActionMessages.GLOBAL_MESSAGE,
- new ActionMessage("newUser.created"));
+ msgs.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage("newUser.created"));
saveMessages(request, msgs);
form.reset(mapping, request);
return createUser(mapping, actionForm, request, response);
- }
- else
- {
+ } else {
// User registered, so go to welcome page
String weblogURL = rollerContext.getAbsoluteContextUrl(request)
- + "/page/"+ud.getUserName();
- request.setAttribute("weblogURL",weblogURL);
+ + "/page/"+ud.getUserName();
+ request.setAttribute("weblogURL",weblogURL);
String rssURL = rollerContext.getAbsoluteContextUrl(request)
- + "/rss/"+ud.getUserName();
- request.setAttribute("rssURL",rssURL);
- request.setAttribute("contextURL",
- rollerContext.getAbsoluteContextUrl(request));
+ + "/rss/"+ud.getUserName();
+ request.setAttribute("rssURL",rssURL);
+ request.setAttribute("contextURL",
+ rollerContext.getAbsoluteContextUrl(request));
return mapping.findForward("welcome.page");
}
- }
- catch (RollerException e)
- {
+ } catch (RollerException e) {
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(e.getMessage()));
- saveErrors(request,errors);
+ saveErrors(request,errors);
mLogger.error("ERROR in addUser", e);
form.setUserName("");
}
-
- if (form.getAdminCreated())
- {
+
+ if (form.getAdminCreated()) {
return mapping.findForward("createUser");
- }
- else
- {
+ } else {
// Error occured, send user back to new user form
return mapping.findForward("registerUser");
}
}
-
- //------------------------------------------------------------------------
+
+
/** Validate user form. TODO: replace with Struts validation. */
protected ActionMessages validate( UserFormEx form, ActionMessages errors ) {
super.validate(form, errors);
if ( StringUtils.isEmpty(form.getPasswordText())
- && StringUtils.isEmpty(form.getPasswordConfirm()))
- {
+ && StringUtils.isEmpty(form.getPasswordConfirm())) {
errors.add( ActionErrors.GLOBAL_ERROR,
- new ActionError("error.add.user.missingPassword"));
+ new ActionError("error.add.user.missingPassword"));
}
return errors;
}
+
}
Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/YourProfileAction.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/YourProfileAction.java?rev=413748&r1=413747&r2=413748&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/YourProfileAction.java (original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/authoring/struts/actions/YourProfileAction.java Mon Jun 12 14:47:54 2006
@@ -1,28 +1,27 @@
/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. The ASF licenses this file to You
-* 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. For additional information regarding
-* copyright in this work, please see the NOTICE file in the top level
-* directory of this distribution.
-*/
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. The ASF licenses this file to You
+ * 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
package org.apache.roller.ui.authoring.struts.actions;
import java.io.IOException;
-
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionErrors;
@@ -40,53 +39,51 @@
import org.apache.roller.ui.authoring.struts.formbeans.UserFormEx;
import org.apache.roller.util.StringUtils;
+
/**
* Allows user to edit his/her profile.
- *
+ *
* @struts.action name="userFormEx" path="/roller-ui/authoring/yourProfile" parameter="method"
* @struts.action-forward name="yourProfile.page" path=".YourProfile"
*/
-public class YourProfileAction extends UserBaseAction
-{
- private static Log mLogger =
- LogFactory.getFactory().getInstance(YourProfileAction.class);
-
+public class YourProfileAction extends UserBaseAction {
+
+ private static Log mLogger = LogFactory.getLog(YourProfileAction.class);
+
+
/** If method param is not specified, use HTTP verb to pick method to call */
public ActionForward unspecified(
ActionMapping mapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response)
- throws Exception
- {
- if (request.getMethod().equals("GET"))
- {
+ throws Exception {
+ if (request.getMethod().equals("GET")) {
return edit(mapping, actionForm, request, response);
}
return save(mapping, actionForm, request, response);
}
+
public ActionForward cancel(
ActionMapping mapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response)
- throws Exception
- {
+ throws Exception {
return mapping.findForward("yourWebsites");
}
+
/** Load form with authenticated user and forward to your-profile page */
public ActionForward edit(
- ActionMapping mapping,
- ActionForm actionForm,
- HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException
- {
+ ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException {
ActionForward forward = mapping.findForward("yourProfile.page");
- try
- {
+ try {
RollerSession rollerSession = RollerSession.getRollerSession(request);
UserData ud = rollerSession.getAuthenticatedUser();
UserFormEx form = (UserFormEx)actionForm;
@@ -96,46 +93,41 @@
form.setLocale(ud.getLocale());
form.setTimeZone(ud.getTimeZone());
request.setAttribute("model", new BasePageModel(
- "yourProfile.title", request, response, mapping));
- }
- catch (Exception e)
- {
+ "yourProfile.title", request, response, mapping));
+ } catch (Exception e) {
mLogger.error("ERROR in action",e);
throw new ServletException(e);
- }
+ }
// if user logged in with a cookie, display a warning that they
// can't change passwords
- if (mLogger.isDebugEnabled())
- {
+ if (mLogger.isDebugEnabled()) {
log.debug("checking for cookieLogin...");
}
if (request.getSession().getAttribute("cookieLogin") != null) {
ActionMessages messages = new ActionMessages();
-
+
// add warning messages
messages.add(ActionMessages.GLOBAL_MESSAGE,
- new ActionMessage("yourProfile.cookieLogin"));
+ new ActionMessage("yourProfile.cookieLogin"));
saveMessages(request, messages);
}
return forward;
}
-
+
+
/** Update user based on posted form data */
public ActionForward save(
- ActionMapping mapping,
- ActionForm actionForm,
- HttpServletRequest request,
- HttpServletResponse response)
- throws IOException, ServletException
- {
+ ActionMapping mapping,
+ ActionForm actionForm,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException {
UserFormEx form = (UserFormEx)actionForm;
ActionForward forward = mapping.findForward("yourProfile.page");
ActionMessages msgs = new ActionMessages();
- try
- {
+ try {
ActionMessages errors = validate(form, new ActionErrors());
- if (errors.size() == 0)
- {
+ if (errors.size() == 0) {
// We ONLY modify the user currently logged in
RollerSession rollerSession = RollerSession.getRollerSession(request);
UserData data = rollerSession.getAuthenticatedUser();
@@ -147,49 +139,35 @@
data.setTimeZone(form.getTimeZone());
// If user set both password and passwordConfirm then reset password
- if ( !StringUtils.isEmpty(form.getPasswordText())
- && !StringUtils.isEmpty(form.getPasswordConfirm()))
- {
- try
- {
- data.resetPassword(RollerFactory.getRoller(),
- form.getPasswordText(),
- form.getPasswordConfirm());
+ if ( !StringUtils.isEmpty(form.getPasswordText())
+ && !StringUtils.isEmpty(form.getPasswordConfirm())) {
+ try {
+ data.resetPassword(RollerFactory.getRoller(),
+ form.getPasswordText(),
+ form.getPasswordConfirm());
+ } catch (RollerException e) {
+ msgs.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage("yourProfile.passwordResetError"));
}
- catch (RollerException e)
- {
- msgs.add(ActionMessages.GLOBAL_MESSAGE,
- new ActionMessage("yourProfile.passwordResetError"));
- }
- }
+ }
// save the updated profile
UserManager mgr = RollerFactory.getRoller().getUserManager();
mgr.saveUser(data);
RollerFactory.getRoller().flush();
-
+
request.setAttribute("model", new BasePageModel(
"yourProfile.title", request, response, mapping));
saveMessages(request, msgs);
- }
- else
- {
+ } else {
saveErrors(request, errors);
}
return mapping.findForward("yourWebsites");
- }
- catch (Exception e)
- {
+ } catch (Exception e) {
mLogger.error("ERROR in action",e);
throw new ServletException(e);
}
}
}
-
-
-
-
-
-