You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2010/01/22 04:57:33 UTC
svn commit: r901979 - in /incubator/jspwiki/trunk/src:
WebContent/WEB-INF/classes/ WebContent/admin/
WebContent/templates/default/admin/ java/org/apache/wiki/action/
java/org/apache/wiki/ui/stripes/
Author: ajaquith
Date: Fri Jan 22 03:57:32 2010
New Revision: 901979
URL: http://svn.apache.org/viewvc?rev=901979&view=rev
Log:
The admin/Admin.jsp JSP receives the Stripes treatment, but badly. It doesn't work and will need to be fixed.
Added:
incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/AdminBeanTypeConverter.java
Removed:
incubator/jspwiki/trunk/src/WebContent/templates/default/admin/AdminTemplate.jsp
Modified:
incubator/jspwiki/trunk/src/WebContent/WEB-INF/classes/CoreResources.properties
incubator/jspwiki/trunk/src/WebContent/admin/Admin.jsp
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/AdminActionBean.java
Modified: incubator/jspwiki/trunk/src/WebContent/WEB-INF/classes/CoreResources.properties
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/WEB-INF/classes/CoreResources.properties?rev=901979&r1=901978&r2=901979&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/WebContent/WEB-INF/classes/CoreResources.properties (original)
+++ incubator/jspwiki/trunk/src/WebContent/WEB-INF/classes/CoreResources.properties Fri Jan 22 03:57:32 2010
@@ -379,3 +379,4 @@
org.apache.wiki.content.inspect.PasswordChallenge.description = To confirm your changes, enter your password.
captcha = CAPTCHA test
changed.email = When you save this page, we will use your profile's e-mail {0} instead of the cookie value {1}. If you want to use {1} instead, change the e-mail address in your profile.
+AdminBeanTypeConverter.illegalAdminBean = AdminBean with ID {2} was not found.
\ No newline at end of file
Modified: incubator/jspwiki/trunk/src/WebContent/admin/Admin.jsp
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/WebContent/admin/Admin.jsp?rev=901979&r1=901978&r2=901979&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/WebContent/admin/Admin.jsp (original)
+++ incubator/jspwiki/trunk/src/WebContent/admin/Admin.jsp Fri Jan 22 03:57:32 2010
@@ -18,68 +18,64 @@
specific language governing permissions and limitations
under the License.
--%>
-<%@ page import="org.apache.wiki.log.Logger" %>
-<%@ page import="org.apache.wiki.log.LoggerFactory" %>
-<%@ page import="org.apache.wiki.*" %>
-<%@ page import="org.apache.wiki.ui.admin.*" %>
-<%@ page import="org.apache.wiki.ui.TemplateManager" %>
-<%@ page import="org.apache.commons.lang.time.StopWatch" %>
+<%@ page import="org.apache.wiki.WikiContext" %>
<%@ page errorPage="/Error.jsp" %>
<%@ taglib uri="http://jakarta.apache.org/jspwiki.tld" prefix="wiki" %>
-<%@ page import="org.apache.wiki.util.TextUtil" %>
-<%!
- Logger log = LoggerFactory.getLogger("JSPWiki");
-%>
-<%
- String bean = request.getParameter("bean");
- WikiEngine wiki = WikiEngine.getInstance( getServletConfig() );
- // Create wiki context and check for authorization
- WikiContext wikiContext = wiki.createContext( request, WikiContext.ADMIN );
+<%@ taglib uri="http://stripes.sourceforge.net/stripes.tld" prefix="s" %>
+<s:useActionBean beanclass="org.apache.wiki.action.AdminActionBean" event="view" id="admin" executeResolution="true" />
+<s:layout-render name="${templates['DefaultLayout.jsp']}">
+ <s:layout-component name="content">
+ <h1>JSPWiki Administration</h1>
+ <div class="information">Not all things can be configured here. Some things need to be configured
+ in your <tt>jspwiki.properties</tt> file.</div>
- //
- // This is an experimental feature, so we will turn it off unless the
- // user really wants to.
- //
- if( !TextUtil.isPositive(wiki.getWikiProperties().getProperty("jspwiki-x.adminui.enable")) )
- {
- %>
- <html>
- <body>
- <h1>Disabled</h1>
- <p>JSPWiki admin UI has been disabled. This is an experimental feature, and is
- not guaranteed to work. You may turn it on by specifying</p>
- <pre>
- jspwiki-x.adminui.enable=true
- </pre>
- <p>in your <tt>jspwiki.properties</tt> file.</p>
- <p>Have a nice day. Don't forget to eat lots of fruits and vegetables.</p>
- </body>
- </html>
- <%
- return;
- }
-
- // Set the content type and include the response content
- response.setContentType("text/html; charset="+wiki.getContentEncoding() );
- String contentPage = wiki.getTemplateManager().findJSP( pageContext,
- wikiContext.getTemplate(),
- "admin/AdminTemplate.jsp" );
+ <wiki:TabbedSection defaultTab="${param['tab']}">
+
+ <wiki:Tab id="users" title="Users">
+ <wiki:Include page="admin/UserManagement.jsp" />
+ </wiki:Tab>
+
+ <wiki:Tab id="groups" title="Groups">
+ <div>
+ <p>This is a list of all groups in this wiki. If you click on the group name,
+ you will be taken to the administration page of that particular group.</p>
+ <p><wiki:Plugin plugin="Groups" /></p>
+ </div>
+ </wiki:Tab>
+
+ <wiki:AdminBeanIterator type="core" id="ab">
+ <wiki:Tab id="${ab.id}" title="${ab.title}">
+ <div class="formcontainer">
+ <s:form beanclass="org.apache.wiki.action.AdminActionBean" method="post" acceptcharset="UTF-8">
+ <s:hidden name="tab-admin" value="core" />
+ <s:hidden name="tab-core" value="${ab.title}" />
+ <s:hidden name="bean" value="${ab.id}" />
+ <%= ab.doGet( (WikiContext)request.getAttribute( "wikiActionBeanContext" ) ) %>
+ <s:submit name="admin" value="Submit" />
+ </s:form>
+ </div>
+ </wiki:Tab>
+ </wiki:AdminBeanIterator>
+
+ <wiki:AdminBeanIterator type="editors" id="ab">
+ <wiki:Tab id="${ab.id}" title="${ab.title}">
+ <div class="formcontainer">
+ <s:form beanclass="org.apache.wiki.action.AdminActionBean" method="post" acceptcharset="UTF-8">
+ <s:hidden name="tab-admin" value="editors" />
+ <s:hidden name="tab-editors" value="${ab.title}" />
+ <s:hidden name="bean" value="${ab.id}" />
+ <%= ab.doGet( (WikiContext)request.getAttribute( "wikiActionBeanContext" ) ) %>
+ <s:submit name="admin" value="Submit" />
+ </s:form>
+ </div>
+ </wiki:Tab>
+ </wiki:AdminBeanIterator>
- pageContext.setAttribute( "engine", wiki, PageContext.REQUEST_SCOPE );
- pageContext.setAttribute( "context", wikiContext, PageContext.REQUEST_SCOPE );
-
- if( request.getMethod().equalsIgnoreCase("post") && bean != null )
- {
- AdminBean ab = wiki.getAdminBeanManager().findBean( bean );
+ <wiki:Tab id="filters" title="Filters">
+ <p>There will be more filter stuff here</p>
+ </wiki:Tab>
- if( ab != null )
- {
- ab.doPost( wikiContext );
- }
- else
- {
- wikiContext.getWikiSession().addMessage( "No such bean "+bean+" was found!" );
- }
- }
-
-%><wiki:Include page="<%=contentPage%>" />
\ No newline at end of file
+ </wiki:TabbedSection>
+ </div>
+ </s:layout-component>
+</s:layout-render>
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/AdminActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/AdminActionBean.java?rev=901979&r1=901978&r2=901979&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/AdminActionBean.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/AdminActionBean.java Fri Jan 22 03:57:32 2010
@@ -5,29 +5,37 @@
import javax.servlet.http.HttpServletResponse;
import net.sourceforge.stripes.action.*;
+import net.sourceforge.stripes.validation.Validate;
import org.apache.wiki.WikiEngine;
import org.apache.wiki.auth.SecurityVerifier;
+import org.apache.wiki.auth.permissions.AllPermission;
+import org.apache.wiki.ui.admin.AdminBean;
+import org.apache.wiki.ui.stripes.HandlerPermission;
import org.apache.wiki.util.TextUtil;
/**
- * Administration actions
+ * Administrative actions, including {@link AdminBean} execution and security
+ * configuration.
*/
public class AdminActionBean extends AbstractActionBean
{
+ private AdminBean m_bean = null;
+
private SecurityVerifier m_securityVerifier = null;
-
+
/**
- * If the security configuration UI is enabled, this method initializes a new
- * {@link SecurityVerifier} and forwards the user to {@code /admin/SecurityConfig.jsp}.
+ * If the security configuration UI is enabled, this method initializes a
+ * new {@link SecurityVerifier} and forwards the user to {@code
+ * /admin/SecurityConfig.jsp}.
+ *
* @return the resolution
*/
- @DefaultHandler
@HandlesEvent( "security" )
public Resolution security()
{
WikiEngine engine = getContext().getEngine();
- if( TextUtil.isPositive(engine.getWikiProperties().getProperty("jspwiki-x.securityconfig.enable")) )
+ if( TextUtil.isPositive( engine.getWikiProperties().getProperty( "jspwiki-x.securityconfig.enable" ) ) )
{
return new StreamingResolution( "text/html" ) {
public void stream( HttpServletResponse response ) throws Exception
@@ -37,19 +45,97 @@
}
};
}
- else
- {
- m_securityVerifier = new SecurityVerifier( engine, getContext().getWikiSession() );
- return new ForwardResolution( "/admin/SecurityConfig.jsp" );
- }
+ m_securityVerifier = new SecurityVerifier( engine, getContext().getWikiSession() );
+ return new ForwardResolution( "/admin/SecurityConfig.jsp" );
}
-
+
/**
* Returns the initialized SecurityVerifier.
+ *
* @return the verifier
*/
public SecurityVerifier getVerifier()
{
return m_securityVerifier;
}
+
+ /**
+ * Return the AdminBean set for this AdminActionBean, which may be {@code
+ * null}.
+ *
+ * @return the admin bean
+ */
+ public AdminBean getBean()
+ {
+ return m_bean;
+ }
+
+ /**
+ * Sets the AdminBean for this AdminActionBean.
+ *
+ * @param bean the admin bean
+ */
+ @Validate( required = true, on = "admin" )
+ public void setBean( AdminBean bean )
+ {
+ m_bean = bean;
+ }
+
+ /**
+ * Returns {@code true} of the Admin UI is enabled.
+ *
+ * @return the result
+ */
+ private boolean isAdminUiEnabled()
+ {
+ // Temporary!
+ return true;
+ }
+
+ /**
+ * If the admin UI is enabled, forwards the user to {@code /admin/Admin.jsp}
+ * .
+ *
+ * @return the resolution
+ */
+ @DefaultHandler
+ @HandlesEvent( "view" )
+ public Resolution view()
+ {
+ if( !isAdminUiEnabled() )
+ {
+ return new StreamingResolution( "text/html" ) {
+ public void stream( HttpServletResponse response ) throws Exception
+ {
+ PrintWriter out = response.getWriter();
+ out.print( "<html><body><p>Admin UI is disabled.</p></body></html>" );
+ }
+ };
+ }
+ return new ForwardResolution( "/admin/Admin.jsp" );
+ }
+
+ /**
+ * If the admin UI is enabled, this method executes
+ * {@link AdminBean#doPost(org.apache.wiki.WikiContext)} for the current
+ * AdminBean and forwards the user to {@code /admin/Admin.jsp}.
+ *
+ * @return the resolution
+ */
+ @HandlesEvent( "admin" )
+ public Resolution admin()
+ {
+ if( !isAdminUiEnabled() )
+ {
+ return new StreamingResolution( "text/html" ) {
+ public void stream( HttpServletResponse response ) throws Exception
+ {
+ PrintWriter out = response.getWriter();
+ out.print( "<html><body><p>Admin UI is disabled.</p></body></html>" );
+ }
+ };
+ }
+ m_bean.doPost( getContext() );
+ return new ForwardResolution( "/admin/Admin.jsp" );
+ }
}
Added: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/AdminBeanTypeConverter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/AdminBeanTypeConverter.java?rev=901979&view=auto
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/AdminBeanTypeConverter.java (added)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/AdminBeanTypeConverter.java Fri Jan 22 03:57:32 2010
@@ -0,0 +1,86 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ 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.wiki.ui.stripes;
+
+import java.util.Collection;
+import java.util.Locale;
+
+import net.sourceforge.stripes.controller.StripesFilter;
+import net.sourceforge.stripes.validation.LocalizableError;
+import net.sourceforge.stripes.validation.TypeConverter;
+import net.sourceforge.stripes.validation.ValidationError;
+
+import org.apache.wiki.WikiEngine;
+import org.apache.wiki.ui.admin.AdminBean;
+import org.apache.wiki.ui.admin.AdminBeanManager;
+
+/**
+ * Stripes type converter that converts an {@link AdminBean} ID, expressed as a
+ * String, into an AdminBean object. This converter is looked up and returned by
+ * the Stripes {@link net.sourceforge.stripes.validation.TypeConverterFactory}
+ * for HTTP request parameters that need to be bound to ActionBean properties of
+ * type AdminBean. Stripes executes this TypeConverter during the
+ * {@link net.sourceforge.stripes.controller.LifecycleStage#BindingAndValidation}
+ * stage of request processing.
+ */
+public class AdminBeanTypeConverter implements TypeConverter<AdminBean>
+{
+ /**
+ * Converts a named AdminBean into a valid {@link AdminBean} object by
+ * retrieving it via the Wiki
+ * {@link org.apache.wiki.ui.admin.AdminBeanManager}. If the bean ID is
+ * illegal, this method will add a validation error to the supplied
+ * Collection of errors. The error will be of type
+ * {@link net.sourceforge.stripes.validation.LocalizableError} and will have
+ * a message key of <code>AdminBeanTypeConverter.illegalAdminBean</code> and
+ * a single parameter {2} (equal to the value passed for <code>beanId</code>
+ * ). If the bean ID does not exist, {@code null} is returned also.
+ *
+ * @param beanId the AdminBean ID to look up
+ * @param targetType the type to return, which will always be of type
+ * {@link AdminBean}
+ * @param errors the current Collection of validation errors for this field
+ * @return the resolved AdminBean
+ */
+ public AdminBean convert( String beanId, Class<? extends AdminBean> targetType, Collection<ValidationError> errors )
+ {
+ WikiRuntimeConfiguration config = (WikiRuntimeConfiguration) StripesFilter.getConfiguration();
+ WikiEngine engine = config.getEngine();
+ AdminBeanManager mgr = engine.getAdminBeanManager();
+ AdminBean bean = mgr.findBean( beanId );
+
+ // AdminBean does not exist
+ if( bean == null )
+ {
+ // Illegal group name
+ errors.add( new LocalizableError( "AdminBeanTypeConverter.illegalAdminBean", beanId ) );
+ }
+ return bean;
+ }
+
+ /**
+ * No-op method that does nothing, because setting the Locale has no effect
+ * on the conversion.
+ */
+ public void setLocale( Locale locale )
+ {
+ };
+}