ThemeStylesheetUserPreferences tsup;
Connection con = RDBMServices.getConnection();
try
{
// get stylesheet description
ThemeStylesheetDescription tsd = getThemeStylesheetDescription(stylesheetId);
// get user defined defaults
int layoutId = this.getLayoutID(userId, profileId);
// if no layout then get the default user id for this user
int origId = userId;
int origProfileId = profileId;
if (layoutId == 0)
{ // First time, grab the default layout for this user
String sQuery = "SELECT USER_DFLT_USR_ID FROM UP_USER WHERE USER_ID=?";
if (log.isDebugEnabled())
log.debug(sQuery + " VALUE = " + userId);
final PreparedStatement pstmt1 = con.prepareStatement(sQuery);
try {
pstmt1.setInt(1,userId);
final ResultSet rs = pstmt1.executeQuery();
try
{
rs.next();
userId = rs.getInt(1);
// get the profile ID for the default user
UserProfile profile = getUserProfileById(person, profileId);
IPerson defaultProfilePerson = new PersonImpl();
defaultProfilePerson.setID(userId);
profileId = getUserProfileByFname(defaultProfilePerson, profile.getProfileFname()).getProfileId();
} finally
{
close(rs);
}
}
finally {
close(pstmt1);
}
}
// create the stylesheet user prefs object then fill
// it with defaults from the stylesheet definition object
tsup = new ThemeStylesheetUserPreferences();
tsup.setStylesheetId(stylesheetId);
// fill stylesheet description with defaults
for (Enumeration e = tsd.getStylesheetParameterNames(); e
.hasMoreElements();)
{
String pName = (String) e.nextElement();
tsup.putParameterValue(pName, tsd
.getStylesheetParameterDefaultValue(pName));
}
for (Enumeration e = tsd.getChannelAttributeNames(); e
.hasMoreElements();)
{
String pName = (String) e.nextElement();
tsup.addChannelAttribute(pName, tsd
.getChannelAttributeDefaultValue(pName));
}
// Now load in the stylesheet parameter preferences
// from the up_ss_user_param but only if they are defined
// parameters in the stylesheet's .sdf file.
//
// First, get the parameters for the effective user ID,
// then for the original user ID. These will differ if
// the user has no layout in the database and is using
// the default user layout. The params from the original
// user ID take precedence.
String sQuery2 =
"SELECT PARAM_NAME, PARAM_VAL " +
"FROM UP_SS_USER_PARM " +
"WHERE USER_ID=?" +
" AND PROFILE_ID=?" +
" AND SS_ID=?" +
" AND SS_TYPE=2";
if (log.isDebugEnabled())
log.debug(sQuery2 + " VALUES " + userId + "," + profileId + "," + stylesheetId);
final PreparedStatement pstmt2 = con.prepareStatement(sQuery2);
try
{
pstmt2.setInt(1, userId);
pstmt2.setInt(2,profileId);
pstmt2.setInt(3,stylesheetId);
final ResultSet rs = pstmt2.executeQuery();
try {
while (rs.next())
{
// stylesheet param
String pName = rs.getString(1);
if (tsd.containsParameterName(pName))
tsup.putParameterValue(pName, rs.getString(2));
}
}
finally {
close(rs);
}
if (userId != origId) {
pstmt2.setInt(1, origId);
pstmt2.setInt(2, origProfileId);
final ResultSet rs2 = pstmt2.executeQuery();
try {
while (rs2.next()) {
String pName = rs2.getString(1);
if (tsd.containsParameterName(pName))
tsup.putParameterValue(pName, rs2.getString(2));
}
}
finally {
close(rs2);