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 2005/05/13 17:40:31 UTC

svn commit: r170041 - in /lenya/trunk/src: java/org/apache/lenya/cms/ac/usecases/IPRangeGroups.java webapp/WEB-INF/cocoon-xconf.xsl webapp/lenya/usecases/admin/ipRangeGroups.jx

Author: andreas
Date: Fri May 13 08:40:30 2005
New Revision: 170041

URL: http://svn.apache.org/viewcvs?rev=170041&view=rev
Log:
implemented ipRangeGroups usecase

Added:
    lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/IPRangeGroups.java
    lenya/trunk/src/webapp/lenya/usecases/admin/ipRangeGroups.jx
Modified:
    lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl

Added: lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/IPRangeGroups.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/IPRangeGroups.java?rev=170041&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/IPRangeGroups.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/ac/usecases/IPRangeGroups.java Fri May 13 08:40:30 2005
@@ -0,0 +1,136 @@
+/*
+ * Copyright  1999-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.lenya.cms.ac.usecases;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.lenya.ac.Group;
+import org.apache.lenya.ac.IPRange;
+import org.apache.lenya.cms.usecase.UsecaseException;
+
+/**
+ * Usecase to edit a IP range's group affiliation.
+ */
+public class IPRangeGroups extends AccessControlUsecase {
+
+    private IPRange ipRange;
+
+    protected static final String IP_RANGE_GROUPS = "ipRangeGroups";
+    protected static final String OTHER_GROUPS = "otherGroups";
+    protected static final String ADD = "add";
+    protected static final String REMOVE = "remove";
+    protected static final String IP_RANGE_GROUP = "ipRangeGroup";
+    protected static final String OTHER_GROUP = "otherGroup";
+
+    /**
+     * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
+     */
+    protected void doExecute() throws Exception {
+        super.doExecute();
+        
+        this.ipRange.removeFromAllGroups();
+        
+        List ipRangeGroups = (List) getParameter(IP_RANGE_GROUPS);
+        for (Iterator i = ipRangeGroups.iterator(); i.hasNext(); ) {
+            Group group = (Group) i.next();
+            group.add(this.ipRange);
+        }
+        ipRange.save();
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.Usecase#advance()
+     */
+    public void advance() throws UsecaseException {
+        super.advance();
+
+        String add = getParameterAsString(ADD);
+        String remove = getParameterAsString(REMOVE);
+        if (add != null || remove != null) {
+
+            List ipRangeGroups = (List) getParameter(IP_RANGE_GROUPS);
+            List otherGroups = (List) getParameter(OTHER_GROUPS);
+            
+            if (add != null) {
+                String groupId = getParameterAsString(OTHER_GROUP);
+                if (groupId != null) {
+                    if (getLogger().isDebugEnabled()) {
+                        getLogger().debug("add group [" + groupId + "]");
+                    }
+                    Group group = getGroupManager().getGroup(groupId);
+                    ipRangeGroups.add(group);
+                    otherGroups.remove(group);
+                }
+            }
+
+            if (remove != null) {
+                String groupId = getParameterAsString(IP_RANGE_GROUP);
+                if (groupId != null) {
+                    if (getLogger().isDebugEnabled()) {
+                        getLogger().debug("remove group [" + groupId + "]");
+                    }
+                    Group group = getGroupManager().getGroup(groupId);
+                    otherGroups.add(group);
+                    ipRangeGroups.remove(group);
+                }
+            }
+            
+            deleteParameter(ADD);
+            deleteParameter(REMOVE);
+            deleteParameter(IP_RANGE_GROUP);
+            deleteParameter(OTHER_GROUP);
+        }
+
+    }
+
+    /**
+     * @see org.apache.lenya.cms.usecase.Usecase#setParameter(java.lang.String,
+     *      java.lang.Object)
+     */
+    public void setParameter(String name, Object value) {
+        super.setParameter(name, value);
+        if (name.equals(IPRangeProfile.ID)) {
+            String ipRangeId = (String) value;
+            this.ipRange = getIpRangeManager().getIPRange(ipRangeId);
+            if (this.ipRange == null) {
+                throw new RuntimeException("IP range [" + ipRangeId + "] not found.");
+            }
+
+            Group[] ipRangeGroupArray = this.ipRange.getGroups();
+            List ipRangeGroups = new ArrayList(Arrays.asList(ipRangeGroupArray));
+
+            setParameter(IP_RANGE_GROUPS, ipRangeGroups);
+
+            Group[] allGroups = getGroupManager().getGroups();
+
+            List otherGroups = new ArrayList();
+
+            for (int i = 0; i < allGroups.length; i++) {
+                if (!ipRangeGroups.contains(allGroups[i])) {
+                    otherGroups.add(allGroups[i]);
+                }
+            }
+
+            setParameter(OTHER_GROUPS, otherGroups);
+        }
+
+    }
+
+}
\ No newline at end of file

Modified: lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl?rev=170041&r1=170040&r2=170041&view=diff
==============================================================================
--- lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl (original)
+++ lenya/trunk/src/webapp/WEB-INF/cocoon-xconf.xsl Fri May 13 08:40:30 2005
@@ -342,6 +342,11 @@
         <parameter name="tab" value="ipRanges"/>
       </view>
     </component-instance>
+    <component-instance name="admin.ipRangeGroups" logger="lenya.admin" class="org.apache.lenya.cms.ac.usecases.IPRangeGroups">
+      <view template="admin/ipRangeGroups" menu="true">
+        <parameter name="tab" value="ipRanges"/>
+      </view>
+    </component-instance>
     <component-instance name="admin.deleteIPRange" logger="lenya.admin" class="org.apache.lenya.cms.ac.usecases.DeleteIPRange">
       <view template="admin/deleteIPRange" menu="true">
         <parameter name="tab" value="ipRanges"/>

Added: lenya/trunk/src/webapp/lenya/usecases/admin/ipRangeGroups.jx
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/webapp/lenya/usecases/admin/ipRangeGroups.jx?rev=170041&view=auto
==============================================================================
--- lenya/trunk/src/webapp/lenya/usecases/admin/ipRangeGroups.jx (added)
+++ lenya/trunk/src/webapp/lenya/usecases/admin/ipRangeGroups.jx Fri May 13 08:40:30 2005
@@ -0,0 +1,88 @@
+<!--
+  Copyright 1999-2005 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.
+-->
+<!-- $Id: userGroups.jx 164233 2005-04-22 13:01:45Z jwkaltz $ -->
+
+<page:page
+  xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
+  xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0"
+  xmlns="http://www.w3.org/1999/xhtml"
+  xmlns:i18n="http://apache.org/cocoon/i18n/2.1"    
+  >
+  
+  <page:body>
+    <jx:import uri="admin/tabs.jx"/>
+    <div id="contentblock1" class="lenya-tab">
+      <h1><i18n:text>Group Affiliation</i18n:text></h1>
+    <form>
+      <input type="hidden" name="lenya.continuation" value="${continuation.id}"/>
+      <input type="hidden" name="lenya.usecase" value="${request.getParameter('lenya.usecase')}"/>
+
+       <table class="lenya-table-noborder">
+        <tr>
+          <td colspan="2">
+            <jx:import uri="templates/messages.jx"/>
+          </td>
+        </tr>
+      </table>
+
+      <table class="lenya-table-noborder-nopadding">
+        <tr>
+          <td>
+            <strong>
+              <i18n:text>IP Range Groups</i18n:text>
+            </strong>
+          </td>
+          <td/>
+          <td>
+            <strong>
+              <i18n:text>All Groups</i18n:text>
+            </strong>
+          </td>
+        </tr>
+        <tr>
+          <td valign="middle">
+            <select name="ipRangeGroup" size="15" class="lenya-form-element-narrow">
+              <jx:forEach var="group" items="${usecase.getParameter('ipRangeGroups')}">
+                <option value="${group}"><jx:out value="${group}"/></option>
+              </jx:forEach>
+            </select>
+          </td>
+          <td valign="middle">
+            <input name="add" type="submit" value="&lt;"/>
+            <br/>
+            <input name="remove" type="submit" value="&gt;"/>
+          </td>
+          <td valign="middle">
+            <select name="otherGroup" size="15" class="lenya-form-element-narrow">
+              <jx:forEach var="otherGroup" items="${usecase.getParameter('otherGroups')}">
+                <option value="${otherGroup}"><jx:out value="${otherGroup}"/></option>
+              </jx:forEach>
+            </select>
+          </td>
+        </tr>
+        <tr>
+          <td colspan="3" style="text-align: center">
+            <br/>
+            <input i18n:attr="value" type="submit" name="submit" value="Save"/>
+            <input i18n:attr="value" type="submit" name="cancel" value="Cancel"/>
+          </td>
+        </tr>
+      </table>
+
+    </form>
+    </div>
+  </page:body>
+</page:page>
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org