You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2008/04/11 15:30:01 UTC
svn commit: r647161 - in /lenya/trunk/src/modules-core/ac:
config/sitemap/userinfo-transformer.xmap java/src/org/apache/lenya/modules/
java/src/org/apache/lenya/modules/ac/
java/src/org/apache/lenya/modules/ac/UserInfoTransformer.java
Author: andreas
Date: Fri Apr 11 06:29:58 2008
New Revision: 647161
URL: http://svn.apache.org/viewvc?rev=647161&view=rev
Log:
Adding UserInfoTransformer.
Added:
lenya/trunk/src/modules-core/ac/config/sitemap/userinfo-transformer.xmap
lenya/trunk/src/modules-core/ac/java/src/org/apache/lenya/modules/
lenya/trunk/src/modules-core/ac/java/src/org/apache/lenya/modules/ac/
lenya/trunk/src/modules-core/ac/java/src/org/apache/lenya/modules/ac/UserInfoTransformer.java
Added: lenya/trunk/src/modules-core/ac/config/sitemap/userinfo-transformer.xmap
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/ac/config/sitemap/userinfo-transformer.xmap?rev=647161&view=auto
==============================================================================
--- lenya/trunk/src/modules-core/ac/config/sitemap/userinfo-transformer.xmap (added)
+++ lenya/trunk/src/modules-core/ac/config/sitemap/userinfo-transformer.xmap Fri Apr 11 06:29:58 2008
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+<xmap xpath="/sitemap/components/transformers"
+ unless="/sitemap/components/transformers/transformer[@name = 'userInfo']"
+ xmlns:map="http://apache.org/cocoon/sitemap/1.0">
+ <map:transformer name="userInfo" logger="lenya.sitemap.transformer.userInfo"
+ src="org.apache.lenya.modules.ac.UserInfoTransformer"/>
+</xmap>
Added: lenya/trunk/src/modules-core/ac/java/src/org/apache/lenya/modules/ac/UserInfoTransformer.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/ac/java/src/org/apache/lenya/modules/ac/UserInfoTransformer.java?rev=647161&view=auto
==============================================================================
--- lenya/trunk/src/modules-core/ac/java/src/org/apache/lenya/modules/ac/UserInfoTransformer.java (added)
+++ lenya/trunk/src/modules-core/ac/java/src/org/apache/lenya/modules/ac/UserInfoTransformer.java Fri Apr 11 06:29:58 2008
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.lenya.modules.ac;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.transformation.AbstractSAXTransformer;
+import org.apache.lenya.ac.AccessControlException;
+import org.apache.lenya.ac.User;
+import org.apache.lenya.cms.ac.PolicyUtil;
+import org.apache.lenya.util.ServletHelper;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+
+/**
+ * <p>
+ * Transformer to retrieve user information based on the user ID. The user ID can
+ * either be provided using the <em>userId</em> attribute or as text inside the element.
+ * </p>
+ * <p>Elements:</p>
+ * <ul>
+ * <li><code><user:fullname></code> - The full name. If the user doesn't exist, the user ID is inserted.</li>
+ * </ul>
+ * <p>
+ * Usage examples:
+ * </p>
+ * <pre><code>
+ * <user:fullname>john</user:fullname>
+ *
+ * <user:fullname userId="john"/>
+ * </code></pre>
+ */
+public class UserInfoTransformer extends AbstractSAXTransformer {
+
+ protected static final String ATTR_USER_ID = "userId";
+ protected static final String ELEM_FULLNAME = "fullname";
+ protected static final String NAMESPACE = "http://apache.org/lenya/userinfo/1.0";
+ private String userId;
+ private String url;
+
+ public UserInfoTransformer() {
+ this.defaultNamespaceURI = NAMESPACE;
+ }
+
+ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters params)
+ throws ProcessingException, SAXException, IOException {
+ super.setup(resolver, objectModel, src, params);
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ this.url = ServletHelper.getWebappURI(request);
+
+ }
+
+ public void startTransformingElement(String uri, String name, String raw, Attributes attr)
+ throws ProcessingException, IOException, SAXException {
+ if (name.equals(ELEM_FULLNAME)) {
+ String userId = attr.getValue(ATTR_USER_ID);
+ if (userId != null) {
+ this.userId = userId;
+ } else {
+ startTextRecording();
+ }
+ }
+ }
+
+ public void endTransformingElement(String uri, String name, String raw)
+ throws ProcessingException, IOException, SAXException {
+ if (name.equals(ELEM_FULLNAME)) {
+ String userId = this.userId != null ? this.userId : endTextRecording();
+ try {
+ User user = PolicyUtil.getUser(this.manager, this.url, userId, getLogger());
+ String output = user != null ? user.getName() : userId;
+ char[] chars = output.toCharArray();
+ characters(chars, 0, chars.length);
+ } catch (AccessControlException e) {
+ throw new ProcessingException(e);
+ }
+ this.userId = null;
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org