All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opencms.db.CmsUserTrackingResourceHandler Maven / Gradle / Ivy

Go to download

OpenCms is an enterprise-ready, easy to use website content management system based on Java and XML technology. Offering a complete set of features, OpenCms helps content managers worldwide to create and maintain beautiful websites fast and efficiently.

There is a newer version: 17.0
Show newest version
/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
 *
 * This library 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 library 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.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.db;

import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.I_CmsResourceInit;
import org.opencms.main.OpenCms;
import org.opencms.util.CmsStringUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;

/**
 * This resource handler checks if a resource has to be marked as visited by the current user.
 * It checks the value of the usertracking.mark property.

* * Possible values are: *

    *
  • online: The resource is marked only in the online project *
  • true: The resource is marked in all projects *
  • false: The resource is not marked at all *
* * @since 8.0 */ public class CmsUserTrackingResourceHandler implements I_CmsResourceInit { /** Property that indicates if resources should be tracked, * value has to be true, false or online. */ public static final String PROPERTY_USERTRACKING_MARK = "usertracking.mark"; /** Constant for the property value online. */ public static final String VALUE_ONLINE = "online"; /** The log object for this class. */ private static final Log LOG = CmsLog.getLog(CmsUserTrackingResourceHandler.class); /** * @see org.opencms.main.I_CmsResourceInit#initResource(org.opencms.file.CmsResource, org.opencms.file.CmsObject, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ public CmsResource initResource( CmsResource resource, CmsObject cms, HttpServletRequest req, HttpServletResponse res) { if ((resource != null) && resource.isFile()) { // only do something if the resource was found and is a file (that can be marked) String mark = ""; try { // read the property value mark = cms.readPropertyObject(resource, PROPERTY_USERTRACKING_MARK, true).getValue(CmsStringUtil.FALSE); } catch (CmsException e) { // ignore, resource will not be marked at all } if (Boolean.valueOf(mark).booleanValue() || (VALUE_ONLINE.equalsIgnoreCase(mark) && cms.getRequestContext().getCurrentProject().isOnlineProject())) { // mark the resource as visited by the current user try { OpenCms.getSubscriptionManager().markResourceAsVisitedBy( cms, resource, cms.getRequestContext().getCurrentUser()); } catch (CmsException e) { // error marking resource LOG.error(e); } } } return resource; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy