1 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 20 public class HtmlEditorModule extends BaseEditorModule 21 { 22 27 public void loadView( WebPageRequest inReq) throws Exception 28 { 29 EditorSession session = startEditSession(inReq); 30 inReq.putPageValue("viewcontent", session.getWysiwygSourceVariable() ); 31 inReq.putPageValue("rawviewcontent", session.getWysiwygSource() ); 32 } 34 39 public void loadSource( WebPageRequest inReq ) throws Exception 40 { 41 EditorSession session = startEditSession(inReq); 42 inReq.putPageValue( "sourcecontent", session.getEscapedSource() ); 50 inReq.putPageValue( "documentModified", new Boolean ( session.isDocumentModified() ) ); 52 } 53 54 58 protected EditorSession startEditSession(WebPageRequest inReq) throws OpenEditException 59 { 60 EditorSession inEditorSession = new EditorSession(); 61 String editPath = inReq.getRequestParameter("editPath"); 62 63 String content = null; 64 Page editPage = getPageManager().getPage( editPath ); 65 66 boolean multipleLang = true; 67 String 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 selectedcode = inReq.getLanguage(); 78 String 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 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 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 String 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 139 { 140 EditorSession session = startEditSession(inReq); 142 String 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 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 } 160 179 protected String getContent( String inPath ) throws Exception 180 { 181 Page page = getPageManager().getPage( inPath ); 182 if ( page.exists() ) 183 { 184 return page.getContent(); 185 } 186 return ""; 187 } 188 214 215 } 216 | Popular Tags |