Index: etc/jspwiki.tld =================================================================== RCS file: /p/cvs/JSPWiki/etc/jspwiki.tld,v retrieving revision 1.61 diff -u -r1.61 jspwiki.tld --- etc/jspwiki.tld 25 Apr 2006 19:51:18 -0000 1.61 +++ etc/jspwiki.tld 3 May 2006 12:31:26 -0000 @@ -207,7 +207,21 @@ com.ecyrd.jspwiki.tags.EditorTag JSP - + + + EditorAlternatives + com.ecyrd.jspwiki.tags.EditorAlternativesTag + empty + + title + true + + + alignment + true + + + FeedDiscovery com.ecyrd.jspwiki.tags.FeedDiscoveryTag Index: src/com/ecyrd/jspwiki/ui/EditorManager.java =================================================================== RCS file: /p/cvs/JSPWiki/src/com/ecyrd/jspwiki/ui/EditorManager.java,v retrieving revision 1.3 diff -u -r1.3 EditorManager.java --- src/com/ecyrd/jspwiki/ui/EditorManager.java 22 Mar 2006 18:07:44 -0000 1.3 +++ src/com/ecyrd/jspwiki/ui/EditorManager.java 3 May 2006 12:31:26 -0000 @@ -44,6 +44,9 @@ /** The property name for setting the editor. Current value is "jspwiki.editor" */ public static final String PROP_EDITORTYPE = "jspwiki.editor"; + /** Parameter for changing editors at run-time */ + public static final String PARA_EDITOR = "editor"; + /** Known name for the plain wikimarkup editor. */ public static final String EDITOR_PLAIN = "plain"; @@ -146,6 +149,11 @@ * looks in is the property file, but in the future this will also look at * user preferences. *

+ * Determines the editor to use by the following order of conditions: + * 1. Attribute in HttpSession: used when an alternative editor link is clicked + * 2. Editor set in User Preferences -> not implemented yet + * 3. Default Editor set in jspwiki.properties + *

* For the PREVIEW context, this method returns the "preview" editor. * * @param context The context that is chosen. @@ -158,9 +166,37 @@ if( context.getRequestContext().equals(WikiContext.PREVIEW) ) return EDITOR_PREVIEW; + String editor = null; + + // If a parameter "editor" is provided, then set it as session attribute, so that following + // calls can make use of it. This parameter is set by the links created + // through the EditorAlternativesTag + + editor = context.getHttpParameter( PARA_EDITOR ); + if (editor != null) + { + context.getHttpRequest().getSession().setAttribute( PARA_EDITOR, editor ); + } + + // First condition: + // an attribute in the Session is provided + editor = (String) context.getHttpRequest().getSession().getAttribute( PARA_EDITOR ); + if (editor != null) + { + return editor; + } + + // Second condition: + // User has set an editor in preferences + // TODO... + + // Third condition: + // use the default editor in jspwiki.properties + try { - String editor = m_engine.getVariableManager().getValue( context, PROP_EDITORTYPE ); + + editor = m_engine.getVariableManager().getValue( context, PROP_EDITORTYPE ); String[] editorlist = getEditorList(); Index: src/webdocs/templates/default/EditTemplate.jsp =================================================================== RCS file: /p/cvs/JSPWiki/src/webdocs/templates/default/EditTemplate.jsp,v retrieving revision 1.21 diff -u -r1.21 EditTemplate.jsp --- src/webdocs/templates/default/EditTemplate.jsp 6 Dec 2005 19:40:43 -0000 1.21 +++ src/webdocs/templates/default/EditTemplate.jsp 3 May 2006 12:31:26 -0000 @@ -12,7 +12,6 @@ - @@ -24,7 +23,9 @@ -

+ + +


Index: src/com/ecyrd/jspwiki/tags/EditorAlternativesTag.java =================================================================== RCS file: src/com/ecyrd/jspwiki/tags/EditorAlternativesTag.java diff -N src/com/ecyrd/jspwiki/tags/EditorAlternativesTag.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/com/ecyrd/jspwiki/tags/EditorAlternativesTag.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,90 @@ +/* + * (C) Janne Jalkanen 2005 + * + */ +package com.ecyrd.jspwiki.tags; + +import java.util.Iterator; + +import com.ecyrd.jspwiki.WikiEngine; +import com.ecyrd.jspwiki.ui.EditorManager; + +/** + * @author Christoph Sauer + * + * @since + */ +public class EditorAlternativesTag extends WikiTagBase +{ + + private String m_title = "Editors: "; + public String m_version = null; + public String m_alignment = "horizontal"; // vertical + + public void setTitle( String s ) + { + m_title = s; + } + + public void setVersion( String vers ) + { + m_version = vers; + } + + public void setAlignment( String align ) + { + m_alignment = align; + } + + public int doWikiStartTag() throws Exception + { + WikiEngine engine = m_wikiContext.getEngine(); + + String editors = ""; + EditorManager editorManager = engine.getEditorManager(); + String curEditor = editorManager.getEditorName(m_wikiContext); + String[] editorList = editorManager.getEditorList(); + if ( editorList.length >= 2 ) + { + for ( int i = 0; i < editorList.length; i++ ) + { + String editorName = editorList[i]; + editors += createEditorOptionElement(editorName, curEditor) + "\n"; + } + + String selectStart = ""; + pageContext.getOut().print("" + m_title + " " + selectStart + editors + "\n" + selectEnd + "\n"); + } + + return SKIP_BODY; + } + + private String createEditorOptionElement(String editorName, String curEditor) { + // Don't break something... + // just get the current edit URL and append the editor parameter + String uri = m_wikiContext.getHttpRequest().getRequestURI(); + String para = m_wikiContext.getHttpRequest().getQueryString(); + String editPara = EditorManager.PARA_EDITOR + "="; + + // if para already contains editor parameter, replace instead of append it + // FIXME: Should cut out parameter instead of simple setting strin to null, maybe + // in futur releases it may change and theres the danger that trailing parameters get lost + int idx = para.indexOf(editPara); + if (idx >= 0) + { + para = para.substring(0, idx-1); + } + + String url = uri + "?" + para + "&" + editPara + editorName; + + if ( editorName.equals(curEditor) ) + { + return ""; + } + else + { + return ""; + } + } +}