Author: bdaw
Date: 2007-07-10 08:30:56 -0400 (Tue, 10 Jul 2007)
New Revision: 7704
Modified:
trunk/identity/build.xml
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateMembershipModuleImpl.java
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserModuleImpl.java
trunk/identity/src/main/org/jboss/portal/test/identity/IdentityTest.java
trunk/widget/src/main/org/jboss/portal/widget/google/GGWidget.java
trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetInfo.java
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetInfoBuilder.java
trunk/widget/src/resources/widget-war/WEB-INF/jsp/edit.jsp
Log:
merge changes from JBoss_Portal_Branch_2_6
Modified: trunk/identity/build.xml
===================================================================
--- trunk/identity/build.xml 2007-07-10 11:50:52 UTC (rev 7703)
+++ trunk/identity/build.xml 2007-07-10 12:30:56 UTC (rev 7704)
@@ -480,11 +480,11 @@
<x-test>
- <!--<test todir="${test.reports}"
name="org.jboss.portal.test.identity.db.DBIdentityTestCase"/>-->
+ <test todir="${test.reports}"
name="org.jboss.portal.test.identity.db.DBIdentityTestCase"/>
<!--<test todir="${test.reports}"
name="org.jboss.portal.test.identity.ldap.LDAPIdentityTestCase"/>-->
<!--<test todir="${test.reports}"
name="org.jboss.portal.test.identity.ldap.LDAPSimpleUserModuleTestCase"/>-->
<!--<test todir="${test.reports}"
name="org.jboss.portal.test.identity.ldap.LDAPSimpleRoleModuleTestCase"/>-->
- <test todir="${test.reports}"
name="org.jboss.portal.test.identity.ldap.LDAPStaticGroupMembershipModuleTestCase"/>
+ <!--<test todir="${test.reports}"
name="org.jboss.portal.test.identity.ldap.LDAPStaticGroupMembershipModuleTestCase"/>-->
<!--<test todir="${test.reports}"
name="org.jboss.portal.test.identity.ldap.LDAPStaticRoleMembershipModuleTestCase"/>-->
<!--<test todir="${test.reports}"
name="org.jboss.portal.test.identity.ldap.LDAPUserProfileModuleTestCase"/>-->
<!--<test todir="${test.reports}"
name="org.jboss.portal.test.identity.ldap.LDAPExtUserModuleTestCase"/>
Modified:
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateMembershipModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateMembershipModuleImpl.java 2007-07-10
11:50:52 UTC (rev 7703)
+++
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateMembershipModuleImpl.java 2007-07-10
12:30:56 UTC (rev 7704)
@@ -110,7 +110,7 @@
{
if (!(role instanceof HibernateRoleImpl))
{
- throw new IllegalArgumentException("User is not a HibernateRoleImpl
user");
+ throw new IllegalArgumentException("Role is not a HibernateRoleImpl
role");
}
// We return an immutable set to avoid modifications
@@ -131,7 +131,7 @@
//throw new UnsupportedOperationException("Not yet implemented");
if (!(role instanceof HibernateRoleImpl))
{
- throw new IllegalArgumentException("User is not a HibernateRoleImpl
user");
+ throw new IllegalArgumentException("Role is not a HibernateRoleImpl
role");
}
for (Iterator i = users.iterator(); i.hasNext();)
@@ -144,7 +144,7 @@
}
else
{
- throw new IllegalArgumentException("Only HibernateUserImpl roles can be
accepted");
+ throw new IllegalArgumentException("Only HibernateUserImpl users can be
accepted");
}
}
Modified:
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserModuleImpl.java
===================================================================
---
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserModuleImpl.java 2007-07-10
11:50:52 UTC (rev 7703)
+++
trunk/identity/src/main/org/jboss/portal/identity/db/HibernateUserModuleImpl.java 2007-07-10
12:30:56 UTC (rev 7704)
@@ -187,6 +187,11 @@
public void removeUser(Object id) throws IdentityException
{
+ if (id == null)
+ {
+ throw new IllegalArgumentException("User id cannot be null");
+ }
+
if (id instanceof Long)
{
try
@@ -194,11 +199,14 @@
Session session = getCurrentSession();
HibernateUserImpl user =
(HibernateUserImpl)session.load(HibernateUserImpl.class, (Serializable)id);
- String userName = user.getUserName();
+
if (user == null)
{
throw new NoSuchUserException("No such user " + id);
}
+
+ String userName = user.getUserName();
+
session.delete(user);
session.flush();
Modified: trunk/identity/src/main/org/jboss/portal/test/identity/IdentityTest.java
===================================================================
--- trunk/identity/src/main/org/jboss/portal/test/identity/IdentityTest.java 2007-07-10
11:50:52 UTC (rev 7703)
+++ trunk/identity/src/main/org/jboss/portal/test/identity/IdentityTest.java 2007-07-10
12:30:56 UTC (rev 7704)
@@ -9,6 +9,7 @@
import org.jboss.portal.identity.Role;
import org.jboss.portal.identity.IdentityException;
import org.jboss.portal.identity.ProfileMap;
+import org.jboss.portal.identity.NoSuchUserException;
import org.jboss.portal.common.util.CollectionBuilder;
import org.jboss.portal.common.p3p.P3PConstants;
@@ -315,6 +316,20 @@
assertNotNull(g2);
Assert.assertEquals("role2", g2.getName());
ctx.commit();
+
+ ctx.begin();
+
+ try
+ {
+ userModule.removeUser(new Long(9999999));
+ fail();
+ }
+ catch (IdentityException e)
+ {
+ //expected
+ }
+
+ ctx.commit();
}
public void testFindRoles() throws Exception
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/GGWidget.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGWidget.java 2007-07-10 11:50:52
UTC (rev 7703)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGWidget.java 2007-07-10 12:30:56
UTC (rev 7704)
@@ -78,6 +78,11 @@
return getInfo().getTitle();
}
+ public LocalizedString getDirectoryTitle()
+ {
+ return getInfo().getDirectoryTitle();
+ }
+
public LocalizedString getDescription()
{
return getInfo().getDescription();
@@ -98,7 +103,8 @@
tmp.append("&synd=open");
tmp.append("&w=").append(info.getWidth());
tmp.append("&h=").append(info.getHeight());
-
tmp.append("&title=").append(FastURLEncoder.DEFAULT_ENCODER.encode(info.getTitle().getDefaultString()));
+ //don's let to override the title param - proper one will be picked up with
i18n support
+
//tmp.append("&title=").append(FastURLEncoder.DEFAULT_ENCODER.encode(info.getTitle().getDefaultString()));
tmp.append("&border=%23ffffff%7C3px%2C1px+none+%23999999"); //
"&border=%23ffffff%7C3px%2C1px+solid+%23999999"
tmp.append("&output=js");
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetInfo.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetInfo.java 2007-07-10
11:50:52 UTC (rev 7703)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetInfo.java 2007-07-10
12:30:56 UTC (rev 7704)
@@ -37,6 +37,9 @@
private final LocalizedString title;
/** . */
+ private final LocalizedString directoryTitle;
+
+ /** . */
private final LocalizedString description;
/** . */
@@ -50,12 +53,14 @@
public GGWidgetInfo(
LocalizedString title,
+ LocalizedString directoryTitle,
LocalizedString description,
int width,
int height,
GGPreferencesInfo preferences)
{
this.title = title;
+ this.directoryTitle = directoryTitle;
this.description = description;
this.width = width;
this.height = height;
@@ -86,4 +91,10 @@
{
return height;
}
+
+
+ public LocalizedString getDirectoryTitle()
+ {
+ return directoryTitle;
+ }
}
Modified:
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetInfoBuilder.java
===================================================================
---
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetInfoBuilder.java 2007-07-10
11:50:52 UTC (rev 7703)
+++
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetInfoBuilder.java 2007-07-10
12:30:56 UTC (rev 7704)
@@ -37,6 +37,8 @@
import org.jboss.portal.widget.google.GGWidgetInfo;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Node;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
@@ -45,6 +47,8 @@
import java.util.Locale;
import java.util.Collection;
import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
import java.io.ByteArrayInputStream;
/**
@@ -53,7 +57,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class GGWidgetInfoBuilder
+public class GGWidgetInfoBuilder
{
/** . */
@@ -96,6 +100,110 @@
Document doc = builder.parse(new ByteArrayInputStream(bytes));
Element moduleElt = doc.getDocumentElement();
+ Map messagesBundle = new HashMap();
+
+ //first process locale bundles
+ Iterator modulePrefsEltIterator = XMLTools.getChildrenIterator(moduleElt,
"ModulePrefs");
+ if (modulePrefsEltIterator.hasNext())
+ {
+ Element modulePrefsElt = (Element)modulePrefsEltIterator.next();
+
+ Iterator localeEltIterator = XMLTools.getChildrenIterator(modulePrefsElt,
"Locale");
+
+ Map messages = new HashMap();
+
+ while(localeEltIterator.hasNext())
+ {
+ Element localeElt = (Element)localeEltIterator.next();
+
+ String langAttr = localeElt.getAttribute("lang");
+ String countryAttr = localeElt.getAttribute("country");
+ String messagesAttr = localeElt.getAttribute("messages");
+
+ //as portal spec defines fallback to EN we'll use it for all_ALL gg
bundle
+ if (langAttr == null || langAttr.length() == 0)
+ {
+ langAttr = "en";
+ }
+
+ Locale locale;
+ if (countryAttr == null || countryAttr.length() == 0)
+ {
+ locale = new Locale(langAttr);
+ }
+ else
+ {
+ locale = new Locale(langAttr, countryAttr);
+ }
+
+
+
+ URL bundleURL = new URL(url, messagesAttr);
+
+ byte[] bundleBytes = obtainLocaleBundle(bundleURL);
+
+ //if no response obtained - ignore this bundle
+ if (bundleBytes == null)
+ {
+ continue;
+ }
+
+ DocumentBuilder bundleDocBuilder = factory.newDocumentBuilder();
+ Document bundleDoc = bundleDocBuilder.parse(new
ByteArrayInputStream(bundleBytes));
+ Element messagebundleElt = bundleDoc.getDocumentElement();
+
+ Iterator messagesEltIterator = XMLTools.getChildrenIterator(messagebundleElt,
"msg");
+
+ while(messagesEltIterator.hasNext())
+ {
+ Element msgElt = (Element)messagesEltIterator.next();
+
+ String name = msgElt.getAttribute("name");
+
+ StringBuffer value = new StringBuffer();
+
+ //create value from the tag content
+ NodeList nodes = msgElt.getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node n = nodes.item(i);
+
+ if (n.getNodeType() == Element.TEXT_NODE) {
+ value.append(n.getNodeValue());
+ }
+ }
+
+
+ Map entries;
+ if (!messages.containsKey(name))
+ {
+ entries = new HashMap();
+ messages.put(name, entries);
+ }
+ else
+ {
+ entries = (Map)messages.get(name);
+ }
+
+ entries.put(locale, value.toString());
+ }
+ }
+
+ //Reiterate whole bundle to store LocalizedString values;
+ for (Iterator iterator = messages.keySet().iterator(); iterator.hasNext();)
+ {
+ String name = (String)iterator.next();
+ Map entries = (Map)messages.get(name);
+
+ messagesBundle.put(name, new LocalizedString(entries, Locale.ENGLISH));
+ }
+
+ }
+ else
+ {
+ throw new Exception(); // Basic for now
+ }
+
+
//
Collection tmp = null;
Iterator userPrefsEltIterator = XMLTools.getChildrenIterator(moduleElt,
"UserPref");
@@ -141,7 +249,8 @@
Element enumValueElt = (Element)i.next();
String valueAttr = enumValueElt.getAttribute("value");
String displayValueAttr =
enumValueElt.getAttribute("display_value");
- EnumType.Value value = new EnumType.Value(valueAttr,
displayValueAttr.length() > 0 ? displayValueAttr : null);
+
+ EnumType.Value value = new EnumType.Value(valueAttr,
resolveLocalizedValue(displayValueAttr, messagesBundle));
values.add(value);
}
dataType = new EnumType(values);
@@ -153,10 +262,12 @@
}
//
+
+
GGPreferenceInfo prefInfo = new GGPreferenceInfo(
nameAttr,
dataType,
- displayNameAttr.length() > 0 ? displayNameAttr : null,
+ resolveLocalizedValue(displayNameAttr, messagesBundle),
requiredAttr.length() > 0 ? Boolean.valueOf(requiredAttr).booleanValue() :
false,
defaultValueAttr.length() > 0 ? defaultValueAttr : null
);
@@ -174,21 +285,25 @@
prefsInfo = new GGPreferencesInfo(tmp);
}
- Iterator modulePrefsEltIterator = XMLTools.getChildrenIterator(moduleElt,
"ModulePrefs");
+ modulePrefsEltIterator = XMLTools.getChildrenIterator(moduleElt,
"ModulePrefs");
if (modulePrefsEltIterator.hasNext())
{
Element modulePrefsElt = (Element)modulePrefsEltIterator.next();
String titleAttr = modulePrefsElt.getAttribute("title");
+ String directoryTitleAttr =
modulePrefsElt.getAttribute("directory_title");
String descriptionAttr = modulePrefsElt.getAttribute("description");
String widthAttr = modulePrefsElt.getAttribute("width");
String heightAttr = modulePrefsElt.getAttribute("height");
//
- LocalizedString title = titleAttr != null ? new LocalizedString(titleAttr,
Locale.ENGLISH) : null;
- LocalizedString description = descriptionAttr != null ? new
LocalizedString(descriptionAttr, Locale.ENGLISH) : null;
+ LocalizedString title = resolveLocalizedStringValue(titleAttr, messagesBundle);
+ LocalizedString directoryTitle = resolveLocalizedStringValue(directoryTitleAttr,
messagesBundle);
+ LocalizedString description = resolveLocalizedStringValue(descriptionAttr,
messagesBundle);
+
+
int width = (widthAttr != null && widthAttr.length() > 0) ?
Integer.parseInt(widthAttr) : 320;
int height = (heightAttr != null && heightAttr.length() > 0) ?
Integer.parseInt(heightAttr) : 200;
- return new GGWidgetInfo(title, description, width, height, prefsInfo);
+ return new GGWidgetInfo(title, directoryTitle, description, width, height,
prefsInfo);
}
else
{
@@ -196,8 +311,61 @@
}
}
+ private LocalizedString resolveLocalizedStringValue(String value, Map bundle)
+ {
+ if(value != null)
+ {
+ if (value.startsWith("__MSG_"))
+ {
+ String name = value.substring("__MSG_".length(), value.length() -
2);
+
+ if (bundle.containsKey(name))
+ {
+ return (LocalizedString)bundle.get(name);
+ }
+ }
+
+ return new LocalizedString(value, Locale.ENGLISH);
+ }
+
+ return null;
+
+ }
+
+ private String resolveLocalizedValue(String value, Map bundle)
+ {
+ LocalizedString out = resolveLocalizedStringValue(value, bundle);
+
+ if (out != null)
+ {
+ return out.getDefaultString();
+ }
+
+ return null;
+
+ }
+
+
+
+ /**
+ * needed for testing
+ */
protected byte[] obtainWidget(URL url) throws Exception
{
+ return obtainURL(url);
+ }
+
+ /**
+ * needed for testing
+ */
+ protected byte[] obtainLocaleBundle(URL url) throws Exception
+ {
+ return obtainURL(url);
+ }
+
+ private byte[] obtainURL(URL url) throws Exception
+ {
return URLTools.performGET(url, 5000, 5000);
}
+
}
Modified: trunk/widget/src/resources/widget-war/WEB-INF/jsp/edit.jsp
===================================================================
--- trunk/widget/src/resources/widget-war/WEB-INF/jsp/edit.jsp 2007-07-10 11:50:52 UTC
(rev 7703)
+++ trunk/widget/src/resources/widget-war/WEB-INF/jsp/edit.jsp 2007-07-10 12:30:56 UTC
(rev 7704)
@@ -97,7 +97,7 @@
String rowClass = selected ? "portlet-section-selected" :
(i.getIndex() % 2 == 0 ? "portlet-section-body" :
"portlet-section-alternate");
%>
<tr class="<%= rowClass %>">
- <td><a href="<%= selectURL %>"><%=
widget.getTitle().getDefaultString() %></a></td>
+ <td><a href="<%= selectURL %>"><%=
widget.getDirectoryTitle().getDefaultString().length() > 0 ?
widget.getDirectoryTitle().getDefaultString() : widget.getTitle().getDefaultString()
%></a></td>
</tr>
<%
}
@@ -152,7 +152,7 @@
}
%>
<tr>
- <td><%= prefInfo.getName() %>:</td>
+ <td><%= prefInfo.getDisplayName() != null ?
prefInfo.getDisplayName() : prefInfo.getName() %>:</td>
<%
switch (prefInfo.getType().getOrdinal())
{