Skip to content

Commit

Permalink
SAK-17880 - Committing CKEditor support to trunk
Browse files Browse the repository at this point in the history
git-svn-id: https://source.sakaiproject.org/svn/portal/trunk@83359 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
botimer committed Oct 18, 2010
2 parents 20ce019 + b6e7e11 commit 16ed838
Show file tree
Hide file tree
Showing 12 changed files with 783 additions and 5 deletions.
55 changes: 55 additions & 0 deletions portal/editor-tool/tool/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>portal-base</artifactId>
<groupId>org.sakaiproject</groupId>
<version>2.8-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<name>sakai-editor</name>
<groupId>org.sakaiproject</groupId>
<artifactId>sakai-editor</artifactId>
<organization>
<name>University of Michigan</name>
<url>http://sakaiproject.org/</url>
</organization>
<inceptionYear>2003</inceptionYear>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-kernel-util</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-kernel-api</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-component-manager</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject</groupId>
<artifactId>sakai-portal-api</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject</groupId>
<artifactId>sakai-portal-util</artifactId>
</dependency>
<!--javax.servletservlet-api${sakai.servletapi.version}-->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
</dependency>
</dependencies>
<build>
<resources/>
<sourceDirectory>src/java</sourceDirectory>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/**********************************************************************************
* $URL: $
* $Id: $
***********************************************************************************
*
* Copyright (c) 2010 The Sakai Foundation
*
* Licensed under the Educational Community 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.osedu.org/licenses/ECL-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.sakaiproject.editor;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.portal.api.Editor;
import org.sakaiproject.portal.api.EditorRegistry;
import org.sakaiproject.portal.api.PortalService;
import org.sakaiproject.portal.util.ErrorReporter;
import org.sakaiproject.site.api.ToolConfiguration;
import org.sakaiproject.site.cover.SiteService;
import org.sakaiproject.util.EditorConfiguration;
import org.sakaiproject.util.StringUtil;

public class EditorServlet extends HttpServlet
{

public static final String EDITOR_BOOTSTRAP_JS = "editor-bootstrap.js";
public static final String EDITOR_JS = "editor.js";
public static final String EDITOR_LAUNCH_JS = "editor-launch.js";

public static final PortalService portalService = (PortalService) ComponentManager.get(PortalService.class);
public static final EditorRegistry editorRegistry = (EditorRegistry) ComponentManager.get(EditorRegistry.class);

/** Our log (commons). */
private static Log M_log = LogFactory.getLog(EditorServlet.class);

/**
* Access the Servlet's information display.
*
* @return servlet information.
*/
@Override
public String getServletInfo()
{
return "Sakai Rich-text Editor Support";
}

/**
* Initialize the servlet.
*
* @param config
* The servlet config.
* @throws ServletException
*/
@Override
public void init(ServletConfig config) throws ServletException
{
super.init(config);

M_log.info("init()");
}

/**
* Shutdown the servlet.
*/
@Override
public void destroy()
{
M_log.info("destroy()");

super.destroy();
}

/**
* Respond to navigation / access requests.
*
* @param req
* The servlet request.
* @param res
* The servlet response.
* @throws ServletException.
* @throws IOException.
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
try
{
// this is either going to be editor.js or editor-launch.js
String path = req.getPathInfo();
if ((path == null) || (path.length() <= 1)) throw new Exception("no path");

// get the requested file, ignoring the first "/"
String[] parts = StringUtil.splitFirst(path.substring(1), "/");
String name = parts[0];

String placementId = req.getParameter("placement");
ToolConfiguration tool = SiteService.findTool(placementId);

Editor editor = portalService.getActiveEditor(tool);

if (EDITOR_JS.equals(name)) {
res.sendRedirect(editor.getEditorUrl());
//res.sendRedirect("/library/editor/FCKeditor/fckeditor.js");
//res.sendRedirect("/library/editor/ckeditor/ckeditor.js");
}
else if (EDITOR_LAUNCH_JS.equals(name)) {
res.sendRedirect(editor.getLaunchUrl());
//res.sendRedirect("/library/editor/launchfck.js");
//res.sendRedirect("/library/editor/ckeditor.launch.js");
}
else if (EDITOR_BOOTSTRAP_JS.equals(name)) {
res.addHeader("Pragma", "no-cache");
res.addHeader("Cache-Control", "no-cache");
res.addHeader("Content-Type", "text/javascript");

//Note that this is the same stuff as in SkinnableCharonPortal. We should probably do a bit of refactoring.
PrintWriter out = res.getWriter();
out.print("var sakai = sakai || {}; sakai.editor = sakai.editor || {}; \n");
out.print("sakai.editor.collectionId = '" + portalService.getBrowserCollectionId(tool) + "';\n");
out.print("sakai.editor.enableResourceSearch = '" + EditorConfiguration.enableResourceSearch() + "';\n");
out.print(editor.getPreloadScript());
}
else {
throw new Exception("unrecognized request");
}

}
catch (Throwable t)
{
doError(req, res, t);
}
}

protected void doError(HttpServletRequest req, HttpServletResponse res, Throwable t)
{
ErrorReporter err = new ErrorReporter();
err.report(req, res, t);
}

/**
* Respond to data posting requests.
*
* @param req
* The servlet request.
* @param res
* The servlet response.
* @throws ServletException.
* @throws IOException.
*/
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
doGet(req, res);
}
}
47 changes: 47 additions & 0 deletions portal/editor-tool/tool/src/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>sakai-editor</display-name>
<description>sakai-editor</description>

<filter>
<filter-name>sakai.request</filter-name>
<filter-class>org.sakaiproject.util.RequestFilter</filter-class>
<!-- Portal URLs encode the placement, so we don't need it added -->
<init-param>
<param-name>tool.placement</param-name>
<param-value>none</param-value>
</init-param>
<!-- Don't parse file uploads in the portal, since a tool may handle this itself. -->
<init-param>
<param-name>upload.enabled</param-name>
<param-value>false</param-value>
</init-param>
<!-- MUST set character encoding in the portal, before parameters are read. -->
<init-param>
<param-name>encoding.enabled</param-name>
<param-value>true</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>sakai.request</filter-name>
<servlet-name>sakai.editor</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>

<servlet>
<servlet-name>sakai.editor</servlet-name>
<servlet-class>org.sakaiproject.editor.EditorServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>sakai.editor</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

</web-app>
1 change: 1 addition & 0 deletions portal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<url>https://source.sakaiproject.org/svn/portal/trunk</url>
</scm>
<modules>
<module>editor-tool/tool</module>
<module>portal-api/api</module>
<module>portal-charon/charon</module>
<module>portal-impl/impl</module>
Expand Down
Loading

0 comments on commit 16ed838

Please sign in to comment.