PageItemPropertyClickListener.java

  1. /*
  2.  * Copyright 2010-2025 James Pether Sörling
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *   http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  *
  16.  *  $Id$
  17.  *  $HeadURL$
  18. */
  19. package com.hack23.cia.web.impl.ui.application.views.pageclicklistener;

  20. import java.io.Serializable;
  21. import java.lang.reflect.InvocationTargetException;
  22. import java.util.Locale;

  23. import org.apache.commons.beanutils.BeanUtils;
  24. import org.slf4j.Logger;
  25. import org.slf4j.LoggerFactory;

  26. /**
  27.  * The Class PageItemPropertyClickListener.
  28.  *
  29.  * @see PageItemPropertyClickEvent
  30.  */
  31. public final class PageItemPropertyClickListener extends AbstractPageItemRendererClickListener<Serializable> {

  32.     /** The Constant ERROR_GETTING_PAGE_ID. */
  33.     private static final String ERROR_GETTING_PAGE_ID = "ErrorGettingPageId";

  34.     /** The Constant LOG_MSG_PROBLEM_GETTING_PROPERTY_FROM_OBJECT_EXCEPTION. */
  35.     private static final String LOG_MSG_PROBLEM_GETTING_PROPERTY_FROM_OBJECT_EXCEPTION = "Problem getting property {} from object {} exception {}";

  36.     /** The Constant LOGGER. */
  37.     private static final Logger LOGGER = LoggerFactory
  38.             .getLogger(PageItemPropertyClickListener.class);

  39.     /** The Constant serialVersionUID. */
  40.     private static final long serialVersionUID = 1L;


  41.     /** The property. */
  42.     private final String property;

  43.     /** The lower case. */
  44.     private boolean lowerCase = false;

  45.     /**
  46.      * Instantiates a new page item property click listener.
  47.      *
  48.      * @param page
  49.      *            the page
  50.      * @param property
  51.      *            the property
  52.      */
  53.     public PageItemPropertyClickListener(final String page, final String property) {
  54.         super(page);
  55.         this.property = property;
  56.     }

  57.     /**
  58.      * Instantiates a new page item property click listener.
  59.      *
  60.      * @param page the page
  61.      * @param property the property
  62.      * @param lowerCase the lower case
  63.      */
  64.     public PageItemPropertyClickListener(final String page, final String property, final boolean lowerCase) {
  65.         super(page);
  66.         this.property = property;
  67.         this.lowerCase = lowerCase;
  68.     }

  69.     @Override
  70.     protected String getPageId(final Serializable t) {
  71.         try {
  72.             if (lowerCase) {
  73.                 return BeanUtils.getProperty(t, property).toLowerCase(Locale.ENGLISH);
  74.             } else {
  75.                 return BeanUtils.getProperty(t, property);
  76.             }
  77.         } catch (IllegalAccessException | InvocationTargetException |
  78.                 NoSuchMethodException e) {
  79.             LOGGER.warn(LOG_MSG_PROBLEM_GETTING_PROPERTY_FROM_OBJECT_EXCEPTION,property,t,e);
  80.             return ERROR_GETTING_PAGE_ID;
  81.         }
  82.     }

  83. }