Ticket #3371: spring_connector.patch

File spring_connector.patch, 19.3 KB (added by Darran, 15 years ago)

spring conenctor project patch

  • java-core/src/main/java/net/fckeditor/connector/ConnectorServlet.java

     
    7777public class ConnectorServlet extends HttpServlet {
    7878        private static final long serialVersionUID = -5742008970929377161L;
    7979        private static final Logger logger = LoggerFactory.getLogger(ConnectorServlet.class);
    80         private Dispatcher dispatcher;
     80        protected Dispatcher dispatcher;
    8181
    8282        /**
    8383         * Initializes the {@link Dispatcher}.
  • java-core/src/main/java/net/fckeditor/connector/Dispatcher.java

     
    8080                this.connector = ConnectorHandler.getConnector();
    8181                this.connector.init(servletContext);
    8282        }
     83       
     84        //TODO Arguably the Connector should be passed into this class
     85        //not the Servlet context or ConecntorHandler
     86        //as this adds a unnecessary dependency on these classes
     87        public Dispatcher(Connector connector){
     88                this.connector = connector;
     89        }
    8390
    8491        /**
    8592         * Manages <code>GET</code> requests (<code>GetFolders</code>,
  • java-core/src/main/java/net/fckeditor/handlers/ConnectorHandler.java

     
    4646                        logger.error("Empty Connector implementation class name provided");
    4747                else {
    4848                        try {
    49                                 Class<?> clazz = Class.forName(className);
     49                                //Class<?> clazz = Class.forName(className);
     50                                Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
    5051                                connector = (Connector) clazz.newInstance();
    5152                                logger.info("Connector initialized to {}", className);
    5253                        } catch (Throwable e) {
  • java-demo/pom.xml

     
    1111                        <version>2.5-SNAPSHOT</version>
    1212                </dependency>
    1313                <dependency>
     14                        <groupId>net.fckeditor</groupId>
     15                        <artifactId>spring-connector</artifactId>
     16                        <version>2.5-SNAPSHOT</version>
     17                </dependency>
     18               
     19                <dependency>
    1420                        <groupId>org.slf4j</groupId>
    1521                        <artifactId>slf4j-simple</artifactId>
    1622                        <version>${slf4j.version}</version>
    1723                        <scope>runtime</scope>
    1824                </dependency>
     25                <dependency>
     26                <groupId>javax.servlet</groupId>
     27                        <artifactId>servlet-api</artifactId>
     28                        <version>2.4</version>
     29                        <scope>provided</scope>
     30                </dependency>
    1931        </dependencies>
    2032        <parent>
    2133                <groupId>net.fckeditor</groupId>
  • java-demo/src/main/java/net/fckeditor/sample/spring/FCKEditorConnector.java

     
     1package net.fckeditor.sample.spring;
     2
     3import java.io.InputStream;
     4import java.util.List;
     5import java.util.Map;
     6
     7import javax.servlet.ServletContext;
     8
     9import net.fckeditor.connector.Connector;
     10import net.fckeditor.connector.exception.FolderAlreadyExistsException;
     11import net.fckeditor.connector.exception.InvalidCurrentFolderException;
     12import net.fckeditor.connector.exception.InvalidNewFolderNameException;
     13import net.fckeditor.connector.exception.ReadException;
     14import net.fckeditor.connector.exception.WriteException;
     15import net.fckeditor.connector.impl.AbstractLocalFileSystemConnector;
     16import net.fckeditor.handlers.ResourceType;
     17
     18/**
     19 * This example will upload files to /spring_connector in the server root
     20 * directory
     21 * @author whiteda
     22 *
     23 */
     24public class FCKEditorConnector extends AbstractLocalFileSystemConnector {
     25        public static final String USER_PATH = "/spring_connector";
     26        @Override
     27        protected String getRealUserFilesAbsolutePath(String path) {
     28                return USER_PATH+path;
     29        }
     30
     31        public void init(ServletContext servletContext) throws Exception {
     32                this.servletContext = servletContext;
     33        }
     34
     35}
  • java-demo/src/main/webapp/jsp/sample06.config.js

     
    4141var sOtherPluginPath = FCKConfig.BasePath.substr(0, FCKConfig.BasePath.length - 7) + 'editor/plugins/' ;
    4242FCKConfig.Plugins.Add( 'placeholder', 'en,it', sOtherPluginPath ) ;
    4343//FCKConfig.Plugins.Add( 'tablecommands', 'en,it', sOtherPluginPath ) ;
     44
     45FCKConfig.ImageUpload = true ;
     46FCKConfig.ImageUploadURL = FCKConfig.BasePath + 'filemanager/connectors/' + _QuickUploadLanguage + '/upload.' + _QuickUploadExtension + '?Type=Image' ;
     47FCKConfig.ImageUploadAllowedExtensions  = ".(jpg|gif|jpeg|png|bmp)$" ;          // empty for all
     48FCKConfig.ImageUploadDeniedExtensions   = "" ; 
     49 No newline at end of file
  • java-demo/src/main/webapp/jsp/sample08.jsp

     
     1<?xml version="1.0" encoding="UTF-8" ?>
     2<%@ page language="java" contentType="text/html; charset=UTF-8"
     3        pageEncoding="UTF-8" %>
     4<%@ taglib uri="http://java.fckeditor.net" prefix="FCK" %>
     5<%--
     6 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
     7 * Copyright (C) 2004-2009 Frederico Caldeira Knabben
     8 *
     9 * == BEGIN LICENSE ==
     10 *
     11 * Licensed under the terms of any of the following licenses at your
     12 * choice:
     13 *
     14 *  - GNU General Public License Version 2 or later (the "GPL")
     15 *    http://www.gnu.org/licenses/gpl.html
     16 *
     17 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
     18 *    http://www.gnu.org/licenses/lgpl.html
     19 *
     20 *  - Mozilla Public License Version 1.1 or later (the "MPL")
     21 *    http://www.mozilla.org/MPL/MPL-1.1.html
     22 *
     23 * == END LICENSE ==
     24 * @version: $Id: sample07.jsp 2869 2009-01-09 22:01:33Z mosipov $
     25--%>
     26<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     27"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     28<html xmlns="http://www.w3.org/1999/xhtml">
     29        <head>
     30                <title>FCKeditor - Sample</title>
     31                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     32                <meta name="robots" content="noindex, nofollow" />
     33                <link href="../sample.css" rel="stylesheet" type="text/css" />
     34                <link rel="shortcut icon" href="../fckeditor.gif"
     35                                type="image/x-icon" />
     36                <script type="text/javascript">
     37                        function FCKeditor_OnComplete(editorInstance) {
     38                                window.status = editorInstance.Description;
     39                        }
     40                </script>
     41        </head><body>
     42                <h1>FCKeditor - JSP - Sample 8</h1>
     43                In this sample the user can upload images to the server using the sample
     44                Spring based connector FCKEditorConnector. Images
     45                will be stored in the server root at /spring_connector/userfiles/image.
     46                <hr />
     47                <form action="sampleposteddata.jsp" method="post" target="_blank">
     48                        <FCK:editor instanceName="EditorDefault">
     49                                <jsp:attribute name="value">
     50                                        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
     51                                                <html>
     52                                                        <head>
     53                                                                <title>Full Page Test</title>
     54                                                                <meta content="text/html; charset=utf-8"
     55                                                                        http-equiv="Content-Type"/>
     56                                                        </head>
     57                                                        <body>This is some <strong>sample text</strong>. You are
     58                                                                using <a href="http://www.fckeditor.net/">FCKeditor
     59                                                                </a>.
     60                                                        </body>
     61                                                </html>
     62                                </jsp:attribute>
     63                                <jsp:body>
     64                                        <FCK:config FullPage="true"/>
     65                                </jsp:body>
     66                        </FCK:editor>
     67                        <br />
     68                        <input type="submit" value="Submit" />
     69                </form>
     70        </body>
     71</html>
  • java-demo/src/main/webapp/sampleslist.jsp

     
    5959                                        support</option>
    6060                                        <option value="jsp/sample07.jsp">Sample 07: Full Page
    6161                                        editing</option>
     62                                        <option value="jsp/sample08.jsp">Sample 08: Image upload using Spring Connector</option>
    6263                                </select></td>
    6364                        </tr>
    6465                </table>
  • java-demo/src/main/webapp/WEB-INF/applicationContext.xml

     
     1<?xml version="1.0" encoding="UTF-8"?>
     2<beans xmlns="http://www.springframework.org/schema/beans"
     3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
     5       
     6        <bean id="FCKEditorConnectorSample" class="net.fckeditor.sample.spring.FCKEditorConnector"/>
     7
     8</beans>
  • java-demo/src/main/webapp/WEB-INF/web.xml

     
    55>
    66<display-name>FCKeditor.Java Sample Web Application</display-name>
    77        <description>FCKeditor.Java Sample Web Application</description>
     8       
     9        <context-param>
     10                <param-name>FCKEDITOR_SPRING_CONNECTOR</param-name>
     11                <param-value>FCKEditorConnectorSample</param-value>
     12        </context-param>
    813
     14        <listener>
     15                <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     16        </listener>
     17       
    918        <servlet>
    10                 <servlet-name>ConnectorServlet</servlet-name>
     19                <servlet-name>SpringConnectorServlet</servlet-name>
    1120                <servlet-class>
    12                         net.fckeditor.connector.ConnectorServlet
     21                        net.fckeditor.spring.connector.SpringConnectorServlet
    1322                </servlet-class>
     23                        <!-- You don`t need to add this init param. By default the servlet
     24                will look for a bean named FCKEditorConnector
     25                in spring web application context. But if you don`t want the default
     26                you can use this init param--> 
     27                <init-param>
     28                <param-name>FCKEDITOR_SPRING_CONNECTOR</param-name>
     29                <param-value>FCKEditorConnectorSample</param-value>
     30         </init-param>
    1431                <load-on-startup>1</load-on-startup>
    1532        </servlet>
    16 
     33       
    1734        <servlet-mapping>
    18                 <servlet-name>ConnectorServlet</servlet-name>
     35                <servlet-name>SpringConnectorServlet</servlet-name>
    1936                <!-- Do not wrap this line otherwise Glassfish will fail to load this file -->
    2037                <url-pattern>/fckeditor/editor/filemanager/connectors/*</url-pattern>
    2138        </servlet-mapping>
     39       
     40        <!-- <servlet>
     41                <servlet-name>ConnectorServlet</servlet-name>
     42                <servlet-class>
     43                        net.fckeditor.connector.ConnectorServlet
     44                </servlet-class>
     45                <load-on-startup>1</load-on-startup>
     46        </servlet>-->
     47
     48        <!--  <servlet-mapping>
     49                <servlet-name>ConnectorServlet</servlet-name>-->
     50                <!-- Do not wrap this line otherwise Glassfish will fail to load this file -->
     51                <!--<url-pattern>/fckeditor/editor/filemanager/connectors/*</url-pattern>
     52        </servlet-mapping>-->
    2253</web-app>
     54 No newline at end of file
  • pom.xml

     
    1 <project xmlns="http://maven.apache.org/POM/4.0.0"
    2         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     1<?xml version="1.0" encoding="UTF-8"?>
     2<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    43        <modelVersion>4.0.0</modelVersion>
    54        <groupId>net.fckeditor</groupId>
    65        <artifactId>fckeditor-java</artifactId>
     
    98        <modules>
    109                <module>java-core</module>
    1110                <module>java-demo</module>
    12         </modules>
     11    <module>spring-connector</module>
     12  </modules>
    1313        <properties>
    1414                <project.build.sourceEncoding>
    1515                        UTF-8
     
    126126                                                </goals>
    127127                                                <configuration>
    128128                                                        <tasks>
    129                                                                 <copy overwrite="true" todir="src/site"
    130                                                                         flatten="true">
     129                                                                <copy overwrite="true" todir="src/site" flatten="true">
    131130                                                                        <fileset dir="..">
    132                                                                                 <include
    133                                                                                         name="src/site/site.xml" />
     131                                                                                <include name="src/site/site.xml"/>
    134132                                                                        </fileset>
    135133                                                                </copy>
    136                                                                 <replace value="&lt;src&gt;../"
    137                                                                         token="&lt;src&gt;/" dir="..">
    138                                                                         <include
    139                                                                                 name="${pom.artifactId}/src/site/site.xml" />
    140                                                                         <exclude
    141                                                                                 name="fckeditor-java/src/site/site.xml" />
     134                                                                <replace value="&lt;src&gt;../" token="&lt;src&gt;/" dir="..">
     135                                                                        <include name="${pom.artifactId}/src/site/site.xml"/>
     136                                                                        <exclude name="fckeditor-java/src/site/site.xml"/>
    142137                                                                </replace>
    143                                                                 <replace value="href=&quot;../"
    144                                                                         token="href=&quot;/" dir="..">
    145                                                                         <include
    146                                                                                 name="${pom.artifactId}/src/site/site.xml" />
    147                                                                         <exclude
    148                                                                                 name="fckeditor-java/src/site/site.xml" />
     138                                                                <replace value="href=&quot;../" token="href=&quot;/" dir="..">
     139                                                                        <include name="${pom.artifactId}/src/site/site.xml"/>
     140                                                                        <exclude name="fckeditor-java/src/site/site.xml"/>
    149141                                                                </replace>
    150                                                                 <replace value="href=&quot;"
    151                                                                         token="href=&quot;../${pom.artifactId}/" dir="..">
    152                                                                         <include
    153                                                                                 name="${pom.artifactId}/src/site/site.xml" />
    154                                                                         <exclude
    155                                                                                 name="fckeditor-java/src/site/site.xml" />
     142                                                                <replace value="href=&quot;" token="href=&quot;../${pom.artifactId}/" dir="..">
     143                                                                        <include name="${pom.artifactId}/src/site/site.xml"/>
     144                                                                        <exclude name="fckeditor-java/src/site/site.xml"/>
    156145                                                                </replace>
    157                                                                 <replace value="href=&quot;../images"
    158                                                                         token="href=&quot;images" dir="..">
    159                                                                         <include
    160                                                                                 name="${pom.artifactId}/src/site/site.xml" />
    161                                                                         <exclude
    162                                                                                 name="fckeditor-java/src/site/site.xml" />
     146                                                                <replace value="href=&quot;../images" token="href=&quot;images" dir="..">
     147                                                                        <include name="${pom.artifactId}/src/site/site.xml"/>
     148                                                                        <exclude name="fckeditor-java/src/site/site.xml"/>
    163149                                                                </replace>
    164150                                                        </tasks>
    165151                                                </configuration>
  • spring-connector/pom.xml

     
     1<?xml version="1.0"?><project>
     2  <parent>
     3    <artifactId>fckeditor-java</artifactId>
     4    <groupId>net.fckeditor</groupId>
     5    <version>2.5-SNAPSHOT</version>
     6  </parent>
     7       
     8  <modelVersion>4.0.0</modelVersion>
     9  <artifactId>spring-connector</artifactId>
     10  <name>spring-connector</name>
     11
     12  <url>http://maven.apache.org</url>
     13  <dependencies>
     14    <dependency>
     15      <groupId>junit</groupId>
     16      <artifactId>junit</artifactId>
     17      <version>3.8.1</version>
     18      <scope>test</scope>
     19    </dependency>
     20         <dependency>
     21      <groupId>org.springframework</groupId>
     22      <artifactId>spring</artifactId>
     23      <version>2.5.1</version>
     24    </dependency>
     25    <dependency>
     26                <groupId>javax.servlet</groupId>
     27                <artifactId>servlet-api</artifactId>
     28                <version>2.4</version>
     29                <scope>provided</scope>
     30                </dependency>
     31    <dependency>
     32        <groupId>net.fckeditor</groupId>
     33        <artifactId>java-core</artifactId>
     34        <version>2.5-SNAPSHOT</version>
     35        <classifier>pom</classifier>
     36    </dependency>
     37  </dependencies>
     38</project>
     39 No newline at end of file
  • spring-connector/src/main/java/META-INF/MANIFEST.MF

     
     1Manifest-Version: 1.0
     2Class-Path:
     3
  • spring-connector/src/main/java/net/fckeditor/spring/connector/SpringConnectorServlet.java

     
     1package net.fckeditor.spring.connector;
     2
     3import javax.servlet.ServletException;
     4
     5import org.slf4j.Logger;
     6import org.slf4j.LoggerFactory;
     7import org.springframework.web.context.WebApplicationContext;
     8import org.springframework.web.context.support.WebApplicationContextUtils;
     9
     10import net.fckeditor.connector.Connector;
     11import net.fckeditor.connector.ConnectorServlet;
     12import net.fckeditor.connector.Dispatcher;
     13
     14public class SpringConnectorServlet extends ConnectorServlet{
     15       
     16        private static final long serialVersionUID = 1L;
     17       
     18        private static final Logger logger = LoggerFactory.getLogger(SpringConnectorServlet.class);
     19        public static final String FCKEDITOR_SPRING_CONNECTOR_INIT_PARAM = "FCKEDITOR_SPRING_CONNECTOR";
     20        public static final String FCKEDITOR_DEFAULT_CONNECTOR_BEAN_NAME = "FCKEditorConnector";
     21       
     22        @Override
     23        public void init() throws ServletException {
     24                try {
     25                       
     26                        WebApplicationContext ctx =
     27                                WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
     28                       
     29                        //Try to look up the Connector bean name from
     30                        //web.xml. If it can`t be found then use the default name
     31                        String connectorBeanName =
     32                                getInitParameter(FCKEDITOR_SPRING_CONNECTOR_INIT_PARAM);
     33                       
     34                        Connector connector = null;
     35                        if(connectorBeanName !=null && connectorBeanName.trim().length()>0){
     36                                connector = (Connector)ctx.getBean(connectorBeanName);
     37                        }else{
     38                                connector = (Connector)ctx.getBean(FCKEDITOR_DEFAULT_CONNECTOR_BEAN_NAME);
     39                        }
     40               
     41                        dispatcher = new Dispatcher(connector);
     42                } catch (Exception e) {
     43                        logger.error("Dispatcher could not be initialized", e);
     44                        throw new ServletException(e);
     45                }
     46        }
     47}
  • spring-connector/src/test/java/net/fckeditor/AppTest.java

     
     1package net.fckeditor;
     2
     3import junit.framework.Test;
     4import junit.framework.TestCase;
     5import junit.framework.TestSuite;
     6
     7/**
     8 * Unit test for simple App.
     9 */
     10public class AppTest
     11    extends TestCase
     12{
     13    /**
     14     * Create the test case
     15     *
     16     * @param testName name of the test case
     17     */
     18    public AppTest( String testName )
     19    {
     20        super( testName );
     21    }
     22
     23    /**
     24     * @return the suite of tests being tested
     25     */
     26    public static Test suite()
     27    {
     28        return new TestSuite( AppTest.class );
     29    }
     30
     31    /**
     32     * Rigourous Test :-)
     33     */
     34    public void testApp()
     35    {
     36        assertTrue( true );
     37    }
     38}
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy