psmlmanageraction.java
来自「jetspeed源代码」· Java 代码 · 共 1,653 行 · 第 1/5 页
JAVA
1,653 行
/*
* Copyright 2000-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.modules.actions.portlets;
// Jetspeed
import org.apache.commons.lang.SerializationUtils;
import org.apache.jetspeed.om.profile.Profile;
import org.apache.jetspeed.om.profile.QueryLocator;
import org.apache.jetspeed.portal.Portlet;
import org.apache.jetspeed.portal.portlets.browser.DatabaseBrowserIterator;
import org.apache.jetspeed.services.Profiler;
import org.apache.jetspeed.util.PortletConfigState;
import org.apache.jetspeed.util.PortletUtils;
import org.apache.jetspeed.util.PortletSessionState;
import org.apache.jetspeed.services.security.PortalResource;
import org.apache.jetspeed.om.security.JetspeedUser;
import org.apache.jetspeed.services.JetspeedSecurity;
import org.apache.jetspeed.modules.actions.portlets.security.SecurityConstants;
import org.apache.jetspeed.om.profile.ProfileLocator;
import org.apache.jetspeed.om.profile.PSMLDocument;
import org.apache.jetspeed.om.profile.Portlets;
import org.apache.jetspeed.om.registry.Parameter;
import org.apache.jetspeed.om.registry.PortletEntry;
import org.apache.jetspeed.services.Registry;
import org.apache.jetspeed.services.PsmlManager;
import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
import org.apache.jetspeed.services.logging.JetspeedLogger;
import org.apache.jetspeed.util.template.JetspeedLink;
import org.apache.jetspeed.util.template.JetspeedLinkFactory;
import org.apache.jetspeed.services.resources.JetspeedResources;
import org.apache.jetspeed.services.psmlmanager.PsmlManagerService;
import org.apache.jetspeed.om.profile.BasePSMLDocument;
import org.apache.jetspeed.om.security.Role;
import org.apache.jetspeed.om.security.Group;
import org.apache.jetspeed.services.rundata.JetspeedRunData;
// Turbine stuff
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.DynamicURI;
import org.apache.turbine.util.StringUtils;
import org.apache.turbine.util.security.EntityExistsException;
import org.apache.turbine.services.TurbineServices;
import org.apache.turbine.services.servlet.TurbineServlet;
import org.apache.turbine.services.resources.ResourceService;
// Velocity Stuff
import org.apache.velocity.context.Context;
// Java
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.io.File;
import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;
import java.util.StringTokenizer;
// castor support
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.ValidationException;
import org.exolab.castor.mapping.Mapping;
import org.exolab.castor.mapping.MappingException;
import org.xml.sax.InputSource;
// serialization support
import org.apache.xml.serialize.Serializer;
import org.apache.xml.serialize.XMLSerializer;
import org.apache.xml.serialize.OutputFormat;
/**
* This action enables to manage psml entries
* within current user's security context
*
* @author <a href="mailto:morciuch@apache.org">Mark Orciuch</a>
* @version $Id: PsmlManagerAction.java,v 1.7 2004/02/23 02:56:58 jford Exp $
*/
public class PsmlManagerAction extends GenericMVCAction
{
public static final String CACHED_PSML = "PsmlManagerAction.cached.psml";
protected static final String PSML_REFRESH_FLAG = "psmlRefreshFlag";
protected static final String TRUE = "true";
protected static final String FALSE = "false";
protected static final String PROFILE_ITERATOR = "profileIterator";
protected static final String LAST_SEARCH_TYPE = "lastSearchType";
protected static final String LAST_SEARCH_VALUE = "lastSearchValue";
protected static final String PAGE_SIZE = "page-size";
protected static final String DEFAULT_SEARCH = "default-search";
protected static final String CUSTOMIZE_TEMPLATE = "customize-template";
private static final String PEID = "js_peid";
/** name of the parameter that holds the filter value */
public static final String FILTER_VALUE = "filter_value";
/** name of the parameter that holds the regexp flag */
public static final String FILTER_REGEXP = "filter_regexp";
/** name of the parameter that holds the filter type */
public static final String FILTER_TYPE = "filter_type";
/** value of the filter type parameter for searching by username */
public static final String FILTER_TYPE_USER = "filter_type_user";
/** value of the filter type parameter for searching by role */
public static final String FILTER_TYPE_ROLE = "filter_type_role";
/** value of the filter type parameter for searching by group */
public static final String FILTER_TYPE_GROUP = "filter_type_group";
private static Hashtable queryModes = new Hashtable();
static
{
queryModes.put("All", String.valueOf(QueryLocator.QUERY_ALL));
queryModes.put("User", String.valueOf(QueryLocator.QUERY_USER));
queryModes.put("Role", String.valueOf(QueryLocator.QUERY_ROLE));
queryModes.put("Group", String.valueOf(QueryLocator.QUERY_GROUP));
}
protected static final String CATEGORY_NAME = "categoryName";
protected static final String CATEGORY_VALUE = "categoryValue";
protected static final String COPY_FROM = "copyFrom";
protected static final String COPY_TO = "copyTo";
protected static final String TEMP_LOCATOR = "tempLocator";
protected static final String PSML_UPDATE_PANE = "PsmlForm";
/**
* Static initialization of the logger for this class
*/
private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(PsmlManagerAction.class.getName());
/**
* Subclasses should override this method if they wish to
* provide their own customization behavior.
* Default is to use Portal base customizer action
*/
protected void buildConfigureContext(Portlet portlet,
Context context,
RunData rundata)
{
try
{
super.buildConfigureContext(portlet, context, rundata);
}
catch (Exception ex)
{
logger.error("Exception", ex);
}
context.put(PAGE_SIZE, PortletConfigState.getParameter(portlet, rundata, PAGE_SIZE, "20"));
setTemplate(rundata, PortletConfigState.getParameter(portlet, rundata, CUSTOMIZE_TEMPLATE, null));
}
/**
* Subclasses must override this method to provide default behavior
* for the portlet action
*
* @param portlet
* @param context
* @param rundata
*/
protected void buildNormalContext(Portlet portlet, Context context, RunData rundata)
{
PortletEntry entry = (PortletEntry) Registry.getEntry(Registry.PORTLET, portlet.getName());
context.put("can-search", canPerformAction(rundata, entry, entry.getParameter("can-search")));
context.put("can-clone", canPerformAction(rundata, entry, entry.getParameter("can-clone")));
context.put("can-import", canPerformAction(rundata, entry, entry.getParameter("can-import")));
context.put("can-export", canPerformAction(rundata, entry, entry.getParameter("can-export")));
context.put("can-import-all", canPerformAction(rundata, entry, entry.getParameter("can-import-all")));
context.put("can-export-all", canPerformAction(rundata, entry, entry.getParameter("can-export-all")));
context.put("can-add", canPerformAction(rundata, entry, entry.getParameter("can-add")));
context.put("can-remove", canPerformAction(rundata, entry, entry.getParameter("can-remove")));
String mode = rundata.getParameters().getString("mode", "browse");
if (mode.equals("browse"))
{
this.setTemplate(rundata, PortletConfigState.getParameter(portlet, rundata, "template", "browser-psml"));
buildBrowseNormalContext(portlet, context, rundata);
}
else
{
this.setTemplate(rundata, PortletConfigState.getParameter(portlet, rundata, "detail-template", "psml-form"));
buildDetailNormalContext(portlet, context, rundata);
}
}
/**
* Performs building of normal context for browsing mode
*
* @param portlet
* @param context
* @param rundata
*/
private void buildBrowseNormalContext(Portlet portlet, Context context, RunData rundata)
{
context.put("queryModes", queryModes);
int start = rundata.getParameters().getInt("start", 0);
if (start < 0)
{
start = 0;
}
String pageSize = PortletConfigState.getParameter(portlet, rundata, PAGE_SIZE, "20");
int size = Integer.parseInt(pageSize);
int next = start + size + 1;
int prev = start - size - 1;
//System.out.println("start="+start+" size="+size+" next="+next+" prev="+prev);
//check to see if resultset has changed due to PsmlUpdateAction
//if so reconstruct the iterator and reset the flag
boolean refreshFlag = getRefreshPsmlFlag(rundata);
// By default, only return psml pages for the current user
String defaultSearch = PortletConfigState.getParameter(portlet, rundata, DEFAULT_SEARCH, "true");
//Get the iterator
DatabaseBrowserIterator windowIterator =
(DatabaseBrowserIterator) PortletSessionState.getAttribute(portlet, rundata, PROFILE_ITERATOR);
if (refreshFlag)
{
setRefreshPsmlFlag(rundata, FALSE);
PortletSessionState.clearAttribute(portlet, rundata, PROFILE_ITERATOR);
// Use last used search value to refresh
Integer type = (Integer) PortletSessionState.getAttribute(portlet, rundata, LAST_SEARCH_TYPE);
String value = (String) PortletSessionState.getAttribute(portlet, rundata, LAST_SEARCH_VALUE);
if (type != null && value != null)
{
windowIterator = performSearch(rundata, portlet, type.intValue(), value);
}
}
else if (windowIterator != null)
{
windowIterator.setTop(start);
}
else if (defaultSearch != null && defaultSearch.equals("true"))
{
windowIterator = performSearch(rundata, portlet, QueryLocator.QUERY_USER, rundata.getUser().getUserName());
}
if (windowIterator != null)
{
context.put("psml", windowIterator);
if (start > 0)
{
context.put("prev", String.valueOf(prev + 1));
}
if (next <= windowIterator.getResultSetSize())
{
context.put("next", String.valueOf(next - 1));
}
}
}
/**
* Returns true if current user can peform specific profile action
*
* @param data
* @param profile
* @return
*/
private String canPerformAction(RunData rundata, PortletEntry entry, Parameter actionParam)
{
String result = "true";
if (actionParam != null && entry != null)
{
PortalResource portalResource = new PortalResource(entry, actionParam);
result = new Boolean(JetspeedSecurity.checkPermission((JetspeedUser) rundata.getUser(),
portalResource,
JetspeedSecurity.PERMISSION_CUSTOMIZE)).toString();
//System.out.println("parameter=" + actionParam.getName() + ", canAccess = " + result.toString());
}
return result;
}
/**
* This method is called when the user configures any of the parameters.
*
* @param rundata
* @param context The velocity context for this request.
*/
public void doUpdate(RunData rundata, Context context)
{
String pageSize = null;
Portlet portlet = (Portlet) context.get("portlet");
if (portlet != null)
{
String peid = portlet.getID();
if ((peid != null)
&& peid.equals(rundata.getParameters().getString(PEID)))
{
pageSize = rundata.getParameters().getString(PAGE_SIZE);
}
if (pageSize != null)
{
PortletConfigState.setInstanceParameter(portlet, rundata, PAGE_SIZE, pageSize);
PortletSessionState.clearAttribute(portlet, rundata, PROFILE_ITERATOR);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?