dlestrat 2004/06/07 18:35:16
Modified: portal/src/java/org/apache/jetspeed/tools/pamanager/rules
LocalizedFieldRule.java PortletRule.java
Added: portal/src/java/org/apache/jetspeed/tools/pamanager/rules
UserAttributeRefRuleSet.java
UserAttributeRefRule.java
Log:
Finalizing http://nagoya.apache.org/jira/browse/JS2-64
Revision Changes Path
1.6 +83 -47
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/rules/LocalizedFieldRule.java
Index: LocalizedFieldRule.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/rules/LocalizedFieldRule.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- LocalizedFieldRule.java 5 Jun 2004 16:19:19 -0000 1.5
+++ LocalizedFieldRule.java 8 Jun 2004 01:35:16 -0000 1.6
@@ -18,61 +18,82 @@
import java.util.Locale;
import org.apache.commons.digester.Rule;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.apache.jetspeed.om.common.GenericMetadata;
import org.apache.jetspeed.om.common.LocalizedField;
+import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
+import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
+
import org.xml.sax.Attributes;
/**
* This class helps load internationalized fields
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Jeremy Ford</a>
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jeremy Ford </a>
* @version $Id$
*/
public class LocalizedFieldRule extends Rule
{
protected final static Log log = LogFactory.getLog(LocalizedFieldRule.class);
-
+
/**
* Handle the beginning of an XML element.
- *
- * @param attributes The attributes of this element
- * @exception Exception if a processing error occurs
+ *
+ * @param attributes
+ * The attributes of this element
+ * @exception Exception
+ * if a processing error occurs
*/
- public void begin(String namespace, String name, Attributes attributes)
- throws Exception {
+ public void begin(String namespace, String name, Attributes attributes) throws
Exception
+ {
if (digester.getLogger().isDebugEnabled())
digester.getLogger().debug("Setting localized field " + name);
- GenericMetadata metadata = (GenericMetadata)digester.peek();
- if(metadata != null)
- {
- LocalizedField child = metadata.createLocalizedField();
-
- if(name.equals("metadata"))
- {
- String nameAttr = attributes.getValue("name");
- child.setName(nameAttr);
- }
- else
- {
- child.setName(name);
- }
- String language = attributes.getValue("xml:lang");
- Locale locale = null;
- if(language == null)
- {
- locale = new Locale("en");
- }
- else
- {
- locale = new Locale(language);
- }
-
- child.setLocale(locale);
- digester.push(child);
+ Object obj = digester.peek();
+ if (null == obj)
+ {
+ digester.push(null);
+ return;
+ }
+ GenericMetadata metadata = null;
+ if (obj instanceof MutablePortletApplication)
+ {
+ metadata = ((MutablePortletApplication) obj).getMetadata();
+ }
+ if (obj instanceof PortletDefinitionComposite)
+ {
+ metadata = ((PortletDefinitionComposite) obj).getMetadata();
+ }
+ if (metadata != null)
+ {
+ LocalizedField child = metadata.createLocalizedField();
+
+ if (name.equals("metadata"))
+ {
+ String nameAttr = attributes.getValue("name");
+ child.setName(nameAttr);
+ }
+ else
+ {
+ child.setName(name);
+ }
+ String language = attributes.getValue("xml:lang");
+ Locale locale = null;
+ if (language == null)
+ {
+ locale = new Locale("en");
+ }
+ else
+ {
+ locale = new Locale(language);
+ }
+
+ child.setLocale(locale);
+ digester.push(child);
}
else
{
@@ -80,24 +101,39 @@
}
}
- public void body(String namespace, String name, String text)
- throws Exception
+ public void body(String namespace, String name, String text) throws Exception
{
LocalizedField child = (LocalizedField) digester.peek(0);
- if(child != null)
- {
+ if (child != null)
+ {
child.setValue(text);
}
}
- public void end(String namespace, String name)
- throws Exception
+ public void end(String namespace, String name) throws Exception
{
LocalizedField child = (LocalizedField) digester.pop();
- if(child != null)
- {
- GenericMetadata metadata = (GenericMetadata)digester.peek();
- metadata.addField(child);
+ if (child != null)
+ {
+ Object obj = digester.peek();
+ if (null == obj)
+ {
+ digester.push(null);
+ return;
+ }
+ GenericMetadata metadata = null;
+ if (obj instanceof MutablePortletApplication)
+ {
+ metadata = ((MutablePortletApplication) obj).getMetadata();
+ }
+ if (obj instanceof PortletDefinitionComposite)
+ {
+ metadata = ((PortletDefinitionComposite) obj).getMetadata();
+ }
+ if (null != metadata)
+ {
+ metadata.addField(child);
+ }
}
}
-}
+}
\ No newline at end of file
1.4 +2 -9
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/rules/PortletRule.java
Index: PortletRule.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/rules/PortletRule.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PortletRule.java 5 Jun 2004 16:19:19 -0000 1.3
+++ PortletRule.java 8 Jun 2004 01:35:16 -0000 1.4
@@ -42,13 +42,6 @@
{
log.debug("Found portlet name " + name);
PortletDefinitionComposite def = (PortletDefinitionComposite)
app.getPortletDefinitionByName(text);
- if (def != null)
- {
- digester.push(def.getMetadata());
- }
- else
- {
- digester.push(null);
- }
+ digester.push(def);
}
}
1.1
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/rules/UserAttributeRefRuleSet.java
Index: UserAttributeRefRuleSet.java
===================================================================
/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.tools.pamanager.rules;
import org.apache.commons.digester.Digester;
import org.apache.commons.digester.RuleSetBase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
import org.apache.jetspeed.om.impl.UserAttributeRefImpl;
/**
* This class helps load the jetspeed portlet extension user attributes.
*
* @author <a href="mailto:[EMAIL PROTECTED]">David Le Strat</a>
*/
public class UserAttributeRefRuleSet extends RuleSetBase
{
protected final static Log log =
LogFactory.getLog(UserAttributeRefRuleSet.class);
private MutablePortletApplication app;
public UserAttributeRefRuleSet(MutablePortletApplication app)
{
this.app = app;
}
/**
* @see
org.apache.commons.digester.RuleSet#addRuleInstances(org.apache.commons.digester.Digester)
*/
public void addRuleInstances(Digester digester)
{
digester.addObjectCreate("portlet-app/user-attribute-ref",
UserAttributeRefImpl.class);
digester.addBeanPropertySetter("portlet-app/user-attribute-ref/name",
"name");
digester.addBeanPropertySetter("portlet-app/user-attribute-ref/name-link",
"nameLink");
digester.addRule("portlet-app/user-attribute-ref", new
UserAttributeRefRule(app));
}
}
1.1
jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/rules/UserAttributeRefRule.java
Index: UserAttributeRefRule.java
===================================================================
/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.tools.pamanager.rules;
import org.apache.commons.digester.Rule;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jetspeed.om.common.UserAttributeRef;
import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
/**
* This class helps load the jetspeed portlet extension user attributes.
*
* @author <a href="mailto:[EMAIL PROTECTED]">David Le Strat</a>
*/
public class UserAttributeRefRule extends Rule
{
protected final static Log log = LogFactory.getLog(UserAttributeRefRule.class);
private MutablePortletApplication app;
public UserAttributeRefRule(MutablePortletApplication app)
{
this.app = app;
}
public void end(String namespace, String name) throws Exception
{
UserAttributeRef userAttributeRef = (UserAttributeRef) digester.peek(0);
app.addUserAttributeRef(userAttributeRef);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]