KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > modules > html > HtmlEditorModule


1 /*
2  * Created on Jan 20, 2004
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */

7 package com.openedit.modules.html;
8
9 import com.openedit.OpenEditException;
10 import com.openedit.WebPageRequest;
11 import com.openedit.modules.edit.BaseEditorModule;
12 import com.openedit.page.Page;
13 import com.openedit.util.PathUtilities;
14 import com.openedit.util.URLUtilities;
15
16 /**
17  * @author dbrown
18  * @author Matt Avery, mavery@einnovation.com
19  */

20 public class HtmlEditorModule extends BaseEditorModule
21 {
22     /**
23      * Loads the WYSIWYG view
24      * @param inReq
25      * @throws Exception
26      */

27     public void loadView( WebPageRequest inReq) throws Exception JavaDoc
28     {
29         EditorSession session = startEditSession(inReq);
30         inReq.putPageValue("viewcontent", session.getWysiwygSourceVariable() );
31         inReq.putPageValue("rawviewcontent", session.getWysiwygSource() );
32         //inReq.putPageValue( "documentModified", new Boolean( session.isDocumentModified() ) );
33
}
34     /**
35      * Load the source code into the source code editor
36      * @param inReq
37      * @throws Exception
38      */

39     public void loadSource( WebPageRequest inReq ) throws Exception JavaDoc
40     {
41         EditorSession session = startEditSession(inReq);
42 /* String type = inReq.getRequestParameter("type");
43         if ( "text".equals( type ))
44         {
45             inReq.putPageValue( "sourcecontent", session.getOriginalSource() );
46         }
47         else
48         {
49 */
inReq.putPageValue( "sourcecontent", session.getEscapedSource() );
50     // }
51
inReq.putPageValue( "documentModified", new Boolean JavaDoc( session.isDocumentModified() ) );
52     }
53
54     /**
55      * @param inEditorSession
56      * @param inEditPath
57      */

58     protected EditorSession startEditSession(WebPageRequest inReq) throws OpenEditException
59     {
60         EditorSession inEditorSession = new EditorSession();
61         String JavaDoc editPath = inReq.getRequestParameter("editPath");
62
63         String JavaDoc content = null;
64         Page editPage = getPageManager().getPage( editPath );
65         
66         boolean multipleLang = true;
67         String JavaDoc savein = inReq.getPageProperty("usemultiplelanguages");
68         if ( savein != null )
69         {
70             multipleLang = Boolean.parseBoolean(savein);
71         }
72         else
73         {
74             multipleLang = false;
75         }
76
77         String JavaDoc selectedcode = inReq.getLanguage();
78         String JavaDoc rootdir = "/translations/" + selectedcode;
79         if( multipleLang )
80         {
81             if( selectedcode == null || selectedcode.equals("default") || editPath.startsWith(rootdir) )
82             {
83                 multipleLang = false;
84             }
85         }
86         if( multipleLang )
87         {
88             editPath = rootdir + editPath;
89         }
90         boolean useDraft = createDraft(editPage,inReq.getUser());
91         if ( useDraft)
92         {
93             editPath = PathUtilities.createDraftPath(editPath);
94             Page draft = getPageManager().getPage(editPath);
95             if( draft.exists() )
96             {
97                 //then use this content.
98
content = draft.getContent();
99             }
100             else
101             {
102                 if( editPage.exists() )
103                 {
104                     content = editPage.getContent();
105                 }
106             }
107         }
108         else if( editPage.exists() )
109         {
110             content = editPage.getContent();
111         }
112         if ( content == null)
113         {
114             content = "";
115         }
116         editPage = getPageManager().getPage(editPath);
117         inEditorSession.setEditPage(editPage);
118         inEditorSession.setOriginalSource(content);
119         inEditorSession.setWorkingSource(content);
120         String JavaDoc origUrl = inReq.getRequestParameter("origURL");
121         inEditorSession.setOriginalUrl(origUrl);
122         
123         URLUtilities urlUtilities = (URLUtilities) inReq.getPageValue( "url_util" );
124         if( urlUtilities != null)
125         {
126             inEditorSession.setBasePath( urlUtilities.buildStandard( editPath ) );
127         }
128         //Is this being used anymore?
129
String JavaDoc parentName = inReq.getRequestParameter( "parentName" );
130         inEditorSession.setParentName( parentName );
131
132         inReq.putPageValue( "editorSession", inEditorSession );
133         inReq.putPageValue("editPath",inEditorSession.getEditPath());
134         
135         return inEditorSession;
136     }
137     
138     public void save(WebPageRequest inReq) throws Exception JavaDoc
139     {
140         //Strip the body junk
141
EditorSession session = startEditSession(inReq);
142         String JavaDoc content = inReq.getRequestParameter("content");
143         if( content == null)
144         {
145             content = "";
146         }
147         content = session.removeBaseHrefAndFixQuotes( content );
148         inReq.setRequestParameter("content",content);
149         session.setWorkingSource( content );
150         String JavaDoc path = inReq.getRequestParameter("savepath");
151         if ( path == null)
152         {
153             inReq.setRequestParameter("savepath",session.getEditPath());
154         }
155         inReq.setRequestParameter("editPath",session.getEditPath());
156         writeContent( inReq );
157         
158         //inReq.redirect(session.getOriginalUrl());
159
}
160 /*
161     protected EditorSession getEditorSessionX( WebPageRequest inReq) throws Exception
162     {
163         EditorSession session = (EditorSession)inReq.getSessionValue("EDITOR_SESSION");
164         if ( session == null)
165         {
166             session = new EditorSession();
167             inReq.putSessionValue("EDITOR_SESSION",session);
168         }
169         String editPath = inReq.getRequestParameter("editPath");
170         if ( editPath != null && ( session.getEditPath() == null || !session.getEditPath().equals( editPath ) ) )
171         {
172             startEditSession(session, inReq);
173         }
174         inReq.putPageValue( "editorSession", session );
175         inReq.putPageValue("editPath",session.getEditPath());
176         return session;
177     }
178     */

179     protected String JavaDoc getContent( String JavaDoc inPath ) throws Exception JavaDoc
180     {
181         Page page = getPageManager().getPage( inPath );
182         if ( page.exists() )
183         {
184             return page.getContent();
185         }
186         return "";
187     }
188     /*
189     public String generatePreview( WebPageRequest inReq, Page inPage ) throws Exception
190     {
191         WebPageRequest childContext = inReq.copy(inPage);
192         childContext.putPageValue( "showToolbar", "false");
193         childContext.putPageValue( "editable", "false" );
194         childContext.putPageValue( "preview-generated", "true" );
195         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
196         StringWriter writer = new StringWriter();
197         childContext.putPageValue( PageRequestKeys.OUTPUT_STREAM, outputStream );
198         childContext.putPageValue( PageRequestKeys.OUTPUT_WRITER, writer );
199         childContext.putPageValue( PageRequestKeys.CONTENT, inPage );
200         
201         PageStreamer streamer = inReq.getPageStreamer().copy();
202         streamer.setWebPageRequest( childContext );
203          
204         childContext.putPageStreamer( streamer );
205         streamer.render();
206         String content = outputStream.toString();
207         if ( "".equals( content ) )
208         {
209             content = writer.toString();
210         }
211         return content;
212     }
213     */

214
215 }
216
Popular Tags