KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > shim > NavModuleForm


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21 package com.methodhead.shim;
22
23 import java.io.Serializable JavaDoc;
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25
26 import org.apache.struts.action.ActionMapping;
27 import org.apache.struts.action.ActionErrors;
28 import org.apache.struts.action.ActionError;
29 import org.apache.struts.validator.DynaValidatorForm;
30 import java.util.List JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import org.apache.struts.util.LabelValueBean;
34 import com.methodhead.sitecontext.SiteContext;
35 import com.methodhead.auth.AuthUtil;
36 import com.methodhead.tree.Tree;
37 import org.apache.commons.lang.StringUtils;
38 import java.io.File JavaDoc;
39
40 public final class NavModuleForm
41 extends
42   DynaValidatorForm
43 implements
44   Serializable JavaDoc {
45
46   /**
47    * Instantiates the policy for this action.
48    */

49   private ShimPolicy getPolicy(
50     ActionMapping mapping ) {
51
52     try {
53       return
54         ( ShimPolicy )Class.forName( mapping.getParameter() ).newInstance();
55     }
56     catch ( Exception JavaDoc e ) {
57       throw new ShimException(
58         "Unexpected exception while instantiating \"" +
59         mapping.getParameter() +"\":" + e.getMessage() );
60     }
61   }
62
63 /*
64   public void reset(
65     ActionMapping mapping,
66     HttpServletRequest request ) {
67
68     //
69     // don't do anything if no one is logged in; action will forward to login
70     //
71     if ( AuthUtil.getUser( request ) == null )
72       return;
73
74     ShimPolicy policy = getPolicy( mapping );
75
76     //
77     // get page options
78     //
79     Page page = policy.newPage();
80     page.setSiteContext( SiteContext.getContext( request ) );
81     List pages = page.loadAll();
82
83     List pageOptions = new ArrayList();
84     pageOptions.add( new LabelValueBean( "Select...", "" ) );
85     for ( Iterator iter = pages.iterator(); iter.hasNext(); ) {
86       Page p = ( Page )iter.next();
87       pageOptions.add( new LabelValueBean( p.getString( "title" ), "" + p.getInt( "id" ) ) );
88     }
89
90     set( "pages", pageOptions );
91   }
92 */

93
94   public ActionErrors validate(
95     ActionMapping mapping,
96     HttpServletRequest JavaDoc request ) {
97
98     //
99
// don't do anything if we're cancelling
100
//
101
if ( !StringUtils.isBlank( ( String JavaDoc )get( "cancel" ) ) )
102       return new ActionErrors();
103
104     ActionErrors errors = super.validate( mapping, request );
105
106     if ( errors.size() == 0 ) {
107
108       if ( "jsp".equals( get( "type" ) ) ) {
109         if ( StringUtils.isBlank( ( String JavaDoc )get( "jsp" ) ) ) {
110           errors.add( "jsp", new ActionError( "shim.navModuleForm.missingJsp" ) );
111         }
112         else {
113           //
114
// verify jsp exists
115
//
116
File JavaDoc file =
117             new File JavaDoc( request.getSession().getServletContext().getRealPath(
118               "/WEB-INF/resources/" +
119               SiteContext.getContext( request ).getInt( "id" ) + "/" +
120               get( "jsp" ) ) );
121
122           if ( !file.exists() || !file.isFile() )
123             errors.add(
124               "jsp", new ActionError( "shim.navModuleForm.invalidJsp" ) );
125         }
126       }
127     }
128     return errors;
129   }
130 }
131
Popular Tags