`
花花人
  • 浏览: 68228 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

com.liferay.util.ParamUtil.java

阅读更多

/**
 * Copyright (c) 2000-2005 Liferay, LLC. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.liferay.util;

import java.text.DateFormat;

import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;

import javax.servlet.ServletRequest;

/**
 * <a href="ParamUtil.java.html"><b><i>View Source</i></b></a>
 *
 * @author  Brian Wing Shun Chan
 * @version $Revision: 1.9 $
 *
 */
public class ParamUtil {

 // Servlet Request

 public static boolean getBoolean(ServletRequest req, String param) {
  return GetterUtil.getBoolean(req.getParameter(param));
 }

 public static boolean getBoolean(
  ServletRequest req, String param, boolean defaultValue) {

  return get(req, param, defaultValue);
 }

 public static Date getDate(
  ServletRequest req, String param, DateFormat df) {

  return GetterUtil.getDate(req.getParameter(param), df);
 }

 public static Date getDate(
  ServletRequest req, String param, DateFormat df, Date defaultValue) {

  return get(req, param, df, defaultValue);
 }

 public static double getDouble(ServletRequest req, String param) {
  return GetterUtil.getDouble(req.getParameter(param));
 }

 public static double getDouble(
  ServletRequest req, String param, double defaultValue) {

  return get(req, param, defaultValue);
 }

 public static float getFloat(ServletRequest req, String param) {
  return GetterUtil.getFloat(req.getParameter(param));
 }

 public static float getFloat(
  ServletRequest req, String param, float defaultValue) {

  return get(req, param, defaultValue);
 }

 public static int getInteger(ServletRequest req, String param) {
  return GetterUtil.getInteger(req.getParameter(param));
 }

 public static int getInteger(
  ServletRequest req, String param, int defaultValue) {

  return get(req, param, defaultValue);
 }

  public static List getIntegers(ServletRequest req, String param) {
    String[] strings = req.getParameterValues(param);
    List values = new ArrayList();
    if(strings != null) {
      for(int i=0; i<strings.length; i++) {
        try {
          int value = Integer.parseInt(strings[i]);
          values.add(new Integer(value));
        } catch(Exception e) {
        }
      }
    }
    return values;
  }

 public static long getLong(ServletRequest req, String param) {
  return GetterUtil.getLong(req.getParameter(param));
 }

 public static long getLong(
  ServletRequest req, String param, long defaultValue) {

  return get(req, param, defaultValue);
 }

 public static short getShort(ServletRequest req, String param) {
  return GetterUtil.getShort(req.getParameter(param));
 }

 public static short getShort(
  ServletRequest req, String param, short defaultValue) {

  return get(req, param, defaultValue);
 }

 public static String getString(ServletRequest req, String param) {
  return GetterUtil.getString(req.getParameter(param));
 }

 public static String getString(
  ServletRequest req, String param, String defaultValue) {

  return get(req, param, defaultValue);
 }

 public static boolean get(
  ServletRequest req, String param, boolean defaultValue) {

  return GetterUtil.get(req.getParameter(param), defaultValue);
 }

 public static Date get(
  ServletRequest req, String param, DateFormat df, Date defaultValue) {

  return GetterUtil.get(req.getParameter(param), df, defaultValue);
 }

 public static double get(
  ServletRequest req, String param, double defaultValue) {

  return GetterUtil.get(req.getParameter(param), defaultValue);
 }

 public static float get(
  ServletRequest req, String param, float defaultValue) {

  return GetterUtil.get(req.getParameter(param), defaultValue);
 }

 public static int get(ServletRequest req, String param, int defaultValue) {
  return GetterUtil.get(req.getParameter(param), defaultValue);
 }

 public static long get(
  ServletRequest req, String param, long defaultValue) {

  return GetterUtil.get(req.getParameter(param), defaultValue);
 }

 public static short get(
  ServletRequest req, String param, short defaultValue) {

  return GetterUtil.get(req.getParameter(param), defaultValue);
 }

 public static String get(
  ServletRequest req, String param, String defaultValue) {

  String returnValue =
   GetterUtil.get(req.getParameter(param), defaultValue);

  if (returnValue != null) {
   return returnValue.trim();
  }

  return null;
 }

 public static void print(ServletRequest req) {
  Enumeration e = req.getParameterNames();

  while (e.hasMoreElements()) {
   String param = (String)e.nextElement();

   String[] values = req.getParameterValues(param);

   for (int i = 0; i < values.length; i++) {
    System.out.println(param + "[" + i + "] = " + values[i]);
   }
  }
 }

}

分享到:
评论

相关推荐

    liferay7.0 com.liferay.blade.cli

    Liferay7.0 通过JPM安装Blade CLi时[ZipFile.open] error in opening zip file ,将此包下载至本地,执行安装命令可解决:http://blog.csdn.net/u012551585/article/details/54346457

    liferay环境搭建.doc

    如果你想让JAR包在部署后直接出现在Liferay的Tomcat目录下,可以修改工作区的`gradle.properties`文件,添加属性`liferay.workspace.home.dir`指向Liferay安装目录。 2. **Service Builder使用** - 创建一个新的...

    liferay-portal-service.jar

    import com.liferay.portal.kernel.util.StringBundler; StringBundler jsonStr1 = new StringBundler(150); 操作如StringBuilder,相同

    Packtpub.Liferay.User.Interface.Development.Nov.2010.rar

    标题 "Packtpub.Liferay.User.Interface.Development.Nov.2010.rar" 暗示这是一款关于Liferay用户界面开发的电子书资源,由Packt Publishing在2010年11月出版。Liferay是一种开源的企业级门户平台,广泛用于构建企业...

    org.jdom2-2.0.6.LIFERAY-PATCHED-1.jar

    org.jdom2-2.0.6.LIFERAY-PATCHED-1.jar

    Packtpub.Liferay.Portal.6.Enterprise.Intranets.May.2010.rar

    《Packtpub.Liferay.Portal.6.Enterprise.Intranets.May.2010》这本书聚焦于Liferay Portal 6版本在构建企业级内网解决方案中的应用。Liferay Portal是一款开源的企业级门户平台,广泛用于创建、管理和整合数字体验...

    简单SpringMVC环境搭建项目代码

    1. **Java环境**:首先确保你已经安装了Java Development Kit (JDK),并且设置了正确的`JAVA_HOME`环境变量。 2. **构建工具**:推荐使用Maven或Gradle来管理项目依赖。这里我们以Maven为例,确保已安装Maven并配置...

    Packt.Publishing.Liferay.Portal.Enterprise.Intranets

    本书《Packt.Publishing.Liferay.Portal.Enterprise.Intranets》由Packt Publishing出版,作者为Jonas X. Yuan,主要介绍了如何利用Liferay Portal搭建企业内部网络。该书不仅提供了理论基础,还包含了大量实用案例...

    liferay portlet

    开发Liferay Portlet时,可以选择继承Liferay提供的基类,如com.liferay.portlet.LiferayPortlet,或者直接继承JSR标准的javax.portlet.GenericPortlet。 在部署Liferay应用到一个新的Tomcat服务器时,需要注意一些...

    com.liferay.tools

    总结起来,"com.liferay.tools" 是一个基于 OSGi enRoute 和 BNDTools 的 Java 开发模板,专为想要使用 Liferay 工具的开发者设计。这个项目简化了 OSGi 开发的初始阶段,提供了一个易于理解的起点,帮助开发者快速...

    Liferay in action

    Liferay is a different portal. 10分下载的, 打包5折提供下载. Part 1 Introduction to Liferay 1. Liferay is a different portal 2. Getting started with the Liferay development platform Part 2 Adding ...

    liferay6.2.1新版sdk依赖jar

    这些 JAR 文件涵盖了从基本的 Java EE 规范(如 Servlet、JSP 和 JSTL)到 Liferay Portal 的特定组件(如服务层、模型层、视图层等)。通过使用这些 JAR 文件,开发者可以快速地访问和集成 Liferay 的核心功能,如...

    Liferay Portal performance

    ### Liferay Portal 性能分析 #### 执行摘要 Liferay Portal 被 Gartner 命名为领导者,在 Gartner 魔力象限 (MQ) 中因其功能完整性和投资回报率而受到认可,它是领先的开源企业门户解决方案。Liferay Portal 企业...

    Liferay7.0自定义登录实例

    你可以使用`com.liferay.portal.security.auth.AuthTokenUtil`和`com.liferay.portal.security.login.util.LoginUtil`类来处理登录尝试。通过调用`AuthTokenUtil.createAuthToken`生成令牌,然后使用`LoginUtil....

    Liferay应用安全配置手册

    - **数据库驱动**:mysql-connector-java-5.1.6-bin.jar作为JDBC驱动,用于Java应用程序与MySQL数据库之间的通信。 - **中文语言包**:IDM_7-1_L10n_zh.zip用于支持中文界面,体现了国际化的需求。 - **策略代理**:...

    liferay入门经典(英文版)

    2. Liferay的架构:深入探讨Liferay的技术架构,包括它是如何利用各种Java技术和框架,如Spring、Hibernate、OSGi等来构建一个灵活、可扩展的平台。 3. Liferay开发环境搭建:书籍可能会提供关于如何搭建Liferay...

Global site tag (gtag.js) - Google Analytics