%--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache 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.apache.org/licenses/LICENSE-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.
--%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://jspwiki.apache.org/tags" prefix="wiki" %>
<%@ page import="java.util.Properties"%>
<%@ page import="org.apache.wiki.*" %>
<%@ page import="org.apache.wiki.auth.*" %>
<%@ page import="org.apache.wiki.auth.permissions.*" %>
<%@ page import="org.apache.wiki.render.*" %>
<%@ page import="org.apache.wiki.parser.JSPWikiMarkupParser" %>
<%@ page import="org.apache.wiki.ui.*" %>
<%@ page import="org.apache.wiki.util.TextUtil" %>
<%@ page import="org.apache.wiki.filters.*" %>
<%@ page import="org.apache.commons.lang.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%--
This provides the WYSIWYG CKeditor for JSPWiki.
--%>
<%
WikiContext context = WikiContext.findContext( pageContext );
WikiEngine engine = context.getEngine();
/* local download of CKeditor */
TemplateManager.addResourceRequest( context, TemplateManager.RESOURCE_SCRIPT,
context.getURL( WikiContext.NONE, "scripts/ckeditor/ckeditor.js" ) );
/* Use CKEditor from a CDN
TemplateManager.addResourceRequest( context, TemplateManager.RESOURCE_SCRIPT,
"//cdn.ckeditor.com/4.5.1/standard/ckeditor.js" );
*/
context.setVariable( RenderingManager.WYSIWYG_EDITOR_MODE, Boolean.TRUE );
context.setVariable( WikiEngine.PROP_RUNFILTERS, "false" );
WikiPage wikiPage = context.getPage();
String originalCCLOption = (String)wikiPage.getAttribute( JSPWikiMarkupParser.PROP_CAMELCASELINKS );
wikiPage.setAttribute( JSPWikiMarkupParser.PROP_CAMELCASELINKS, "false" );
String usertext = EditorManager.getEditedText(pageContext);
%>
<%-- this is a new page, check if we're cloning --%>
<%
String clone = request.getParameter( "clone" );
if( clone != null )
{
WikiPage p = engine.getPage( clone );
if( p != null )
{
AuthorizationManager mgr = engine.getAuthorizationManager();
PagePermission pp = new PagePermission( p, PagePermission.VIEW_ACTION );
try
{
if( mgr.checkPermission( context.getWikiSession(), pp ) )
{
usertext = engine.getPureText( p );
}
}
catch( Exception e ) { /*log.error( "Accessing clone page "+clone, e );*/ }
}
}
%>
<%
if( usertext == null )
{
usertext = engine.getPureText( context.getPage() );
}
%>
<%
if( usertext == null ) usertext = "";
RenderingManager renderingManager = engine.getRenderingManager();
// since the WikiProperties are shared, we'll want to make our own copy of it for modifying.
Properties copyOfWikiProperties = new Properties();
copyOfWikiProperties.putAll( engine.getWikiProperties() );
copyOfWikiProperties.setProperty( "jspwiki.renderingManager.renderer", WysiwygEditingRenderer.class.getName() );
renderingManager.initialize( engine, copyOfWikiProperties );
String pageAsHtml;
try
{
//pageAsHtml = StringEscapeUtils.escapeJavaScript( renderingManager.getHTML( context, usertext ) );
pageAsHtml = renderingManager.getHTML( context, usertext );
}
catch( Exception e )
{
pageAsHtml = "Error in converting wiki-markup to well-formed HTML \n" + e.toString();
//pageAsHtml = e.toString() + "\n" + usertext; //error
}
// Disable the WYSIWYG_EDITOR_MODE and reset the other properties immediately
// after the XHTML for CKeditor has been rendered.
context.setVariable( RenderingManager.WYSIWYG_EDITOR_MODE, Boolean.FALSE );
context.setVariable( WikiEngine.PROP_RUNFILTERS, null );
wikiPage.setAttribute( JSPWikiMarkupParser.PROP_CAMELCASELINKS, originalCCLOption );
/*not used
String templateDir = (String)copyOfWikiProperties.get( WikiEngine.PROP_TEMPLATEDIR );
String protocol = "http://";
if( request.isSecure() )
{
protocol = "https://";
}
*/
%>