psmlmanageraction.java
来自「jetspeed源代码」· Java 代码 · 共 1,653 行 · 第 1/5 页
JAVA
1,653 行
buildNormalContext(portlet, context, rundata);
}
/**
* This method is to refresh psml from disk or database.
*
* @param rundata
* @param context The velocity context for this request.
*/
public void doRefresh(RunData rundata, Context context)
{
Portlet portlet = (Portlet) context.get("portlet");
PortletSessionState.clearAttribute(portlet, rundata, PROFILE_ITERATOR);
PortletSessionState.clearAttribute(portlet, rundata, LAST_SEARCH_TYPE);
PortletSessionState.clearAttribute(portlet, rundata, LAST_SEARCH_VALUE);
rundata.getParameters().remove(FILTER_VALUE);
buildNormalContext(portlet, context, rundata);
}
/**
* This method is to enter filtering mode.
*
* @param rundata
* @param context The velocity context for this request.
*/
public void doFilter(RunData rundata, Context context)
{
// Is filtering requested?
int filterType = rundata.getParameters().getInt(FILTER_TYPE, QueryLocator.QUERY_ALL);
String filterValue = rundata.getParameters().getString(FILTER_VALUE, null);
Portlet portlet = (Portlet) context.get("portlet");
performSearch(rundata, portlet, filterType, filterValue);
buildNormalContext(portlet, context, rundata);
}
/**
*
* @param rundata
* @param portlet
* @param type
* @param value
* @return
*/
private DatabaseBrowserIterator performSearch(RunData rundata, Portlet portlet, int type, String value)
{
// Initialize the query locator
QueryLocator ql = new QueryLocator(type);
if (value != null)
{
switch (type)
{
case QueryLocator.QUERY_USER:
{
try
{
ql.setUser(JetspeedSecurity.getUser(value));
}
catch (Exception e)
{
}
}
case QueryLocator.QUERY_ROLE:
{
try
{
ql.setRole(JetspeedSecurity.getRole(value));
}
catch (Exception e)
{
}
}
case QueryLocator.QUERY_GROUP:
{
try
{
ql.setGroup(JetspeedSecurity.getGroup(value));
}
catch (Exception e)
{
}
}
}
}
//ql.setQueryString(value);
ArrayList entries = new ArrayList();
Iterator i = Profiler.query(ql);
try
{
while (i.hasNext())
{
Profile profile = (Profile) i.next();
if (PortletUtils.canAccessProfile(rundata, profile))
{
entries.add(profile);
}
}
}
catch (Exception e)
{
logger.error("Exception", e);
}
ArrayList entryType = new ArrayList();
entryType.add("Profile");
int size = Integer.parseInt(PortletConfigState.getParameter(portlet, rundata, PAGE_SIZE, "20"));
DatabaseBrowserIterator windowIterator = new DatabaseBrowserIterator(entries, entryType, entryType, size);
PortletSessionState.clearAttribute(portlet, rundata, PROFILE_ITERATOR);
PortletSessionState.setAttribute(portlet, rundata, PROFILE_ITERATOR, windowIterator);
PortletSessionState.setAttribute(portlet, rundata, LAST_SEARCH_TYPE, new Integer(type));
PortletSessionState.setAttribute(portlet, rundata, LAST_SEARCH_VALUE, value);
return windowIterator;
}
/**
* Build the normal state context for detail modes.
*
* @param portlet The template-based portlet that is being built.
* @param context The velocity context for this request.
* @param rundata The turbine rundata context for this request.
*/
private void buildDetailNormalContext(Portlet portlet,
Context context,
RunData rundata)
{
try
{
//
// if there was an error, display the message
//
String msgid = rundata.getParameters().getString(SecurityConstants.PARAM_MSGID);
if (msgid != null)
{
int id = Integer.parseInt(msgid);
if (id < SecurityConstants.MESSAGES.length)
{
context.put(SecurityConstants.PARAM_MSG, SecurityConstants.MESSAGES[id]);
}
// get the bad entered data and put it back for convenient update
ProfileLocator locator = (ProfileLocator) rundata.getUser().getTemp(TEMP_LOCATOR);
if (locator != null)
{
context.put("profile", Profiler.createProfile(locator));
}
}
String mode = rundata.getParameters().getString(SecurityConstants.PARAM_MODE);
context.put(SecurityConstants.PARAM_MODE, mode);
String path = rundata.getParameters().getString(SecurityConstants.PARAM_ENTITY_ID);
if (mode != null && mode.equals(SecurityConstants.PARAM_MODE_DELETE))
{
ProfileLocator locator = Profiler.createLocator();
locator.createFromPath(path);
Profile profile = Profiler.getProfile(locator);
if (profile != null)
{
rundata.getUser().setTemp(TEMP_LOCATOR, locator);
context.put("profile", profile);
}
else
{
logger.error("Profile for Path:" + path + " Not Found!");
}
}
if (mode != null && mode.equals(SecurityConstants.PARAM_MODE_INSERT))
{
org.apache.jetspeed.om.registry.Registry mediaTypes = Registry.get(Registry.MEDIA_TYPE);
context.put("mediaTypes", mediaTypes.listEntryNames());
JetspeedRunData jdata = (JetspeedRunData) rundata;
context.put("defMediaType", jdata.getCapability().getPreferredMediaType());
if (msgid == null)
{
if (((String) context.get("can-clone")).equals("false"))
{
context.put(CATEGORY_NAME, "user");
context.put("categoryValue", rundata.getUser().getUserName());
context.put("copyFrom", "none");
context.put("title", "My Page");
}
else if (path == null)
{
context.put(CATEGORY_NAME, "user");
context.put("categoryValue", "anon");
context.put("copyFrom", "user/anon/media-type/html/page/default.psml");
}
else
{
ProfileLocator tmpLocator = Profiler.createLocator();
tmpLocator.createFromPath(path);
Profile profile = Profiler.getProfile(tmpLocator);
if (profile != null)
{
rundata.getUser().setTemp(TEMP_LOCATOR, tmpLocator);
context.put("profile", profile);
context.put("title", profile.getRootSet().getTitle());
}
String categoryName = "group";
String categoryValue = tmpLocator.getGroupName();
if (categoryValue == null)
{
categoryName = "role";
categoryValue = tmpLocator.getRoleName();
if (categoryValue == null)
{
categoryName = "user";
categoryValue = tmpLocator.getUserName();
if (categoryValue == null)
{
categoryName = "user";
categoryValue = "anon";
}
}
}
context.put(CATEGORY_NAME, categoryName);
context.put("categoryValue", categoryValue);
context.put("copyFrom", path);
}
}
else
{
context.put(CATEGORY_NAME, rundata.getUser().getTemp(CATEGORY_NAME));
context.put(CATEGORY_VALUE, rundata.getUser().getTemp(CATEGORY_VALUE));
context.put(COPY_FROM, rundata.getUser().getTemp(COPY_FROM));
}
}
if (mode != null && mode.equals("export"))
{
if (msgid == null)
{
String tmpPath = JetspeedResources.getString(JetspeedResources.TEMP_DIRECTORY_KEY, "/tmp");
String exportPath = JetspeedResources.getString("psml.export.default.path",
TurbineServlet.getRealPath(tmpPath));
if (path == null)
{
context.put(COPY_TO, exportPath);
context.put(COPY_FROM,
Profiler.PARAM_USER +
File.separator +
Profiler.PARAM_ANON +
File.separator +
Profiler.PARAM_MEDIA_TYPE +
File.separator +
"html" +
File.separator +
Profiler.PARAM_PAGE +
File.separator +
Profiler.FULL_DEFAULT_PROFILE);
}
else
{
ProfileLocator tmpLocator = Profiler.createLocator();
tmpLocator.createFromPath(path);
Profile profile = Profiler.getProfile(tmpLocator);
if (profile != null)
{
rundata.getUser().setTemp(TEMP_LOCATOR, tmpLocator);
context.put("profile", profile);
}
String categoryName = Profiler.PARAM_GROUP;
String categoryValue = tmpLocator.getGroupName();
if (categoryValue == null)
{
categoryName = Profiler.PARAM_ROLE;
categoryValue = tmpLocator.getRoleName();
if (categoryValue == null)
{
categoryName = Profiler.PARAM_USER;
categoryValue = tmpLocator.getUserName();
if (categoryValue == null)
{
categoryName = Profiler.PARAM_USER;
categoryValue = Profiler.PARAM_ANON;
}
}
}
context.put(COPY_TO, exportPath + File.separator + tmpLocator.getName());
context.put(COPY_FROM, path);
}
}
else
{
context.put(COPY_TO, rundata.getUser().getTemp(COPY_TO));
context.put(COPY_FROM, rundata.getUser().getTemp(COPY_FROM));
}
}
if (mode != null && mode.equals("export_all"))
{
if (msgid == null)
{
// get the PSML Root Directory
ResourceService serviceConf = ((TurbineServices) TurbineServices.getInstance())
.getResources(PsmlManagerService.SERVICE_NAME);
String root = serviceConf.getString("root", "/WEB-INF/psml");
context.put(COPY_TO, TurbineServlet.getRealPath(root));
}
else
{
context.put(COPY_TO, rundata.getUser().getTemp(COPY_TO));
}
}
if (mode != null && mode.equals("import"))
{
org.apache.jetspeed.om.registry.Registry mediaTypes = Registry.get(Registry.MEDIA_TYPE);
context.put("mediaTypes", mediaTypes.listEntryNames());
if (msgid == null)
{
// get the PSML Root Directory
ResourceService serviceConf = ((TurbineServices) TurbineServices.getInstance())
.getResources(PsmlManagerService.SERVICE_NAME);
String root = serviceConf.getString("root", "/WEB-INF/psml");
root = TurbineServlet.getRealPath(root);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?