customizesetaction.java
来自「jetspeed源代码」· Java 代码 · 共 1,280 行 · 第 1/4 页
JAVA
1,280 行
if (refProfile.getCountry() != null)
{
if (profile.getCountry().equals(refProfile.getCountry()) == false)
{
// Profile and Ref are different countries
continue;
}
}
}
else
{
if (refProfile.getCountry() != null)
{
// Profile has no country and Ref has a country
continue;
}
}
}
else
{
// Profile and Ref are different languages
continue;
}
}
}
else
{
if (refProfile.getLanguage() != null)
{
// Profile has no Language and Ref has a country
continue;
}
}
if (profile.getPath().equals(refProfile.getPath()) == true)
{
// Do not allow Profile to reference it self
continue;
}
// Only add profiles to list that will be displayed
if (profileCounter >= (start + size))
{
break;
}
if (profileCounter >= start)
{
psmlList.add(refProfile);
}
profileCounter++;
}
// Add Start to context
if (start > 0)
{
context.put("prev", String.valueOf(Math.max(start - size, 0)));
}
// Set end to context
if ((size == psmlList.size()) && (psmlIterator.hasNext()))
{
context.put("next", String.valueOf(start + size));
}
context.put("psml", psmlList.iterator());
}
else // build context for layout mode
{
// nothing specific to do
}
}
public int getSize(VelocityPortlet portlet)
{
int size = 15;
try
{
size = Integer.parseInt(portlet.getPortletConfig()
.getInitParameter("size"));
}
catch (Exception e)
{
logger.debug("CustomizeSetAction: Init param 'size' not parsed");
}
return size;
}
/** Clean up the customization state */
public void doCancel(RunData rundata, Context context)
{
//((JetspeedRunData)rundata).setCustomized(null);
//rundata.setScreenTemplate("Home");
SessionState customizationState = ((JetspeedRunData) rundata).getPageSessionState();
customizationState.setAttribute("customize-mode", "layout");
}
/** Save the general informations for this set */
public void doSave(RunData rundata, Context context)
{
doMetainfo(rundata, context);
doSkin(rundata, context);
doLayout(rundata, context);
doSecurity(rundata, context);
Profile profile = ((JetspeedRunData) rundata).getCustomizedProfile();
try
{
String mtype = rundata.getParameters().getString("mtype");
if (mtype != null)
{
profile.setMediaType(mtype);
}
profile.store();
}
catch (Exception e)
{
logger.error("Exception occured while saving PSML", e);
}
}
/** Save customizations and get out of customization state */
public void doApply(RunData rundata, Context context)
{
doSave(rundata, context);
}
/** Add a new portlets element in the customized set */
public void doAddset(RunData rundata, Context context)
{
PortletSet set = (PortletSet) ((JetspeedRunData) rundata).getCustomized();
String title = rundata.getParameters().getString("title", "My Pane");
if (set != null)
{
Portlets portlets = ((JetspeedRunData) rundata).getCustomizedProfile()
.getDocument()
.getPortletsById(set.getID());
if (portlets != null)
{
Portlets p = new PsmlPortlets();
p.setMetaInfo(new PsmlMetaInfo());
p.getMetaInfo().setTitle(title);
p.setId(JetspeedIdGenerator.getNextPeid());
SecurityReference defaultRef = PortalToolkit.getDefaultSecurityRef(
((JetspeedRunData) rundata).getCustomizedProfile());
if (defaultRef != null)
{
if (logger.isDebugEnabled())
{
logger.debug("CustomizeSetAction: setting default portlet set security to [" + defaultRef.getParent() + "]");
}
p.setSecurityRef(defaultRef);
}
portlets.addPortlets(p);
}
}
SessionState customizationState = ((JetspeedRunData) rundata).getPageSessionState();
customizationState.setAttribute("customize-mode", "layout");
}
public void doPrevious(RunData rundata, Context context) throws Exception
{
int queryStart = rundata.getParameters().getInt("previous", 0);
String mtype = rundata.getParameters().getString("mtype", null);
maintainUserSelections(rundata);
JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
DynamicURI duri = null;
if (mtype == null)
{
duri = link.setTemplate("Customize").addQueryData("start", String.valueOf(queryStart));
}
else
{
duri = link.setTemplate("Customize").
addQueryData("start", String.valueOf(queryStart)).
addQueryData("mtype", mtype);
}
JetspeedLinkFactory.putInstance(link);
rundata.setRedirectURI(duri.toString());
return;
}
public void doNext(RunData rundata, Context context) throws Exception
{
int queryStart = rundata.getParameters().getInt("next", 0);
String mtype = rundata.getParameters().getString("mtype", null);
maintainUserSelections(rundata);
JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
DynamicURI duri = null;
if (mtype == null)
{
duri = link.setTemplate("Customize").addQueryData("start", String.valueOf(queryStart));
}
else
{
duri = link.setTemplate("Customize").
addQueryData("start", String.valueOf(queryStart)).
addQueryData("mtype", mtype);
}
JetspeedLinkFactory.putInstance(link);
rundata.setRedirectURI(duri.toString());
return;
}
protected void maintainUserSelections(RunData rundata) throws Exception
{
int size = rundata.getParameters().getInt("size", 0);
int previous = rundata.getParameters().getInt("previous", -1);
int start = 0;
if (previous >= 0)
{
start = previous + size;
}
String[] pnames = rundata.getParameters().getStrings("pname");
//System.out.println("start = "+start+" size = "+size);
//System.out.println("pnames = "+rundata.getParameters());
Map userSelections = getUserSelections(rundata);
List portlets = (List) PortletSessionState.getAttribute(rundata, PORTLET_LIST, null);
if (portlets != null)
{
int end = Math.min(start + size, portlets.size());
int pnamesIndex = 0;
//Go through all the portlets on this page and figure out which ones have been
//checked and which ones unchecked and accordingly update the userSelectionMap
for (int portletIndex = start; portletIndex < end; portletIndex++)
{
PortletEntry entry = (PortletEntry) portlets.get(portletIndex);
if (pnames != null
&& pnamesIndex < pnames.length
&& pnames[pnamesIndex].equals(entry.getName()))
{
userSelections.put(entry.getName(), entry);
pnamesIndex++;
}
else
{
userSelections.remove(entry.getName());
}
}
PortletSessionState.setAttribute(rundata, USER_SELECTIONS, userSelections);
/*
Iterator it = userSelections.keySet().iterator();
System.out.print("User Selections: ");
while (it.hasNext())
{
System.out.print(", "+it.next());
}
System.out.println("\n");
*/
}
else
{
throw new Exception("Master Portlet List is null!");
}
}
/** Add new portlets in the customized set */
public void doAdd(RunData rundata, Context context) throws Exception
{
/**
* Special handling for wml profiles
* no skins, no properties menuentry, no panes
* --------------------------------------------------------------------------
* last modified: 10/31/01
* Andreas Kempf, Siemens ICM S CP PE, Munich
* mailto: A.Kempf@web.de
*/
//boolean isWML = AutoProfile.doIt (rundata, true).getMediaType().equalsIgnoreCase("wml");
PortletSet set = (PortletSet) ((JetspeedRunData) rundata).getCustomized();
maintainUserSelections(rundata);
Map userSelections = getUserSelections(rundata);
String[] pnames = new String[userSelections.size()];
userSelections.keySet().toArray(pnames);
//String[] pnames = rundata.getParameters().getStrings("pname");
// Create a ClearPortletControl
Control ctrl = new PsmlControl();
ctrl.setName ("ClearPortletControl");
if ((pnames != null) && (set != null))
{
Portlets portlets = ((JetspeedRunData) rundata).getCustomizedProfile()
.getDocument()
.getPortletsById(set.getID());
List usedPortlets = AutoProfile.getPortletList(rundata);
boolean addIt;
int cc;
Entry usedEntry;
for (int i = 0; i < pnames.length; i++)
{
PortletEntry entry = (PortletEntry) Registry.getEntry(Registry.PORTLET, pnames[i]);
// add only new portlets!
if ((entry != null) && (portlets != null))
{
addIt = true;
/*
for (cc=0; cc<usedPortlets.size(); cc++)
{
usedEntry = (Entry) usedPortlets.get(cc);
if (entry.getName().equals(usedEntry.getParent()))
{
addIt = false;
break;
}
}
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?