taylor 01/05/07 23:26:12
Added: src/java/org/apache/jetspeed/util/customization
AllowableColumnSet.java AllowablePortletSet.java
CustomizerException.java CustomizerResources.java
ElementNotFoundException.java JetspeedColors.java
PSMLDocument.java PSMLEntry.java
UserNotLoggedInException.java
Log:
adding Glucode customizer for 1.3a2
Revision Changes Path
1.1
jakarta-jetspeed/src/java/org/apache/jetspeed/util/customization/AllowableColumnSet.java
Index: AllowableColumnSet.java
===================================================================
package org.apache.jetspeed.util.customization;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache" or
* "Apache Jetspeed", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
// Java
import java.util.*;
// Required Turbine classes
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.Log;
/**
* This class represents all the allowable layout columns for a given user.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Van Truong </a>
* @author <a href="mailto:[EMAIL PROTECTED]">Ernest Ros </a>
* @version $Id: AllowableColumnSet.java,v 1.1 2001/05/08 06:26:09 taylor Exp $
*
*/
public class AllowableColumnSet
{
// Allowable Columns
private final int maxAllowableColumn = 3;
// Column Attributes
public static final int HEADINGCOLOR = 0;
public static final int BACKGROUNDCOLOR = 1;
private String[] defaultHeadingColors = null;
private String[] defaultBackgroundColors = null;
private String[] columnDescription = null;
// User Atributes
private RunData data = null;
public AllowableColumnSet(RunData data) throws Exception
{
this.data = data;
refresh();
} //end AllowablePortletSet
/**
*Refreshes the attributes of the object.
*
*/
public void refresh() throws CustomizerException,
java.io.FileNotFoundException,
UserNotLoggedInException,
ElementNotFoundException
{
PSMLDocument psmlDoc = new PSMLDocument(data);
defaultHeadingColors = new String[maxAllowableColumn];
defaultBackgroundColors = new String[maxAllowableColumn];
columnDescription = new String[]{"Left Column", "Middle Column", "Right
Column"};
for (int i=0; i<maxAllowableColumn; i++)
{
defaultHeadingColors[i] = psmlDoc.getTitleColor(new int[]{i});
defaultBackgroundColors[i] = psmlDoc.getBackgroundColor(new int[]{i});
}
} //end refresh
/**
* Set the color for the column.
*
* @param column int representing column number.
* @param columnAttr int representing the column's attribute, such as
* AllowableColumnSet.HEADINGCOLOR or AllowableColumnSet.BACKGROUNDCOLOR.
*
* @throws Exception if the column or the column's attribute is invalid.
*/
public void setColor(int column, int columnAttr, String color) throws
ArrayIndexOutOfBoundsException,
CustomizerException
{
switch (columnAttr)
{
case HEADINGCOLOR:
{
defaultHeadingColors[column] = color;
break;
}
case BACKGROUNDCOLOR:
{
defaultBackgroundColors[column] = color;
break;
}
default:
{
throw new CustomizerException("The column attribute is invalid.");
}
} //end switch
} //end setColor
/**
* Get the color for the column.
*
* @param column int representing column number.
* @param columnAttr int representing the column's attribute, such as
* AllowableColumnSet.HEADINGCOLOR or
AllowableColumnSet.BACKGROUNDCOLOR.
* @return String The hexidecimal value of this color.
* @throws Exception if the column or the column's attribute is invalid.
*/
public String getColor(int column, int columnAttr) throws
ArrayIndexOutOfBoundsException,
CustomizerException
{
switch (columnAttr)
{
case HEADINGCOLOR:
{
return defaultHeadingColors[column];
}
case BACKGROUNDCOLOR:
{
return defaultBackgroundColors[column];
}
default:
{
throw new CustomizerException("The column attribute is invalid.");
}
} //end switch
} //end getColor
/**
* Get the column description.
*
* @param column int representing column number.
* @return String Description of this column.
* @throws Exception if the column is invalid.
*/
public String getColumnDescription(int column) throws
ArrayIndexOutOfBoundsException
{
return columnDescription[column];
} //end getColor
/**
* Return the maximum columns allowed for the user's layout.
*
* @return int Maximum columns allowed.
*/
public int getMaximumNumOfColumnAllowed()
{
return maxAllowableColumn;
} //end getMaximumNumOfColumnAllowed
} //end class AllowableColumnSet
1.1
jakarta-jetspeed/src/java/org/apache/jetspeed/util/customization/AllowablePortletSet.java
Index: AllowablePortletSet.java
===================================================================
package org.apache.jetspeed.util.customization;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache" or
* "Apache Jetspeed", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
// Java
import java.util.*;
// Required Turbine classes
import org.apache.turbine.util.RunData;
import org.apache.turbine.util.Log;
// Jetspeed
import org.apache.jetspeed.services.resources.JetspeedResources;
import org.apache.jetspeed.cache.disk.*;
import org.apache.jetspeed.util.*;
import org.apache.jetspeed.xml.api.jetspeedconfig.JetspeedConfig;
import org.apache.jetspeed.om.registry.EntryFactory;
import org.apache.jetspeed.om.registry.peer.PortletEntry;
/**
* This class represents all the allowable portlets for a given user, including
those that
* are within the user's psml file and those that are mandatory for this user.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Van Truong </a>
* @author <a href="mailto:[EMAIL PROTECTED]">Ernest Ros </a>
* @version $Id: AllowablePortletSet.java,v 1.1 2001/05/08 06:26:10 taylor Exp $
*
*/
public class AllowablePortletSet
{
private Hashtable portletEntry = new Hashtable(); // PortletEntryWrapper
private RunData data = null; // User data
public AllowablePortletSet(RunData data) throws ElementNotFoundException,
CustomizerException,
Exception
{
this.data = data;
refresh();
} //end AllowablePortletSet
/**
* Return a PortletEntry when given a portlet name.
*
* @param name The name of the PortletEntry.
* @return PortletEntry if the given name is mapped to an existing PortletEntry,
else null.
* @throws ElementNotFoundException if the portlet does not exist in this
allowable set.
*/
public PortletEntry getPortletEntry(String name) throws ElementNotFoundException
{
PortletEntryWrapper pw = (PortletEntryWrapper)portletEntry.get(name);
if (pw == null)
{
Log.error("The portlet name, " + name + ", is not within user "
+ data.getUser().getUserName() + "'s allowable portlet set.");
throw new ElementNotFoundException("The portlet name, " + name + ", is
not within user "
+ data.getUser().getUserName()
+ "'s allowable portlet set.");
}
return pw.getPortletEntry();
} //end getPortletEntry
/**
* Reset all the user's default portlet to only include the mandatory ones.
*
*/
public void resetAllUserDefaultPortlets()
{
Enumeration elements = portletEntry.elements();
while (elements.hasMoreElements())
{
PortletEntryWrapper pw = (PortletEntryWrapper)elements.nextElement();
pw.setAsUserDefaultPortlet(pw.isMandatoryPortlet());
}
} //resetAllUserDefaultPortlets
/**
* Set the give portlet name as a the user's default portlet.
*
* @param name The name of a portlet.
* @throws ElementNotFoundException if the portlet does not exist in this
allowable set.
*/
public void setPortletAsUserDefault(String name) throws ElementNotFoundException
{
try
{
PortletEntryWrapper pw = (PortletEntryWrapper)portletEntry.get(name);
pw.setAsUserDefaultPortlet(true);
}
catch (NullPointerException n)
{
Log.error("The portlet name, " + name + ", is not within user "
+ data.getUser().getUserName() + "'s allowable portlet set.");
throw new ElementNotFoundException("The portlet name, " + name
+ ", is not within user "
+ data.getUser().getUserName()
+ "'s allowable portlet set.");
}
} //end setPortletAsUserDefault
/**
* Given the portlet name, if it is the user default portlet, returns its
position within a column.
*
* @param The name of the portlet.
* @return An int representing the position of this portlet.
* @throws ElementNotFoundException if the portlet does not exist in this
allowable set or
* CustimizerException if the portlet is not register to the user.
*/
public int getUserDefaultPortletPosition(String name) throws
ElementNotFoundException, CustomizerException
{
try
{
PortletEntryWrapper pw = (PortletEntryWrapper)portletEntry.get(name);
if (!pw.isUserDefaultPortlet())
{
Log.error("The portlet name, " + name + ", is currently not
registered to user "
+ data.getUser().getUserName() + ".");
throw new CustomizerException("The portlet name, " + name
+ ", is currently not registered to
user "
+ data.getUser().getUserName() + ".");
}
return pw.getPortletPosition();
}
catch (NullPointerException n)
{
Log.error("The portlet name, " + name + ", is not within user "
+ data.getUser().getUserName() + "'s allowable portlet set.");
throw new ElementNotFoundException("The portlet name, " + name
+ ", is not within user "
+ data.getUser().getUserName()
+ "'s allowable portlet set.");
}
} //end getUserDefaultPortletPosition
/**
* Given the portlet name, if it is the user default portlet, returns its column.
*
* @param The name of the portlet.
* @return An int representing the column of this portlet.
* @throws ElementNotFoundException if the portlet does not exist in this
allowable set or
* CustimizerException if the portlet is not register to the user.
*/
public int getUserDefaultPortletColumn(String name) throws
ElementNotFoundException, CustomizerException
{
try
{
PortletEntryWrapper pw = (PortletEntryWrapper)portletEntry.get(name);
if (!pw.isUserDefaultPortlet())
{
Log.error("The portlet name, " + name + ", is currently not
registered to user "
+ data.getUser().getUserName() + ".");
throw new CustomizerException("The portlet name, " + name
+ ", is currently not registered to
user "
+ data.getUser().getUserName() + ".");
}
return pw.getPortletColumn();
}
catch (NullPointerException n)
{
Log.error("The portlet name, " + name + ", is not within user "
+ data.getUser().getUserName() + "'s allowable portlet set.");
throw new ElementNotFoundException("The portlet name, " + name
+ ", is not within user "
+ data.getUser().getUserName()
+ "'s allowable portlet set.");
}
} //end getUserDefaultPortletColumn
/**
*Return the names of portlets that the user selected as his/her set of default
portlets.
*
*@return String[] of portlet names.
*/
public String[] getUserDefaultPortletNames()
{
Enumeration elements = portletEntry.elements();
LinkedList list = new LinkedList();
while (elements.hasMoreElements())
{
PortletEntryWrapper pw = (PortletEntryWrapper)elements.nextElement();
if (pw.isUserDefaultPortlet())
{
list.add(pw.getPortletEntry().getName());
}
} //end while
if (list.size() == 0)
{
return new String[0];
}
else
{
String[] portlets = new String[list.size()];
for (int i=0; i<list.size(); i++)
{
portlets[i] = (String)list.get(i);
}
return portlets;
} //end if-else
} //getUserDefaultPortletNames
/**
* Return the description for the portlet with the given name.
*
* @return String description of the portlet.
* @throws ElementNotFoundException if the portlet does not exist in this
allowable set.
*/
public String getPortletDescription(String name) throws ElementNotFoundException
{
try
{
PortletEntryWrapper pw = (PortletEntryWrapper)portletEntry.get(name);
return pw.getPortletEntry().getMetaInfo().getDescription();
}
catch (NullPointerException n)
{
Log.error("The portlet name, " + name + ", is not within user "
+ data.getUser().getUserName() + "'s allowable portlet set.");
throw new ElementNotFoundException("The portlet name, " + name
+ ", is not within user "
+ data.getUser().getUserName()
+ "'s allowable portlet set.");
}
} //end getPortletDescription
/**
* Return the title for the portlet with the given name.
*
* @return String title of the portlet.
* @throws ElementNotFoundException if the portlet does not exist in this
allowable set.
*/
public String getPortletTitle(String name) throws ElementNotFoundException
{
try
{
PortletEntryWrapper pw = (PortletEntryWrapper)portletEntry.get(name);
String title = pw.getPortletEntry().getMetaInfo().getTitle();
if (title == null || title.trim().equals(""))
{
return name;
}
return title;
}
catch (NullPointerException n)
{
Log.error("The portlet name, " + name + ", is not within user "
+ data.getUser().getUserName() + "'s allowable portlet set.");
throw new ElementNotFoundException("The portlet name, " + name
+ ", is not within user "
+ data.getUser().getUserName()
+ "'s allowable portlet set.");
}
} //end getPortletTitle
/**
* Get the allowable portlet set from the config file and store the entries in
* this object's hashtable.
*
* @throws ElementNotFoundException if no entry are found or CustomizerException
if any other exceptions occur.
*/
private void loadPortletEntryFromJetspeedConfigFile() throws
ElementNotFoundException, CustomizerException
{
try
{
// Read from the Jetspeed config file
// FIXME: this needs to be converted over to the new Registry interface
String url =
JetspeedResources.getString("services.RegistryManager.url");
DiskCacheEntry pde = JetspeedDiskCache.getInstance().getEntry(url);
JetspeedConfig jetspeedConfig =
JetspeedConfig.unmarshal(pde.getReader());
// Get the PortletEntry
org.apache.jetspeed.xml.api.jetspeedconfig.PortletEntry[] xml_pe =
jetspeedConfig.getPortletRegistry().getPortletEntry();
for (int i=0; i<xml_pe.length; i++)
{
PortletEntry reg_pe = EntryFactory.getEntry(xml_pe[i]);
if (!reg_pe.getType().equals(PortletEntry.TYPE_ABSTRACT) &&
!reg_pe.getType().equals(PortletEntry.TYPE_UNKNOWN))
{
portletEntry.put(reg_pe.getName(), new
PortletEntryWrapper(reg_pe));
}
} //end for
}
catch (NullPointerException n)
{
// This might occur when xml_pe is null or xml_pe[i] is null
Log.error("Error, unable to retrieve PortletEntry from the Jetspeed
config file.");
throw new ElementNotFoundException("Error, unable to retrieve
PortletEntry from the Jetspeed config file.");
}
catch (Exception e)
{
Log.error(e.toString() + "\n Invalid PortletEntry encountered.");
throw new CustomizerException(e.toString() + "\n Invalid PortletEntry
encountered.");
} //end try-catch
if (portletEntry.size() == 0)
{
Log.error("Error, unable to retrieve the PortletEntry.");
throw new ElementNotFoundException("Error, unable to retrieve the
PortletEntry.");
}
} //end getPortletEntryFromJetspeedConfigFile
/**
* Set the user default portlets.
*
* @throws Exception if the user psml document object is null.
*/
private void setUserPortletsData() throws Exception
{
PSMLDocument psmlDoc = new PSMLDocument(this.data);
if (psmlDoc == null)
{
Log.error("The allowable portlet set for this user is not retrievable " +
"because of possible error/s within the user's psml file.");
throw new Exception("The allowable portlet set for this user is not
retrievable " +
"because of possible error/s within the user's psml
file.");
}
Enumeration en = this.portletEntry.elements();
while(en.hasMoreElements())
{
PortletEntryWrapper pw = (PortletEntryWrapper)en.nextElement();
if (psmlDoc.inDocument(pw.getPortletEntry().getName()))
{
PSMLEntry psmlEntry =
psmlDoc.getPSMLEntry(pw.getPortletEntry().getName());
pw.setAsUserDefaultPortlet(true);
pw.setPortletColumn(psmlEntry.getCoordinates()[0]);
pw.setPortletPosition(psmlEntry.getPosition());
}
} //end while
} //end setUserPortletData
/**
* Set the madatory portlets.
*
* Note: Should we throw an exception if the mandatory portlet does not exist in
the config file?
*/
private void setMandatoryPortlet()
{
String mandatory =
JetspeedResources.getString(JetspeedResources.MANDATORY_PORTLET);
if (mandatory != null)
{
StringTokenizer st = new StringTokenizer(mandatory.trim(), " ");
while (st.hasMoreTokens())
{
PortletEntryWrapper pw =
(PortletEntryWrapper)portletEntry.get(st.nextToken().trim());
if (pw != null)
{
pw.setAsMandatoryPortlet(true);
pw.setAsUserDefaultPortlet(true);
}
} //end while
} //end if
} //end setMandatoryPortlet
/**
* Get the names of the allowable portlet set.
*
*/
public String[] getAllowablePortletNames()
{
Enumeration elements = portletEntry.keys();
String[] names = new String[portletEntry.size()];
for (int i=0; i<names.length; i++)
{
names[i] = (String)elements.nextElement();
}
return names;
} //end getAllowablePortletNames
/**
* Refresh the data within this object
*
* @throws Exception if an error occurs.
*/
public void refresh() throws ElementNotFoundException,
CustomizerException,
Exception
{
portletEntry.clear();
loadPortletEntryFromJetspeedConfigFile();
setUserPortletsData();
setMandatoryPortlet();
} //end refresh
/**
* Verify if the given portlet name is within the user's set of default portlet.
*
* @param String name of the portlet.
*/
public boolean isUserDefaultPortlet(String name) throws ElementNotFoundException,
Exception
{
try
{
PortletEntryWrapper pw = (PortletEntryWrapper)portletEntry.get(name);
return pw.isUserDefaultPortlet();
}
catch (NullPointerException n)
{
Log.error("The portlet name, " + name + ", is not within user "
+ data.getUser().getUserName() + "'s allowable portlet set.");
throw new ElementNotFoundException("The portlet name, " + name
+ ", is not within user "
+ data.getUser().getUserName()
+ "'s allowable portlet set.");
}
} //end isUserDefaultPortlet
/**
* Verify if the given portlet name is a mandatory portlet.
*
* @param String name of the portlet.
*/
public boolean isMandatoryPortlet(String name) throws ElementNotFoundException,
Exception
{
try
{
PortletEntryWrapper pw = (PortletEntryWrapper)portletEntry.get(name);
return pw.isMandatoryPortlet();
}
catch (Exception e)
{
Log.error("The portlet name, " + name + ", is not within user "
+ data.getUser().getUserName() + "'s allowable portlet set.");
throw new ElementNotFoundException("The portlet name, " + name
+ ", is not within user "
+ data.getUser().getUserName()
+ "'s allowable portlet set.");
}
} //end isMandatoryPortlet
/**
* Use as a data structure to hold additional information for PortletEntry.
*/
private class PortletEntryWrapper
{
private PortletEntry pe = null;
private boolean defaultPortlet = false; // Indicates user's
default PE
private boolean mandatoryPortlet = false; // Indicates mandatory PE
private int portletCol = -1; // PE col number.
private int portletPos = -1; // PE row number.
public PortletEntryWrapper(PortletEntry portletEntry)
{
this.pe = portletEntry;
}
public PortletEntry getPortletEntry()
{
return this.pe;
}
public boolean isUserDefaultPortlet()
{
return this.defaultPortlet;
}
public boolean isMandatoryPortlet()
{
return mandatoryPortlet;
}
public void setAsUserDefaultPortlet(boolean b)
{
this.defaultPortlet = b;
}
public void setAsMandatoryPortlet(boolean b)
{
this.mandatoryPortlet = b;
}
public int getPortletPosition()
{
return this.portletPos;
}
public int getPortletColumn()
{
return this.portletCol;
}
public void setPortletPosition(int pos)
{
this.portletPos = pos;
}
public void setPortletColumn(int col)
{
this.portletCol = col;
}
} //end PortletEntryWrapper
} //end class AllowablePortletSet
1.1
jakarta-jetspeed/src/java/org/apache/jetspeed/util/customization/CustomizerException.java
Index: CustomizerException.java
===================================================================
package org.apache.jetspeed.util.customization;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache" or
* "Apache Jetspeed", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/**
* This class represents all the allowable portlets for a given user, including
those that
* are within the user's psml file and those that are mandatory for this user.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Yoo </a>
* @author <a href="mailto:[EMAIL PROTECTED]">Ernest Ros </a>
* @version $Id: CustomizerException.java,v 1.1 2001/05/08 06:26:10 taylor Exp $
*
*/
public class CustomizerException extends Exception
{
public CustomizerException()
{
super();
}
public CustomizerException(String msg)
{
super(msg);
}
}
1.1
jakarta-jetspeed/src/java/org/apache/jetspeed/util/customization/CustomizerResources.java
Index: CustomizerResources.java
===================================================================
package org.apache.jetspeed.util.customization;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache" or
* "Apache Jetspeed", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/**
* Resource class providing static keys to use by the customization classes.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Yoo </a>
* @author <a href="mailto:[EMAIL PROTECTED]">Ernest Ros </a>
* @version $Id: CustomizerResources.java,v 1.1 2001/05/08 06:26:10 taylor Exp $
*
*/
public class CustomizerResources
{
public static final String CUSTOMIZATIONPREFIX = "CUSTOMIZATION:";
public static final String PORTLET = CUSTOMIZATIONPREFIX + "PORTLET";
public static final String ALLOWABLEPORTLETSET = CUSTOMIZATIONPREFIX +
"ALLOWABLEPORTLETSET";
public static final String ALLOWABLECOLUMNSET = CUSTOMIZATIONPREFIX +
"ALLOWABLECOLUMNSET";
public static final String CUSTOMIZERSCREEN1 = "Customizer1";
public static final String CUSTOMIZERSCREEN2 = "Customizer2";
public static final String CUSTOMIZERACTION1 = "CustomizeUserPSMLFile";
public static final String CHECKBOXPREFIX = CUSTOMIZATIONPREFIX + "CHECKBOX";
public static final String SELECTBOXPREFIX = CUSTOMIZATIONPREFIX + "SELECTBOX";
public static final String COLUMNPREFIX = CUSTOMIZATIONPREFIX + "COLUMN";
public static final String ROWPREFIX = CUSTOMIZATIONPREFIX + "ROW";
public static final String PREVIOUSSCREEN = CUSTOMIZATIONPREFIX +
"PREVIOUS-SCREEN";
public static final String COLORS = CUSTOMIZATIONPREFIX + "COLOR";
public static final String HEADINGCOLOR = CUSTOMIZATIONPREFIX + "HEADING-COLOR";
public static final String BACKGROUNDCOLOR = CUSTOMIZATIONPREFIX +
"BACKGROUND-COLOR";
} //end CustomizerResources
1.1
jakarta-jetspeed/src/java/org/apache/jetspeed/util/customization/ElementNotFoundException.java
Index: ElementNotFoundException.java
===================================================================
package org.apache.jetspeed.util.customization;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache" or
* "Apache Jetspeed", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Yoo </a>
* @author <a href="mailto:[EMAIL PROTECTED]">Ernest Ros </a>
* @version $Id: ElementNotFoundException.java,v 1.1 2001/05/08 06:26:11 taylor
Exp $
*
*/
public class ElementNotFoundException extends Exception
{
public ElementNotFoundException()
{
super();
}
public ElementNotFoundException(String msg)
{
super(msg);
}
}
1.1
jakarta-jetspeed/src/java/org/apache/jetspeed/util/customization/JetspeedColors.java
Index: JetspeedColors.java
===================================================================
package org.apache.jetspeed.util.customization;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache" or
* "Apache Jetspeed", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import org.apache.jetspeed.services.resources.JetspeedResources;
import org.apache.turbine.util.Log;
/**
*
* JetspeedColors loads all the html colors defined in the JetspeedProperties
* file. These colors are defined with both names and hexidecimal values.
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Yoo </a>
* @author <a href="mailto:[EMAIL PROTECTED]">Ernest Ros </a>
* @version $Id: JetspeedColors.java,v 1.1 2001/05/08 06:26:11 taylor Exp $
*
*/
public class JetspeedColors
{
private String[] hexColors;
private String[] colorNames;
private int size;
/**
* This constructor stores the colors defined in the JetspeedResources.properties
* file into 2 private String arrays.
*/
public JetspeedColors() throws CustomizerException
{
String hexColorKey = JetspeedResources.HTML_HEX_COLOR_KEY;
String colorNameKey = JetspeedResources.HTML_COLOR_NAME_KEY;
// Get the colors from the JetspeedResources.properties file and store them
// in memory.
this.hexColors = this.getValues(hexColorKey);
this.colorNames = this.getValues(colorNameKey);
// Checksum
if (this.hexColors.length != this.colorNames.length)
throw new CustomizerException("The number of hexadecimal color values differs
from the "
+ "number of color names. Each color must have a name and vice versa.");
if (this.hexColors.length == 0)
throw new CustomizerException("Colors have not been defined in " +
"JetspeedResources.properties!"
+ "\n use the keys: " + hexColorKey + ".x and " + colorNameKey + ".x");
this.size = this.hexColors.length;
this.sort();
}// end constructor
/**
* getHexColor() A simple getter method.
*/
public String getHexColor(int i)
{
if (0 <= i && i < this.size)
{
return this.hexColors[i];
}
return null;
}// end getHexColor()
/**
* getColorNames() A simple getter method.
*/
public String getColorName(int i)
{
if (0 <= i && i < this.size)
{
return this.colorNames[i];
}
return null;
}// end getColorName()
/**
* getColorName() Returns the name of the color that corresponds to the hex
* value given.
*/
public String getColorName(String hexVal) throws ElementNotFoundException
{
for (int i=0; i<this.hexColors.length; i++)
{
if (hexVal.toLowerCase().equals(this.hexColors[i].toLowerCase()))
{
return this.colorNames[i];
}// end if
}// end for
// Nothing was found.
throw new ElementNotFoundException("The name for color: " + hexVal +
"was not found.");
}// end getColorName()
/**
* getHexValue() Returns the hex value of the color that corresponds to
* to the color name given.
*/
public String getHexValue(String name) throws ElementNotFoundException
{
for (int i=0; i<this.colorNames.length; i++)
{
if (name.toLowerCase().equals(this.colorNames[i].toLowerCase()))
{
return this.hexColors[i];
}// end if
}// end for
// Nothing was found.
throw new ElementNotFoundException("The hex value for color: " + name +
"was not found.");
}// end getColorName()
/**
* getSize() A simple getter method.
*/
public int getSize()
{
return this.size;
}
/**
* This version of getValues is the initiator method for the recursive version
* of the method.
*/
private String[] getValues(String key)
{
return this.getValues(key, 1);
}// end getValues()
/**
* getValues recursively extracts the indicated data elements from the
* JetspeedResources.properties file.
*/
private String[] getValues(String key, int depth)
{
// Get the value.
String theValue = JetspeedResources.getString(key+depth);
// Test the value returned.
if (theValue == null || theValue.trim().equals(""))
// There are no further values available, return null.
return null;
//end if
// Recursively retrieve the later values.
String[] values = this.getValues(key, depth+1);
// If this is the last element, then a new array must be created.
if (values == null){
values = new String[depth];
}// end if
// Insert the value into the result array.
values[depth-1] = theValue;
return values;
}// end getValues()
/**
* This method sorts the colors by name.
*/
private void sort()
{
this.sort(0, this.size-1);
}// end sort()
/**
* sort by Quicksort
*/
private void sort(int start, int end)
{
if (start < end)
{
int left = start;
int right = end;
int pivot = left;
String holder = null;
while (left < right) {
while (this.colorNames[left].compareToIgnoreCase(this.colorNames[pivot]) <=
0)
left++;
while (this.colorNames[right].compareToIgnoreCase(this.colorNames[pivot]) >
0)
right--;
if (left < right) {
holder = this.colorNames[left];
this.colorNames[left] = this.colorNames[right];
this.colorNames[right] = holder;
holder = this.hexColors[left];
this.hexColors[left] = this.hexColors[right];
this.hexColors[right] = holder;
}// end if
}// end while
holder = this.colorNames[pivot];
this.colorNames[pivot] = this.colorNames[right];
this.colorNames[right] = holder;
holder = this.hexColors[pivot];
this.hexColors[pivot] = this.hexColors[right];
this.hexColors[right] = holder;
this.sort(start, right-1);
this.sort(right+1, end);
}// end if
}// end sort()
}// end class JetspeedColors
1.1
jakarta-jetspeed/src/java/org/apache/jetspeed/util/customization/PSMLDocument.java
Index: PSMLDocument.java
===================================================================
package org.apache.jetspeed.util.customization;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache" or
* "Apache Jetspeed", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
// Basic Java stuff
import java.io.*;
import org.apache.turbine.util.RunData;
import org.apache.jetspeed.xml.api.portletmarkup.Portlets;
import org.apache.jetspeed.xml.api.portletmarkup.Entry;
// For portlets marshalling.
import org.apache.jetspeed.services.resources.JetspeedResources;
import org.apache.jetspeed.cache.disk.DiskCacheEntry;
import org.apache.jetspeed.cache.disk.JetspeedDiskCache;
import org.apache.jetspeed.portal.factory.PortletSetFactory;
import org.apache.jetspeed.portal.PortletSet;
import org.apache.jetspeed.xml.api.portletmarkup.Skin;
import org.apache.jetspeed.xml.api.portletmarkup.Property;
import org.apache.jetspeed.xml.api.portletmarkup.Layout;
import org.apache.jetspeed.util.PSMLManager;
import org.apache.jetspeed.util.MimeType;
import org.apache.jetspeed.profiler.*;
// Turbine
import org.apache.turbine.om.security.User;
import org.apache.turbine.util.Log;
// Castor
import org.exolab.castor.xml.ValidationException;
import org.exolab.castor.xml.MarshalException;
/**
*
* PSMLDocument is a class that represents the psml document itself. This class
* will fetch the user psml document in the RunData object. After modifications
* have been made, it can write the document back to the original file or to a
* new file.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Yoo </a>
* @author <a href="mailto:[EMAIL PROTECTED]">Ernest Ros </a>
* @version $Id: PSMLDocument.java,v 1.1 2001/05/08 06:26:11 taylor Exp $
*
*/
public class PSMLDocument
{
private JetspeedColors jColors;
private RunData rundata;
private Portlets portlets;
private DiskCacheEntry diskEntry;
private String psmlFileName;
private String psmlFilePath;
// The UserProfiler that handles conversions by MimeTypes
private static MultiDeviceUserProfiler profiler = null;
static
{
profiler = new MultiDeviceUserProfiler();
}
/**
* The constructor extracts the Jetspeed configuration information to locate
* the psml file to be read. The Porlets class then unmarshals the file.
*/
public PSMLDocument(RunData rdata) throws CustomizerException,
FileNotFoundException, UserNotLoggedInException
{
// Create a JetspeedColors object.
this.jColors = new JetspeedColors();
// Set the default file name in case it is needed.
String defaultFileName =
JetspeedResources.getString(JetspeedResources.PSML_DEFAULT_USER_KEY)
+ ".psml";
// Set rundata
this.rundata = rdata;
// Determine the name of this user's psml file.
User theUser = this.rundata.getUser();
if (theUser.hasLoggedIn())
{
this.psmlFileName = theUser.getUserName() + ".psml";
}
else
throw new UserNotLoggedInException("The user must log in before attempting to"
+
" customize preferences.");
// end if-else
// Set the location of the psml files.
this.psmlFilePath =
JetspeedResources.getString(JetspeedResources.PSML_BASE_URL_KEY);
MimeType mimetype = new MimeType("text/html");
String psmlURL = profiler.getUserURL( rundata.getUser().getUserName(),
mimetype.HTML );
try
{
DiskCacheEntry pde = JetspeedDiskCache.getInstance().getEntry( psmlURL );
Reader theReader;
try
{
// Open the user's psml file.
theReader = pde.getReader();
}
catch (FileNotFoundException fnfe)
{
pde = JetspeedDiskCache.getInstance().getEntry( this.psmlFilePath +
defaultFileName );
theReader = pde.getReader();
}// end try-catch
try
{
// Unmarshal the PSML file and build the portlets object.
this.portlets = Portlets.unmarshal(theReader);
}
catch (ValidationException ve)
{
throw new CustomizerException("The psml file is invalid.");
}
catch (MarshalException me)
{
throw new CustomizerException("An error occurred while reading the psml "
+ "file.");
}
}
catch (Exception e)
{
Log.error("PSMLDocument: Error reading PSML", e);
}
}// end constructor
/**
* getEntry finds the Entry object in the portlets object with the name
* given. getEntry then packages the entry into a PSMLEntry object so it can
* include the positioning information for the indicated Entry.
*/
public PSMLEntry getPSMLEntry(String portletName) throws ElementNotFoundException
{
return this.find(portletName, this.portlets);
}// end PSMLEntry()
/**
* addPSMLEntry adds an entry to the portlets object indicated by the
* coordinates of the PSMLEntry object passed in.
*/
public void addPSMLEntry(PSMLEntry theEntry) throws CustomizerException
{
Portlets thePortlets = null;
try
{
// Get the "parent" portlets object.
thePortlets = this.getPortletsObject(theEntry.getCoordinates());
}
catch (ElementNotFoundException enf)
{
enf.printStackTrace();
throw new CustomizerException("The coordinates of the entry are invalid.");
}// end try-catch
// Add the new Entry.
thePortlets.addEntry(theEntry.getEntry());
}// end addPSMLEntry
/**
* setPSMLEntry re-sets an existing entry in the portlets object indicated by
* the coordinates of the PSMLEntry object passed in.
*/
public void setPSMLEntry(PSMLEntry theEntry) throws CustomizerException,
ElementNotFoundException
{
Portlets thePortlets = null;
// Get the "parent" portlets object.
thePortlets = this.getPortletsObject(theEntry.getCoordinates());
// Find the current index of the entry we wish to replace.
int idx = this.findIndex(thePortlets, theEntry);
// Entry has been found.
thePortlets.setEntry(theEntry.getEntry(), idx);
}// end setEntry()
/**
* deleteEntry deletes the named portlet from the document. If the portlet
* cannot be found or if the name is blank or null, an exception is thrown.
*/
public void deleteEntry(String portletName) throws ElementNotFoundException
{
// Find the entry that is to be deleted.
PSMLEntry markedForDeath = this.find(portletName, this.portlets);
// Get the portlets object that contains the entry to be deleted.
Portlets thePortlets = this.getPortletsObject(markedForDeath.getCoordinates());
// Get the index of the object to be deleted.
int idx = this.findIndex(thePortlets, markedForDeath);
// Delete the entry
thePortlets.removeEntry(idx);
}// end deleteEntry()
/**
* deleteAllEntries removes all entries in the portlets object found at the
* coordinates given. This method deletes all entries in sub-Portlets objects.
*/
public void deleteAllEntries(int[] coord) throws CustomizerException
{
Portlets targetPortlets = null;
try
{
// Get the portlets object that is to be modified.
targetPortlets = this.getPortletsObject(coord);
}
catch (ElementNotFoundException enf)
{
enf.printStackTrace();
throw new CustomizerException("The coordinates provided are invalid.");
}// end try-catch
// Delete the Entries from the portlets object.
targetPortlets.removeAllEntry();
int[] newCoord = null;
int thisCoord = 0;
if (coord == null)
{
// thisCoord is already 0.
newCoord = new int[1];
}
else
{
// Create a new coordinates array.
thisCoord = coord.length;
newCoord = new int[coord.length+1];
System.arraycopy(coord, 0, newCoord, 0, coord.length);
}// end if-else
// Delete entries from sub-portlets.
Portlets[] subPortlets = targetPortlets.getPortlets();
for (newCoord[thisCoord]=0; newCoord[thisCoord]<subPortlets.length;
newCoord[thisCoord]++)
{
this.deleteAllEntries(newCoord);
}// end for
}// end deleteAllEntries()
/**
* inDocument returns true if an Entry object with the specified portlet name
* is found in the Portlets object.
*/
public boolean inDocument(String portletName)
{
try
{
if (this.find(portletName, this.portlets) != null)
return true;
}
catch (ElementNotFoundException enf)
{
return false;
}// end try-catch
return false;
}// end inDocument()
/**
* getTitleColor returns the title color set for the portlets object indicated
* by the position array.
*/
public String getTitleColor(int[] coord) throws CustomizerException
{
return this.getSkinPropertyValue("title-color", coord);
}// end getTitleColor()
/**
* setTitleColor sets the title color value for the portlets object indicated
* by the postion array.
*/
public void setTitleColor(String newColor, int[] coord) throws CustomizerException
{
this.setSkinPropertyValue("title-color", newColor, coord);
}// end setTitleColor()
/**
* getBackgoundColor returns the background color set for the portlets object
* indicated by the position array.
*/
public String getBackgroundColor(int[] coord) throws CustomizerException
{
return this.getSkinPropertyValue("background-color", coord);
}// end getBackgroundColor()
/**
* setBackgroundColor sets the title color value for the portlets object
* indicated by the postion array.
*/
public void setBackgroundColor(String newColor, int[] coord) throws
CustomizerException
{
this.setSkinPropertyValue("background-color", newColor, coord);
}// end setBackgroundColor()
/**
* writePSMLDocument generates the default filename for the current user
* defined in the RunData object and then calls the PSMLManager
* to actually write the file.
*/
public void writePSMLDocument() throws CustomizerException
{
MimeType mimetype = new MimeType ( "text/html" );
PSMLManager.setPSMLContent ( rundata, mimetype.HTML, this.portlets );
}// end writePSMLDocument()
/**
* getPortletsObjectAt is a goto method. This method traverses the portlets
* tree and returns the portlets object found there.
*/
private Portlets getPortletsObject(int[] coord) throws ElementNotFoundException
{
// if coord is null, return the top level portlets object.
if (coord == null)
return this.portlets;
// The portlets tree starts with the top level portlets object.
Portlets holder = this.portlets;
// Traverse the Portlets tree to get to the desired portlets
for (int i = 0; i < coord.length; i++)
{
if (i < holder.getPortletsCount()-1)
holder = holder.getPortlets(coord[i]);
else
throw new ElementNotFoundException("A request was made for a portlets "
+ "object that cannot be found.");
// end if-else
}// end for
// Return the last portlets object found.
return holder;
}// end getPorteletsObjectAt()
/**
* setPortletsObject re-inserts a (presumably) modified portlets object into
* the portlets tree at the specified coordinates.
*/
private void setPortletsObject(Portlets thePortlets, int[] coord)
throws ElementNotFoundException
{
// Set the layout for this portlets object.
if (coord != null) {
Layout aLayout = new Layout();
aLayout.setPosition(String.valueOf(coord[coord.length-1]));
thePortlets.setLayout(aLayout);
}// end if
// If coord is null, then we have reached the top. The portlets object that
// was passed in should be the new top level portlets object.
if (coord == null)
this.portlets = thePortlets;
else {
// Since coord is not null, we must discern the coordinates of the
// "parent" portlets object.
// Declare an array to hold the parent coordinates.
int[] parentCoordinates = null;
// Find the "parent" portlets object.
Portlets parent;
if (coord.length > 1)
{
// Create a new coordinates array for the "parent".
parentCoordinates = new int[coord.length-1];
System.arraycopy(coord, 0, parentCoordinates, 0, coord.length-1);
// Get the parent using the new coordinates array.
parent = this.getPortletsObject(parentCoordinates);
}
else
// If there is only one coordinate in coord, the parent must be the
// root portlets object.
parent = this.portlets;
}// end if-else
}// end setPortletsObject()
/**
* This find method calls the recursive find method properly. This method
* allows programmers to call find without having to know about how
* find works.
*/
private PSMLEntry find(String portletName, Portlets pTree) throws
NullPointerException, ElementNotFoundException
{
return this.find(portletName, pTree, null);
}// end find()
/**
* This find method recursively traverses the portlets tree and discovers the
* location of the Entry with the matching portlet name (There can be only
* one.) Once it has been found, the location information and the Entry object
* itself is bundled into a PSMLEntry object and returned.
*/
private PSMLEntry find(String portletName, Portlets pTree, int[] coord)
throws ElementNotFoundException
{
// If coord is null, then we need to create a new array that has 1 empty
// slot. The empty slot is for this portlets object's position number.
// If coord is not null, then we need to grow the array by 1 space so the
// array can accomodate this portlets object's position numbber
int colnum = 0;
if (coord == null)
{
coord = new int[1];
colnum = -1;
}
else
{
colnum = coord[coord.length-1];
// Declare a new array that is one size longer.
int[] newCoord = new int[coord.length+1];
// Copy the contents of the old array into the new one.
System.arraycopy(coord, 0, newCoord, 0, coord.length);
// Replace the old array with the new array.
coord = newCoord;
}// end if else
// Declare a counter and a PSMLEntry holder variable.
int counter = 0;
Entry testEntry;
// Check each entry in this portlets object.
Log.note("Column " + colnum + " has " + pTree.getEntryCount() + " Entries.");
for (counter=0; counter < pTree.getEntryCount(); counter++)
{
testEntry = pTree.getEntry(counter);
if (portletName.equals(testEntry.getParent()))
{
coord[coord.length-1] = counter;
// Create a new PSML object with this info and return it.
return new PSMLEntry(testEntry, coord);
}// end if
}// end for
// Declare a PSMLEntry to hold any possible result.
PSMLEntry resultEntry = null;
// If we have gotten to this point, the desired entry is not in this portlets
// object. Re-use the counter integer to step through each portlets object.
for (counter=0; counter < pTree.getPortletsCount() && resultEntry== null;
counter++)
{
coord[coord.length-1] = counter;
try
{
resultEntry = this.find(portletName, pTree.getPortlets(counter), coord);
}
catch (ElementNotFoundException enf)
{
//Do nothing.
}// end try-catch
}// end for
// If nothing was found.
if (resultEntry == null)
throw new ElementNotFoundException("The entry, " + portletName + " was " +
"not found.");
return resultEntry;
}// end find()
/**
* Returns the default color (in hex) for the given property name.
*/
private String getDefaultColor(String propertyName)
{
try
{
if (propertyName.equals("background-color"))
return jColors.getHexValue("DEFAULT_BC");
if (propertyName.equals("title-color"))
return jColors.getHexValue("DEFAULT_TC");
}
catch (ElementNotFoundException enf)
{
}// end try-catch
return "#FFFFFF";
}// end getDefaultColor
/**
* getSkinPropertyValue returns the property value for the portlets object
* indicated by the coordinates.
*/
private String getSkinPropertyValue(String propertyName, int[] coord)
throws CustomizerException
{
Portlets thePortlets = null;
try
{
// Get the portlets object found at the coordinates given.
thePortlets = this.getPortletsObject(coord);
}
catch (ElementNotFoundException enf)
{
enf.printStackTrace();
throw new CustomizerException("The coordinates are invalid.");
}
// Extract the skin object.
Skin theSkin = thePortlets.getSkin();
if (theSkin == null)
return this.getDefaultColor(propertyName);
// Extract the skin properties.
Property[] props = thePortlets.getSkin().getProperty();
// Search for the desired property.
Property found = null;
for (int i=0; i<props.length; i++)
{
if (props[i].getName().equals(propertyName))
{
found = props[i];
break;
}// end if
}// end for
// if nothing was found, get the default color.
if (found == null)
return this.getDefaultColor(propertyName);
// Otherwise, return the value string of the found property.
return found.getValue();
}// end getSkinPropertyValue()
/**
* setSkinPropertyValue sets the property value for the portlets object
* indicated by the coordinates.
*/
private void setSkinPropertyValue(String propertyName, String value,
int[] coord) throws CustomizerException
{
Portlets thePortlets = null;
try
{
// Get the portlets object found at the coordinates given.
thePortlets = this.getPortletsObject(coord);
}
catch (ElementNotFoundException enf)
{
enf.printStackTrace();
throw new CustomizerException("The coordinates are invalid.");
}
// Extract the skin.
Skin theSkin = thePortlets.getSkin();
// Check for null skin
if (theSkin == null)
{
// Create a new skin.
theSkin = new Skin();
}
// Extract the Properties.
Property[] props = theSkin.getProperty();
// Search for the desired property.
Property found = null;
int foundIndex = -1;
if (props != null)
{
for (int i=0; i<props.length; i++)
{
if (props[i].getName().equals(propertyName))
{
foundIndex = i;
found = props[foundIndex];
break;
}// end if
}// end for
}// end if
// if nothing was found, add a new property
if (found == null)
{
found = new Property();
found.setName(propertyName);
}// end if
found.setValue(value);
if (foundIndex != -1)
theSkin.setProperty(found, foundIndex);
else
theSkin.addProperty(found);
// end if
thePortlets.setSkin(theSkin);
}// end setSkinPropertyValue()
private int findIndex(Portlets thePortlets, PSMLEntry theEntry) throws
ElementNotFoundException
{
return this.findIndex(thePortlets, theEntry.getEntry());
}// end findIndex()
private int findIndex(Portlets thePortlets, Entry theEntry) throws
ElementNotFoundException
{
// Find the current index of the entry we wish to replace.
int idx = -1;
for (int i=0; i<thePortlets.getEntryCount(); i++)
{
if (theEntry.getParent().equals(thePortlets.getEntry(i).getParent()))
{
idx = i;
break;
}// end if
}// end for
if (idx == -1)
throw new ElementNotFoundException("The entry does not exist in the " +
"Portlets object indicated.");
return idx;
}// end findIndex()
}// end class PSMLDocument
1.1
jakarta-jetspeed/src/java/org/apache/jetspeed/util/customization/PSMLEntry.java
Index: PSMLEntry.java
===================================================================
package org.apache.jetspeed.util.customization;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache" or
* "Apache Jetspeed", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import org.apache.jetspeed.xml.api.portletmarkup.Entry;
import org.apache.jetspeed.om.registry.peer.PortletEntry;
import org.apache.jetspeed.xml.api.portletmarkup.Layout;
import org.apache.turbine.util.Log;
import java.lang.NullPointerException;
/**
*
* PSMLEntry is a wrapper class that bundles the Entry object and positioning
* information for a particular portlet together.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Yoo </a>
* @author <a href="mailto:[EMAIL PROTECTED]">Ernest Ros </a>
* @version $Id: PSMLEntry.java,v 1.1 2001/05/08 06:26:11 taylor Exp $
*
*/
public class PSMLEntry
{
private Entry theEntry;
/**
* The coordinates of a portlet is defined by an integer array. This array
* contains the position information ranging from least specific to most
* specific. For example, the position of a portlet located in column 2,
* row 1 would be defined by the following array: [2, 1]. Remember that the
* coordinate does not include the portlet's actual position number within the
* space defined by the coordinates.
*/
private int[] coordinates;
//private String bgColor;
//private String titleColor;
public PSMLEntry(Entry entry, int[] coord) throws NullPointerException
{
if (entry == null || coord == null)
throw new NullPointerException("Neither parameter of PSMLEntry constructor may
be null.");
this.setEntry(entry);
this.setCoordinates(coord);
//this.bgColor = bColor;
//this.titleColor = tColor;
}// end contructor()
/**
* Alternate constructor takes a PortletEntry from the PortletRegistry
* and converts it into an Entry object.
*/
public PSMLEntry(PortletEntry entry, Layout layout, int [] coord)
throws NullPointerException
{
if (entry == null || layout == null || coord == null)
throw new NullPointerException("No parameter of PSMLEntry constructor may be
null.");
Entry ne = PSMLEntry.portletEntryToEntry(entry, layout);
this.setEntry(ne);
this.setCoordinates(coord);
}// end contstructor()
// Getters -------------------------------------------------------------------
public Entry getEntry()
{
return this.theEntry;
}// end getEntry()
public int[] getCoordinates()
{
Log.note("Returning the coordinates: " + this.coordinates[0]);
return this.coordinates;
}// end getCoordinates()
public int getPosition()
{
Layout theLayout = this.theEntry.getLayout();
if (theLayout == null)
return 0;
return Integer.parseInt(theLayout.getPosition());
}// end getPosition()
/* For later use
public String getBackgoundColor(){
return this.bgColor;
}// end getBackgroundColor()
public String getTitleColor(){
return this.titleColor;
}// end getTitleColor()
*/
// Setters -------------------------------------------------------------------
public void setEntry(Entry newEntry)
{
this.theEntry = newEntry;
}// end setEntry()
public void setEntry(PortletEntry newEntry, Layout layout) throws Exception
{
this.setEntry(PSMLEntry.portletEntryToEntry(newEntry, layout));
}// end setEntry()
public void setCoordinates(int[] coord)
{
this.coordinates = coord;
}// end setPosition()
public void setPosition(int position)
{
this.setPosition(String.valueOf(position));
}// end setPosition()
public void setPosition(String position)
{
Layout theLayout = this.theEntry.getLayout();
if (theLayout == null)
theLayout = new Layout();
theLayout.setPosition(position);
this.theEntry.setLayout(theLayout);
}// end setPosition()
/* For later use
public void setBackgroundColor(String newColor){
this.bgColor = newColor;
}// end setBackgroundColor()
public void setTitleColor(String newColor){
this.titleColor = newColor;
}// end setTitleColor()
*/
private static Entry portletEntryToEntry(PortletEntry entry, Layout layout)
{
Entry result = new Entry();
result.setParent(entry.getName());
result.setLayout(layout);
result.setType(entry.getType().toString());
return result;
}// end portletEntryToEntry
}// end class PSMLEntry
1.1
jakarta-jetspeed/src/java/org/apache/jetspeed/util/customization/UserNotLoggedInException.java
Index: UserNotLoggedInException.java
===================================================================
package org.apache.jetspeed.util.customization;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Jetspeed" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache" or
* "Apache Jetspeed", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Yoo </a>
* @author <a href="mailto:[EMAIL PROTECTED]">Ernest Ros </a>
* @version $Id: UserNotLoggedInException.java,v 1.1 2001/05/08 06:26:11 taylor
Exp $
*
*/
public class UserNotLoggedInException extends Exception
{
public UserNotLoggedInException()
{
super();
}
public UserNotLoggedInException(String msg)
{
super(msg);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]