JBoss Portal SVN: r8071 - in trunk/core-identity/src: main/org/jboss/portal/core/identity/services/workflow and 8 other directories.
by portal-commits@lists.jboss.org
Author: emuckenhuber
Date: 2007-08-28 13:50:11 -0400 (Tue, 28 Aug 2007)
New Revision: 8071
Added:
trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/IdentityManagementService.java
trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/
trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/CreateUserAction.java
trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/IdentityManagementServiceImpl.java
trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/RegistrationServiceImpl.java
trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/SendValidationMailAction.java
trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/UpdateEmailAction.java
trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/ValidateEmailServiceImpl.java
trunk/core-identity/src/resources/portal-identity-sar/conf/processes/jbp_identity_validation_workflow.xml
trunk/core-identity/src/resources/portal-identity-war/WEB-INF/jsf/admin/user/searchUsers.xhtml
Removed:
trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/ApproveRegistration.java
trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/CreateUserAction.java
trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/SendValidationMailAction.java
trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/ValidateEmailServiceImpl.java
Modified:
trunk/core-identity/src/main/org/jboss/portal/core/identity/services/IdentityCommandFactoryService.java
trunk/core-identity/src/main/org/jboss/portal/core/identity/services/IdentityMailServiceImpl.java
trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/RegistrationService.java
trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/UserContainer.java
trunk/core-identity/src/main/org/jboss/portal/core/identity/ui/admin/RoleManagementBean.java
trunk/core-identity/src/main/org/jboss/portal/core/identity/ui/admin/UserAdministrationBean.java
trunk/core-identity/src/main/org/jboss/portal/core/identity/ui/common/IdentityRoleBean.java
trunk/core-identity/src/main/org/jboss/portal/core/identity/ui/common/IdentityUserBean.java
trunk/core-identity/src/resources/portal-identity-sar/META-INF/jboss-service.xml
trunk/core-identity/src/resources/portal-identity-sar/conf/processes/jbp_identity_validate_email.xml
trunk/core-identity/src/resources/portal-identity-sar/conf/processes/jbp_identity_validation_approval_workflow.xml
trunk/core-identity/src/resources/portal-identity-war/WEB-INF/
trunk/core-identity/src/resources/portal-identity-war/WEB-INF/faces-config.xml
trunk/core-identity/src/resources/portal-identity-war/WEB-INF/jsf/admin/index.xhtml
trunk/core-identity/src/resources/portal-identity-war/WEB-INF/jsf/admin/user/pendingUsers.xhtml
trunk/core-identity/src/resources/portal-identity-war/WEB-INF/portlet-instances.xml
Log:
- some changes at registration process with jBPM
- changeEmail request is now also validated over jBPM
Modified: trunk/core-identity/src/main/org/jboss/portal/core/identity/services/IdentityCommandFactoryService.java
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/services/IdentityCommandFactoryService.java 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/services/IdentityCommandFactoryService.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -27,14 +27,12 @@
import org.jboss.portal.core.controller.ControllerCommand;
import org.jboss.portal.core.controller.ControllerContext;
import org.jboss.portal.core.controller.command.mapper.AbstractCommandFactory;
-import org.jboss.portal.core.identity.services.workflow.RegistrationService;
import org.jboss.portal.core.identity.services.workflow.ValidateEmailService;
import org.jboss.portal.core.model.portal.PortalObjectId;
import org.jboss.portal.core.model.portal.PortalObjectPath;
import org.jboss.portal.core.model.portal.command.action.InvokePortletWindowRenderCommand;
import org.jboss.portal.portlet.PortletParametersStateString;
import org.jboss.portal.server.ServerInvocation;
-import org.jboss.portal.server.config.ServerConfig;
/**
* @author <a href="mailto:emuckenh@redhat.com">Emanuel Muckenhuber</a>
@@ -50,12 +48,6 @@
protected PortalObjectId targetWindowId;
/** . */
- protected ServerConfig serverConfig;
-
- /** . */
- protected RegistrationService registrationService = null;
-
- /** . */
protected ValidateEmailService validateEmailService = null;
public PortalObjectId getTargetWindowId()
@@ -63,26 +55,6 @@
return targetWindowId;
}
- public ServerConfig getServerConfig()
- {
- return serverConfig;
- }
-
- public void setServerConfig(ServerConfig serverConfig)
- {
- this.serverConfig = serverConfig;
- }
-
- public RegistrationService getRegistrationService()
- {
- return registrationService;
- }
-
- public void setRegistrationService(RegistrationService registrationService)
- {
- this.registrationService = registrationService;
- }
-
public ValidateEmailService getValidateEmailService()
{
return validateEmailService;
@@ -115,12 +87,12 @@
validateEmailService.validateEmail(bpmId, hash);
// TODO
- this.targetWindowId = PortalObjectId.parse("default.default.wizardWindow_10", PortalObjectPath.LEGACY_FORMAT);
+ this.targetWindowId = PortalObjectId.parse("default.default.CoreIdentityUserPortletWindow", PortalObjectPath.LEGACY_FORMAT);
}
else
{
- this.targetWindowId = PortalObjectId.parse("default.default.wizardWindow_10",
+ this.targetWindowId = PortalObjectId.parse("default.default.CoreIdentityUserPortletWindow",
PortalObjectPath.LEGACY_FORMAT);
}
Modified: trunk/core-identity/src/main/org/jboss/portal/core/identity/services/IdentityMailServiceImpl.java
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/services/IdentityMailServiceImpl.java 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/services/IdentityMailServiceImpl.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -91,10 +91,6 @@
jndiBinding = new JNDI.Binding(jndiName, this);
jndiBinding.bind();
}
-
- this.mailModule = (MailModule) new InitialContext().lookup("java:/portal/MailModule");
- if (mailModule == null)
- throw new Exception("no mail module");
}
public void stopService() throws Exception
@@ -130,6 +126,17 @@
public MailModule getMailModule()
{
+ if (this.mailModule == null)
+ {
+ try
+ {
+ this.mailModule = (MailModule) new InitialContext().lookup("java:/portal/MailModule");
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
return mailModule;
}
@@ -181,7 +188,7 @@
this.generateEmailText();
// Sending mail
- // mailModule.send(emailFrom, to , subject, emailText);
+ // this.getMailModule.send(emailFrom, to , subject, emailText);
log.debug(subject + to + this.emailText);
}
@@ -199,7 +206,7 @@
}
if (config == null)
{
- throw new FileNotFoundException("Cannot load a suitable emailTemplate.tpl in templates/"
+ throw new FileNotFoundException("Cannot load a suitable emailTemplate.tpl in conf/templates/"
+ this.templateLocation);
}
InputStream in = config.openStream();
Deleted: trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/ApproveRegistration.java
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/ApproveRegistration.java 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/ApproveRegistration.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -1,291 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.identity.services.workflow;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-import org.jboss.logging.Logger;
-import org.jboss.portal.common.io.IOTools;
-import org.jboss.portal.core.identity.services.IdentityConstants;
-import org.jboss.portal.identity.User;
-import org.jboss.portal.jems.as.JNDI;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-import org.jboss.portal.workflow.service.WorkflowService;
-import org.jbpm.JbpmContext;
-import org.jbpm.db.GraphSession;
-import org.jbpm.graph.def.Node;
-import org.jbpm.graph.def.ProcessDefinition;
-import org.jbpm.graph.exe.ProcessInstance;
-import org.jbpm.graph.exe.Token;
-
-/**
- * @author <a href="mailto:emuckenh@redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public class ApproveRegistration extends AbstractJBossService implements RegistrationService
-{
-
- /** . */
- private static final Logger log = Logger.getLogger(ApproveRegistration.class);
-
- /** . */
- private WorkflowService workflowService = null;
-
- /** . */
- private String processName = "jbp_identity_validation_approval_workflow";
-
- /** . */
- private boolean overwrite = false;
-
- /** . */
- private String processFile = "conf/processes/" + processName + ".xml";
-
- /** . */
- private JNDI.Binding jndiBinding;
-
- /** . */
- private String jndiName = null;
-
- /** . */
- private ValidateEmailService validateEmailService;
-
- public void startService() throws Exception
- {
- super.startService();
-
- if (this.jndiName != null)
- {
- jndiBinding = new JNDI.Binding(jndiName, this);
- jndiBinding.bind();
- }
-
- InputStream is = null;
- JbpmContext jbpmContext = null;
- try
- {
- jbpmContext = this.workflowService.getJbpmConfiguration().createJbpmContext();
-
- ProcessDefinition processDefinition = jbpmContext.getGraphSession().findLatestProcessDefinition(
- this.processName);
- if (processDefinition == null)
- {
- processDefinition = ProcessDefinition.parseXmlResource(processFile);
- jbpmContext.deployProcessDefinition(processDefinition);
- }
- else
- {
- // A process definition already exists....should deploy a new version
- // of the definition if overwrite is true
- ProcessDefinition fromConfig = ProcessDefinition.parseXmlResource(processFile);
- if (this.overwrite)
- {
- // If the two of them are not same, create a new version
- // of this process definition
- jbpmContext.deployProcessDefinition(fromConfig);
- }
- }
- }
- catch (Exception e)
- {
- //
- this.stopService();
-
- //
- throw e;
- }
- finally
- {
- IOTools.safeClose(is);
- IOTools.safeClose(jbpmContext);
- }
- }
-
- public void stopService() throws Exception
- {
- super.stopService();
-
- if (jndiBinding != null)
- {
- jndiBinding.unbind();
- jndiBinding = null;
- }
- }
-
- /** @return */
- public WorkflowService getWorkflowService()
- {
- return this.workflowService;
- }
-
- /** @param workflowService */
- public void setWorkflowService(WorkflowService workflowService)
- {
- this.workflowService = workflowService;
- }
-
- /** @return */
- public String getJNDIName()
- {
- return this.jndiName;
- }
-
- /** @param jndiName */
- public void setJNDIName(String jndiName)
- {
- this.jndiName = jndiName;
- }
-
- public ValidateEmailService getValidateEmailService()
- {
- return validateEmailService;
- }
-
- public void setValidateEmailService(ValidateEmailService validateEmailService)
- {
- this.validateEmailService = validateEmailService;
- }
-
- public String registerUser(String username, String password, Map profileMap, List roles, Locale locale)
- {
- JbpmContext jbpmContext = null;
- ProcessInstance processInstance = null;
- // String registrationHash = this.hashGen(); - done at send email action
- boolean success = false;
- try
- {
- jbpmContext = this.workflowService.getJbpmConfiguration().createJbpmContext();
- processInstance = jbpmContext.newProcessInstance(this.processName);
- Token token = processInstance.getRootToken();
-
- // Setting required attributes for the workflow
- UserContainer user = new UserContainer(username, password, profileMap, roles);
- processInstance.getContextInstance().setVariable(IdentityConstants.VARIABLE_USER, user);
- processInstance.getContextInstance().setVariable(IdentityConstants.VARIABLE_EMAIL, user.getProfileMap().get(User.INFO_USER_EMAIL_REAL));
- processInstance.getContextInstance().setVariable(IdentityConstants.VARIABLE_LOCALE, locale);
- processInstance.getContextInstance().setVariable(IdentityConstants.ACTION, IdentityConstants.ACTION_REGISTER_USER);
- token.signal();
- success = true;
- }
- catch (Exception e)
- {
- success = false;
- log.error("Exception in Workflow", e);
- // throw new WorkflowException(e);
- }
- finally
- {
- if (processInstance != null && success)
- {
- jbpmContext.save(processInstance);
- }
- IOTools.safeClose(jbpmContext);
- }
- return IdentityConstants.REGISTRATION_PENDING;
- }
-
- public String approve(String id, boolean approve)
- {
- JbpmContext jbpmContext = null;
- try
- {
- long processId = Long.valueOf(id).longValue();
- jbpmContext = jbpmContext.getJbpmConfiguration().createJbpmContext();
- ProcessInstance processInstance = jbpmContext.getProcessInstance(processId);
-
- if (processInstance != null)
- {
- Node n = processInstance.getRootToken().getNode();
- if (n.getName().equals("adminApproval"))
- {
- if (approve)
- {
- processInstance.signal("approved");
- }
- else
- {
- processInstance.signal("rejected");
- }
- }
- }
- }
- catch (Exception e)
- {
- log.error("", e);
- }
- finally
- {
- IOTools.safeClose(jbpmContext);
- }
- return IdentityConstants.REGISTRATION_PENDING;
- }
-
- public List getPendingUsers()
- {
- List queue = new ArrayList();
- JbpmContext jbpmContext = null;
- try
- {
- jbpmContext = this.workflowService.getJbpmConfiguration().createJbpmContext();
-
- GraphSession graphSession = jbpmContext.getGraphSession();
- ProcessDefinition processDef = graphSession.findLatestProcessDefinition(this.processName);
- List processInstances = graphSession.findProcessInstances(processDef.getId());
-
- if (processInstances != null)
- {
- Iterator i = processInstances.iterator();
- while (i.hasNext())
- {
- ProcessInstance instance = (ProcessInstance) i.next();
- if (!instance.hasEnded())
- {
- Object obj = instance.getContextInstance().getVariable(IdentityConstants.VARIABLE_USER);
- if (obj instanceof UserContainer)
- {
- // Filling pending user List
- UserContainer user = (UserContainer) obj;
- user.setProcessId(String.valueOf(instance.getId()));
- user.setCurrentNode(instance.getRootToken().getNode().getName());
- queue.add(user);
- }
- }
- }
- }
- }
- catch (Exception e)
- {
- log.error("", e);
- }
- finally
- {
- IOTools.safeClose(jbpmContext);
- }
- return queue;
- }
-
-}
Deleted: trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/CreateUserAction.java
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/CreateUserAction.java 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/CreateUserAction.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -1,45 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.identity.services.workflow;
-
-import org.jboss.logging.Logger;
-import org.jbpm.graph.def.ActionHandler;
-import org.jbpm.graph.exe.ExecutionContext;
-
-/**
- * @author <a href="mailto:emuckenh@redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public class CreateUserAction implements ActionHandler
-{
- private static Logger log = Logger.getLogger(CreateUserAction.class);
-
- public void execute(ExecutionContext ectx) throws Exception
- {
- UserContainer user = (UserContainer) ectx.getContextInstance().getVariable("user");
- // FIXME execute
- log.debug("creating User: "+ user.getUsername() );
- }
-
-}
-
Added: trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/IdentityManagementService.java
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/IdentityManagementService.java (rev 0)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/IdentityManagementService.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -0,0 +1,41 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.identity.services.workflow;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:emuckenh@redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public interface IdentityManagementService
+{
+ boolean createUser(String username, String password, Map profileMap, List roles);
+
+ public String getCurrentEmail(String username);
+
+ public boolean updateEmail(String username, String email);
+
+}
+
Modified: trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/RegistrationService.java
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/RegistrationService.java 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/RegistrationService.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -40,5 +40,7 @@
/** . */
List getPendingUsers();
+
+ int getPendingCount();
}
Deleted: trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/SendValidationMailAction.java
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/SendValidationMailAction.java 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/SendValidationMailAction.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -1,178 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.identity.services.workflow;
-
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
-import java.util.HashMap;
-import java.util.Locale;
-
-import javax.naming.InitialContext;
-
-import org.jboss.logging.Logger;
-import org.jboss.portal.common.util.Tools;
-import org.jboss.portal.core.identity.services.IdentityConstants;
-import org.jboss.portal.core.identity.services.IdentityMailService;
-import org.jboss.portal.identity.User;
-import org.jboss.portal.identity.UserModule;
-import org.jboss.portal.identity.UserProfileModule;
-import org.jbpm.graph.def.ActionHandler;
-import org.jbpm.graph.exe.ExecutionContext;
-
-/**
- * @author <a href="mailto:emuckenh@redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public class SendValidationMailAction implements ActionHandler
-{
- /** . */
- private UserModule userModule;
-
- /** . */
- private UserProfileModule userProfileModule;
-
- /** . */
- private IdentityMailService identityMailService;
-
- /** . */
- private static Logger log = Logger.getLogger(SendValidationMailAction.class);
-
- public void execute(ExecutionContext ectx) throws Exception
- {
- HashMap emailMap = new HashMap();
- String hash = this.hashGen();
-
- String action = (String) ectx.getContextInstance().getVariable(IdentityConstants.ACTION);
- String email = (String) ectx.getContextInstance().getVariable(IdentityConstants.VARIABLE_EMAIL);
- Locale locale = (Locale) ectx.getContextInstance().getVariable(IdentityConstants.VARIABLE_LOCALE);
-
- if ( locale == null)
- {
- locale = new Locale(IdentityConstants.DEFAULT_LOCALE);
- }
-
- UserContainer uc = (UserContainer) ectx.getContextInstance().getVariable(IdentityConstants.VARIABLE_USER);
-
- // Register new user
- if (IdentityConstants.ACTION_REGISTER_USER.equals(action))
- {
- emailMap.put("to", email);
- emailMap.put("username", uc.getUsername());
- emailMap.put("password", uc.getPassword());
- }
- // Change email
- else if (IdentityConstants.ACTION_CHANGE_EMAIL.equals(action))
- {
- User user = this.getUserModule().findUserByUserName(uc.getUsername());
- emailMap.put("to", (String) this.getUserProfileModule().getProperty(user, User.INFO_USER_EMAIL_REAL));
- }
- else
- {
- throw new RuntimeException("wrong Action");
- }
-
- ectx.getContextInstance().setVariable(IdentityConstants.VALIDATION_HASH, hash);
- // TODO - build url
- String activationLink = "validateEmail/" + ectx.getProcessInstance().getId() + "/" + hash;
- emailMap.put("activationLink", activationLink);
-
- this.getIdentityMailService().sendMail(action, emailMap, locale);
- }
-
- // generating a random hash
- private String hashGen()
- {
- try
- {
- SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
-
- byte[] bytes = new byte[512];
- secureRandom.nextBytes(bytes);
-
- double rand = secureRandom.nextDouble();
- long time = System.currentTimeMillis();
- String salt = IdentityConstants.HASH_SALT;
-
- StringBuffer buffer = new StringBuffer();
- buffer.append(rand);
- buffer.append(salt);
- buffer.append(time);
-
- return Tools.md5AsHexString(buffer.toString());
- }
- catch (NoSuchAlgorithmException e)
- {
- log.error("No Such Algorithm exists " + e);
- }
- return null;
- }
-
- private IdentityMailService getIdentityMailService()
- {
- if (identityMailService == null)
- {
- try
- {
- this.identityMailService = (IdentityMailService) new InitialContext().lookup("java:/portal/IdentityMailService");
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
- return identityMailService;
- }
-
- private UserModule getUserModule()
- {
- if (userModule == null)
- {
- try
- {
- this.userModule = (UserModule) new InitialContext().lookup("java:/portal/UserModule");
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
- return userModule;
- }
-
- private UserProfileModule getUserProfileModule()
- {
- if (userProfileModule == null)
- {
- try
- {
- this.userProfileModule = (UserProfileModule) new InitialContext().lookup("java:/portal/UserProfileModule");
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
- return userProfileModule;
- }
-
-}
Modified: trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/UserContainer.java
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/UserContainer.java 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/UserContainer.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -24,7 +24,6 @@
import java.io.Serializable;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
import org.jboss.portal.identity.User;
@@ -35,17 +34,22 @@
*/
public class UserContainer implements Serializable
{
-
+ /** . */
private String processId;
+ /** . */
private String username;
+ /** . */
private String password;
+ /** . */
private Map profileMap;
+ /** . */
private List roles;
+ /** . */
private String currentNode;
public UserContainer(User user)
@@ -127,6 +131,7 @@
}
public String getRegistrationDate(){
- return (String) this.profileMap.get(User.INFO_USER_REGISTRATION_DATE);
+ Object obj = this.profileMap.get(User.INFO_USER_REGISTRATION_DATE);
+ return obj != null ? obj.toString() : null;
}
}
Deleted: trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/ValidateEmailServiceImpl.java
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/ValidateEmailServiceImpl.java 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/ValidateEmailServiceImpl.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -1,234 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.core.identity.services.workflow;
-
-import java.io.InputStream;
-import java.util.Locale;
-
-import org.jboss.logging.Logger;
-import org.jboss.portal.common.io.IOTools;
-import org.jboss.portal.core.identity.services.IdentityConstants;
-import org.jboss.portal.identity.User;
-import org.jboss.portal.jems.as.JNDI;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-import org.jboss.portal.workflow.service.WorkflowService;
-import org.jbpm.JbpmContext;
-import org.jbpm.graph.def.Node;
-import org.jbpm.graph.def.ProcessDefinition;
-import org.jbpm.graph.exe.ProcessInstance;
-import org.jbpm.graph.exe.Token;
-
-/**
- * @author <a href="mailto:emuckenh@redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public class ValidateEmailServiceImpl extends AbstractJBossService implements ValidateEmailService
-{
- private static final Logger log = Logger.getLogger(ValidateEmailService.class);
-
- private WorkflowService workflowService = null;
-
- private String processName = "jbp_identity_validate_email";
-
- private String processFile = "conf/processes/" + processName + ".xml";
-
- private boolean overwrite = false;
-
- private JNDI.Binding jndiBinding;
-
- private String jndiName = null;
-
- public void startService() throws Exception
- {
- super.startService();
-
- if (this.jndiName != null)
- {
- jndiBinding = new JNDI.Binding(jndiName, this);
- jndiBinding.bind();
- }
-
- InputStream is = null;
- JbpmContext jbpmContext = null;
- try
- {
- jbpmContext = this.workflowService.getJbpmConfiguration().createJbpmContext();
-
- ProcessDefinition processDefinition = jbpmContext.getGraphSession().findLatestProcessDefinition(
- this.processName);
- if (processDefinition == null)
- {
- processDefinition = ProcessDefinition.parseXmlResource(processFile);
- jbpmContext.deployProcessDefinition(processDefinition);
- }
- else
- {
- // A process definition already exists....should deploy a new version
- // of the definition if overwrite is true
- ProcessDefinition fromConfig = ProcessDefinition.parseXmlResource(processFile);
- if (this.overwrite)
- {
- // If the two of them are not same, create a new version
- // of this process definition
- jbpmContext.deployProcessDefinition(fromConfig);
- }
- }
- }
- catch (Exception e)
- {
- //
- this.stopService();
-
- //
- throw e;
- }
- finally
- {
- IOTools.safeClose(is);
- IOTools.safeClose(jbpmContext);
- }
- }
-
- public void stopService() throws Exception
- {
- super.stopService();
-
- if (jndiBinding != null)
- {
- jndiBinding.unbind();
- jndiBinding = null;
- }
- }
-
- /** @return */
- public WorkflowService getWorkflowService()
- {
- return this.workflowService;
- }
-
- /** @param workflowService */
- public void setWorkflowService(WorkflowService workflowService)
- {
- this.workflowService = workflowService;
- }
-
- /** @return */
- public String getJNDIName()
- {
- return this.jndiName;
- }
-
- /** @param jndiName */
- public void setJNDIName(String jndiName)
- {
- this.jndiName = jndiName;
- }
-
- /*
- * Create new changeEmail request
- */
- public String changeEmail(User user, String email, Locale locale)
- {
- JbpmContext jbpmContext = null;
- ProcessInstance processInstance = null;
- // String registrationHash = this.hashGen(); - generated when sending email
- boolean success = false;
- try
- {
- jbpmContext = this.workflowService.getJbpmConfiguration().createJbpmContext();
- processInstance = jbpmContext.newProcessInstance(this.processName);
- Token token = processInstance.getRootToken();
-
- processInstance.getContextInstance().setVariable(IdentityConstants.VARIABLE_USER, new UserContainer(user));
- processInstance.getContextInstance().setVariable(IdentityConstants.VARIABLE_EMAIL, email);
- processInstance.getContextInstance().setVariable(IdentityConstants.VARIABLE_LOCALE, locale);
- processInstance.getContextInstance().setVariable(IdentityConstants.ACTION, IdentityConstants.ACTION_CHANGE_EMAIL);
-
- token.signal();
- success = true;
- }
- catch (Exception e)
- {
- success = false;
- log.error("Exception in Workflow", e);
- // throw new WorkflowException(e);
- }
- finally
- {
- if (processInstance != null && success)
- {
- jbpmContext.save(processInstance);
- }
- IOTools.safeClose(jbpmContext);
- }
- // TODO
- return IdentityConstants.REGISTRATION_PENDING;
- }
-
- public boolean validateEmail(String id, String registrationHash)
- {
- JbpmContext jbpmContext = null;
- boolean success = false;
- try
- {
- long processId = Long.valueOf(id).longValue();
- jbpmContext = this.workflowService.getJbpmConfiguration().createJbpmContext();
- ProcessInstance processInstance = jbpmContext.getProcessInstance(processId);
-
- if (processInstance != null)
- {
- Node n = processInstance.getRootToken().getNode();
- if (n.getName().equals("validate_email"))
- {
- String hash = (String) processInstance.getContextInstance().getVariable(IdentityConstants.VALIDATION_HASH);
- if (registrationHash.equals(hash) && !processInstance.hasEnded())
- {
- Token token = processInstance.getRootToken();
- String action = (String) processInstance.getContextInstance().getVariable(IdentityConstants.ACTION);
- // Processing email change request to transition changeEmail
- if(IdentityConstants.ACTION_CHANGE_EMAIL.equals(action))
- {
- token.signal("changeEmail");
- }
- // Processing other requests to end state with ok
- else
- {
- token.signal("ok");
- }
- success = true;
- }
- }
- }
- }
- catch (Exception e)
- {
- log.error("", e);
- }
- finally
- {
- IOTools.safeClose(jbpmContext);
- }
- return success;
- }
-}
-
Copied: trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/CreateUserAction.java (from rev 8051, trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/CreateUserAction.java)
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/CreateUserAction.java (rev 0)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/CreateUserAction.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -0,0 +1,71 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.identity.services.workflow.impl;
+
+import javax.naming.InitialContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.portal.core.identity.services.workflow.IdentityManagementService;
+import org.jboss.portal.core.identity.services.workflow.UserContainer;
+import org.jbpm.graph.def.ActionHandler;
+import org.jbpm.graph.exe.ExecutionContext;
+
+/**
+ * @author <a href="mailto:emuckenh@redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class CreateUserAction implements ActionHandler
+{
+
+ /** . */
+ private IdentityManagementService identityManagementService;
+
+ /** . */
+ private static Logger log = Logger.getLogger(CreateUserAction.class);
+
+ public void execute(ExecutionContext ectx) throws Exception
+ {
+ UserContainer uc = (UserContainer) ectx.getContextInstance().getVariable("user");
+
+ this.getIdentityManagementService().createUser(uc.getUsername(), uc.getPassword(), uc.getProfileMap(), uc.getRoles());
+
+ log.debug("creating User: "+ uc.getUsername() );
+ }
+
+ private IdentityManagementService getIdentityManagementService()
+ {
+ if (this.identityManagementService == null)
+ {
+ try
+ {
+ this.identityManagementService = (IdentityManagementService) new InitialContext().lookup("java:/portal/IdentityManagementService");
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ return this.identityManagementService;
+ }
+
+}
\ No newline at end of file
Added: trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/IdentityManagementServiceImpl.java
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/IdentityManagementServiceImpl.java (rev 0)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/IdentityManagementServiceImpl.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -0,0 +1,288 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.identity.services.workflow.impl;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.naming.InitialContext;
+
+import org.jboss.portal.core.identity.services.workflow.IdentityManagementService;
+import org.jboss.portal.identity.IdentityException;
+import org.jboss.portal.identity.MembershipModule;
+import org.jboss.portal.identity.Role;
+import org.jboss.portal.identity.RoleModule;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.identity.UserModule;
+import org.jboss.portal.identity.UserProfileModule;
+import org.jboss.portal.jems.as.JNDI;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+
+/**
+ * @author <a href="mailto:emuckenh@redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class IdentityManagementServiceImpl extends AbstractJBossService implements IdentityManagementService
+{
+ /** . */
+ private UserModule userModule;
+
+ /** . */
+ private RoleModule roleModule;
+
+ /** . */
+ private UserProfileModule userProfileModule;
+
+ /** . */
+ private MembershipModule membershipModule;
+
+ /** . */
+ private JNDI.Binding jndiBinding;
+
+ /** . */
+ private String jndiName = null;
+
+ /** . */
+ private InitialContext initialContext;
+
+ public void startService() throws Exception
+ {
+ super.startService();
+
+ this.initialContext = new InitialContext();
+
+ if (this.jndiName != null)
+ {
+ jndiBinding = new JNDI.Binding(jndiName, this);
+ jndiBinding.bind();
+ }
+ }
+
+ public void stopService() throws Exception
+ {
+ super.stopService();
+
+ if (jndiBinding != null)
+ {
+ jndiBinding.unbind();
+ jndiBinding = null;
+ }
+ }
+
+ public String getJNDIName()
+ {
+ return this.jndiName;
+ }
+
+ public void setJNDIName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+
+ public UserModule getUserModule()
+ {
+ if (userModule == null)
+ {
+ try
+ {
+ userModule = (UserModule) initialContext.lookup("java:/portal/UserModule");
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ return userModule;
+ }
+
+ public void setUserModule(UserModule userModule)
+ {
+ this.userModule = userModule;
+ }
+
+ public RoleModule getRoleModule()
+ {
+ if (roleModule == null)
+ {
+ try
+ {
+ roleModule = (RoleModule) initialContext.lookup("java:/portal/RoleModule");
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ return roleModule;
+ }
+
+ public void setRoleModule(RoleModule roleModule)
+ {
+ this.roleModule = roleModule;
+ }
+
+ public UserProfileModule getUserProfileModule()
+ {
+ if (userProfileModule == null)
+ {
+ try
+ {
+ userProfileModule = (UserProfileModule) initialContext.lookup("java:/portal/UserProfileModule");
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ return userProfileModule;
+ }
+
+ public void setUserProfileModule(UserProfileModule userProfileModule)
+ {
+ this.userProfileModule = userProfileModule;
+ }
+
+ public MembershipModule getMembershipModule()
+ {
+ if (membershipModule == null)
+ {
+ try
+ {
+ membershipModule = (MembershipModule) initialContext.lookup("java:/portal/MembershipModule");
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ return membershipModule;
+ }
+
+ public void setMembershipModule(MembershipModule membershipModule)
+ {
+ this.membershipModule = membershipModule;
+ }
+
+ public boolean createUser(String username, String password, Map profileMap, List roles)
+ {
+ try
+ {
+ User user = this.getUserModule().createUser(username, password);
+ Set roleSet = this.checkRoles(roles);
+
+ // Enable the user
+ profileMap.put(User.INFO_USER_ENABLED, Boolean.TRUE);
+
+ Iterator i = profileMap.keySet().iterator();
+ while (i.hasNext())
+ {
+ String key = (String) i.next();
+ Object value = profileMap.get(key);
+ this.getUserProfileModule().setProperty(user, key, value);
+ }
+
+ this.getMembershipModule().assignRoles(user, roleSet);
+ return true;
+ }
+ catch (Exception e)
+ {
+ log.error("Error when creating user", e);
+ }
+
+ return false;
+ }
+
+ public String getCurrentEmail(String username)
+ {
+ try
+ {
+ User user = this.getUserModule().findUserByUserName(username);
+ return (String) this.getUserProfileModule().getProperty(user, User.INFO_USER_EMAIL_REAL);
+ }
+ catch (Exception e)
+ {
+ log.error("failed to retrieve current email address", e);
+ }
+ return null;
+ }
+
+ public boolean updateEmail(String username, String email)
+ {
+ try
+ {
+ User user = this.getUserModule().findUserByUserName(username);
+ this.getUserProfileModule().setProperty(user, User.INFO_USER_EMAIL_REAL, email);
+ return true;
+ }
+ catch (Exception e)
+ {
+ log.error("failed to update email", e);
+ }
+ return false;
+ }
+
+ private Set checkRoles(List roles) throws IllegalArgumentException, IdentityException
+ {
+ Set roleSet = new HashSet();
+ if (roles != null && roles.size() > 0)
+ { // Checking existing roles
+ Iterator i = roles.iterator();
+
+ while (i.hasNext())
+ {
+ String roleName = (String) i.next();
+ Role role = this.getRoleModule().findRoleByName(roleName);
+
+ if (role == null)
+ {
+ // Create new role ?
+ }
+ else
+ {
+ roleSet.add(role);
+ }
+ }
+ return roleSet;
+ }
+ else
+ {
+ // TODO default Role
+ Role role = this.getRoleModule().findRoleByName("User");
+
+ if (role != null)
+ {
+ roleSet.add(role);
+ }
+ else
+ {
+ throw new IllegalArgumentException();
+ }
+
+ return roleSet;
+ }
+ }
+
+}
Added: trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/RegistrationServiceImpl.java
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/RegistrationServiceImpl.java (rev 0)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/RegistrationServiceImpl.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -0,0 +1,324 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.identity.services.workflow.impl;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import org.jboss.logging.Logger;
+import org.jboss.portal.common.io.IOTools;
+import org.jboss.portal.core.identity.services.IdentityConstants;
+import org.jboss.portal.core.identity.services.workflow.RegistrationService;
+import org.jboss.portal.core.identity.services.workflow.UserContainer;
+import org.jboss.portal.core.identity.services.workflow.ValidateEmailService;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.jems.as.JNDI;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+import org.jboss.portal.workflow.service.WorkflowService;
+import org.jbpm.JbpmContext;
+import org.jbpm.db.GraphSession;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.graph.exe.Token;
+
+/**
+ * @author <a href="mailto:emuckenh@redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class RegistrationServiceImpl extends AbstractJBossService implements RegistrationService
+{
+
+ /** . */
+ private static final Logger log = Logger.getLogger(RegistrationServiceImpl.class);
+
+ /** . */
+ private WorkflowService workflowService = null;
+
+ /** . */
+ private String processName = "jbp_identity_validation_approval_workflow";
+
+ /** . */
+ private boolean overwrite = false;
+
+ /** . */
+ private String processFile = "conf/processes/" + processName + ".xml";
+
+ /** . */
+ private JNDI.Binding jndiBinding;
+
+ /** . */
+ private String jndiName = null;
+
+ /** . */
+ private ValidateEmailService validateEmailService;
+
+ public void startService() throws Exception
+ {
+ super.startService();
+
+ if (this.jndiName != null)
+ {
+ jndiBinding = new JNDI.Binding(jndiName, this);
+ jndiBinding.bind();
+ }
+
+ InputStream is = null;
+ JbpmContext jbpmContext = null;
+ try
+ {
+ jbpmContext = this.workflowService.getJbpmConfiguration().createJbpmContext();
+
+ ProcessDefinition processDefinition = jbpmContext.getGraphSession().findLatestProcessDefinition(
+ this.processName);
+ if (processDefinition == null)
+ {
+ processDefinition = ProcessDefinition.parseXmlResource(processFile);
+ jbpmContext.deployProcessDefinition(processDefinition);
+ }
+ else
+ {
+ ProcessDefinition fromConfig = ProcessDefinition.parseXmlResource(processFile);
+ if (this.overwrite)
+ {
+ jbpmContext.deployProcessDefinition(fromConfig);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ //
+ this.stopService();
+ //
+ throw e;
+ }
+ finally
+ {
+ IOTools.safeClose(is);
+ IOTools.safeClose(jbpmContext);
+ }
+ }
+
+ public void stopService() throws Exception
+ {
+ super.stopService();
+
+ if (jndiBinding != null)
+ {
+ jndiBinding.unbind();
+ jndiBinding = null;
+ }
+ }
+
+ /** @return */
+ public WorkflowService getWorkflowService()
+ {
+ return this.workflowService;
+ }
+
+ /** @param workflowService */
+ public void setWorkflowService(WorkflowService workflowService)
+ {
+ this.workflowService = workflowService;
+ }
+
+ /** @return */
+ public String getJNDIName()
+ {
+ return this.jndiName;
+ }
+
+ /** @param jndiName */
+ public void setJNDIName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+
+ public ValidateEmailService getValidateEmailService()
+ {
+ return validateEmailService;
+ }
+
+ public void setValidateEmailService(ValidateEmailService validateEmailService)
+ {
+ this.validateEmailService = validateEmailService;
+ }
+
+ public String registerUser(String username, String password, Map profileMap, List roles, Locale locale)
+ {
+ JbpmContext jbpmContext = null;
+ ProcessInstance processInstance = null;
+ // String registrationHash = this.hashGen(); - done at send email action
+ boolean success = false;
+ try
+ {
+ jbpmContext = this.workflowService.getJbpmConfiguration().createJbpmContext();
+ processInstance = jbpmContext.newProcessInstance(this.processName);
+ Token token = processInstance.getRootToken();
+
+ // Setting required attributes for the workflow
+ UserContainer user = new UserContainer(username, password, profileMap, roles);
+ processInstance.getContextInstance().setVariable(IdentityConstants.VARIABLE_USER, user);
+ processInstance.getContextInstance().setVariable(IdentityConstants.VARIABLE_EMAIL,
+ user.getProfileMap().get(User.INFO_USER_EMAIL_REAL));
+ processInstance.getContextInstance().setVariable(IdentityConstants.VARIABLE_LOCALE, locale);
+ processInstance.getContextInstance().setVariable(IdentityConstants.ACTION,
+ IdentityConstants.ACTION_REGISTER_USER);
+
+ token.signal();
+ success = true;
+ }
+ catch (Exception e)
+ {
+ success = false;
+ log.error("Exception in Workflow", e);
+ // throw new WorkflowException(e);
+ }
+ finally
+ {
+ if (processInstance != null && success)
+ {
+ jbpmContext.save(processInstance);
+ }
+ IOTools.safeClose(jbpmContext);
+ }
+ return IdentityConstants.REGISTRATION_PENDING;
+ }
+
+ public String approve(String id, boolean approve)
+ {
+ JbpmContext jbpmContext = null;
+ try
+ {
+ long processId = Long.valueOf(id).longValue();
+ jbpmContext = this.workflowService.getJbpmConfiguration().createJbpmContext();
+ ProcessInstance processInstance = jbpmContext.getProcessInstance(processId);
+
+ if (processInstance != null)
+ {
+ Token token = processInstance.getRootToken();
+ if (token.getNode().getName().equals("adminApproval"))
+ {
+ if (approve)
+ {
+ token.signal("approved");
+ }
+ else
+ {
+ token.signal("rejected");
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("", e);
+ }
+ finally
+ {
+ IOTools.safeClose(jbpmContext);
+ }
+ return IdentityConstants.REGISTRATION_PENDING;
+ }
+
+ public int getPendingCount()
+ {
+ int count = 0;
+ JbpmContext jbpmContext = null;
+ try
+ {
+ jbpmContext = this.workflowService.getJbpmConfiguration().createJbpmContext();
+
+ GraphSession graphSession = jbpmContext.getGraphSession();
+ ProcessDefinition processDef = graphSession.findLatestProcessDefinition(this.processName);
+ List processInstances = graphSession.findProcessInstances(processDef.getId());
+
+ if (processInstances != null)
+ {
+ Iterator i = processInstances.iterator();
+ while (i.hasNext())
+ {
+ ProcessInstance instance = (ProcessInstance) i.next();
+ count = !instance.hasEnded() ? count + 1 : count;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("", e);
+ }
+ finally
+ {
+ IOTools.safeClose(jbpmContext);
+ }
+ return count;
+ }
+
+ public List getPendingUsers()
+ {
+ List queue = new ArrayList();
+ JbpmContext jbpmContext = null;
+ try
+ {
+ jbpmContext = this.workflowService.getJbpmConfiguration().createJbpmContext();
+
+ GraphSession graphSession = jbpmContext.getGraphSession();
+ ProcessDefinition processDef = graphSession.findLatestProcessDefinition(this.processName);
+ List processInstances = graphSession.findProcessInstances(processDef.getId());
+
+ if (processInstances != null)
+ {
+ Iterator i = processInstances.iterator();
+ while (i.hasNext())
+ {
+ ProcessInstance instance = (ProcessInstance) i.next();
+ if (!instance.hasEnded())
+ {
+ Object obj = instance.getContextInstance().getVariable(IdentityConstants.VARIABLE_USER);
+ if (obj instanceof UserContainer)
+ {
+ // Filling pending user List
+ UserContainer user = (UserContainer) obj;
+ user.setProcessId(String.valueOf(instance.getId()));
+ user.setCurrentNode(instance.getRootToken().getNode().getName());
+ queue.add(user);
+ }
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("", e);
+ }
+ finally
+ {
+ IOTools.safeClose(jbpmContext);
+ }
+ return queue;
+ }
+
+}
Copied: trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/SendValidationMailAction.java (from rev 8051, trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/SendValidationMailAction.java)
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/SendValidationMailAction.java (rev 0)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/SendValidationMailAction.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -0,0 +1,158 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.identity.services.workflow.impl;
+
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.util.HashMap;
+import java.util.Locale;
+
+import javax.naming.InitialContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.core.identity.services.IdentityConstants;
+import org.jboss.portal.core.identity.services.IdentityMailService;
+import org.jboss.portal.core.identity.services.workflow.IdentityManagementService;
+import org.jboss.portal.core.identity.services.workflow.UserContainer;
+import org.jbpm.graph.def.ActionHandler;
+import org.jbpm.graph.exe.ExecutionContext;
+
+/**
+ * @author <a href="mailto:emuckenh@redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class SendValidationMailAction implements ActionHandler
+{
+ /** . */
+ private IdentityManagementService identityManagementService;
+
+ /** . */
+ private IdentityMailService identityMailService;
+
+ /** . */
+ private static Logger log = Logger.getLogger(SendValidationMailAction.class);
+
+ public void execute(ExecutionContext ectx) throws Exception
+ {
+ HashMap emailMap = new HashMap();
+ String hash = this.hashGen();
+
+ String action = (String) ectx.getContextInstance().getVariable(IdentityConstants.ACTION);
+ String email = (String) ectx.getContextInstance().getVariable(IdentityConstants.VARIABLE_EMAIL);
+ Locale locale = (Locale) ectx.getContextInstance().getVariable(IdentityConstants.VARIABLE_LOCALE);
+
+ if ( locale == null)
+ {
+ locale = new Locale(IdentityConstants.DEFAULT_LOCALE);
+ }
+
+ UserContainer uc = (UserContainer) ectx.getContextInstance().getVariable(IdentityConstants.VARIABLE_USER);
+
+ // Register new user
+ if (IdentityConstants.ACTION_REGISTER_USER.equals(action))
+ {
+ emailMap.put("to", email);
+ emailMap.put("username", uc.getUsername());
+ emailMap.put("password", uc.getPassword());
+ }
+ // Change email
+ else if (IdentityConstants.ACTION_CHANGE_EMAIL.equals(action))
+ {
+ String emailTo = this.getIdentityManagementService().getCurrentEmail(uc.getUsername());
+ emailMap.put("to", emailTo);
+ }
+ else
+ {
+ throw new RuntimeException("wrong Action");
+ }
+
+ ectx.getContextInstance().setVariable(IdentityConstants.VALIDATION_HASH, hash);
+ // TODO - build url
+ String activationLink = "validateEmail/" + ectx.getProcessInstance().getId() + "/" + hash;
+ emailMap.put("activationLink", activationLink);
+
+ this.getIdentityMailService().sendMail(action, emailMap, locale);
+ }
+
+ // generating a random hash
+ private String hashGen()
+ {
+ try
+ {
+ SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
+
+ byte[] bytes = new byte[512];
+ secureRandom.nextBytes(bytes);
+
+ double rand = secureRandom.nextDouble();
+ long time = System.currentTimeMillis();
+ String salt = IdentityConstants.HASH_SALT;
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(rand);
+ buffer.append(salt);
+ buffer.append(time);
+
+ return Tools.md5AsHexString(buffer.toString());
+ }
+ catch (NoSuchAlgorithmException e)
+ {
+ log.error("No Such Algorithm exists " + e);
+ }
+ return null;
+ }
+
+ private IdentityMailService getIdentityMailService()
+ {
+ if (identityMailService == null)
+ {
+ try
+ {
+ this.identityMailService = (IdentityMailService) new InitialContext().lookup("java:/portal/IdentityMailService");
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ return identityMailService;
+ }
+
+ private IdentityManagementService getIdentityManagementService()
+ {
+ if (identityManagementService == null)
+ {
+ try
+ {
+ this.identityManagementService = (IdentityManagementService) new InitialContext().lookup("java:/portal/IdentityManagementService");
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ return identityManagementService;
+ }
+
+}
Added: trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/UpdateEmailAction.java
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/UpdateEmailAction.java (rev 0)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/UpdateEmailAction.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -0,0 +1,71 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.identity.services.workflow.impl;
+
+import javax.naming.InitialContext;
+
+import org.jboss.logging.Logger;
+import org.jboss.portal.core.identity.services.IdentityConstants;
+import org.jboss.portal.core.identity.services.workflow.IdentityManagementService;
+import org.jboss.portal.core.identity.services.workflow.UserContainer;
+import org.jbpm.graph.def.ActionHandler;
+import org.jbpm.graph.exe.ExecutionContext;
+
+/**
+ * @author <a href="mailto:emuckenh@redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class UpdateEmailAction implements ActionHandler
+{
+
+ /** . */
+ private IdentityManagementService identityManagementService;
+
+ /** . */
+ private static Logger log = Logger.getLogger(CreateUserAction.class);
+
+ public void execute(ExecutionContext ectx) throws Exception
+ {
+ UserContainer uc = (UserContainer) ectx.getContextInstance().getVariable(IdentityConstants.VARIABLE_USER);
+ String email = (String) ectx.getContextInstance().getVariable(IdentityConstants.VARIABLE_EMAIL);
+
+ this.getIdentityManagementService().updateEmail(uc.getUsername(), email);
+ }
+
+ private IdentityManagementService getIdentityManagementService()
+ {
+ if (identityManagementService == null)
+ {
+ try
+ {
+ identityManagementService = (IdentityManagementService) new InitialContext().lookup("java:/portal/IdentityManagementService");
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ return identityManagementService;
+ }
+}
+
Copied: trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/ValidateEmailServiceImpl.java (from rev 8051, trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/ValidateEmailServiceImpl.java)
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/ValidateEmailServiceImpl.java (rev 0)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/services/workflow/impl/ValidateEmailServiceImpl.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -0,0 +1,237 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.identity.services.workflow.impl;
+
+import java.io.InputStream;
+import java.util.Locale;
+
+import org.jboss.logging.Logger;
+import org.jboss.portal.common.io.IOTools;
+import org.jboss.portal.core.identity.services.IdentityConstants;
+import org.jboss.portal.core.identity.services.workflow.UserContainer;
+import org.jboss.portal.core.identity.services.workflow.ValidateEmailService;
+import org.jboss.portal.identity.User;
+import org.jboss.portal.jems.as.JNDI;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+import org.jboss.portal.workflow.service.WorkflowService;
+import org.jbpm.JbpmContext;
+import org.jbpm.graph.def.ProcessDefinition;
+import org.jbpm.graph.exe.ProcessInstance;
+import org.jbpm.graph.exe.Token;
+
+/**
+ * @author <a href="mailto:emuckenh@redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ValidateEmailServiceImpl extends AbstractJBossService implements ValidateEmailService
+{
+ /** . */
+ private static final Logger log = Logger.getLogger(ValidateEmailService.class);
+
+ /** . */
+ private WorkflowService workflowService = null;
+
+ /** . */
+ private String processName = "jbp_identity_validate_email";
+
+ /** . */
+ private String processFile = "conf/processes/" + processName + ".xml";
+
+ /** . */
+ private boolean overwrite = false;
+
+ /** . */
+ private JNDI.Binding jndiBinding;
+
+ /** . */
+ private String jndiName = null;
+
+ public void startService() throws Exception
+ {
+ super.startService();
+
+ if (this.jndiName != null)
+ {
+ jndiBinding = new JNDI.Binding(jndiName, this);
+ jndiBinding.bind();
+ }
+
+ InputStream is = null;
+ JbpmContext jbpmContext = null;
+ try
+ {
+ jbpmContext = this.workflowService.getJbpmConfiguration().createJbpmContext();
+
+ ProcessDefinition processDefinition = jbpmContext.getGraphSession().findLatestProcessDefinition(
+ this.processName);
+ if (processDefinition == null)
+ {
+ processDefinition = ProcessDefinition.parseXmlResource(processFile);
+ jbpmContext.deployProcessDefinition(processDefinition);
+ }
+ else
+ {
+ ProcessDefinition fromConfig = ProcessDefinition.parseXmlResource(processFile);
+ if (this.overwrite)
+ {
+ jbpmContext.deployProcessDefinition(fromConfig);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ //
+ this.stopService();
+
+ //
+ throw e;
+ }
+ finally
+ {
+ IOTools.safeClose(is);
+ IOTools.safeClose(jbpmContext);
+ }
+ }
+
+ public void stopService() throws Exception
+ {
+ super.stopService();
+
+ if (jndiBinding != null)
+ {
+ jndiBinding.unbind();
+ jndiBinding = null;
+ }
+ }
+
+ /** @return */
+ public WorkflowService getWorkflowService()
+ {
+ return this.workflowService;
+ }
+
+ /** @param workflowService */
+ public void setWorkflowService(WorkflowService workflowService)
+ {
+ this.workflowService = workflowService;
+ }
+
+ /** @return */
+ public String getJNDIName()
+ {
+ return this.jndiName;
+ }
+
+ /** @param jndiName */
+ public void setJNDIName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+
+ /*
+ * Create new changeEmail request
+ */
+ public String changeEmail(User user, String email, Locale locale)
+ {
+ JbpmContext jbpmContext = null;
+ ProcessInstance processInstance = null;
+ // String registrationHash = this.hashGen(); - generated when sending email
+ boolean success = false;
+ try
+ {
+ jbpmContext = this.workflowService.getJbpmConfiguration().createJbpmContext();
+ processInstance = jbpmContext.newProcessInstance(this.processName);
+ Token token = processInstance.getRootToken();
+
+ processInstance.getContextInstance().setVariable(IdentityConstants.VARIABLE_USER, new UserContainer(user));
+ processInstance.getContextInstance().setVariable(IdentityConstants.VARIABLE_EMAIL, email);
+ processInstance.getContextInstance().setVariable(IdentityConstants.VARIABLE_LOCALE, locale);
+ processInstance.getContextInstance().setVariable(IdentityConstants.ACTION, IdentityConstants.ACTION_CHANGE_EMAIL);
+
+ token.signal();
+ success = true;
+ }
+ catch (Exception e)
+ {
+ success = false;
+ log.error("Exception in Workflow", e);
+ // throw new WorkflowException(e);
+ }
+ finally
+ {
+ if (processInstance != null && success)
+ {
+ jbpmContext.save(processInstance);
+ }
+ IOTools.safeClose(jbpmContext);
+ }
+ // TODO
+ return IdentityConstants.REGISTRATION_PENDING;
+ }
+
+ public boolean validateEmail(String id, String registrationHash)
+ {
+ JbpmContext jbpmContext = null;
+ boolean success = false;
+ try
+ {
+ long processId = Long.valueOf(id).longValue();
+ jbpmContext = this.workflowService.getJbpmConfiguration().createJbpmContext();
+ ProcessInstance processInstance = jbpmContext.getProcessInstance(processId);
+
+ if (processInstance != null)
+ {
+ Token token = processInstance.getRootToken();
+ if (token != null && token.getNode().getName().equals("validate_email"))
+ {
+ String hash = (String) processInstance.getContextInstance().getVariable(IdentityConstants.VALIDATION_HASH);
+ if (registrationHash.equals(hash) && ! processInstance.hasEnded())
+ {
+ String action = (String) processInstance.getContextInstance().getVariable(IdentityConstants.ACTION);
+ // Processing email change request to transition changeEmail
+ if(IdentityConstants.ACTION_CHANGE_EMAIL.equals(action))
+ {
+ token.signal("changeEmail");
+ }
+ // Processing other requests to end state with ok
+ else
+ {
+ token.signal("ok");
+ }
+ success = true;
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ log.error("", e);
+ }
+ finally
+ {
+ IOTools.safeClose(jbpmContext);
+ }
+ return success;
+ }
+}
+
Modified: trunk/core-identity/src/main/org/jboss/portal/core/identity/ui/admin/RoleManagementBean.java
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/ui/admin/RoleManagementBean.java 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/ui/admin/RoleManagementBean.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -32,12 +32,10 @@
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.model.ListDataModel;
-import javax.faces.model.SelectItem;
import org.jboss.portal.core.identity.ui.IdentityUIUser;
import org.jboss.portal.core.identity.ui.UIRole;
import org.jboss.portal.core.identity.ui.common.IdentityRoleBean;
-import org.jboss.portal.core.identity.ui.common.IdentityUserBean;
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.Role;
import org.jboss.portal.identity.User;
Modified: trunk/core-identity/src/main/org/jboss/portal/core/identity/ui/admin/UserAdministrationBean.java
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/ui/admin/UserAdministrationBean.java 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/ui/admin/UserAdministrationBean.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -27,7 +27,6 @@
import java.util.List;
import java.util.Map;
-import javax.faces.application.FacesMessage;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
@@ -62,7 +61,7 @@
private int limit = 10;
/** . */
- private int userCount;
+ private int userCount = 0;
/** . */
private List roles = new ArrayList();
@@ -201,7 +200,7 @@
e.printStackTrace();
}
}
- return "userAdmin";
+ return "searchUsers";
}
public String enableUser()
@@ -241,9 +240,30 @@
// Updating search
return this.searchUsers();
}
- return "userAdmin";
+ return "searchUsers";
}
+ public int getPendingCount()
+ {
+ return this.registrationService.getPendingCount();
+ }
+
+ public int getUserCount()
+ {
+ if (userCount == 0)
+ {
+ try
+ {
+ userCount = this.identityUserBean.getUserModule().getUserCount();
+ }
+ catch (Exception e)
+ {
+ log.error("", e);
+ }
+ }
+ return userCount;
+ }
+
public List getPendingUsers()
{
List list = new ArrayList();
@@ -285,14 +305,14 @@
{
this.page++;
this.searchUsers();
- return "userAdmin";
+ return "searchUsers";
}
public String prevPage()
{
this.page--;
this.searchUsers();
- return "userAdmin";
+ return "searchUsers";
}
public String approveRegistration()
Modified: trunk/core-identity/src/main/org/jboss/portal/core/identity/ui/common/IdentityRoleBean.java
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/ui/common/IdentityRoleBean.java 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/ui/common/IdentityRoleBean.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -88,7 +88,7 @@
Set roleSet = this.checkRoles(roles);
this.membershipModule.assignRoles(user, roleSet);
}
-
+
private Set checkRoles(List roles) throws IllegalArgumentException, IdentityException
{
Set roleSet = new HashSet();
@@ -110,23 +110,8 @@
roleSet.add(role);
}
}
- return roleSet;
}
- else
- {
- Role role = roleModule.findRoleByName(defaultRole);
-
- if (role != null)
- {
- roleSet.add(role);
- }
- else
- {
- throw new IllegalArgumentException();
- }
-
- return roleSet;
- }
+ return roleSet;
}
public void updateRoleDisplayName(String roleName, String roleDisplayName) throws IllegalArgumentException,
Modified: trunk/core-identity/src/main/org/jboss/portal/core/identity/ui/common/IdentityUserBean.java
===================================================================
--- trunk/core-identity/src/main/org/jboss/portal/core/identity/ui/common/IdentityUserBean.java 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/main/org/jboss/portal/core/identity/ui/common/IdentityUserBean.java 2007-08-28 17:50:11 UTC (rev 8071)
@@ -164,7 +164,15 @@
public Class getPropertyType(String propertyName) throws IdentityException
{
UIAttribute uiAttribute = (UIAttribute) this.metaDataService.getValue(propertyName).getObject();
- return userProfileModule.getProfileInfo().getPropertyInfo(uiAttribute.getIdentifier()).getClass();
+ String type = userProfileModule.getProfileInfo().getPropertyInfo(uiAttribute.getIdentifier()).getType();
+ try
+ {
+ return ClassLoader.getSystemClassLoader().loadClass(type);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
}
public Object getUserProperty(String username, String propertyName) throws IllegalArgumentException, NoSuchUserException, IdentityException
Modified: trunk/core-identity/src/resources/portal-identity-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/core-identity/src/resources/portal-identity-sar/META-INF/jboss-service.xml 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/resources/portal-identity-sar/META-INF/jboss-service.xml 2007-08-28 17:50:11 UTC (rev 8071)
@@ -29,12 +29,6 @@
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
<xmbean/>
<depends
- optional-attribute-name="ServerConfig"
- proxy-type="attribute">portal:service=ServerConfig</depends>
- <depends
- optional-attribute-name="RegistrationService"
- proxy-type="attribute">portal:service=RegistrationService,type=Workflow</depends>
- <depends
optional-attribute-name="ValidateEmailService"
proxy-type="attribute">portal:service=ValidateEmailService,type=Workflow</depends>
</mbean>
@@ -45,6 +39,7 @@
xmbean-dd=""
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
<xmbean/>
+ <!-- depends on MailModule -->
<attribute name="JNDIName">java:portal/IdentityMailService</attribute>
</mbean>
@@ -64,7 +59,17 @@
</mbean>
<mbean
- code="org.jboss.portal.core.identity.services.workflow.ApproveRegistration"
+ code="org.jboss.portal.core.identity.services.workflow.impl.IdentityManagementServiceImpl"
+ name="portal:service=IdentityManagementService,type=IdentityUI"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <xmbean/>
+ <!-- depends on UserModule, RoleModule, UserProfileModule, MemberShipModule -->
+ <attribute name="JNDIName">java:portal/IdentityManagementService</attribute>
+ </mbean>
+
+ <mbean
+ code="org.jboss.portal.core.identity.services.workflow.impl.RegistrationServiceImpl"
name="portal:service=RegistrationService,type=Workflow"
xmbean-dd=""
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
@@ -72,13 +77,14 @@
<depends optional-attribute-name="WorkflowService" proxy-type="attribute">
portal:service=Workflow,type=WorkflowService
</depends>
- <depends optional-attribute-name="ValidateEmailService"
- proxy-type="attribute">portal:service=ValidateEmailService,type=Workflow</depends>
+ <depends optional-attribute-name="ValidateEmailService" proxy-type="attribute">
+ portal:service=ValidateEmailService,type=Workflow
+ </depends>
<attribute name="JNDIName">java:portal/RegistrationService</attribute>
</mbean>
<mbean
- code="org.jboss.portal.core.identity.services.workflow.ValidateEmailServiceImpl"
+ code="org.jboss.portal.core.identity.services.workflow.impl.ValidateEmailServiceImpl"
name="portal:service=ValidateEmailService,type=Workflow"
xmbean-dd=""
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
Modified: trunk/core-identity/src/resources/portal-identity-sar/conf/processes/jbp_identity_validate_email.xml
===================================================================
--- trunk/core-identity/src/resources/portal-identity-sar/conf/processes/jbp_identity_validate_email.xml 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/resources/portal-identity-sar/conf/processes/jbp_identity_validate_email.xml 2007-08-28 17:50:11 UTC (rev 8071)
@@ -6,15 +6,15 @@
<process-definition name="jbp_identity_validate_email">
<start-state>
<transition to="validate_email">
- <action class="org.jboss.portal.core.identity.services.workflow.SendValidationMailAction"/>
+ <action class="org.jboss.portal.core.identity.services.workflow.impl.SendValidationMailAction"/>
</transition>
</start-state>
<state name="validate_email">
- <create-timer name="time_to_expire" duedate="24 hours" transition="timedOut" />
+ <create-timer name="time_to_expire" duedate="5 minutes" transition="timedOut" />
<transition name="ok" to="validated"/>
<transition name="timedOut" to="expired"/>
<transition name="changeEmail" to="validated">
- <!-- call action and update email -->
+ <action class="org.jboss.portal.core.identity.services.workflow.impl.UpdateEmailAction"/>
</transition>
</state>
<end-state name="validated"/>
Modified: trunk/core-identity/src/resources/portal-identity-sar/conf/processes/jbp_identity_validation_approval_workflow.xml
===================================================================
--- trunk/core-identity/src/resources/portal-identity-sar/conf/processes/jbp_identity_validation_approval_workflow.xml 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/resources/portal-identity-sar/conf/processes/jbp_identity_validation_approval_workflow.xml 2007-08-28 17:50:11 UTC (rev 8071)
@@ -17,8 +17,8 @@
<transition name="expired" to="end"/>
</process-state>
<state name="adminApproval">
- <transition name="validated" to="end">
- <action class="org.jboss.portal.core.identity.services.workflow.CreateUserAction"/>
+ <transition name="approved" to="end">
+ <action class="org.jboss.portal.core.identity.services.workflow.impl.CreateUserAction"/>
</transition>
<transition name="rejected" to="end"/>
</state>
Added: trunk/core-identity/src/resources/portal-identity-sar/conf/processes/jbp_identity_validation_workflow.xml
===================================================================
--- trunk/core-identity/src/resources/portal-identity-sar/conf/processes/jbp_identity_validation_workflow.xml (rev 0)
+++ trunk/core-identity/src/resources/portal-identity-sar/conf/processes/jbp_identity_validation_workflow.xml 2007-08-28 17:50:11 UTC (rev 8071)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE process-definition PUBLIC
+ "-//jBpm/jBpm Mapping DTD 2.0//EN"
+ "http://jbpm.org/dtd/processdefinition-2.0.dtd">
+
+<process-definition name="jbp_identity_validation_workflow">
+ <start-state>
+ <transition to="emailValidation"/>
+ </start-state>
+ <process-state name="emailValidation">
+ <sub-process name="jbp_identity_validate_email"/>
+ <variable name="user" access="read" mapped-name="user"/>
+ <variable name="email" access="read" mapped-name="email"/>
+ <variable name="locale" access="read" mapped-name="locale"/>
+ <variable name="action" access="read" mapped-name="action"/>
+ <transition name="validated" to="end">
+ <action class="org.jboss.portal.core.identity.services.workflow.impl.CreateUserAction"/>
+ </transition>
+ <transition name="expired" to="end"/>
+ </process-state>
+ <end-state name="end"/>
+</process-definition>
\ No newline at end of file
Property changes on: trunk/core-identity/src/resources/portal-identity-war/WEB-INF
___________________________________________________________________
Name: svn:ignore
+ portal-identity-objects.xml
portal-identity-object.xml
Modified: trunk/core-identity/src/resources/portal-identity-war/WEB-INF/faces-config.xml
===================================================================
--- trunk/core-identity/src/resources/portal-identity-war/WEB-INF/faces-config.xml 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/resources/portal-identity-war/WEB-INF/faces-config.xml 2007-08-28 17:50:11 UTC (rev 8071)
@@ -302,6 +302,13 @@
<navigation-rule>
<from-view-id>/WEB-INF/jsf/admin/index.xhtml</from-view-id>
<navigation-case>
+ <from-outcome>searchUsers</from-outcome>
+ <to-view-id>/WEB-INF/jsf/admin/user/searchUsers.xhtml</to-view-id>
+ </navigation-case>
+ </navigation-rule>
+ <navigation-rule>
+ <from-view-id>/WEB-INF/jsf/admin/index.xhtml</from-view-id>
+ <navigation-case>
<from-outcome>showPendingUsers</from-outcome>
<to-view-id>/WEB-INF/jsf/admin/user/pendingUsers.xhtml</to-view-id>
</navigation-case>
@@ -323,7 +330,7 @@
<navigation-case>
<from-action>#{editprofilemgr.updateProfile}</from-action>
<from-outcome>editProfile</from-outcome>
- <to-view-id>/WEB-INF/jsf/admin/index.xhtml</to-view-id>
+ <to-view-id>/WEB-INF/jsf/admin/user/searchUsers.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
@@ -395,7 +402,7 @@
<navigation-case>
<from-action>#{lostpasswordmgr.doomed}</from-action>
<from-outcome>status</from-outcome>
- <to-view-id>/WEB-INF/jsf/admin/index.xhtml</to-view-id>
+ <to-view-id>/WEB-INF/jsf/admin/user/searchUsers.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{lostpasswordmgr.doomed}</from-action>
Modified: trunk/core-identity/src/resources/portal-identity-war/WEB-INF/jsf/admin/index.xhtml
===================================================================
--- trunk/core-identity/src/resources/portal-identity-war/WEB-INF/jsf/admin/index.xhtml 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/resources/portal-identity-war/WEB-INF/jsf/admin/index.xhtml 2007-08-28 17:50:11 UTC (rev 8071)
@@ -7,80 +7,22 @@
class="identity-ui">
<ui:composition template="/WEB-INF/jsf/admin/user/userTemplate.xhtml">
-<ui:define name="title"><h:outputText value="#{bundle.IDENTITY_MANAGEMENT_SEARCH_USER}"/></ui:define>
+<ui:define name="title"/>
<ui:define name="content">
-<h:commandLink value="show pending users" action="showPendingUsers"/>
-
- <h:form>
- <h:panelGrid columns="3">
- <h:inputText id="searchString" value="#{useradministrationbean.searchString}" />
- <h:commandButton value="Search" action="#{useradministrationbean.searchUsers}" styleClass="portlet-form-button"/>
- <h:selectOneMenu id="limit" value="#{useradministrationbean.limit}">
- <f:selectItem id="limit1" itemValue="10"/>
- <f:selectItem id="limit2" itemValue="20"/>
- <f:selectItem id="limit5" itemValue="50"/>
- <f:selectItem id="limit10" itemValue="100"/>
- </h:selectOneMenu>
+ <ul>
+ <li><h:commandLink value="#{bundle.IDENTITY_MANAGEMENT_SEARCH_USER}" action="searchUsers"/></li>
+ <li><h:commandLink value="Show pending registrations" action="showPendingUsers"/></li>
+ <li><h:commandLink value="#{bundle.IDENTITY_MANAGEMENT_CREATE_USER}" action="createUser"/></li>
+ </ul>
+ <hr/>
+ <h:panelGrid columns="2">
+ <h:outputText value="Registered Users"/>
+ <h:outputText value="#{useradministrationbean.userCount}" />
+ <h:outputText value="Pending Registrations" />
+ <h:outputText value="#{useradministrationbean.pendingCount}" />
</h:panelGrid>
- </h:form>
-<hr/>
-
- <h:dataTable id="userlist" value="#{useradministrationbean.userList}" var="uiUser" rendered="#{useradministrationbean.userList.rowCount > 0}" rows="#{useradministrationbean.limit}" rowClasses="portlet-section-body,portlet-section-alternate" headerClass="portlet-section-header" width="100%">
- <h:column>
- <f:facet name="header">
- <h:outputText value="#{bundle.IDENTITY_USERNAME}"/>
- </f:facet>
- <h:outputText value="#{uiUser.username}"/>
- </h:column>
- <h:column>
- <f:facet name="header">
- <h:outputText value="#{bundle.IDENTITY_GIVENNAME}"/>
- </f:facet>
- <h:outputText value="#{uiUser.attribute.givenname}"/>
- </h:column>
- <h:column>
- <f:facet name="header">
- <h:outputText value="#{bundle.IDENTITY_FAMILYNAME}"/>
- </f:facet>
- <h:outputText value="#{uiUser.attribute.familyname}"/>
- </h:column>
- <h:column>
- <f:facet name="header">
- <h:outputText value="#{bundle.IDENTITY_ENABLED}"/>
- </f:facet>
- <h:selectBooleanCheckbox id="enabled" value="#{uiUser.attribute.enabled}" disabled="true" />
- </h:column>
- <h:column>
- <f:facet name="header">
- <h:outputText value="#{bundle.IDENTITY_MANAGEMENT_ACTION}"/>
- </f:facet>
- <h:commandLink action="#{editprofilemgr.editProfile}">
- <h:outputText value="#{bundle.IDENTITY_MANAGEMENT_ACTION_EDIT_PROFILE}"/>
- <f:param name="currentUser" value="#{uiUser.username}"/>
- </h:commandLink> |
- <h:commandLink action="#{assignrolemgr.assignRoles}">
- <h:outputText value="#{bundle.IDENTITY_MANAGEMENT_ACTION_ROLES}"/>
- <f:param name="currentUser" value="#{uiUser.username}"/>
- </h:commandLink> |
- <h:commandLink action="#{useradministrationbean.enableUser}">
- <h:outputText value="#{uiUser.attribute.enabled == true ? bundle.IDENTITY_MANAGEMENT_DISABLE : bundle.IDENTITY_MANAGEMENT_ENABLE}" />
- <f:param name="currentUser" value="#{uiUser.username}"/>
- <f:param name="enableAction" value="#{uiUser.attribute.enabled == true ? 'disable' : 'enable'}" />
- </h:commandLink> |
- <h:commandLink action="#{useradministrationbean.deleteUser}">
- <h:outputText value="#{bundle.IDENTITY_MANAGEMENT_ACTION_DELETE}"/>
- <f:param name="currentUser" value="#{uiUser.username}"/>
- </h:commandLink>
- </h:column>
- </h:dataTable>
-
-
- <h:commandLink value=" < " action="#{useradministrationbean.prevPage}" rendered="#{useradministrationbean.page > 1}" styleClass="portlet-form-button"/>
- <h:commandLink value=" > " action="#{useradministrationbean.nextPage}" rendered="#{useradministrationbean.userList.rowCount > useradministrationbean.limit}" styleClass="portlet-form-button"/>
-
-
- <p style="text-align: right"><h:commandLink value="#{bundle.IDENTITY_MANAGEMENT_CREATE_USER}" action="createUser"/></p>
+
</ui:define>
</ui:composition>
Modified: trunk/core-identity/src/resources/portal-identity-war/WEB-INF/jsf/admin/user/pendingUsers.xhtml
===================================================================
--- trunk/core-identity/src/resources/portal-identity-war/WEB-INF/jsf/admin/user/pendingUsers.xhtml 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/resources/portal-identity-war/WEB-INF/jsf/admin/user/pendingUsers.xhtml 2007-08-28 17:50:11 UTC (rev 8071)
@@ -8,12 +8,12 @@
<ui:composition template="/WEB-INF/jsf/admin/user/userTemplate.xhtml">
-<ui:define name="title">title TODO pending users</ui:define>
+<ui:define name="title">Pending registrations</ui:define>
<ui:define name="content">
-<h:dataTable value="#{useradministrationbean.pendingUsers}" var="user">
+<h:dataTable value="#{useradministrationbean.pendingUsers}" var="user" rowClasses="portlet-section-body,portlet-section-alternate" headerClass="portlet-section-header" width="100%">
<h:column>
<f:facet name="header">
- <h:outputText value="processId"/>
+ <h:outputText value="id"/>
</f:facet>
<h:outputText value="#{user.processId}"/>
</h:column>
@@ -40,18 +40,18 @@
<h:outputText value="status"/>
</f:facet>
<h:outputText value="Pending" rendered="#{user.currentNode == 'emailValidation'}"/>
- <c:if test="#{user.currentNode == 'adminApproval'}">
- <h:commandLink action="#{useradministrationbean.approveRegistration}">
+ <!-- #{user.currentNode == 'adminApproval'} -->
+ <h:commandLink action="#{useradministrationbean.approveRegistration}" rendered="#{user.currentNode == 'adminApproval'}">
<h:outputText value="approve"/>
<f:param name="processId" value="#{user.processId}" />
<f:param name="action" value="approve" />
- </h:commandLink> |
- <h:commandLink action="#{useradministrationbean.approveRegistration}">
+ </h:commandLink>
+ <h:outputText value=" | " rendered="#{user.currentNode == 'adminApproval'}" />
+ <h:commandLink action="#{useradministrationbean.approveRegistration}" rendered="#{user.currentNode == 'adminApproval'}">
<h:outputText value="reject"/>
<f:param name="processId" value="#{user.processId}" />
<f:param name="action" value="reject" />
- </h:commandLink>
- </c:if>
+ </h:commandLink>
</h:column>
</h:dataTable>
Added: trunk/core-identity/src/resources/portal-identity-war/WEB-INF/jsf/admin/user/searchUsers.xhtml
===================================================================
--- trunk/core-identity/src/resources/portal-identity-war/WEB-INF/jsf/admin/user/searchUsers.xhtml (rev 0)
+++ trunk/core-identity/src/resources/portal-identity-war/WEB-INF/jsf/admin/user/searchUsers.xhtml 2007-08-28 17:50:11 UTC (rev 8071)
@@ -0,0 +1,84 @@
+<div
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:c="http://java.sun.com/jstl/core"
+ class="identity-ui">
+
+<ui:composition template="/WEB-INF/jsf/admin/user/userTemplate.xhtml">
+
+<ui:define name="title">
+ <h:outputText value="#{bundle.IDENTITY_MANAGEMENT_SEARCH_USER}"/>
+</ui:define>
+<ui:define name="content">
+ <h:form>
+ <h:panelGrid columns="3">
+ <h:inputText id="searchString" value="#{useradministrationbean.searchString}" />
+ <h:commandButton value="Search" action="#{useradministrationbean.searchUsers}" styleClass="portlet-form-button"/>
+ <h:selectOneMenu id="limit" value="#{useradministrationbean.limit}">
+ <f:selectItem id="limit1" itemValue="10"/>
+ <f:selectItem id="limit2" itemValue="20"/>
+ <f:selectItem id="limit5" itemValue="50"/>
+ <f:selectItem id="limit10" itemValue="100"/>
+ </h:selectOneMenu>
+ </h:panelGrid>
+ </h:form>
+ <hr/>
+
+ <h:dataTable id="userlist" value="#{useradministrationbean.userList}" var="uiUser" rendered="#{useradministrationbean.userList.rowCount > 0}" rows="#{useradministrationbean.limit}" rowClasses="portlet-section-body,portlet-section-alternate" headerClass="portlet-section-header" width="100%">
+ <h:column>
+ <f:facet name="header">
+ <h:outputText value="#{bundle.IDENTITY_USERNAME}"/>
+ </f:facet>
+ <h:outputText value="#{uiUser.username}"/>
+ </h:column>
+ <h:column>
+ <f:facet name="header">
+ <h:outputText value="#{bundle.IDENTITY_GIVENNAME}"/>
+ </f:facet>
+ <h:outputText value="#{uiUser.attribute.givenname}"/>
+ </h:column>
+ <h:column>
+ <f:facet name="header">
+ <h:outputText value="#{bundle.IDENTITY_FAMILYNAME}"/>
+ </f:facet>
+ <h:outputText value="#{uiUser.attribute.familyname}"/>
+ </h:column>
+ <h:column>
+ <f:facet name="header">
+ <h:outputText value="#{bundle.IDENTITY_ENABLED}"/>
+ </f:facet>
+ <h:selectBooleanCheckbox id="enabled" value="#{uiUser.attribute.enabled}" disabled="true" />
+ </h:column>
+ <h:column>
+ <f:facet name="header">
+ <h:outputText value="#{bundle.IDENTITY_MANAGEMENT_ACTION}"/>
+ </f:facet>
+ <h:commandLink action="#{editprofilemgr.editProfile}">
+ <h:outputText value="#{bundle.IDENTITY_MANAGEMENT_ACTION_EDIT_PROFILE}"/>
+ <f:param name="currentUser" value="#{uiUser.username}"/>
+ </h:commandLink> |
+ <h:commandLink action="#{assignrolemgr.assignRoles}">
+ <h:outputText value="#{bundle.IDENTITY_MANAGEMENT_ACTION_ROLES}"/>
+ <f:param name="currentUser" value="#{uiUser.username}"/>
+ </h:commandLink> |
+ <h:commandLink action="#{useradministrationbean.enableUser}">
+ <h:outputText value="#{uiUser.attribute.enabled == true ? bundle.IDENTITY_MANAGEMENT_DISABLE : bundle.IDENTITY_MANAGEMENT_ENABLE}" />
+ <f:param name="currentUser" value="#{uiUser.username}"/>
+ <f:param name="enableAction" value="#{uiUser.attribute.enabled == true ? 'disable' : 'enable'}" />
+ </h:commandLink> |
+ <h:commandLink action="#{useradministrationbean.deleteUser}">
+ <h:outputText value="#{bundle.IDENTITY_MANAGEMENT_ACTION_DELETE}"/>
+ <f:param name="currentUser" value="#{uiUser.username}"/>
+ </h:commandLink>
+ </h:column>
+ </h:dataTable>
+
+
+ <h:commandLink value=" < " action="#{useradministrationbean.prevPage}" rendered="#{useradministrationbean.page > 1}" styleClass="portlet-form-button"/>
+ <h:commandLink value=" > " action="#{useradministrationbean.nextPage}" rendered="#{useradministrationbean.userList.rowCount > useradministrationbean.limit}" styleClass="portlet-form-button"/>
+ <br/>
+</ui:define>
+</ui:composition>
+</div>
\ No newline at end of file
Modified: trunk/core-identity/src/resources/portal-identity-war/WEB-INF/portlet-instances.xml
===================================================================
--- trunk/core-identity/src/resources/portal-identity-war/WEB-INF/portlet-instances.xml 2007-08-28 16:08:00 UTC (rev 8070)
+++ trunk/core-identity/src/resources/portal-identity-war/WEB-INF/portlet-instances.xml 2007-08-28 17:50:11 UTC (rev 8071)
@@ -37,12 +37,14 @@
<instance>
<instance-id>CoreIdentityAdminPortletInstance</instance-id>
<portlet-ref>CoreIdentityAdminPortlet</portlet-ref>
+<!--
<security-constraint>
<policy-permission>
<role-name>Admin</role-name>
<action-name>view</action-name>
</policy-permission>
</security-constraint>
+ -->
</instance>
</deployment>
</deployments>
\ No newline at end of file
16 years, 9 months
JBoss Portal SVN: r8070 - docs/branches/JBoss_Portal_Branch_2_6/referenceGuide/en/modules.
by portal-commits@lists.jboss.org
Author: thomas.heute(a)jboss.com
Date: 2007-08-28 12:08:00 -0400 (Tue, 28 Aug 2007)
New Revision: 8070
Modified:
docs/branches/JBoss_Portal_Branch_2_6/referenceGuide/en/modules/installation.xml
Log:
JBPORTAL-1649: Update installation instruction for JBoss AS 4.2.1.GA
Modified: docs/branches/JBoss_Portal_Branch_2_6/referenceGuide/en/modules/installation.xml
===================================================================
--- docs/branches/JBoss_Portal_Branch_2_6/referenceGuide/en/modules/installation.xml 2007-08-28 15:53:58 UTC (rev 8069)
+++ docs/branches/JBoss_Portal_Branch_2_6/referenceGuide/en/modules/installation.xml 2007-08-28 16:08:00 UTC (rev 8070)
@@ -110,7 +110,8 @@
<sect3>
<title>Application Server Setup</title>
<para>Of course you will need to install JBoss Application Server prior to installing JBoss
- portal, if you didn't do so yet, please install JBoss 4.0.5+ from
+ portal, if you didn't do so yet, please install JBoss EAP 4.2, JBoss AS 4.2.1 or JBoss AS 4.0.5 if
+ you have to. You can have access to the EAP version from the support portal or the other versions
<ulink
url="http://labs.jboss.com/portal/jbossas/download/index.html"
>here
@@ -126,7 +127,7 @@
</sect3>
<sect3>
<title>Database Setup</title>
- <para>You will need a database for JBoss Portal to function, you can use any database
+ <para>You will need a database for JBoss Portal to run, you can use any database
supported by Hibernate.
<orderedlist>
<listitem>
@@ -271,7 +272,8 @@
<sect3>
<title>Application Server Setup</title>
<para>Of course you will need to install JBoss Application Server prior to installing JBoss
- portal, if you didn't do so yet, please install JBoss 4.0.5+ from
+ portal, if you didn't do so yet, please install JBoss EAP 4.2, JBoss AS 4.2.1 or JBoss AS 4.0.5 if
+ you have to. You can have access to the EAP version from the support portal or the other versions
<ulink
url="http://labs.jboss.com/portal/jbossas/download/index.html"
>here
16 years, 9 months
JBoss Portal SVN: r8069 - in branches/UIServer: uiserver and 6 other directories.
by portal-commits@lists.jboss.org
Author: sohil.shah(a)jboss.com
Date: 2007-08-28 11:53:58 -0400 (Tue, 28 Aug 2007)
New Revision: 8069
Added:
branches/UIServer/uiserver/src/main/org/jboss/portal/test/uiserver/layout/TestRegionLayoutManager.java
branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/classic/RegionConstraints.java
branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/classic/RegionLayoutManager.java
branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/protocol/
branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/protocol/PageResult.java
branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/protocol/WindowResult.java
branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/service/
branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/service/UIServer.java
Modified:
branches/UIServer/core/src/main/org/jboss/portal/core/theme/PageRendition.java
branches/UIServer/uiserver/
branches/UIServer/uiserver/build.xml
branches/UIServer/uiserver/src/main/org/jboss/portal/test/uiserver/layout/TestFlexibleGrid.java
branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/Component.java
branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/LayoutService.java
branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/Page.java
branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/Window.java
branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/classic/FlexibleGrid.java
branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/classic/FlexibleGridLayoutManager.java
Log:
Prototype for the LayoutManagement service of UIServer
Modified: branches/UIServer/core/src/main/org/jboss/portal/core/theme/PageRendition.java
===================================================================
--- branches/UIServer/core/src/main/org/jboss/portal/core/theme/PageRendition.java 2007-08-28 13:44:21 UTC (rev 8068)
+++ branches/UIServer/core/src/main/org/jboss/portal/core/theme/PageRendition.java 2007-08-28 15:53:58 UTC (rev 8069)
@@ -30,12 +30,21 @@
import org.jboss.portal.theme.PortalTheme;
import org.jboss.portal.theme.page.PageResult;
import org.jboss.portal.common.util.MarkupInfo;
+import org.jboss.portal.theme.page.WindowContext;
+import org.jboss.portal.theme.page.WindowResult;
import org.jboss.portal.web.ServletContextDispatcher;
import org.jboss.portal.core.controller.ControllerResponse;
import javax.servlet.ServletException;
+import java.io.PrintWriter;
import java.io.IOException;
+import java.util.Map;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
+import org.jboss.portal.uiserver.service.UIServer;
+
/**
* Should not be a controller response, but it comes from legacy design.
*
@@ -72,8 +81,9 @@
/** Performs the page rendition. */
public void render(MarkupInfo markupInfo, ServletContextDispatcher dispatcher) throws IOException, ServletException
{
+ /*
// Compute correct content type response header
-// String contentType = rendererContext.getContentType() + "; charset=" + rendererContext.getCharset();
+ //String contentType = rendererContext.getContentType() + "; charset=" + rendererContext.getCharset();
String contentType = markupInfo.getContentType() + "; charset=" + markupInfo.getCharset();
// Set charset and content type on the response
@@ -86,8 +96,9 @@
//
RendererContext rendererContext = layout.getRenderContext(themeContext, markupInfo, dispatcher);
-
+
//
+ //This is the non-uiserver based rendering
try
{
rendererContext.render(pageResult);
@@ -96,10 +107,35 @@
{
e.printStackTrace();
}
+ */
+
+ //Prototyping with the new ui server delegated rendering
+ UIServer uiServer = new UIServer(); //This will actually be a jmx service...instead of instantiating the UiServer here
+
+ //Setup the Windows for the UIServer
+ List uiWindows = new ArrayList();
+ Map windowContexts = pageResult.getWindowContextMap();
+ for(Iterator itr=windowContexts.values().iterator();itr.hasNext();)
+ {
+ WindowContext wc = (WindowContext)itr.next();
+ WindowResult result = wc.getResult();
+
+ org.jboss.portal.uiserver.protocol.WindowResult uiWindow = new org.jboss.portal.uiserver.protocol.WindowResult(wc.getId(),
+ result.getTitle(), result.getContent(), result.getHeaderContent(), result.getWindowState(), result.getMode()
+ );
+
+ uiWindows.add(uiWindow);
+ }
+
+ //Setup the Page for the UIServer
+ org.jboss.portal.uiserver.protocol.PageResult uiPageResult = new org.jboss.portal.uiserver.protocol.PageResult(this.pageResult.getPageName(), uiWindows);
+
+ //Delegate Rendering to the UIServer
+ uiServer.render(new PrintWriter(dispatcher.getResponse().getOutputStream()), uiPageResult);
}
public PageResult getPageResult()
{
return pageResult;
- }
+ }
}
Property changes on: branches/UIServer/uiserver
___________________________________________________________________
Name: svn:ignore
+ output
src-backup
Modified: branches/UIServer/uiserver/build.xml
===================================================================
--- branches/UIServer/uiserver/build.xml 2007-08-28 13:44:21 UTC (rev 8068)
+++ branches/UIServer/uiserver/build.xml 2007-08-28 15:53:58 UTC (rev 8069)
@@ -96,6 +96,7 @@
<!-- Configure modules -->
<call target="configure-modules"/>
<path id="dependentmodule.classpath">
+ <path refid="jboss.portlet-api.classpath"/>
<path refid="jboss.portal-common.classpath"/>
<path refid="jboss.portal-jems.classpath"/>
<path refid="jboss.portal-server.classpath"/>
Modified: branches/UIServer/uiserver/src/main/org/jboss/portal/test/uiserver/layout/TestFlexibleGrid.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/test/uiserver/layout/TestFlexibleGrid.java 2007-08-28 13:44:21 UTC (rev 8068)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/test/uiserver/layout/TestFlexibleGrid.java 2007-08-28 15:53:58 UTC (rev 8069)
@@ -75,12 +75,12 @@
Window window2 = new Window("window-2", htmlContent);
container.addComponent(window1);
container.addComponent(window2);
- page.getContainers().add(container);
+ page.addContainer(container);
Container container2 = new Container("container-2");
container2.addComponent(window1);
container2.addComponent(window2);
- page.getContainers().add(container2);
+ page.addContainer(container2);
// Setup a Flexible Grid for laying out a container of portlet windows
@@ -196,6 +196,10 @@
constraints.setWidthPercentage(widthPercentage);
constraints.setRow(row);
constraints.setColumn(column);
+ constraints.setTop(top);
+ constraints.setBottom(bottom);
+ constraints.setLeft(left);
+ constraints.setRight(right);
return constraints;
}
}
Added: branches/UIServer/uiserver/src/main/org/jboss/portal/test/uiserver/layout/TestRegionLayoutManager.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/test/uiserver/layout/TestRegionLayoutManager.java (rev 0)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/test/uiserver/layout/TestRegionLayoutManager.java 2007-08-28 15:53:58 UTC (rev 8069)
@@ -0,0 +1,151 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.uiserver.layout;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+
+import java.io.FileOutputStream;
+
+import org.jboss.portal.uiserver.layout.Container;
+import org.jboss.portal.uiserver.layout.Window;
+import org.jboss.portal.uiserver.layout.Page;
+import org.jboss.portal.uiserver.layout.classic.RegionConstraints;
+import org.jboss.portal.uiserver.layout.classic.RegionLayoutManager;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class TestRegionLayoutManager extends TestCase
+{
+ /**
+ *
+ */
+ private static Logger log = Logger.getLogger(TestRegionLayoutManager.class);
+
+ /**
+ *
+ */
+ protected void setUp() throws Exception
+ {
+ }
+
+ /**
+ *
+ */
+ protected void tearDown() throws Exception
+ {
+ }
+
+ /**
+ *
+ * @throws Exception
+ */
+ public void testDoLayout() throws Exception
+ {
+ // Setup a Page and a container with two portlet windows...
+ // This part is generic with no decoupling to anything layout specific
+ String htmlContent = this.getHtmlContent();
+ Page page = new Page();
+ Container container = new Container("container-1");
+ Window window1 = new Window("window-1", htmlContent);
+ Window window2 = new Window("window-2", htmlContent);
+ container.addComponent(window1);
+ container.addComponent(window2);
+ page.addContainer(container);
+
+ Container container2 = new Container("container-2");
+ Window window3 = new Window("window-3", htmlContent);
+ Window window4 = new Window("window-4", htmlContent);
+ container2.addComponent(window3);
+ container2.addComponent(window4);
+ page.addContainer(container2);
+
+
+ // Setup a two RegionConstraints for laying out using RegionLayoutManager
+ RegionConstraints leftRegion = new RegionConstraints("container-1",RegionConstraints.LEFT);
+ RegionConstraints centerRegion = new RegionConstraints("container-2",RegionConstraints.CENTER);
+ RegionLayoutManager layoutManager = new RegionLayoutManager();
+ layoutManager.addRegionConstraints(leftRegion);
+ layoutManager.addRegionConstraints(centerRegion);
+
+ // Perform the actual layout of the Page using the
+ // RegionLayoutManager
+ String output = layoutManager.doLayout(page);
+
+ log.info("--------------------------------------");
+ log.info(output);
+ log.info("--------------------------------------");
+
+ // Write this output to local file to test in a browser
+ FileOutputStream fos = new FileOutputStream(
+ "/home/soshah/html/layout/regionLayout.html");
+
+ StringBuffer buffer = new StringBuffer();
+
+ buffer
+ .append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><base href=\"http://localhost/\"/><title>CSS Layout Strategies</title><link rel=\"stylesheet\" type=\"text/css\" href=\"file:///home/soshah/html/layout/unitTest.css\"/></head><body id=\"body\">\n");
+ buffer.append(output);
+ buffer.append("</body></html>\n");
+
+ fos.write(buffer.toString().getBytes());
+ fos.flush();
+ fos.close();
+ }
+
+ /**
+ *
+ * @return
+ */
+ private String getHtmlContent()
+ {
+ String markup = null;
+
+ try
+ {
+ java.io.FileInputStream fis = new java.io.FileInputStream(
+ "/home/soshah/html/layout/greetings2.html");
+
+ StringBuffer buffer = new StringBuffer();
+ int read = 0;
+ byte[] data = new byte[1000];
+ while ((read = fis.read(data)) != -1)
+ {
+ byte[] bufferData = new byte[read];
+ System.arraycopy(data, 0, bufferData, 0, read);
+ buffer.append(new String(bufferData));
+ }
+
+ markup = buffer.toString();
+ fis.close();
+ }
+ catch (Exception e)
+ {
+
+ }
+
+ return markup;
+ }
+}
Modified: branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/Component.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/Component.java 2007-08-28 13:44:21 UTC (rev 8068)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/Component.java 2007-08-28 15:53:58 UTC (rev 8069)
@@ -69,5 +69,5 @@
*
* @return
*/
- public abstract String render();
+ public abstract String getMarkup();
}
Modified: branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/LayoutService.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/LayoutService.java 2007-08-28 13:44:21 UTC (rev 8068)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/LayoutService.java 2007-08-28 15:53:58 UTC (rev 8069)
@@ -33,8 +33,7 @@
*
*/
public LayoutService()
- {
-
+ {
}
/**
Modified: branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/Page.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/Page.java 2007-08-28 13:44:21 UTC (rev 8068)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/Page.java 2007-08-28 15:53:58 UTC (rev 8069)
@@ -71,4 +71,13 @@
{
this.containers = containers;
}
+
+ /**
+ *
+ * @param container
+ */
+ public void addContainer(Container container)
+ {
+ this.getContainers().add(container);
+ }
}
Modified: branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/Window.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/Window.java 2007-08-28 13:44:21 UTC (rev 8068)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/Window.java 2007-08-28 15:53:58 UTC (rev 8069)
@@ -54,16 +54,34 @@
this(id);
this.content = content;
}
+
+ /**
+ *
+ * @return
+ */
+ public String getContent()
+ {
+ return content;
+ }
/**
*
+ * @param content
*/
- public String render()
+ public void setContent(String content)
{
+ this.content = content;
+ }
+
+ /**
+ *
+ */
+ public String getMarkup()
+ {
String markup = "";
markup = this.content;
return markup;
- }
+ }
}
Modified: branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/classic/FlexibleGrid.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/classic/FlexibleGrid.java 2007-08-28 13:44:21 UTC (rev 8068)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/classic/FlexibleGrid.java 2007-08-28 15:53:58 UTC (rev 8069)
@@ -226,12 +226,99 @@
return output;
}
+
/**
*
+ * @param container
+ * @return
+ */
+ String generateInlineStyle(Container container)
+ {
+ String style = null;
+
+ StringBuffer buffer = new StringBuffer();
+
+ for(int row=0;row<this.rows;row++)
+ {
+ for(int column=0;column<this.columns;column++)
+ {
+ String cellStyle = this.getCellStyle(row, column);
+ if(cellStyle != null && cellStyle.trim().length()>0)
+ {
+ buffer.append(cellStyle);
+ }
+ }
+ }
+
+ style = buffer.toString();
+
+ return style;
+ }
+
+ /**
+ *
* @param row
* @param column
* @return
*/
+ String getCellStyle(int row, int column)
+ {
+ String style = null;
+
+ if(this.constraints != null)
+ {
+ for(int i=0;i<this.constraints.length;i++)
+ {
+ FlexibleGridConstraints constraint = this.constraints[i];
+ if(constraint.getRow() == row && constraint.getColumn() == column)
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ //Generate the layout style to be used for this cell
+ buffer.append("#grid-"+this.containerId+"-"+row+"-"+column+"{float: left; margin: 0px; padding: 0px; width: "+constraint.getWidthPercentage()+"%; position: relative;");
+
+ if(constraint.getTop() > 0)
+ {
+ buffer.append(" top: "+String.valueOf(constraint.getTop())+"%;");
+ }
+
+ if(constraint.getBottom() > 0)
+ {
+ buffer.append(" bottom: "+String.valueOf(constraint.getBottom())+"%;");
+ }
+
+ if(constraint.getLeft() > 0)
+ {
+ buffer.append(" left: "+String.valueOf(constraint.getLeft())+"%;");
+ }
+
+ if(constraint.getRight() > 0)
+ {
+ buffer.append(" right: "+String.valueOf(constraint.getRight())+"%;");
+ }
+
+ buffer.append("}\n");
+
+ style = buffer.toString();
+
+ return style;
+ }
+ }
+
+ //If we get here....need to use a spacer for this cell
+ int minWidth = 770/this.columns;
+ style = "#grid-"+this.containerId+"-"+row+"-"+column+"{float: left; line-height: 0px; font-size: 0px; min-width: "+minWidth+"px; height: "+minWidth+"px;}\n";
+ }
+
+ return style;
+ }
+
+ /**
+ *
+ * @param row
+ * @param column
+ * @return
+ */
private String getPortletMarkup(Container container,int row,int column)
{
String markup = "";
@@ -246,7 +333,7 @@
{
String componentId = constraint.getComponentId();
Window window = (Window)container.getComponent(componentId);
- markup = window.render();
+ markup = window.getMarkup();
}
}
Modified: branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/classic/FlexibleGridLayoutManager.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/classic/FlexibleGridLayoutManager.java 2007-08-28 13:44:21 UTC (rev 8068)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/classic/FlexibleGridLayoutManager.java 2007-08-28 15:53:58 UTC (rev 8069)
@@ -91,7 +91,7 @@
FlexibleGrid grid = grids[gridCounter];
Container container = containers[gridCounter];
- buffer.append(this.generateMarkup(grid, container));
+ buffer.append(grid.doLayout(container));
}
}
@@ -173,7 +173,7 @@
//Now generate the styles for each individual cell of the grid which will hold
//the components of this container
- buffer.append(this.generateInlineStyle(grid, container));
+ buffer.append(grid.generateInlineStyle(container));
}
buffer.append("</style>\n");
@@ -181,109 +181,5 @@
inlineStyle = buffer.toString();
return inlineStyle;
- }
-
- /**
- *
- * @param container
- * @return
- */
- private String generateInlineStyle(FlexibleGrid grid, Container container)
- {
- String style = null;
-
- StringBuffer buffer = new StringBuffer();
-
- int rows = grid.getRows();
- int columns = grid.getColumns();
- for(int row=0;row<rows;row++)
- {
- for(int column=0;column<columns;column++)
- {
- String cellStyle = this.getCellStyle(grid, row, column);
- if(cellStyle != null && cellStyle.trim().length()>0)
- {
- buffer.append(cellStyle);
- }
- }
- }
-
- style = buffer.toString();
-
- return style;
- }
-
- /**
- *
- * @param row
- * @param column
- * @return
- */
- private String getCellStyle(FlexibleGrid grid,int row, int column)
- {
- String style = null;
-
- FlexibleGridConstraints[] constraints = grid.getConstraints();
- if(constraints != null)
- {
- for(int i=0;i<constraints.length;i++)
- {
- FlexibleGridConstraints constraint = constraints[i];
- if(constraint.getRow() == row && constraint.getColumn() == column)
- {
- StringBuffer buffer = new StringBuffer();
-
- //Generate the layout style to be used for this cell
- buffer.append("#grid-"+grid.getContainerId()+"-"+row+"-"+column+"{float: left; margin: 0px; padding: 0px; width: "+constraint.getWidthPercentage()+"%; position: relative;");
-
- if(constraint.getTop() > 0)
- {
- buffer.append(" top: "+String.valueOf(constraint.getTop())+"%;");
- }
-
- if(constraint.getBottom() > 0)
- {
- buffer.append(" bottom: "+String.valueOf(constraint.getBottom())+"%;");
- }
-
- if(constraint.getLeft() > 0)
- {
- buffer.append(" left: "+String.valueOf(constraint.getLeft())+"%;");
- }
-
- if(constraint.getRight() > 0)
- {
- buffer.append(" right: "+String.valueOf(constraint.getRight())+"%;");
- }
-
- buffer.append("}\n");
-
- style = buffer.toString();
-
- return style;
- }
- }
-
- //If we get here....need to use a spacer for this cell
- int minWidth = 770/grid.getColumns();
- style = "#grid-"+grid.getContainerId()+"-"+row+"-"+column+"{float: left; line-height: 0px; font-size: 0px; min-width: "+minWidth+"px; height: "+minWidth+"px;}\n";
- }
-
- return style;
- }
-
- /**
- *
- * @param grid
- * @param container
- * @return
- */
- private String generateMarkup(FlexibleGrid grid, Container container)
- {
- String markup = null;
-
- markup = grid.doLayout(container);
-
- return markup;
- }
+ }
}
Added: branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/classic/RegionConstraints.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/classic/RegionConstraints.java (rev 0)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/classic/RegionConstraints.java 2007-08-28 15:53:58 UTC (rev 8069)
@@ -0,0 +1,101 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.uiserver.layout.classic;
+
+import java.io.Serializable;
+
+/**
+ * The RegionConstraints class specifies constraints for containers that are laid out using the Region based layout manager.
+ *
+ * These constraints apply to an instance of a Container and its placement as its laid out within a specified region on the Page
+ *
+ * When the Container is placed, all its Components (which are Windows) are laid out vertically inside the Region
+ *
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class RegionConstraints implements Serializable
+{
+ public static final int LEFT = 1;
+ public static final int CENTER = 2;
+ public static final int RIGHT = 3;
+
+ /**
+ * Unique Id of the container that these constraints should be applied to
+ */
+ private String containerId = null;
+
+ /**
+ * Type of region where the component should be added
+ *
+ * makes it belong to LEFT region by default
+ */
+ private int type = 1;
+
+ /**
+ *
+ * @param containerId
+ * @param type
+ */
+ public RegionConstraints(String containerId, int type)
+ {
+ this.containerId = containerId;
+ this.type = type;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public String getContainerId()
+ {
+ return containerId;
+ }
+
+ /**
+ *
+ * @param containerId
+ */
+ public void setContainerId(String containerId)
+ {
+ this.containerId = containerId;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public int getType()
+ {
+ return type;
+ }
+
+ /**
+ *
+ * @param type
+ */
+ public void setType(int type)
+ {
+ this.type = type;
+ }
+}
Added: branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/classic/RegionLayoutManager.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/classic/RegionLayoutManager.java (rev 0)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/layout/classic/RegionLayoutManager.java 2007-08-28 15:53:58 UTC (rev 8069)
@@ -0,0 +1,183 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.uiserver.layout.classic;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import org.jboss.portal.uiserver.layout.LayoutManager;
+import org.jboss.portal.uiserver.layout.Page;
+import org.jboss.portal.uiserver.layout.Container;
+import org.jboss.portal.uiserver.layout.Window;
+
+/**
+ * This layout manager splits the page up into Regions. Containers which contain the Portlet Windows
+ * are then laid out vertically inside each Region.
+ *
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class RegionLayoutManager implements LayoutManager
+{
+ /**
+ *
+ */
+ private List regionConstraints = null;
+
+ /**
+ *
+ *
+ */
+ public RegionLayoutManager()
+ {
+ this.regionConstraints = new ArrayList();
+ }
+
+ /**
+ *
+ * @param constraints
+ */
+ public void addRegionConstraints(RegionConstraints constraints)
+ {
+ this.regionConstraints.add(constraints);
+ }
+
+ /**
+ *
+ */
+ public String doLayout(Page page)
+ {
+ String output = null;
+
+ StringBuffer buffer = new StringBuffer();
+
+ buffer.append("<div id=\"portal-container\">\n");
+
+ //Perform layout of the containers on this page
+ Container leftContainer = this.findContainerByRegion(RegionConstraints.LEFT, page);
+ Container centerContainer = this.findContainerByRegion(RegionConstraints.CENTER, page);
+ Container rightContainer = this.findContainerByRegion(RegionConstraints.RIGHT, page);
+
+ if(leftContainer != null)
+ {
+ buffer.append(this.layoutRegion(RegionConstraints.LEFT, leftContainer));
+ }
+
+ if(centerContainer != null)
+ {
+ buffer.append(this.layoutRegion(RegionConstraints.CENTER, centerContainer));
+ }
+
+ if(rightContainer != null)
+ {
+ buffer.append(this.layoutRegion(RegionConstraints.RIGHT, rightContainer));
+ }
+
+ buffer.append("</div>\n");
+
+ output = buffer.toString();
+
+ return output;
+ }
+
+ /**
+ *
+ * @param regionType
+ * @param page
+ * @return
+ */
+ private Container findContainerByRegion(int regionType, Page page)
+ {
+ Container container = null;
+
+ for(int containerCtr=0; containerCtr<page.getContainers().size(); containerCtr++)
+ {
+ Container cour = (Container)page.getContainers().get(containerCtr);
+
+ for(int constraintCtr=0; constraintCtr<this.regionConstraints.size(); constraintCtr++)
+ {
+ RegionConstraints constraints = (RegionConstraints)this.regionConstraints.get(constraintCtr);
+
+ if(constraints.getContainerId() == cour.getId() && constraints.getType() == regionType)
+ {
+ container = cour;
+ break;
+ }
+ }
+
+ if(container != null)
+ {
+ break;
+ }
+ }
+
+ return container;
+ }
+
+ /**
+ *
+ * @param regionType
+ * @param container
+ */
+ private String layoutRegion(int regionType, Container container)
+ {
+ String output = null;
+
+ StringBuffer buffer = new StringBuffer();
+
+ switch(regionType)
+ {
+ case RegionConstraints.LEFT:
+ buffer.append("<div id=\"regionA\">\n");
+ break;
+
+ case RegionConstraints.CENTER:
+ buffer.append("<div id=\"regionB\">\n");
+ break;
+
+ case RegionConstraints.RIGHT:
+ buffer.append("<div id=\"regionC\">\n");
+ break;
+
+ default:
+ buffer.append("<div id=\"regionA\">\n");
+ break;
+ }
+
+ for(int i=0; i<container.getComponents().size(); i++)
+ {
+ Window window = (Window)container.getComponents().get(i);
+
+ buffer.append("<div class=\"portlet-container\"><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"portlet-titlebar-left\"></td><td class=\"portlet-titlebar-center\"><div class=\"portlet-titlebar-decoration\"></div><span class=\"portlet-titlebar-title\"></span><div class=\"portlet-mode-container\"><span title=\"minimized\"><a class=\"portlet-mode-minimized\" href=\"\"> </a></span><span title=\"maximized\"><a class=\"portlet-mode-maximized\" href=\"\"> </a></span></div></td><td class=\"portlet-titlebar-right\"></td></tr><tr><td class=\"portlet-content-left\"></td><td class=\"portlet-body\"><div class=\"portlet-content-center\">\n");
+
+ buffer.append(window.getMarkup());
+
+ buffer.append("</div></td><td class=\"portlet-content-right\"></td></tr><tr><td class=\"portlet-footer-left\"></td><td class=\"portlet-footer-center\"></td><td class=\"portlet-footer-right\"></td></tr></table></div>\n\n\n\n");
+ }
+
+ buffer.append("</div>\n\n\n\n");
+ output = buffer.toString();
+
+ return output;
+ }
+}
Added: branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/protocol/PageResult.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/protocol/PageResult.java (rev 0)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/protocol/PageResult.java 2007-08-28 15:53:58 UTC (rev 8069)
@@ -0,0 +1,85 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.uiserver.protocol;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * PageResult represents data associated with the Page to be rendered on the client.
+ *
+ * Its part of the protocol package since this is the object that is exposed to the core portal layer for communication with the UIServer
+ *
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class PageResult implements Serializable
+{
+ /**
+ * A list of WindowResult objects signifying the Windows to be rendered on this Page
+ */
+ private final List windows;
+
+ /**
+ * The name of this page
+ */
+ private String pageName;
+
+ /**
+ *
+ * @param pageName
+ * @param windows
+ */
+ public PageResult(String pageName, List windows)
+ {
+ this.pageName = pageName;
+ this.windows = windows;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public String getPageName()
+ {
+ return pageName;
+ }
+
+ /**
+ *
+ * @param pageName
+ */
+ public void setPageName(String pageName)
+ {
+ this.pageName = pageName;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public List getWindows()
+ {
+ return windows;
+ }
+}
Added: branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/protocol/WindowResult.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/protocol/WindowResult.java (rev 0)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/protocol/WindowResult.java 2007-08-28 15:53:58 UTC (rev 8069)
@@ -0,0 +1,155 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.uiserver.protocol;
+
+import java.io.Serializable;
+
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+
+/**
+ * WindowResult represents data associated with a Window to be rendered on a Page.
+ *
+ * Its part of the protocol package since this is the object that is exposed to the core portal layer for communication with the UIServer
+ *
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class WindowResult implements Serializable
+{
+ /**
+ * Unique WIndowId of this Window to be rendered on the Page
+ */
+ private String id = null;
+
+ /**
+ * Title for this Window
+ */
+ private String title = null;
+
+ /**
+ * Content/Markup to be displayed inside this Window
+ */
+ private String content = null;
+
+ /**
+ * Content/Markup related to the header of this Window
+ */
+ private final String headerContent;
+
+ /**
+ * The State of this Window such as Normal, Maximized, Minimized etc
+ */
+ private final WindowState windowState;
+
+ /**
+ * The Mode of this Window such as View, Edit, Help etc
+ */
+ private final Mode mode;
+
+ /**
+ *
+ *
+ */
+ public WindowResult(String id,String title, String content, String headerContent, WindowState windowState, Mode mode)
+ {
+ this.id = id;
+ this.title = title;
+ this.content = content;
+ this.headerContent = headerContent;
+ this.windowState = windowState;
+ this.mode = mode;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public String getId()
+ {
+ return this.id;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public String getContent()
+ {
+ return content;
+ }
+
+ /**
+ *
+ * @param content
+ */
+ public void setContent(String content)
+ {
+ this.content = content;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public String getTitle()
+ {
+ return title;
+ }
+
+ /**
+ *
+ * @param title
+ */
+ public void setTitle(String title)
+ {
+ this.title = title;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public String getHeaderContent()
+ {
+ return headerContent;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public Mode getMode()
+ {
+ return mode;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public WindowState getWindowState()
+ {
+ return windowState;
+ }
+}
Added: branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/service/UIServer.java
===================================================================
--- branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/service/UIServer.java (rev 0)
+++ branches/UIServer/uiserver/src/main/org/jboss/portal/uiserver/service/UIServer.java 2007-08-28 15:53:58 UTC (rev 8069)
@@ -0,0 +1,294 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.uiserver.service;
+
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.List;
+
+
+import org.jboss.portal.uiserver.layout.Container;
+import org.jboss.portal.uiserver.layout.Page;
+import org.jboss.portal.uiserver.layout.Window;
+import org.jboss.portal.uiserver.layout.LayoutManager;
+import org.jboss.portal.uiserver.layout.classic.FlexibleGrid;
+import org.jboss.portal.uiserver.layout.classic.FlexibleGridConstraints;
+import org.jboss.portal.uiserver.layout.classic.FlexibleGridLayoutManager;
+import org.jboss.portal.uiserver.layout.classic.RegionLayoutManager;
+import org.jboss.portal.uiserver.layout.classic.RegionConstraints;
+import org.jboss.portal.uiserver.protocol.PageResult;
+import org.jboss.portal.uiserver.protocol.WindowResult;
+
+/**
+ * The UIServer is responsible for generating the output that is sent back to the client based on the Portal state of a particular Portal Request
+ *
+ * The UIServer provides various UI level services like Page Aggregation, Page Layout, Web 2.0 client interactions etc.
+ *
+ * Typically the Core component of the Portal delegates all UI specific functions to this component
+ *
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class UIServer
+{
+ /**
+ *
+ *
+ */
+ public UIServer()
+ {
+ }
+
+ /**
+ *
+ * @param clientConnection
+ * @param page
+ */
+ public void render(PrintWriter clientConnection, PageResult pageResult)
+ {
+ /**
+ * Special Note: Currently this prototype code and layout configuration including page result creation is hard coded for the purpose
+ * of getting the architecture right
+ *
+ * In the real implementation, LayoutState would be fetched dynamically based on the Page State/Configuration being rendered
+ * Even type of Client considerations would be handled here
+ *
+ * Basically the UIServer would delegate functions to its various components and then send back the result to the client
+ *
+ */
+
+
+ /**
+ * Some flexible grid layout testing code
+ */
+ //Object[] gridData = this.getFlexibleGridLayoutManager(pageResult);
+ //Page page = (Page)gridData[0];
+ //LayoutManager layoutManager = (LayoutManager)gridData[1];
+
+ /**
+ * Some region layout testing code
+ */
+ Object[] regionData = this.getRegionBasedLayoutManager(pageResult);
+ Page page = (Page)regionData[0];
+ LayoutManager layoutManager = (LayoutManager)regionData[1];
+
+ //Peform Page Layout
+ String output = layoutManager.doLayout(page);
+
+
+ //Create the final output...Also hardcoded without any preprocessing/postprocessing etc
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>JBoss Portal UIServer</title><link rel=\"stylesheet\" id=\"dyna_css\" href=\"/portal-ajax/dyna/style.css\" type=\"text/css\"/><link rel=\"stylesheet\" type=\"text/css\" id=\"main_css\" href=\"/portal-core/themes/renaissance/portal_style.css\"/><link rel=\"shortcut icon\" href=\"/portal-core/themes/renaissance/images/favicon.ico\" /><link rel=\"icon\" type=\"image/gif\" href=\"/portal-core/themes/renaissance/images/animated_favicon1.gif\" /></head><body id=\"body\">\n");
+ buffer.append(output);
+ buffer.append("</body></html>\n");
+
+
+ //Sending the results back to the Client
+ clientConnection.write(buffer.toString());
+ clientConnection.flush();
+ }
+
+
+ //---------All these are just helper methods for the prototype-----------------------------------------------------------------------------------------------
+ //----It containts mostly hard coded logic for the prototype-------------------------------------------------------------------------------------------------
+ /**
+ *
+ */
+ private Object[] getFlexibleGridLayoutManager(PageResult pageResult)
+ {
+ /**
+ * Hard coding the FlexibleGridLayout Management here
+ */
+ Page page = new Page();
+ Container header = new Container("header");
+ Container leftPanel = new Container("leftPanel");
+ Container mainPanel = new Container("mainPanel");
+ Window headerTabsWindow = new Window("header-tabs-window");
+ Window menuWindow = new Window("menu-window");
+ Window leftPanelWindow1 = new Window("left-panel-window1");
+ Window leftPanelWindow2 = new Window("left-panel-window2");
+ Window mainPanelWindow = new Window("main-panel-window");
+ header.addComponent(headerTabsWindow);
+ header.addComponent(menuWindow);
+ leftPanel.addComponent(leftPanelWindow1);
+ leftPanel.addComponent(leftPanelWindow2);
+ mainPanel.addComponent(mainPanelWindow);
+
+ //Setup the Grid for headerTabs container
+ page.addContainer(header);
+ FlexibleGrid headerGrid = this.getGrid("header", 1, 2);
+ FlexibleGridConstraints[] headerTabConstraints = { this.getConstraints("header-tabs-window", "100", 0, 0, 10, 0, 0, 0),
+ this.getConstraints("menu-window", "100", 0, 0, 0, 0, 0, 1) };
+ headerGrid.setConstraints(headerTabConstraints);
+
+ //Setup the Grid for left panel container
+ page.addContainer(leftPanel);
+ FlexibleGrid leftPanelGrid = this.getGrid("leftPanel", 2, 1);
+ FlexibleGridConstraints[] leftPanelConstraints = { this.getConstraints("left-panel-window1", "75", 0, 0, 0, 0, 0, 0),
+ this.getConstraints("left-panel-window2", "75", 0, 0, 0, 0, 1, 0) };
+ leftPanelGrid.setConstraints(leftPanelConstraints);
+
+ //Setup the Grid for main panel container
+ page.addContainer(mainPanel);
+ FlexibleGrid mainPanelGrid = this.getGrid("mainPanel", 1, 1);
+ FlexibleGridConstraints[] mainPanelConstraints = { this.getConstraints("main-panel-window", "100", 0, 0, 0, 0, 0, 0) };
+ mainPanelGrid.setConstraints(mainPanelConstraints);
+
+ //Setup the FlexibleGrid Layout Manager with the different grids
+ FlexibleGrid[] row1 = { headerGrid };
+ FlexibleGrid[] row2 = { leftPanelGrid, mainPanelGrid };
+ FlexibleGridLayoutManager layoutManager = new FlexibleGridLayoutManager();
+ layoutManager.addRowOfGrids(row1);
+ layoutManager.addRowOfGrids(row2);
+
+ //Populate the grid windows with proper content
+ List windows = pageResult.getWindows();
+ int counter = 0;
+ for(Iterator itr=windows.iterator();itr.hasNext();)
+ {
+ WindowResult result = (WindowResult)itr.next();
+
+ switch(counter)
+ {
+ case 0:
+ leftPanelWindow1.setContent(result.getContent());
+ break;
+
+ case 1:
+ leftPanelWindow2.setContent(result.getContent());
+ break;
+
+ case 2:
+ mainPanelWindow.setContent(result.getContent());
+ break;
+
+ case 3:
+ menuWindow.setContent(result.getContent());
+ break;
+
+ case 4:
+ headerTabsWindow.setContent(result.getContent());
+ break;
+ }
+
+ counter++;
+ }
+
+ return new Object[]{page, layoutManager};
+ }
+
+
+ /**
+ *
+ * @param containerId
+ * @param rows
+ * @param columns
+ * @return
+ */
+ private FlexibleGrid getGrid(String containerId,int rows, int columns)
+ {
+ FlexibleGrid grid = new FlexibleGrid(containerId);
+ grid.setRows(rows);
+ grid.setColumns(columns);
+ return grid;
+ }
+
+ /**
+ *
+ * @param componentId
+ * @param widthPercentage
+ * @param top
+ * @param bottom
+ * @param left
+ * @param right
+ */
+ private FlexibleGridConstraints getConstraints(String componentId, String widthPercentage, int top, int bottom, int left, int right, int row, int column)
+ {
+ FlexibleGridConstraints constraints = new FlexibleGridConstraints();
+ constraints.setComponentId(componentId);
+ constraints.setWidthPercentage(widthPercentage);
+ constraints.setRow(row);
+ constraints.setColumn(column);
+ constraints.setTop(top);
+ constraints.setBottom(bottom);
+ constraints.setLeft(left);
+ constraints.setRight(right);
+ return constraints;
+ }
+
+ /**
+ *
+ * @param pageResult
+ * @return
+ */
+ private Object[] getRegionBasedLayoutManager(PageResult pageResult)
+ {
+ Page page = new Page();
+ Container left = new Container("left");
+ Container center = new Container("center");
+ page.addContainer(left);
+ page.addContainer(center);
+
+ //Populate the grid windows with proper content
+ List windows = pageResult.getWindows();
+ int counter = 0;
+ for(Iterator itr=windows.iterator();itr.hasNext();)
+ {
+ WindowResult result = (WindowResult)itr.next();
+ Window uiWindow = new Window(result.getId());
+ uiWindow.setContent(result.getContent());
+ switch(counter)
+ {
+ case 0:
+ left.addComponent(uiWindow);
+ break;
+
+ case 1:
+ left.addComponent(uiWindow);
+ break;
+
+ case 2:
+ center.addComponent(uiWindow);
+ break;
+
+ case 3:
+ center.addComponent(uiWindow);
+ break;
+
+ case 4:
+ left.addComponent(uiWindow);
+ break;
+ }
+
+ counter++;
+ }
+
+ RegionLayoutManager layoutManager = new RegionLayoutManager();
+ RegionConstraints leftConstraints = new RegionConstraints("left", RegionConstraints.LEFT);
+ RegionConstraints centerConstraints = new RegionConstraints("center", RegionConstraints.CENTER);
+ layoutManager.addRegionConstraints(leftConstraints);
+ layoutManager.addRegionConstraints(centerConstraints);
+
+ return new Object[]{page, layoutManager};
+ }
+}
16 years, 9 months
JBoss Portal SVN: r8068 - docs/branches/JBoss_Portal_Branch_2_6/referenceGuide/en/modules.
by portal-commits@lists.jboss.org
Author: thomas.heute(a)jboss.com
Date: 2007-08-28 09:44:21 -0400 (Tue, 28 Aug 2007)
New Revision: 8068
Modified:
docs/branches/JBoss_Portal_Branch_2_6/referenceGuide/en/modules/portalapi.xml
Log:
Fixed the IPC chapter
Modified: docs/branches/JBoss_Portal_Branch_2_6/referenceGuide/en/modules/portalapi.xml
===================================================================
--- docs/branches/JBoss_Portal_Branch_2_6/referenceGuide/en/modules/portalapi.xml 2007-08-28 10:08:36 UTC (rev 8067)
+++ docs/branches/JBoss_Portal_Branch_2_6/referenceGuide/en/modules/portalapi.xml 2007-08-28 13:44:21 UTC (rev 8068)
@@ -459,7 +459,7 @@
<para>The first version of the Portlet Specification (JSR 168), regretfully, did not cover interaction between
portlets. The side-effect of diverting the issue to the subsequent release of the specification, has
forced portal vendors to each craft their own proprietary API to achieve interportlet communication. Here we will
- see how we can use the event mechanism to pass parameters from one portlet to the other.</para>
+ see how we can use the event mechanism to pass parameters from one portlet to the other (and only to the other portlet).</para>
<para>The overall scenario will be that Portlet B will need to be updated based on some parameter set on Portlet A.
To achieve that we will use a portal node event.</para>
<para>Portlet A is a simple Generic portlet that has a form that sends a color name:
@@ -539,6 +539,12 @@
// We can redirect
newEvent = new WindowActionEvent(windowB);
newEvent.setParameters(wae.getParameters());
+
+ // Due to a bug those 2 following lines are required but have no meaning for now
+ // See: http://jira.jboss.com/jira/browse/JBPORTAL-1604
+ newEvent.setMode(wae.getMode());
+ newEvent.setWindowState(WindowState.MAXIMIZED);
+
// Redirect to the new event
return newEvent;
}
@@ -570,6 +576,41 @@
newEvent.setWindowState(wae.getWindowState()); // WindowState.MAXIMIZED</programlisting>
</para>
-->
+ <para>
+ We still need to register our listener as an mbean:
+ <programlisting>
+<![CDATA[<mbean
+ code="org.jboss.portal.core.event.PortalEventListenerServiceImpl"
+ name="portal:service=ListenerService,type=test_listener"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <xmbean/>
+ <depends
+ optional-attribute-name="Registry"
+ proxy-type="attribute">portal:service=ListenerRegistry</depends>
+ <attribute name="RegistryId">test_listener</attribute>
+ <attribute name="ListenerClassName">org.jboss.portal.core.samples.basic.event.PortletB$Listener</attribute>
+</mbean>]]></programlisting>
+ For node events, we also need to declare on which node we want to listen, this is done by modifying
+ the <literal>*-object.xml</literal> that defines your portal nodes. In this example we want to trigger
+ the listener each time the window containing the portlet A is actioned. We can add the <literal>listener</literal>
+ tag to specify that out listener with <literal>RegistryId</literal>=test_listener should be triggered
+ on events on the embedding object.
+ <programlisting>
+<![CDATA[...
+ <window>
+ <window-name>PortletAWindow</window-name>
+ <instance-ref>PortletAInstance</instance-ref>
+ <region>center</region>
+ <height>0</height>
+ <listener>test_listener</listener>
+ </window>
+...]]>
+ </programlisting>
+ Of course we could have added it at the page level instead of the window level. Note that a unique listener
+ can be specified, the event mechanism is primarily done to let the developer change the navigation state of the
+ portal, this example being a nice side-effect of this feature.
+ </para>
<note>The portlet 2.0 specification (JSR 286) will cover Inter Portlet Communication so that portlets using it
can work with different portal vendors.</note>
</sect2>
16 years, 9 months
JBoss Portal SVN: r8067 - branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/deployment/jboss.
by portal-commits@lists.jboss.org
Author: thomas.heute(a)jboss.com
Date: 2007-08-28 06:08:36 -0400 (Tue, 28 Aug 2007)
New Revision: 8067
Modified:
branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/deployment/jboss/Deployment.java
Log:
JBPORTAL-1648: Undeploying a portlet in an exploded form causes a NullPointerException
Modified: branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/deployment/jboss/Deployment.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/deployment/jboss/Deployment.java 2007-08-28 10:00:04 UTC (rev 8066)
+++ branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/deployment/jboss/Deployment.java 2007-08-28 10:08:36 UTC (rev 8067)
@@ -103,7 +103,15 @@
{
File f = new File(warURL.getFile());
f = new File(f, "WEB-INF");
- return f.toURL();
+ // this dir doesn't exist on exploded deployments and would miss the trailing slash then [JBPORTAL-1648]
+ if(f.exists())
+ {
+ return f.toURL();
+ }
+ else
+ {
+ return new URL(warURL + "WEB-INF/");
+ }
}
else
{
16 years, 9 months
JBoss Portal SVN: r8066 - in branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules: faces and 2 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-08-28 06:00:04 -0400 (Tue, 28 Aug 2007)
New Revision: 8066
Modified:
branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/core/core.iml
branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/faces/faces.iml
branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/theme/theme.iml
branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/widget/widget.iml
Log:
2.6 project file updates
Modified: branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/core/core.iml
===================================================================
--- branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/core/core.iml 2007-08-28 09:58:23 UTC (rev 8065)
+++ branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/core/core.iml 2007-08-28 10:00:04 UTC (rev 8066)
@@ -312,6 +312,15 @@
</library>
</orderEntry>
<orderEntry type="module" module-name="jems" />
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/../../../../../../thirdparty/jboss-portal/modules/identity/lib/portal-identity-lib.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
<orderEntryProperties />
</component>
<component name="VcsManagerConfiguration">
Modified: branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/faces/faces.iml
===================================================================
--- branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/faces/faces.iml 2007-08-28 09:58:23 UTC (rev 8065)
+++ branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/faces/faces.iml 2007-08-28 10:00:04 UTC (rev 8066)
@@ -77,6 +77,24 @@
<orderEntry type="module" module-name="portlet" />
<orderEntry type="module" module-name="server" />
<orderEntry type="module" module-name="bridge" />
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/../../../../../../thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/../../../../../../thirdparty/jboss-portal/modules/common/lib/portal-common-portal-lib.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
<orderEntryProperties />
</component>
<component name="VcsManagerConfiguration">
Modified: branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/theme/theme.iml
===================================================================
--- branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/theme/theme.iml 2007-08-28 09:58:23 UTC (rev 8065)
+++ branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/theme/theme.iml 2007-08-28 10:00:04 UTC (rev 8066)
@@ -95,6 +95,24 @@
</library>
</orderEntry>
<orderEntry type="module" module-name="jems" />
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/../../../../../../thirdparty/jboss-portal/modules/common/lib/portal-common-portal-lib.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/../../../../../../thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
<orderEntryProperties />
</component>
<component name="VcsManagerConfiguration">
Modified: branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/widget/widget.iml
===================================================================
--- branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/widget/widget.iml 2007-08-28 09:58:23 UTC (rev 8065)
+++ branches/JBoss_Portal_Branch_2_6/build/ide/intellij/idea60/modules/widget/widget.iml 2007-08-28 10:00:04 UTC (rev 8066)
@@ -66,6 +66,15 @@
<SOURCES />
</library>
</orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/../../../../../../thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
<orderEntryProperties />
</component>
<component name="VcsManagerConfiguration">
16 years, 9 months
JBoss Portal SVN: r8065 - in branches/JBoss_Portal_Branch_2_6: faces/src/main/org/jboss/portal/faces/component/portlet and 3 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-08-28 05:58:23 -0400 (Tue, 28 Aug 2007)
New Revision: 8065
Modified:
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/command/mapping/DashboardPortalObjectPathMapper.java
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/command/mapping/DefaultPortalObjectPathMapper.java
branches/JBoss_Portal_Branch_2_6/faces/src/main/org/jboss/portal/faces/component/portlet/JSFInvocation.java
branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java
branches/JBoss_Portal_Branch_2_6/theme/src/main/org/jboss/portal/test/theme/ObjectURL.java
branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/GGWidget.java
Log:
- update 2.6 to use URL encoder refactorings
Modified: branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/command/mapping/DashboardPortalObjectPathMapper.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/command/mapping/DashboardPortalObjectPathMapper.java 2007-08-28 09:26:34 UTC (rev 8064)
+++ branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/command/mapping/DashboardPortalObjectPathMapper.java 2007-08-28 09:58:23 UTC (rev 8065)
@@ -25,7 +25,6 @@
import org.jboss.portal.core.model.portal.PortalObject;
import org.jboss.portal.core.model.portal.PortalObjectId;
import org.jboss.portal.core.model.portal.Portal;
-import org.jboss.portal.core.model.portal.Context;
import org.jboss.portal.core.model.portal.PortalObjectContainer;
import org.jboss.portal.core.model.CustomizationManager;
import org.jboss.portal.core.controller.ControllerContext;
@@ -114,7 +113,7 @@
while (iterator.hasNext())
{
String name = (String)iterator.next();
- name = FastURLEncoder.DEFAULT_ENCODER.encode(name);
+ name = FastURLEncoder.getInstance().encode(name);
buffer.append('/').append(name);
}
}
Modified: branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/command/mapping/DefaultPortalObjectPathMapper.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/command/mapping/DefaultPortalObjectPathMapper.java 2007-08-28 09:26:34 UTC (rev 8064)
+++ branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/command/mapping/DefaultPortalObjectPathMapper.java 2007-08-28 09:58:23 UTC (rev 8065)
@@ -125,7 +125,7 @@
for (Iterator i = id.getPath().names();i.hasNext();)
{
String name = (String)i.next();
- name = FastURLEncoder.DEFAULT_ENCODER.encode(name);
+ name = FastURLEncoder.getInstance().encode(name);
buffer.append('/').append(name);
}
}
Modified: branches/JBoss_Portal_Branch_2_6/faces/src/main/org/jboss/portal/faces/component/portlet/JSFInvocation.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/faces/src/main/org/jboss/portal/faces/component/portlet/JSFInvocation.java 2007-08-28 09:26:34 UTC (rev 8064)
+++ branches/JBoss_Portal_Branch_2_6/faces/src/main/org/jboss/portal/faces/component/portlet/JSFInvocation.java 2007-08-28 09:58:23 UTC (rev 8065)
@@ -123,13 +123,13 @@
for (Iterator i = encoder.getQueryParameters().entrySet().iterator();i.hasNext();)
{
Map.Entry entry = (Map.Entry)i.next();
- String name = FastURLEncoder.DEFAULT_ENCODER.encode((String)entry.getKey());
+ String name = FastURLEncoder.getInstance().encode((String)entry.getKey());
String[] values = (String[])entry.getValue();
for (int j = 0;j < values.length;j++)
{
String value = values[j];
url.append("&").append(name).append('=');
- FastURLEncoder.DEFAULT_ENCODER.encode(value, url);
+ FastURLEncoder.getInstance().encode(value, url);
}
}
Modified: branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java 2007-08-28 09:26:34 UTC (rev 8064)
+++ branches/JBoss_Portal_Branch_2_6/server/src/main/org/jboss/portal/server/impl/ServerInvocationContextImpl.java 2007-08-28 09:58:23 UTC (rev 8065)
@@ -49,7 +49,7 @@
{
/** The fast url encoder. */
- private static final FastURLEncoder urlEncoder = FastURLEncoder.create("UTF8", 0, 1024);
+ private static final FastURLEncoder urlEncoder = FastURLEncoder.getInstance();
/** The client request. */
private final HttpServletRequest req;
Modified: branches/JBoss_Portal_Branch_2_6/theme/src/main/org/jboss/portal/test/theme/ObjectURL.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/theme/src/main/org/jboss/portal/test/theme/ObjectURL.java 2007-08-28 09:26:34 UTC (rev 8064)
+++ branches/JBoss_Portal_Branch_2_6/theme/src/main/org/jboss/portal/test/theme/ObjectURL.java 2007-08-28 09:58:23 UTC (rev 8065)
@@ -72,7 +72,7 @@
{
WindowObject window = (WindowObject)object;
url.append("/window/");
- FastURLEncoder.DEFAULT_ENCODER.encode(window.getId(), url);
+ FastURLEncoder.getInstance().encode(window.getId(), url);
}
else
{
@@ -86,9 +86,9 @@
String key = (String)entry.getKey();
String value = (String)entry.getValue();
url.append(i.isFirst() ? '?' : '&');
- FastURLEncoder.DEFAULT_ENCODER.encode(key, url);
+ FastURLEncoder.getInstance().encode(key, url);
url.append('=');
- FastURLEncoder.DEFAULT_ENCODER.encode(value, url);
+ FastURLEncoder.getInstance().encode(value, url);
}
return url.toString();
Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/GGWidget.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/GGWidget.java 2007-08-28 09:26:34 UTC (rev 8064)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/GGWidget.java 2007-08-28 09:58:23 UTC (rev 8065)
@@ -135,7 +135,7 @@
String value = values != null ? values[0] : prefInfo.getDefaultValue();
if (value != null)
{
- tmp.append("&up_").append(FastURLEncoder.DEFAULT_ENCODER.encode(prefName)).append("=").append(FastURLEncoder.DEFAULT_ENCODER.encode(value));
+ tmp.append("&up_").append(FastURLEncoder.getInstance().encode(prefName)).append("=").append(FastURLEncoder.getInstance().encode(value));
}
}
16 years, 9 months
JBoss Portal SVN: r8064 - in modules/common/trunk/common: src/main/org/jboss/portal/common/invocation and 6 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-08-28 05:26:34 -0400 (Tue, 28 Aug 2007)
New Revision: 8064
Added:
modules/common/trunk/common/src/main/org/jboss/portal/common/io/WriterCharWriter.java
modules/common/trunk/common/src/main/org/jboss/portal/common/text/AbstractCharEncoder.java
modules/common/trunk/common/src/main/org/jboss/portal/common/text/CharEncoder.java
modules/common/trunk/common/src/main/org/jboss/portal/common/text/CharToByteEncoder.java
modules/common/trunk/common/src/main/org/jboss/portal/common/text/CharWriter.java
modules/common/trunk/common/src/main/org/jboss/portal/common/text/EncodingException.java
modules/common/trunk/common/src/main/org/jboss/portal/common/text/FastURLDecoder.java
modules/common/trunk/common/src/main/org/jboss/portal/common/text/MalformedInputException.java
modules/common/trunk/common/src/main/org/jboss/portal/common/text/TextTools.java
modules/common/trunk/common/src/main/org/jboss/portal/common/text/UnsupportedCharsetException.java
modules/common/trunk/common/src/main/org/jboss/portal/test/common/io/WriterCharWriterTestCase.java
modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/
modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/CharBufferTestCase.java
modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/CharToByteEncoderTestCase.java
modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/FastURLDecoderTestCase.java
modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/FastURLEncoderTestCase.java
modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/TextToolsTestCase.java
Removed:
modules/common/trunk/common/src/main/org/jboss/portal/test/common/CharBufferTestCase.java
modules/common/trunk/common/src/main/org/jboss/portal/test/common/FastURLEncoderTestCase.java
Modified:
modules/common/trunk/common/build.xml
modules/common/trunk/common/src/main/org/jboss/portal/common/invocation/InterceptorStack.java
modules/common/trunk/common/src/main/org/jboss/portal/common/markup/MarkupAttribute.java
modules/common/trunk/common/src/main/org/jboss/portal/common/text/CharBuffer.java
modules/common/trunk/common/src/main/org/jboss/portal/common/text/FastURLEncoder.java
Log:
- refactored and improved the common.text package
- reimplemented FastURLEncoder
- implemented FastURLDecoder
Modified: modules/common/trunk/common/build.xml
===================================================================
--- modules/common/trunk/common/build.xml 2007-08-28 09:16:47 UTC (rev 8063)
+++ modules/common/trunk/common/build.xml 2007-08-28 09:26:34 UTC (rev 8064)
@@ -211,9 +211,15 @@
</x-sysproperty>
<x-test>
+ <test todir="${test.reports}" name="org.jboss.portal.test.common.text.FastURLDecoderTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.test.common.text.CharBufferTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.test.common.text.TextToolsTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.test.common.text.FastURLEncoderTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.test.common.text.CharToByteEncoderTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.net.URLNavigatorTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.net.URLToolsTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.io.IOToolsTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.test.common.io.WriterCharWriterTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.reflect.ReflectionTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.reflect.ModifierTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.adapter.AdapterTestCase"/>
@@ -223,7 +229,6 @@
<test todir="${test.reports}" name="org.jboss.portal.test.common.ObjectLoaderTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.MarkupTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.TypedMapTestCase"/>
- <test todir="${test.reports}" name="org.jboss.portal.test.common.FastURLEncoderTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.AbstractInvocationContextTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.LocaleFormatTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.ParentChildResourceBundleTestCase"/>
@@ -240,7 +245,6 @@
<test todir="${test.reports}" name="org.jboss.portal.test.common.LocalizedStringTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.ImplodeTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.BufferedStreamTestCase"/>
- <test todir="${test.reports}" name="org.jboss.portal.test.common.CharBufferTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.CopyOnWriteRegistryTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.ToolsTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.IteratorStatusTestCase"/>
Modified: modules/common/trunk/common/src/main/org/jboss/portal/common/invocation/InterceptorStack.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/common/invocation/InterceptorStack.java 2007-08-28 09:16:47 UTC (rev 8063)
+++ modules/common/trunk/common/src/main/org/jboss/portal/common/invocation/InterceptorStack.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -31,7 +31,7 @@
public interface InterceptorStack
{
/**
- * Returns the stack length.
+ * Returns the stack length.
*
* @return the length
*/
Added: modules/common/trunk/common/src/main/org/jboss/portal/common/io/WriterCharWriter.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/common/io/WriterCharWriter.java (rev 0)
+++ modules/common/trunk/common/src/main/org/jboss/portal/common/io/WriterCharWriter.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -0,0 +1,164 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.io;
+
+import org.jboss.portal.common.text.CharWriter;
+import org.jboss.portal.common.io.UndeclaredIOException;
+
+import java.io.Writer;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class WriterCharWriter implements CharWriter
+{
+
+ /** . */
+ private final Writer writer;
+
+ /**
+ * @param writer the target writer
+ * @throws IllegalArgumentException if the writer is null
+ */
+ public WriterCharWriter(Writer writer) throws IllegalArgumentException
+ {
+ if (writer == null)
+ {
+ throw new IllegalArgumentException("No null writer accepted");
+ }
+ this.writer = writer;
+ }
+
+ public CharWriter append(char c) throws UndeclaredIOException
+ {
+ try
+ {
+ writer.write(c);
+ }
+ catch (IOException e)
+ {
+ throw new UndeclaredIOException(e);
+ }
+ return this;
+ }
+
+ public CharWriter append(char[] chars, int off, int len) throws UndeclaredIOException
+ {
+ if (chars == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (off < 0)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (len < 0)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (off + len > chars.length)
+ {
+ throw new IllegalArgumentException();
+ }
+ try
+ {
+ writer.write(chars, off, len);
+ }
+ catch (IOException e)
+ {
+ throw new UndeclaredIOException(e);
+ }
+ return this;
+ }
+
+ public CharWriter append(char[] chars) throws UndeclaredIOException
+ {
+ if (chars == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ try
+ {
+ writer.write(chars, 0, chars.length);
+ }
+ catch (IOException e)
+ {
+ throw new UndeclaredIOException(e);
+ }
+ return this;
+ }
+
+ public CharWriter append(CharSequence s) throws UndeclaredIOException
+ {
+ if (s == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ try
+ {
+ if (s instanceof String)
+ {
+ writer.write((String)s);
+ }
+ else
+ {
+ for (int i = 0;i < s.length();i++)
+ {
+ char c = s.charAt(i);
+ writer.write(c);
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ throw new UndeclaredIOException(e);
+ }
+ return this;
+ }
+
+ public void flush() throws UndeclaredIOException
+ {
+ try
+ {
+ writer.flush();
+ }
+ catch (IOException e)
+ {
+ throw new UndeclaredIOException(e);
+ }
+ }
+
+ public void close() throws UndeclaredIOException
+ {
+ try
+ {
+ writer.flush();
+ }
+ catch (IOException e)
+ {
+ throw new UndeclaredIOException(e);
+ }
+ }
+}
Modified: modules/common/trunk/common/src/main/org/jboss/portal/common/markup/MarkupAttribute.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/common/markup/MarkupAttribute.java 2007-08-28 09:16:47 UTC (rev 8063)
+++ modules/common/trunk/common/src/main/org/jboss/portal/common/markup/MarkupAttribute.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -23,11 +23,15 @@
package org.jboss.portal.common.markup;
import org.jboss.portal.common.io.UndeclaredIOException;
+import org.jboss.portal.common.io.WriterCharWriter;
import org.jboss.portal.common.text.FastURLEncoder;
+import org.jboss.portal.common.text.CharEncoder;
+import org.jboss.portal.common.text.AbstractCharEncoder;
+import org.jboss.portal.common.text.CharWriter;
+import org.jboss.portal.common.text.EncodingException;
import java.io.IOException;
import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
import java.io.Writer;
/**
@@ -143,32 +147,35 @@
/** %ContentType required : CDATA -- media type, as per [RFC2045]. */
public static final Type CONTENT_TYPE = new CDATAType();
+ private static final char[] SLASH_ARRAY = "/".toCharArray();
+
/** %URI : CDATA -- a Uniform Resource Identifier, see [URI]. */
public static final Type URI = new CDATAType()
{
{
- try
+ // Patches the encoder to let '/' not being encoded
+ encoder = new AbstractCharEncoder()
{
- // Patches the encoder to let '/' not being encoded
- encoder = new FastURLEncoder("UTF-8", 0, 512)
+ public void encode(char c, CharWriter writer) throws EncodingException
{
+ if (c == '/')
{
- table[(int)'/'] = "/".toCharArray();
+ writer.append(SLASH_ARRAY);
}
- };
- }
- catch (UnsupportedEncodingException e)
- {
- throw new Error(e);
- }
+ else
+ {
+ FastURLEncoder.getInstance().encode(c, writer);
+ }
+ }
+ };
}
/** Our encoder for URI. */
- final FastURLEncoder encoder;
+ final CharEncoder encoder;
public void encode(String string, Writer writer)
{
- encoder.encode(string, writer);
+ encoder.encode(string, new WriterCharWriter(writer));
}
};
Added: modules/common/trunk/common/src/main/org/jboss/portal/common/text/AbstractCharEncoder.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/common/text/AbstractCharEncoder.java (rev 0)
+++ modules/common/trunk/common/src/main/org/jboss/portal/common/text/AbstractCharEncoder.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -0,0 +1,52 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.text;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractCharEncoder implements CharEncoder
+{
+
+ public void encode(char[] chars, int off, int len, CharWriter writer) throws EncodingException
+ {
+ for (int i = off;i < len;i++)
+ {
+ encode(chars[i], writer);
+ }
+ }
+
+ public void encode(char[] chars, CharWriter writer) throws EncodingException
+ {
+ encode(chars, 0, chars.length, writer);
+ }
+
+ public void encode(CharSequence s, CharWriter writer) throws EncodingException
+ {
+ for (int i = 0;i < s.length();i++)
+ {
+ encode(s.charAt(i), writer);
+ }
+ }
+}
Modified: modules/common/trunk/common/src/main/org/jboss/portal/common/text/CharBuffer.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/common/text/CharBuffer.java 2007-08-28 09:16:47 UTC (rev 8063)
+++ modules/common/trunk/common/src/main/org/jboss/portal/common/text/CharBuffer.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -22,14 +22,13 @@
******************************************************************************/
package org.jboss.portal.common.text;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-
/**
+ * A simple char buffer.
+ *
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 7228 $
*/
-public class CharBuffer
+public class CharBuffer implements CharWriter
{
/** . */
@@ -38,7 +37,12 @@
/** . */
protected int length;
- public CharBuffer(int size)
+ /**
+ *
+ * @param size the initial size
+ * @throws IllegalArgumentException if the initial size is not a positive value.
+ */
+ public CharBuffer(int size) throws IllegalArgumentException
{
if (size < 0)
{
@@ -54,66 +58,78 @@
this.length = 0;
}
- public CharBuffer append(String s)
+ public CharBuffer append(String s, CharEncoder encoder)
{
if (s == null)
{
throw new IllegalArgumentException();
}
- appendNoCheck(s);
+ if (encoder == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ encoder.encode(s, this);
return this;
}
- public CharBuffer append(String s, FastURLEncoder encoder)
+ public CharWriter append(CharSequence s)
{
if (s == null)
{
throw new IllegalArgumentException();
}
- if (encoder == null)
- {
- throw new IllegalArgumentException();
- }
- for (int i = 0; i < s.length(); i++)
- {
- char c = s.charAt(i);
- if (c >= encoder.from && c < encoder.to)
- {
- appendNoCheck(encoder.table[c - encoder.from]);
- }
- else
- {
- try
- {
- appendNoCheck(URLEncoder.encode(Character.toString(c), encoder.encoding));
- }
- catch (UnsupportedEncodingException e)
- {
- // That should never happen has the encoding validity is check at construction time
- throw new Error(e);
- }
- }
- }
+ appendNoCheck(s);
return this;
}
- public CharBuffer append(char[] chars)
+ public CharWriter append(char[] chars, int off, int len)
{
if (chars == null)
{
throw new IllegalArgumentException();
}
- appendNoCheck(chars);
+ if (off < 0)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (off + len > chars.length)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ appendNoCheck(chars, off, len);
+
+ //
return this;
}
- public CharBuffer append(char c)
+
+ public CharWriter append(char c)
{
ensureCapacity(length + 1);
+
+ //
buffer[length++] = c;
+
+ //
return this;
}
+ public CharWriter append(char[] chars)
+ {
+ if (chars == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ appendNoCheck(chars, 0, chars.length);
+
+ //
+ return this;
+ }
+
public String asString()
{
return new String(buffer, 0, length);
@@ -153,32 +169,44 @@
this.length = 0;
}
- protected final void appendNoCheck(char[] chars)
+ protected final void appendNoCheck(char[] chars, int off, int len)
{
- ensureCapacity(length + chars.length);
- if (chars.length < 10)
+ ensureCapacity(length + len);
+ if (len < 10)
{
- for (int i = 0; i < chars.length; i++)
+ while (off < len)
{
- buffer[length++] = chars[i];
+ buffer[length++] = chars[off++];
}
}
else
{
- System.arraycopy(chars, 0, buffer, length, chars.length);
- length += chars.length;
+ System.arraycopy(chars, off, buffer, length, len);
+ length += len;
}
}
- protected final void appendNoCheck(String s)
+ protected final void appendNoCheck(CharSequence s)
{
ensureCapacity(length + s.length());
- s.getChars(0, s.length(), buffer, length);
- length += s.length();
+
+ //
+ if (s instanceof String)
+ {
+ ((String)s).getChars(0, s.length(), buffer, length);
+ length += s.length();
+ }
+ else
+ {
+ for (int i = 0;i < s.length();i++)
+ {
+ char c = s.charAt(i);
+ buffer[length++] = c;
+ }
+ }
}
- /** Can be subclassed to provide a customized implementation. */
- protected void ensureCapacity(int minimumCapacity)
+ protected final void ensureCapacity(int minimumCapacity)
{
int capacity = buffer.length;
if (capacity < minimumCapacity)
Added: modules/common/trunk/common/src/main/org/jboss/portal/common/text/CharEncoder.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/common/text/CharEncoder.java (rev 0)
+++ modules/common/trunk/common/src/main/org/jboss/portal/common/text/CharEncoder.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.text;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface CharEncoder
+{
+ void encode(char c, CharWriter writer) throws EncodingException;
+ void encode(char[] chars, int off, int len, CharWriter writer) throws EncodingException;
+ void encode(char[] chars, CharWriter writer) throws EncodingException;
+ void encode(CharSequence s, CharWriter writer) throws EncodingException;
+}
Added: modules/common/trunk/common/src/main/org/jboss/portal/common/text/CharToByteEncoder.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/common/text/CharToByteEncoder.java (rev 0)
+++ modules/common/trunk/common/src/main/org/jboss/portal/common/text/CharToByteEncoder.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -0,0 +1,113 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.text;
+
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.Charset;
+import java.nio.CharBuffer;
+import java.nio.ByteBuffer;
+
+/**
+ * Defines an interface for encoding a char to a sequence of bytes.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface CharToByteEncoder
+{
+
+ /**
+ * Encode the specified char. The returned byte array can be used safely until a new invocation to the same
+ * object is done. If the returned array has a length of zero it means that the char cannot be encoded.
+ *
+ * @param c the char to encode
+ * @return the encoded char as a byte array
+ * @throws EncodingException
+ */
+ byte[] encode(char c) throws EncodingException;
+
+ /** . */
+ final byte[] EMPTY = new byte[0];
+
+ /**
+ * Generic implementation that works for any charset, based on NIO.
+ */
+ public static class Generic implements CharToByteEncoder
+ {
+
+ /** . */
+ public static final Generic UTF8 = new Generic("UTF8");
+
+ /** . */
+ private final CharsetEncoder encoder;
+
+ /** . */
+ private final java.nio.CharBuffer in;
+
+ /** . */
+ private final ByteBuffer out;
+
+ /** . */
+ private final byte[][] arrays = {new byte[0],new byte[1],new byte[2],new byte[3],new byte[4], new byte[5]};
+
+ public Generic(Charset charset)
+ {
+ encoder = charset.newEncoder();
+ in = CharBuffer.allocate(1);
+ out = ByteBuffer.allocate(100);
+ }
+
+ public Generic(String encoding)
+ {
+ this(Charset.forName(encoding));
+ }
+
+ public byte[] encode(char c) throws EncodingException
+ {
+ switch(Character.getType(c))
+ {
+ case Character.SURROGATE:
+ case Character.PRIVATE_USE:
+ return EMPTY;
+ default:
+ if (encoder.canEncode(c))
+ {
+ in.rewind();
+ out.rewind();
+ in.put(0, c);
+ encoder.reset();
+ encoder.encode(in, out, true);
+ encoder.flush(out);
+ int length = out.position();
+ byte[] bytes = arrays[length];
+ System.arraycopy(out.array(), 0, bytes, 0, length);
+ return bytes;
+ }
+ else
+ {
+ return EMPTY;
+ }
+ }
+ }
+ }
+}
Added: modules/common/trunk/common/src/main/org/jboss/portal/common/text/CharWriter.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/common/text/CharWriter.java (rev 0)
+++ modules/common/trunk/common/src/main/org/jboss/portal/common/text/CharWriter.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.text;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface CharWriter
+{
+ CharWriter append(char c);
+ CharWriter append(char[] chars, int off, int len);
+ CharWriter append(char[] chars);
+ CharWriter append(CharSequence s);
+}
Added: modules/common/trunk/common/src/main/org/jboss/portal/common/text/EncodingException.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/common/text/EncodingException.java (rev 0)
+++ modules/common/trunk/common/src/main/org/jboss/portal/common/text/EncodingException.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -0,0 +1,49 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.text;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class EncodingException extends RuntimeException
+{
+ public EncodingException()
+ {
+ }
+
+ public EncodingException(String string)
+ {
+ super(string);
+ }
+
+ public EncodingException(String string, Throwable throwable)
+ {
+ super(string, throwable);
+ }
+
+ public EncodingException(Throwable throwable)
+ {
+ super(throwable);
+ }
+}
Added: modules/common/trunk/common/src/main/org/jboss/portal/common/text/FastURLDecoder.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/common/text/FastURLDecoder.java (rev 0)
+++ modules/common/trunk/common/src/main/org/jboss/portal/common/text/FastURLDecoder.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -0,0 +1,335 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.text;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class FastURLDecoder implements CharEncoder
+{
+
+ /** . */
+ private static final FastURLDecoder INSTANCE = new FastURLDecoder(CharToByteEncoder.Generic.UTF8);
+
+ public static FastURLDecoder getInstance()
+ {
+ return INSTANCE;
+ }
+
+ /** . */
+ private static final int AS_IS = 0;
+
+ /** . */
+ private static final int PLUS = 1;
+
+ /** . */
+ private static final int ESCAPE = 2;
+
+ /** . */
+ private static final int ERROR = 3;
+
+ /** . */
+ private final LookupNonTerm root = new LookupNonTerm();
+
+ /** . */
+ private final int[] decisions;
+
+ /** . */
+ private final int[][] conversions;
+
+ public FastURLDecoder(CharToByteEncoder encoder)
+ {
+ this(encoder, (char)0, (char)0x10FFFD);
+ }
+
+ public FastURLDecoder(CharToByteEncoder encoder, char from, char to)
+ {
+ for (char c = from;c <= to;c++)
+ {
+ byte[] v = encoder.encode(c);
+ LookupNonTerm node = root;
+ int k = v.length;
+ for (int i = 0; i < k; i++)
+ {
+ int index = (int)v[i] & 0xFF;
+ if (i == k - 1)
+ {
+ node.children[index] = new LookupTerm(c);
+ }
+ else
+ {
+ if (node.children[index] == null)
+ {
+ node.children[index] = new LookupNonTerm();
+ }
+ node = (LookupNonTerm)node.children[index];
+ }
+ }
+ }
+
+ //
+ conversions = new int[256][256];
+ for (char i = 0;i < 256;i++)
+ {
+ int x = hexValue(i);
+ for (char j = 0;j < 256;j++)
+ {
+ int y = hexValue(j);
+ if (x != -1 && y != -1)
+ {
+ conversions[i][j] = (x << 4) + y;
+ }
+ else
+ {
+ conversions[i][j] = -1;
+ }
+ }
+ }
+
+
+ //
+ decisions = new int[256];
+ for (int i = 0;i < decisions.length;i++)
+ {
+ if (TextTools.isAlphaNumeric((char)i))
+ {
+ decisions[i] = AS_IS;
+ }
+ else
+ {
+ switch(i)
+ {
+ case '+':
+ decisions[i] = PLUS;
+ break;
+ case '.':
+ case '-':
+ case '*':
+ case '_':
+ decisions[i] = AS_IS;
+ break;
+ case '%':
+ decisions[i] = ESCAPE;
+ break;
+ default:
+ decisions[i] = ERROR;
+ }
+ }
+ }
+ }
+
+ public void encode(char c, CharWriter writer)
+ {
+ encode(new char[]{c}, writer);
+ }
+
+ public void encode(char[] chars, int off, int len, CharWriter writer)
+ {
+ if (chars == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (off < 0)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (len < 0)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (off + len > chars.length)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (writer == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ encodeNoCheck(chars, off, len, writer);
+ }
+
+ public void encode(char[] chars, CharWriter writer)
+ {
+ if (chars == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (writer == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ encodeNoCheck(chars, 0, chars.length, writer);
+ }
+
+ public void encode(CharSequence s, CharWriter writer)
+ {
+ if (s == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (writer == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ if (s instanceof String)
+ {
+ char[] chars = ((String)s).toCharArray();
+ encodeNoCheck(chars, 0, chars.length, writer);
+ }
+ else
+ {
+ char[] chars = new char[s.length()];
+ for (int i = 0;i < s.length();i++)
+ {
+ char c = s.charAt(i);
+ chars[i] = c;
+ }
+ encodeNoCheck(chars, 0, chars.length, writer);
+ }
+ }
+
+ private void encodeNoCheck(char[] chars, int i, int length, CharWriter tmp)
+ {
+ while (i < length)
+ {
+ char c = chars[i++];
+ int decision = c < 256 ? decisions[c] : ERROR;
+ switch(decision)
+ {
+ case AS_IS:
+ tmp.append(c);
+ break;
+ case PLUS:
+ tmp.append(' ');
+ break;
+ case ESCAPE:
+ if (i + 2 > length)
+ {
+ throw new MalformedInputException("Not enough chars to decode an escaped value length should have been" +
+ (i + 2) + " but is " + length);
+ }
+
+ //
+ int j = i;
+
+ //
+ LookupNonTerm current = root;
+ while (true)
+ {
+ char c1 = chars[j++];
+ char c2 = chars[j++];
+
+ //
+ if (c1 > 255)
+ {
+ throw new MalformedInputException("Input out of the lookup range (" + c1 + "," + c2 + ")");
+ }
+ if (c2 > 255)
+ {
+ throw new MalformedInputException("Input out of the lookup range (" + c1 + "," + c2 + ")");
+ }
+
+
+ int z = conversions[c1][c2];
+
+ //
+ if (z == -1)
+ {
+ throw new MalformedInputException("Input out of the lookup range (" + c1 + "," + c2 + ")");
+ }
+
+ //
+ LookupNode child = current.children[z];
+ if (child instanceof LookupTerm)
+ {
+ LookupTerm term = (LookupTerm)child;
+ tmp.append(term.c);
+ i = j;
+ break;
+ }
+ else
+ {
+ current = (LookupNonTerm)child;
+ }
+
+ //
+ j++;
+ }
+ break;
+ case ERROR:
+ throw new MalformedInputException("Cannot decode char " + c);
+ }
+ }
+ }
+
+ private static class LookupNode
+ {
+ }
+
+ private static class LookupTerm extends LookupNode
+ {
+
+ /** . */
+ private final char c;
+
+ public LookupTerm(char c)
+ {
+ this.c = c;
+ }
+ }
+
+ private static class LookupNonTerm extends LookupNode
+ {
+ private final LookupNode[] children = new LookupNode[256];
+ }
+
+ /**
+ * Returns the hex value of the char c. If the char cannot be converted then -1 is returned.
+ *
+ * @param c the char to convert
+ * @return the converted hex value
+ */
+ private static int hexValue(char c)
+ {
+ if (c >= 'A' && c <= 'F')
+ {
+ return c - 'A' + 10;
+ }
+ if (c >= 'a' && c <= 'f')
+ {
+ return c - 'a' + 10;
+ }
+ if (c >= '0' && c <= '9')
+ {
+ return c - '0';
+ }
+ return -1;
+ }
+}
Modified: modules/common/trunk/common/src/main/org/jboss/portal/common/text/FastURLEncoder.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/common/text/FastURLEncoder.java 2007-08-28 09:16:47 UTC (rev 8063)
+++ modules/common/trunk/common/src/main/org/jboss/portal/common/text/FastURLEncoder.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -25,61 +25,183 @@
import org.jboss.portal.common.io.UndeclaredIOException;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
import java.io.Writer;
-import java.net.URLEncoder;
/**
+ * An implementation based on a table for lookups.
+ *
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 7228 $
*/
-public class FastURLEncoder
+public class FastURLEncoder implements CharEncoder
{
/** . */
- public static final FastURLEncoder DEFAULT_ENCODER = create("UTF-8", 0, 1024);
+ private static final FastURLEncoder DEFAULT_ENCODER = new FastURLEncoder(CharToByteEncoder.Generic.UTF8);
- /** . */
- protected final String encoding;
+ public static FastURLEncoder getInstance()
+ {
+ return DEFAULT_ENCODER;
+ }
/** . */
- protected final char[][] table;
+ private final char[][] table;
/** . */
- protected final int from;
+ private static final char MAX = (char)0x10FFFD;
- /** . */
- protected final int to;
-
- public FastURLEncoder(String encoding, int from, int to) throws UnsupportedEncodingException, IllegalArgumentException
+ public FastURLEncoder(CharToByteEncoder encoder) throws IllegalArgumentException
{
- if (encoding == null)
+ if (encoder == null)
{
throw new IllegalArgumentException("No encoding provided");
}
- if (to <= from)
+
+ //
+ this.table = new char[MAX + 1][];
+
+ //
+ for (char c = 0;c <= MAX;c++)
{
- throw new IllegalArgumentException("Bad range [" + from + "," + to + "[");
+ char[] z;
+ if (TextTools.isAlphaNumeric(c))
+ {
+ z = new char[]{c};
+ }
+ else
+ {
+ switch(c)
+ {
+ case ' ':
+ z = new char[]{'+'};
+ break;
+ case '.':
+ case '-':
+ case '*':
+ case '_':
+ z = new char[]{c};
+ break;
+ default:
+ byte[] v = encoder.encode(c);
+ if (v.length > 0)
+ {
+ z = new char[v.length * 3];
+ int index = 0;
+ for (int i = 0;i < v.length;i++)
+ {
+ byte b = v[i];
+ z[index++] = '%';
+ z[index++] = TextTools.toHex((b & 0xF0) >> 4);
+ z[index++] = TextTools.toHex(b & 0x0F);
+ }
+ }
+ else
+ {
+ z = null;
+ }
+ break;
+ }
+ }
+ table[c] = z;
}
- if (from < 0)
+ }
+
+ public void encode(CharSequence s, CharWriter out) throws IllegalArgumentException
+ {
+ if (s == null)
{
- throw new IllegalArgumentException("Lower bound cannot be negative " + to);
+ throw new IllegalArgumentException();
}
+ if (out == null)
+ {
+ throw new IllegalArgumentException();
+ }
//
- this.encoding = encoding;
- this.from = from;
- this.to = to;
- this.table = new char[to - from][];
+ for (int i = 0; i < s.length(); i++)
+ {
+ char c = s.charAt(i);
+ char[] z = table[c];
+ if (z == null)
+ {
+ throw new MalformedInputException("Wrong");
+ }
+ out.append(z);
+ }
+ }
+ public void encode(char c, CharWriter writer)
+ {
+ if (writer == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
//
- for (int c = (to - 1); c >= from; c--)
+ char[] z = table[c];
+ if (z == null)
{
- String v = URLEncoder.encode(Character.toString((char)c), encoding);
- table[c - from] = v.toCharArray();
+ throw new MalformedInputException("Wrong");
}
+ writer.append(z);
}
+ public void encode(char[] chars, int off, int len, CharWriter writer)
+ {
+ if (chars == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (off < 0)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (len < 0)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (off + len > chars.length)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (writer == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ encodeNoCheck(chars, off, len, writer);
+ }
+
+ public void encode(char[] chars, CharWriter writer)
+ {
+ if (chars == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (writer == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ encodeNoCheck(chars, 0, chars.length, writer);
+ }
+
+ private void encodeNoCheck(char[] chars, int off, int len, CharWriter writer)
+ {
+ for (int i = off; i < len; i++)
+ {
+ char c = chars[i];
+ char[] z = table[c];
+ if (z == null)
+ {
+ throw new IllegalArgumentException("Wrong");
+ }
+ writer.append(z);
+ }
+ }
+
public String encode(String s) throws IllegalArgumentException
{
StringBuffer tmp = new StringBuffer();
@@ -100,22 +222,12 @@
for (int i = 0; i < s.length(); i++)
{
char c = s.charAt(i);
- if (c >= from && c < to)
+ char[] z = table[c];
+ if (z == null)
{
- out.append(table[c - from]);
+ throw new MalformedInputException("Cannot encode char=" + (int)c);
}
- else
- {
- try
- {
- out.append(URLEncoder.encode(Character.toString(c), encoding));
- }
- catch (UnsupportedEncodingException e)
- {
- // That should never happen has the encoding validity is check at construction time
- throw new Error(e);
- }
- }
+ out.append(z);
}
}
@@ -134,22 +246,12 @@
for (int i = 0; i < s.length(); i++)
{
char c = s.charAt(i);
- if (c >= from && c < to)
+ char[] z = table[c];
+ if (z == null)
{
- out.write(table[c - from]);
+ throw new MalformedInputException("Wrong");
}
- else
- {
- try
- {
- out.write(URLEncoder.encode(Character.toString(c), encoding));
- }
- catch (UnsupportedEncodingException e)
- {
- // That should never happen has the encoding validity is check at construction time
- throw new Error(e);
- }
- }
+ out.write(z);
}
}
catch (IOException e)
@@ -160,20 +262,6 @@
public String toString()
{
- return "FastURLEncoder[" + encoding + ",[" + from + "," + to + "]]";
+ return "FastURLEncoder[" + "" + ",[" + 0 + "," + MAX + "]]";
}
-
- public static FastURLEncoder create(String encoding, int from, int to) throws IllegalArgumentException
- {
- try
- {
- return new FastURLEncoder(encoding, from, to);
- }
- catch (UnsupportedEncodingException e)
- {
- IllegalArgumentException iae = new IllegalArgumentException();
- iae.initCause(e);
- throw iae;
- }
- }
}
Added: modules/common/trunk/common/src/main/org/jboss/portal/common/text/MalformedInputException.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/common/text/MalformedInputException.java (rev 0)
+++ modules/common/trunk/common/src/main/org/jboss/portal/common/text/MalformedInputException.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -0,0 +1,49 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.text;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class MalformedInputException extends EncodingException
+{
+ public MalformedInputException()
+ {
+ }
+
+ public MalformedInputException(String string)
+ {
+ super(string);
+ }
+
+ public MalformedInputException(String string, Throwable throwable)
+ {
+ super(string, throwable);
+ }
+
+ public MalformedInputException(Throwable throwable)
+ {
+ super(throwable);
+ }
+}
Added: modules/common/trunk/common/src/main/org/jboss/portal/common/text/TextTools.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/common/text/TextTools.java (rev 0)
+++ modules/common/trunk/common/src/main/org/jboss/portal/common/text/TextTools.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -0,0 +1,64 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.text;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class TextTools
+{
+
+ /**
+ * Returns true if the char c is alpha numeric i.e it belongs to one of the following ranges [0,9], [A,Z] or
+ * [a,z]
+ * @param c the char to test
+ * @return true if c is alpha numeric
+ */
+ public static boolean isAlphaNumeric(char c)
+ {
+ return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
+ }
+
+ /**
+ * Returns the hexadecimal value of the provided numeric value.
+ * @param z the numeric value to convert
+ * @return the hexadecimal char
+ * @throws IllegalArgumentException if the value is not between 0 and 15
+ */
+ public static char toHex(int z) throws IllegalArgumentException
+ {
+ if (z >= 0 && z < 10)
+ {
+ return (char)('0' + z);
+ }
+ else if (z >= 10 && z < 16)
+ {
+ return (char)('A' - 10 + z);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Wrong character");
+ }
+ }
+}
Added: modules/common/trunk/common/src/main/org/jboss/portal/common/text/UnsupportedCharsetException.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/common/text/UnsupportedCharsetException.java (rev 0)
+++ modules/common/trunk/common/src/main/org/jboss/portal/common/text/UnsupportedCharsetException.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -0,0 +1,49 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.common.text;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class UnsupportedCharsetException extends EncodingException
+{
+ public UnsupportedCharsetException()
+ {
+ }
+
+ public UnsupportedCharsetException(String string)
+ {
+ super(string);
+ }
+
+ public UnsupportedCharsetException(String string, Throwable throwable)
+ {
+ super(string, throwable);
+ }
+
+ public UnsupportedCharsetException(Throwable throwable)
+ {
+ super(throwable);
+ }
+}
Deleted: modules/common/trunk/common/src/main/org/jboss/portal/test/common/CharBufferTestCase.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/test/common/CharBufferTestCase.java 2007-08-28 09:16:47 UTC (rev 8063)
+++ modules/common/trunk/common/src/main/org/jboss/portal/test/common/CharBufferTestCase.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -1,118 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.test.common;
-
-import junit.framework.TestCase;
-import org.jboss.portal.common.text.CharBuffer;
-import org.jboss.portal.common.text.FastURLEncoder;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class CharBufferTestCase extends TestCase
-{
-
- private FastURLEncoder encoder = FastURLEncoder.create("utf-8", 0, 512);
-
- public void testUTF8EncodedStringAppend()
- {
- CharBuffer buffer = new CharBuffer(0);
- buffer.append("/ a$\u0400", encoder);
- assertEquals("%2F+a%24%D0%80", buffer.asString());
- }
-
- public void testStringAppend()
- {
- CharBuffer buffer = new CharBuffer(0);
- buffer.append("abc");
- assertEquals("abc", buffer.asString());
- }
-
- public void testCharArrayAppend()
- {
- CharBuffer buffer = new CharBuffer(0);
- buffer.append("abc".toCharArray());
- assertEquals("abc", buffer.asString());
- }
-
- public void testCharsAppend()
- {
- CharBuffer buffer = new CharBuffer(0);
- buffer.append('a').append('b').append('c');
- assertEquals("abc", buffer.asString());
- }
-
- public void testReset()
- {
- CharBuffer buffer = new CharBuffer(0);
- buffer.append("abc".toCharArray());
- assertEquals("abc", buffer.asString());
- buffer.reset();
- buffer.append("def".toCharArray());
- assertEquals("def", buffer.asString());
- }
-
- public void testCharArrayAppendThrowsIAE()
- {
- CharBuffer buffer = new CharBuffer(0);
- try
- {
- buffer.append((char[])null);
- }
- catch (IllegalArgumentException e)
- {
- }
- }
-
- public void testStringAppendThrowsIAE()
- {
- CharBuffer buffer = new CharBuffer(0);
- try
- {
- buffer.append((String)null);
- }
- catch (IllegalArgumentException e)
- {
- }
- }
-
- public void testUTF8EncodedAppendThrowsIAE()
- {
- CharBuffer buffer = new CharBuffer(0);
- try
- {
- buffer.append(null, encoder);
- }
- catch (IllegalArgumentException e)
- {
- }
- try
- {
- buffer.append("abc", null);
- }
- catch (IllegalArgumentException e)
- {
- }
- }
-}
Deleted: modules/common/trunk/common/src/main/org/jboss/portal/test/common/FastURLEncoderTestCase.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/test/common/FastURLEncoderTestCase.java 2007-08-28 09:16:47 UTC (rev 8063)
+++ modules/common/trunk/common/src/main/org/jboss/portal/test/common/FastURLEncoderTestCase.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -1,177 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.test.common;
-
-import org.jboss.portal.common.text.FastURLEncoder;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-
-import junit.framework.TestCase;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class FastURLEncoderTestCase extends TestCase
-{
-
- public void testConstructor() throws Exception
- {
- try
- {
- new FastURLEncoder(null, 0, 10);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- }
- try
- {
- new FastURLEncoder("UTF8", -1, 10);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- }
- try
- {
- new FastURLEncoder("UTF8", -2, -1);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- }
- try
- {
- new FastURLEncoder("UTF8", 1, 0);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- }
- try
- {
- new FastURLEncoder("UTF8", 0, 0);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- }
- try
- {
- new FastURLEncoder("ABCDEF", 0, 10);
- fail();
- }
- catch (UnsupportedEncodingException expected)
- {
- }
- }
-
- public void testFactory() throws Exception
- {
- try
- {
- FastURLEncoder.create(null, 0, 10);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- }
- try
- {
- FastURLEncoder.create("UTF8", -1, 10);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- }
- try
- {
- FastURLEncoder.create("UTF8", -2, -1);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- }
- try
- {
- FastURLEncoder.create("UTF8", 1, 0);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- }
- try
- {
- FastURLEncoder.create("UTF8", 0, 0);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- }
- try
- {
- FastURLEncoder.create("ABCDEF", 0, 10);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- }
- }
-
- public void testEncodeThrowsIAE() throws Exception
- {
- FastURLEncoder encoder = new FastURLEncoder("UTF8", 0, 256);
- try
- {
- encoder.encode(null, new StringBuffer());
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- }
- try
- {
- encoder.encode("", (StringBuffer)null);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- }
- }
-
- public void testEncode() throws Exception
- {
- FastURLEncoder encoder = new FastURLEncoder("UTF8", 0, 512);
- StringBuffer tmp = new StringBuffer();
- for (int i = 0;i < 512;i++)
- {
- tmp.append((char)i);
- }
- String s = tmp.toString();
- String u1 = encoder.encode(s);
- String u2 = URLEncoder.encode(s, "UTF8");
- assertEquals(u2, u1);
- }
-}
Added: modules/common/trunk/common/src/main/org/jboss/portal/test/common/io/WriterCharWriterTestCase.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/test/common/io/WriterCharWriterTestCase.java (rev 0)
+++ modules/common/trunk/common/src/main/org/jboss/portal/test/common/io/WriterCharWriterTestCase.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -0,0 +1,203 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.common.io;
+
+import org.jboss.portal.common.io.WriterCharWriter;
+import org.jboss.portal.common.io.UndeclaredIOException;
+
+import java.io.StringWriter;
+import java.io.IOException;
+import java.io.Writer;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class WriterCharWriterTestCase extends TestCase
+{
+
+ public void testAppend1() throws IOException
+ {
+ StringWriter s = new StringWriter();
+ WriterCharWriter writer = new WriterCharWriter(s);
+ writer.append('a');
+ s.close();
+ assertEquals("a", s.toString());
+ }
+
+ public void testAppend2() throws IOException
+ {
+ StringWriter s = new StringWriter();
+ WriterCharWriter writer = new WriterCharWriter(s);
+ writer.append("abc".toCharArray());
+ s.close();
+ assertEquals("abc", s.toString());
+ }
+
+ public void testAppend3() throws IOException
+ {
+ StringWriter s = new StringWriter();
+ WriterCharWriter writer = new WriterCharWriter(s);
+ writer.append("abcdef".toCharArray(), 1, 3);
+ s.close();
+ assertEquals("bcd", s.toString());
+ }
+
+ public void testAppend4() throws IOException
+ {
+ StringWriter s = new StringWriter();
+ WriterCharWriter writer = new WriterCharWriter(s);
+ writer.append("abc");
+ s.close();
+ assertEquals("abc", s.toString());
+ }
+
+ private Writer failingWriter = new Writer()
+ {
+ public void write(char[] chars, int i, int i1) throws IOException
+ {
+ throw new IOException();
+ }
+
+ public void flush() throws IOException
+ {
+ throw new IOException();
+ }
+
+ public void close() throws IOException
+ {
+ throw new IOException();
+ }
+ };
+
+ public void testWrappedIOException()
+ {
+ WriterCharWriter writer = new WriterCharWriter(failingWriter);
+ try
+ {
+ writer.append('c');
+ fail("Was expecting an UndeclaredIOException");
+ }
+ catch (UndeclaredIOException expected)
+ {
+ }
+ try
+ {
+ writer.append("abc".toCharArray());
+ fail("Was expecting an UndeclaredIOException");
+ }
+ catch (UndeclaredIOException expected)
+ {
+ }
+ try
+ {
+ writer.append("abcdef".toCharArray(), 1, 3);
+ fail("Was expecting an UndeclaredIOException");
+ }
+ catch (UndeclaredIOException expected)
+ {
+ }
+ try
+ {
+ writer.append("abc");
+ fail("Was expecting an UndeclaredIOException");
+ }
+ catch (UndeclaredIOException expected)
+ {
+ }
+ }
+
+ public void testAppendThrowsIAE()
+ {
+ try
+ {
+ new WriterCharWriter(null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ //
+ WriterCharWriter writer = new WriterCharWriter(new StringWriter());
+ try
+ {
+ writer.append(new char[10], -1, 0);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ writer.append(new char[10], 5, -1);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ writer.append(new char[10], 15, 0);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ writer.append(new char[10], 5, 6);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ writer.append(null, 0, 5);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ writer.append((char[])null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ writer.append((CharSequence)null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+
+}
Copied: modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/CharBufferTestCase.java (from rev 7954, modules/common/trunk/common/src/main/org/jboss/portal/test/common/CharBufferTestCase.java)
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/CharBufferTestCase.java (rev 0)
+++ modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/CharBufferTestCase.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -0,0 +1,118 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.common.text;
+
+import junit.framework.TestCase;
+import org.jboss.portal.common.text.CharBuffer;
+import org.jboss.portal.common.text.FastURLEncoder;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class CharBufferTestCase extends TestCase
+{
+
+ private FastURLEncoder encoder = FastURLEncoder.getInstance();
+
+ public void testUTF8EncodedStringAppend()
+ {
+ CharBuffer buffer = new CharBuffer(0);
+ buffer.append("/ a$\u0400", encoder);
+ assertEquals("%2F+a%24%D0%80", buffer.asString());
+ }
+
+ public void testStringAppend()
+ {
+ CharBuffer buffer = new CharBuffer(0);
+ buffer.append("abc");
+ assertEquals("abc", buffer.asString());
+ }
+
+ public void testCharArrayAppend()
+ {
+ CharBuffer buffer = new CharBuffer(0);
+ buffer.append("abc".toCharArray());
+ assertEquals("abc", buffer.asString());
+ }
+
+ public void testCharsAppend()
+ {
+ CharBuffer buffer = new CharBuffer(0);
+ buffer.append('a').append('b').append('c');
+ assertEquals("abc", buffer.asString());
+ }
+
+ public void testReset()
+ {
+ CharBuffer buffer = new CharBuffer(0);
+ buffer.append("abc".toCharArray());
+ assertEquals("abc", buffer.asString());
+ buffer.reset();
+ buffer.append("def".toCharArray());
+ assertEquals("def", buffer.asString());
+ }
+
+ public void testCharArrayAppendThrowsIAE()
+ {
+ CharBuffer buffer = new CharBuffer(0);
+ try
+ {
+ buffer.append((char[])null);
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testStringAppendThrowsIAE()
+ {
+ CharBuffer buffer = new CharBuffer(0);
+ try
+ {
+ buffer.append((String)null);
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testUTF8EncodedAppendThrowsIAE()
+ {
+ CharBuffer buffer = new CharBuffer(0);
+ try
+ {
+ buffer.append(null, encoder);
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ try
+ {
+ buffer.append("abc", null);
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+}
Added: modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/CharToByteEncoderTestCase.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/CharToByteEncoderTestCase.java (rev 0)
+++ modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/CharToByteEncoderTestCase.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -0,0 +1,61 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.common.text;
+
+import junit.framework.TestCase;
+import org.jboss.portal.common.text.CharToByteEncoder;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class CharToByteEncoderTestCase extends TestCase
+{
+
+ public void testCorrectness()
+ {
+ CharToByteEncoder encoder = new CharToByteEncoder.Generic("UTF8");
+
+ //
+ for (int i = 0;i <= 0x10FFFD;i++)
+ {
+ char c = (char)i;
+ int type = Character.getType(c);
+ byte[] r = encoder.encode(c);
+ if (type == Character.SURROGATE || type == Character.PRIVATE_USE)
+ {
+ if (r.length != 0)
+ {
+ fail("Char " + i + " has length " + r.length);
+ }
+ }
+ else
+ {
+ if (r.length < 1)
+ {
+ fail("Char " + i + " has length " + r.length);
+ }
+ }
+ }
+ }
+}
Added: modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/FastURLDecoderTestCase.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/FastURLDecoderTestCase.java (rev 0)
+++ modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/FastURLDecoderTestCase.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -0,0 +1,218 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.common.text;
+
+import junit.framework.TestCase;
+import org.jboss.portal.common.text.FastURLDecoder;
+import org.jboss.portal.common.text.CharEncoder;
+import org.jboss.portal.common.text.CharBuffer;
+import org.jboss.portal.common.text.MalformedInputException;
+
+import java.net.URLEncoder;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class FastURLDecoderTestCase extends TestCase
+{
+
+ public void testEncodeThrowsIAE() throws Exception
+ {
+ CharEncoder encoder = FastURLDecoder.getInstance();
+ try
+ {
+ encoder.encode(new char[10], -1, 0, new CharBuffer());
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode(new char[10], 5, -1, new CharBuffer());
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode(new char[10], 15, 0, new CharBuffer());
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode(new char[10], 5, 6, new CharBuffer());
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode(null, 0, 5, new CharBuffer());
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode((char[])null, new CharBuffer());
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode((CharSequence)null, new CharBuffer());
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ //
+ try
+ {
+ encoder.encode(new char[10], 0, 10, null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode(new char[10], null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode('A', null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode("abc", null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+
+ public void testEncode() throws Exception
+ {
+ FastURLDecoder encoder = FastURLDecoder.getInstance();
+ StringBuffer tmp = new StringBuffer();
+ for (int i = 0;i < 512;i++)
+ {
+ tmp.append((char)i);
+ }
+ CharBuffer out = new CharBuffer();
+ String s = tmp.toString();
+ String t = URLEncoder.encode(s, "UTF8");
+ encoder.encode(t, out);
+ assertEquals(s, out.asString());
+ }
+
+ public void testEncodeMalformedInput()
+ {
+ FastURLDecoder encoder = FastURLDecoder.getInstance();
+ try
+ {
+ encoder.encode("%0T", new CharBuffer());
+ fail("Was expecting a malformed input exception");
+ }
+ catch (MalformedInputException expected)
+ {
+ }
+ try
+ {
+ encoder.encode("%T0", new CharBuffer());
+ fail("Was expecting a malformed input exception");
+ }
+ catch (MalformedInputException expected)
+ {
+ }
+ try
+ {
+ encoder.encode("%0\u0100", new CharBuffer());
+ fail("Was expecting a malformed input exception");
+ }
+ catch (MalformedInputException expected)
+ {
+ }
+ try
+ {
+ encoder.encode("%\u01000", new CharBuffer());
+ fail("Was expecting a malformed input exception");
+ }
+ catch (MalformedInputException expected)
+ {
+ }
+ try
+ {
+ encoder.encode("%0", new CharBuffer());
+ fail("Was expecting a malformed input exception");
+ }
+ catch (MalformedInputException expected)
+ {
+ }
+ try
+ {
+ encoder.encode("%", new CharBuffer());
+ fail("Was expecting a malformed input exception");
+ }
+ catch (MalformedInputException expected)
+ {
+ }
+ try
+ {
+ encoder.encode(";", new CharBuffer());
+ fail("Was expecting a malformed input exception");
+ }
+ catch (MalformedInputException expected)
+ {
+ }
+ try
+ {
+ encoder.encode("\u0100", new CharBuffer());
+ fail("Was expecting a malformed input exception");
+ }
+ catch (MalformedInputException expected)
+ {
+ }
+ }
+}
Copied: modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/FastURLEncoderTestCase.java (from rev 7954, modules/common/trunk/common/src/main/org/jboss/portal/test/common/FastURLEncoderTestCase.java)
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/FastURLEncoderTestCase.java (rev 0)
+++ modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/FastURLEncoderTestCase.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -0,0 +1,149 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.common.text;
+
+import org.jboss.portal.common.text.FastURLEncoder;
+import org.jboss.portal.common.text.CharBuffer;
+import org.jboss.portal.common.text.CharEncoder;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class FastURLEncoderTestCase extends TestCase
+{
+
+ public void testEncodeThrowsIAE() throws Exception
+ {
+ CharEncoder encoder = FastURLEncoder.getInstance();
+ try
+ {
+ encoder.encode(new char[10], -1, 0, new CharBuffer());
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode(new char[10], 5, -1, new CharBuffer());
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode(new char[10], 15, 0, new CharBuffer());
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode(new char[10], 5, 6, new CharBuffer());
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode(null, 0, 5, new CharBuffer());
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode((char[])null, new CharBuffer());
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode((CharSequence)null, new CharBuffer());
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ //
+ try
+ {
+ encoder.encode(new char[10], 0, 10, null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode(new char[10], null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode('A', null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ try
+ {
+ encoder.encode("abc", null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+
+ public void testEncode() throws Exception
+ {
+ FastURLEncoder encoder = FastURLEncoder.getInstance();
+ StringBuffer tmp = new StringBuffer();
+ for (int i = 0;i < 512;i++)
+ {
+ tmp.append((char)i);
+ }
+ String s = tmp.toString();
+ String u1 = encoder.encode(s);
+ String u2 = URLEncoder.encode(s, "UTF8");
+ assertEquals(u2, u1);
+ }
+}
Added: modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/TextToolsTestCase.java
===================================================================
--- modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/TextToolsTestCase.java (rev 0)
+++ modules/common/trunk/common/src/main/org/jboss/portal/test/common/text/TextToolsTestCase.java 2007-08-28 09:26:34 UTC (rev 8064)
@@ -0,0 +1,96 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.common.text;
+
+import junit.framework.TestCase;
+import org.jboss.portal.common.text.TextTools;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class TextToolsTestCase extends TestCase
+{
+
+ public void testIsAlphaNumeric()
+ {
+ assertForChar(false, 0, '0');
+ assertForChar(true, '0', '9' + 1);
+ assertForChar(false, '9' + 1, 'A');
+ assertForChar(true, 'A', 'Z' + 1);
+ assertForChar(false, 'Z' + 1, 'a');
+ assertForChar(true, 'a', 'z' + 1);
+ assertForChar(false, 'z' + 1, 512);
+ }
+
+ private void assertForChar(boolean result, int from, int to)
+ {
+ while (from < to)
+ {
+ assertEquals(result, TextTools.isAlphaNumeric((char)(from++)));
+ }
+ }
+
+ public void testToHex()
+ {
+ assertEquals('0', TextTools.toHex(0));
+ assertEquals('1', TextTools.toHex(1));
+ assertEquals('2', TextTools.toHex(2));
+ assertEquals('3', TextTools.toHex(3));
+ assertEquals('4', TextTools.toHex(4));
+ assertEquals('5', TextTools.toHex(5));
+ assertEquals('6', TextTools.toHex(6));
+ assertEquals('7', TextTools.toHex(7));
+ assertEquals('8', TextTools.toHex(8));
+ assertEquals('9', TextTools.toHex(9));
+ assertEquals('A', TextTools.toHex(10));
+ assertEquals('B', TextTools.toHex(11));
+ assertEquals('C', TextTools.toHex(12));
+ assertEquals('D', TextTools.toHex(13));
+ assertEquals('E', TextTools.toHex(14));
+ assertEquals('F', TextTools.toHex(15));
+ for (int i = 16;i < 512;i++)
+ {
+ try
+ {
+ TextTools.toHex(i);
+ fail("Was expecting an IAE at index=" + i);
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+ for (int i = -512;i < 0;i++)
+ {
+ try
+ {
+ TextTools.toHex(i);
+ fail("Was expecting an IAE at index=" + i);
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+ }
+
+}
16 years, 9 months
JBoss Portal SVN: r8063 - in branches/JBoss_Portal_Branch_2_6: cms and 16 other directories.
by portal-commits@lists.jboss.org
Author: thomas.heute(a)jboss.com
Date: 2007-08-28 05:16:47 -0400 (Tue, 28 Aug 2007)
New Revision: 8063
Added:
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/CurrentUsersPortlet.java
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/event/
Removed:
branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/user/
Modified:
branches/JBoss_Portal_Branch_2_6/api/.classpath
branches/JBoss_Portal_Branch_2_6/cms/.classpath
branches/JBoss_Portal_Branch_2_6/core-admin/.classpath
branches/JBoss_Portal_Branch_2_6/core-cms/.classpath
branches/JBoss_Portal_Branch_2_6/core-samples/.classpath
branches/JBoss_Portal_Branch_2_6/core-search/.classpath
branches/JBoss_Portal_Branch_2_6/core/.classpath
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsServiceImpl.java
branches/JBoss_Portal_Branch_2_6/faces/.classpath
branches/JBoss_Portal_Branch_2_6/portlet-server/.classpath
branches/JBoss_Portal_Branch_2_6/portlet/.classpath
branches/JBoss_Portal_Branch_2_6/search/.classpath
branches/JBoss_Portal_Branch_2_6/server/.classpath
branches/JBoss_Portal_Branch_2_6/theme/.classpath
branches/JBoss_Portal_Branch_2_6/workflow/.classpath
branches/JBoss_Portal_Branch_2_6/wsrp/.classpath
Log:
- Eclipse classpath update
- Fixed wrong package for UsersActivityStatesService
Modified: branches/JBoss_Portal_Branch_2_6/api/.classpath
===================================================================
--- branches/JBoss_Portal_Branch_2_6/api/.classpath 2007-08-27 23:21:44 UTC (rev 8062)
+++ branches/JBoss_Portal_Branch_2_6/api/.classpath 2007-08-28 09:16:47 UTC (rev 8063)
@@ -2,5 +2,6 @@
<classpath>
<classpathentry kind="src" path="src/main"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-portal-lib.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: branches/JBoss_Portal_Branch_2_6/cms/.classpath
===================================================================
--- branches/JBoss_Portal_Branch_2_6/cms/.classpath 2007-08-27 23:21:44 UTC (rev 8062)
+++ branches/JBoss_Portal_Branch_2_6/cms/.classpath 2007-08-28 09:16:47 UTC (rev 8063)
@@ -31,12 +31,10 @@
<classpathentry kind="lib" path="/thirdparty/jgroups/lib/jgroups.jar"/>
<classpathentry kind="lib" path="/thirdparty/apache-collections/lib/commons-collections.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/jems"/>
- <classpathentry combineaccessrules="false" kind="src" path="/test"/>
<classpathentry combineaccessrules="false" kind="src" path="/server"/>
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
<classpathentry combineaccessrules="false" kind="src" path="/portlet"/>
<classpathentry kind="lib" path="/thirdparty/sun-servlet/lib/servlet-api.jar"/>
- <classpathentry combineaccessrules="false" kind="src" path="/identity"/>
<classpathentry combineaccessrules="false" kind="src" path="/workflow"/>
<classpathentry kind="lib" path="/thirdparty/jackrabbit/lib/jackrabbit-core.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/security"/>
@@ -44,5 +42,7 @@
<classpathentry combineaccessrules="false" kind="src" path="/search"/>
<classpathentry kind="lib" path="/thirdparty/apache-lucene/lib/lucene.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/identity/lib/portal-identity-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/test/lib/portal-test-lib.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: branches/JBoss_Portal_Branch_2_6/core/.classpath
===================================================================
--- branches/JBoss_Portal_Branch_2_6/core/.classpath 2007-08-27 23:21:44 UTC (rev 8062)
+++ branches/JBoss_Portal_Branch_2_6/core/.classpath 2007-08-28 09:16:47 UTC (rev 8063)
@@ -38,9 +38,7 @@
<classpathentry combineaccessrules="false" kind="src" path="/server"/>
<classpathentry combineaccessrules="false" kind="src" path="/security"/>
<classpathentry combineaccessrules="false" kind="src" path="/cms"/>
- <classpathentry combineaccessrules="false" kind="src" path="/test"/>
<classpathentry combineaccessrules="false" kind="src" path="/theme"/>
- <classpathentry combineaccessrules="false" kind="src" path="/identity"/>
<classpathentry combineaccessrules="false" kind="src" path="/format"/>
<classpathentry combineaccessrules="false" kind="src" path="/registration"/>
<classpathentry combineaccessrules="false" kind="src" path="/workflow"/>
@@ -51,5 +49,12 @@
<classpathentry kind="lib" path="/thirdparty/freemarker/lib/freemarker.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/web/lib/portal-web-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-portal-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/identity/lib/portal-identity-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-microcontainer.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-dependency.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jbossas/core-libs/lib/jbossha.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss/backport-concurrent/lib/jboss-backport-concurrent.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/test/lib/portal-test-lib.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsServiceImpl.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsServiceImpl.java 2007-08-27 23:21:44 UTC (rev 8062)
+++ branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/identity/UsersActivityStatsServiceImpl.java 2007-08-28 09:16:47 UTC (rev 8063)
@@ -22,32 +22,27 @@
package org.jboss.portal.core.identity;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-import org.jboss.logging.Logger;
-import org.jboss.mx.util.MBeanServerLocator;
-import org.jboss.mx.util.MBeanProxy;
-import org.jboss.mx.util.MBeanProxyCreationException;
-
-import java.util.Set;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Set;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+
+import org.jboss.logging.Logger;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+
+import edu.emory.mathcs.backport.java.util.Queue;
+import edu.emory.mathcs.backport.java.util.concurrent.Callable;
import edu.emory.mathcs.backport.java.util.concurrent.Executor;
-import edu.emory.mathcs.backport.java.util.concurrent.ScheduledExecutorService;
-import edu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingQueue;
import edu.emory.mathcs.backport.java.util.concurrent.Executors;
-import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
import edu.emory.mathcs.backport.java.util.concurrent.FutureTask;
-import edu.emory.mathcs.backport.java.util.concurrent.Callable;
-import edu.emory.mathcs.backport.java.util.Queue;
+import edu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingQueue;
+import edu.emory.mathcs.backport.java.util.concurrent.ScheduledExecutorService;
+import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
-import javax.management.NotificationListener;
-import javax.management.Notification;
-import javax.management.ObjectName;
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-
/**
* @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot com">Boleslaw Dawidowicz</a>
* @author <a href="mailto:jedim@vige.it">Luca Stancapiano</a>
Modified: branches/JBoss_Portal_Branch_2_6/core-admin/.classpath
===================================================================
--- branches/JBoss_Portal_Branch_2_6/core-admin/.classpath 2007-08-27 23:21:44 UTC (rev 8062)
+++ branches/JBoss_Portal_Branch_2_6/core-admin/.classpath 2007-08-28 09:16:47 UTC (rev 8063)
@@ -5,7 +5,6 @@
<classpathentry combineaccessrules="false" kind="src" path="/faces"/>
<classpathentry combineaccessrules="false" kind="src" path="/security"/>
<classpathentry kind="lib" path="/thirdparty/apache-myfaces/lib/myfaces-api.jar"/>
- <classpathentry combineaccessrules="false" kind="src" path="/identity"/>
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
<classpathentry combineaccessrules="false" kind="src" path="/core"/>
<classpathentry combineaccessrules="false" kind="src" path="/portlet"/>
@@ -21,5 +20,7 @@
<classpathentry kind="lib" path="/thirdparty/sun-servlet/lib/jsp-api.jar"/>
<classpathentry kind="lib" path="/thirdparty/apache-log4j/lib/log4j.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-portal-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/identity/lib/portal-identity-lib.jar"/>
<classpathentry kind="output" path="output/classes"/>
</classpath>
Modified: branches/JBoss_Portal_Branch_2_6/core-cms/.classpath
===================================================================
--- branches/JBoss_Portal_Branch_2_6/core-cms/.classpath 2007-08-27 23:21:44 UTC (rev 8062)
+++ branches/JBoss_Portal_Branch_2_6/core-cms/.classpath 2007-08-28 09:16:47 UTC (rev 8063)
@@ -8,7 +8,6 @@
<classpathentry combineaccessrules="false" kind="src" path="/portlet"/>
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
<classpathentry kind="lib" path="/thirdparty/jbossas/core-libs/lib/jboss-jmx.jar"/>
- <classpathentry combineaccessrules="false" kind="src" path="/identity"/>
<classpathentry combineaccessrules="false" kind="src" path="/jems"/>
<classpathentry kind="lib" path="/thirdparty/jbossas/core-libs/lib/jboss-system.jar"/>
<classpathentry kind="lib" path="/thirdparty/jbossas/core-libs/lib/jboss-common.jar"/>
@@ -25,5 +24,7 @@
<classpathentry combineaccessrules="false" kind="src" path="/search"/>
<classpathentry kind="lib" path="/thirdparty/apache-lucene/lib/lucene.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/identity/lib/portal-identity-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-portal-lib.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: branches/JBoss_Portal_Branch_2_6/core-samples/.classpath
===================================================================
--- branches/JBoss_Portal_Branch_2_6/core-samples/.classpath 2007-08-27 23:21:44 UTC (rev 8062)
+++ branches/JBoss_Portal_Branch_2_6/core-samples/.classpath 2007-08-28 09:16:47 UTC (rev 8063)
@@ -6,12 +6,14 @@
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
<classpathentry combineaccessrules="false" kind="src" path="/format"/>
<classpathentry combineaccessrules="false" kind="src" path="/core"/>
- <classpathentry combineaccessrules="false" kind="src" path="/identity"/>
<classpathentry combineaccessrules="false" kind="src" path="/portlet"/>
<classpathentry combineaccessrules="false" kind="src" path="/theme"/>
<classpathentry kind="lib" path="/thirdparty/jbossas/core-libs/lib/jboss-j2ee.jar"/>
<classpathentry kind="lib" path="/thirdparty/apache-fileupload/lib/commons-fileupload.jar"/>
<classpathentry kind="lib" path="/thirdparty/oswego-concurrent/lib/concurrent.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/identity/lib/portal-identity-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-portal-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jbossas/core-libs/lib/jboss-jmx.jar" sourcepath="/JBoss_AS_4.0.5/jmx/src/main"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Copied: branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/CurrentUsersPortlet.java (from rev 8062, branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/user/CurrentUsersPortlet.java)
===================================================================
--- branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/CurrentUsersPortlet.java (rev 0)
+++ branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/CurrentUsersPortlet.java 2007-08-28 09:16:47 UTC (rev 8063)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.portal.core.samples.users;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Set;
+
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.UnavailableException;
+
+import org.apache.log4j.Logger;
+import org.jboss.portal.core.identity.UsersActivityStatsService;
+import org.jboss.portal.core.servlet.jsp.PortalJsp;
+import org.jboss.portal.core.servlet.jsp.taglib.context.DelegateContext;
+import org.jboss.portlet.JBossPortlet;
+import org.jboss.portlet.JBossRenderRequest;
+import org.jboss.portlet.JBossRenderResponse;
+
+/**
+ * Read the current users online and write them in output.
+ *
+ * @author <a href="mailto:jedim@vige.it">Luca Stancapiano</a>
+ */
+public class CurrentUsersPortlet extends JBossPortlet {
+
+ /**
+ * Logger
+ */
+ public static Logger log = Logger.getLogger(CurrentUsersPortlet.class);
+
+ protected void doView(JBossRenderRequest rRequest, JBossRenderResponse rResponse)
+ throws PortletException, IOException, UnavailableException {
+ UsersActivityStatsService uass = (UsersActivityStatsService) this
+ .getPortletContext().getAttribute("UsersActivityStats");
+
+ rResponse.setContentType("text/html");
+ PrintWriter writer = rResponse.getWriter();
+
+ //TODO: this is wrong - should pass period instead of current time - actually it works by a coincedence...
+ Set users = uass.getActiveUsersNames(System.currentTimeMillis());
+
+ if (users.size() == 1) {
+ DelegateContext ctx = new DelegateContext();
+ ctx.put("USERS", users.toString());
+ ctx.put("USERS_COUNT", Integer.toString(users.size()));
+ rRequest.setAttribute(PortalJsp.CTX_REQUEST, ctx);
+ PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/users/oneUser.jsp");
+ rd.include(rRequest, rResponse);
+ } else if (users.size() > 1) {
+ DelegateContext ctx = new DelegateContext();
+ ctx.put("USERS", users.toString());
+ ctx.put("USERS_COUNT", Integer.toString(users.size()));
+ rRequest.setAttribute(PortalJsp.CTX_REQUEST, ctx);
+ PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/users/users.jsp");
+ rd.include(rRequest, rResponse);
+ } else {
+ PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/users/noUser.jsp");
+ rd.include(rRequest, rResponse);
+ }
+
+
+ writer.close();
+ }
+}
Copied: branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/users/event (from rev 8062, branches/JBoss_Portal_Branch_2_6/core-samples/src/main/org/jboss/portal/core/samples/user/event)
Modified: branches/JBoss_Portal_Branch_2_6/core-search/.classpath
===================================================================
--- branches/JBoss_Portal_Branch_2_6/core-search/.classpath 2007-08-27 23:21:44 UTC (rev 8062)
+++ branches/JBoss_Portal_Branch_2_6/core-search/.classpath 2007-08-28 09:16:47 UTC (rev 8063)
@@ -15,5 +15,6 @@
<classpathentry combineaccessrules="false" kind="src" path="/search"/>
<classpathentry combineaccessrules="false" kind="src" path="/faces"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-portal-lib.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: branches/JBoss_Portal_Branch_2_6/faces/.classpath
===================================================================
--- branches/JBoss_Portal_Branch_2_6/faces/.classpath 2007-08-27 23:21:44 UTC (rev 8062)
+++ branches/JBoss_Portal_Branch_2_6/faces/.classpath 2007-08-28 09:16:47 UTC (rev 8063)
@@ -15,5 +15,6 @@
<classpathentry kind="lib" path="/thirdparty/sun-servlet/lib/servlet-api.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/bridge"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-portal-lib.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: branches/JBoss_Portal_Branch_2_6/portlet/.classpath
===================================================================
--- branches/JBoss_Portal_Branch_2_6/portlet/.classpath 2007-08-27 23:21:44 UTC (rev 8062)
+++ branches/JBoss_Portal_Branch_2_6/portlet/.classpath 2007-08-28 09:16:47 UTC (rev 8063)
@@ -21,10 +21,11 @@
<classpathentry kind="lib" path="/thirdparty/apache-log4j/lib/log4j.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/server"/>
<classpathentry combineaccessrules="false" kind="src" path="/jems"/>
- <classpathentry combineaccessrules="false" kind="src" path="/test"/>
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
<classpathentry combineaccessrules="false" kind="src" path="/security"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/web/lib/portal-web-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-portal-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/test/lib/portal-test-lib.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: branches/JBoss_Portal_Branch_2_6/portlet-server/.classpath
===================================================================
--- branches/JBoss_Portal_Branch_2_6/portlet-server/.classpath 2007-08-27 23:21:44 UTC (rev 8062)
+++ branches/JBoss_Portal_Branch_2_6/portlet-server/.classpath 2007-08-28 09:16:47 UTC (rev 8063)
@@ -14,5 +14,7 @@
<classpathentry combineaccessrules="false" kind="src" path="/security"/>
<classpathentry kind="lib" path="/thirdparty/oswego-concurrent/lib/concurrent.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-portal-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jbossas/core-libs/lib/jboss.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: branches/JBoss_Portal_Branch_2_6/search/.classpath
===================================================================
--- branches/JBoss_Portal_Branch_2_6/search/.classpath 2007-08-27 23:21:44 UTC (rev 8062)
+++ branches/JBoss_Portal_Branch_2_6/search/.classpath 2007-08-28 09:16:47 UTC (rev 8063)
@@ -9,7 +9,7 @@
<classpathentry kind="lib" path="/thirdparty/apache-lucene/lib/lucene.jar"/>
<classpathentry kind="lib" path="/thirdparty/jcr/lib/jcr-1.0.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/jems"/>
- <classpathentry combineaccessrules="false" kind="src" path="/identity"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/identity/lib/portal-identity-lib.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: branches/JBoss_Portal_Branch_2_6/server/.classpath
===================================================================
--- branches/JBoss_Portal_Branch_2_6/server/.classpath 2007-08-27 23:21:44 UTC (rev 8062)
+++ branches/JBoss_Portal_Branch_2_6/server/.classpath 2007-08-28 09:16:47 UTC (rev 8063)
@@ -3,7 +3,6 @@
<classpathentry kind="src" path="src/main"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/thirdparty/sun-servlet/lib/servlet-api.jar"/>
- <classpathentry combineaccessrules="false" kind="src" path="/test"/>
<classpathentry kind="lib" path="/thirdparty/apache-httpclient/lib/commons-httpclient.jar"/>
<classpathentry kind="lib" path="/thirdparty/apache-log4j/lib/log4j.jar"/>
<classpathentry kind="lib" path="/thirdparty/jbossas/core-libs/lib/jboss.jar"/>
@@ -15,5 +14,7 @@
<classpathentry kind="lib" path="/thirdparty/jboss/backport-concurrent/lib/jboss-backport-concurrent.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/web/lib/portal-web-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/test/lib/portal-test-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/test/lib/portal-test-jboss-lib.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: branches/JBoss_Portal_Branch_2_6/theme/.classpath
===================================================================
--- branches/JBoss_Portal_Branch_2_6/theme/.classpath 2007-08-27 23:21:44 UTC (rev 8062)
+++ branches/JBoss_Portal_Branch_2_6/theme/.classpath 2007-08-28 09:16:47 UTC (rev 8063)
@@ -17,8 +17,9 @@
<classpathentry combineaccessrules="false" kind="src" path="/jems"/>
<classpathentry combineaccessrules="false" kind="src" path="/portlet"/>
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
- <classpathentry combineaccessrules="false" kind="src" path="/test"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/web/lib/portal-web-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-portal-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/test/lib/portal-test-lib.jar"/>
<classpathentry kind="output" path="output/classes"/>
</classpath>
Modified: branches/JBoss_Portal_Branch_2_6/workflow/.classpath
===================================================================
--- branches/JBoss_Portal_Branch_2_6/workflow/.classpath 2007-08-27 23:21:44 UTC (rev 8062)
+++ branches/JBoss_Portal_Branch_2_6/workflow/.classpath 2007-08-28 09:16:47 UTC (rev 8063)
@@ -10,8 +10,8 @@
<classpathentry kind="lib" path="/thirdparty/jbossas/core-libs/lib/jboss-common.jar"/>
<classpathentry kind="lib" path="/thirdparty/sun-servlet/lib/servlet-api.jar"/>
<classpathentry kind="lib" path="/thirdparty/junit/lib/junit.jar"/>
- <classpathentry combineaccessrules="false" kind="src" path="/identity"/>
<classpathentry kind="lib" path="/thirdparty/jbpm/jaronly/lib/jbpm.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/identity/lib/portal-identity-lib.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Modified: branches/JBoss_Portal_Branch_2_6/wsrp/.classpath
===================================================================
--- branches/JBoss_Portal_Branch_2_6/wsrp/.classpath 2007-08-27 23:21:44 UTC (rev 8062)
+++ branches/JBoss_Portal_Branch_2_6/wsrp/.classpath 2007-08-28 09:16:47 UTC (rev 8063)
@@ -8,7 +8,6 @@
<classpathentry combineaccessrules="false" kind="src" path="/portlet"/>
<classpathentry kind="lib" path="/thirdparty/oswego-concurrent/lib/concurrent.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
- <classpathentry combineaccessrules="false" kind="src" path="/test"/>
<classpathentry kind="lib" path="/thirdparty/apache-httpclient/lib/commons-httpclient.jar"/>
<classpathentry kind="lib" path="/thirdparty/apache-log4j/lib/log4j.jar"/>
<classpathentry kind="lib" path="/thirdparty/jbossas/core-libs/lib/jboss.jar"/>
@@ -31,5 +30,7 @@
<classpathentry kind="lib" path="/thirdparty/apache-myfaces/lib/myfaces-api.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar"/>
<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/web/lib/portal-web-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/test/lib/portal-test-lib.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-portal-lib.jar"/>
<classpathentry kind="output" path="output/classes"/>
</classpath>
16 years, 9 months