Search in sources :

Example 1 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class MailUtilTest method setUp.

@Before
public void setUp() throws Exception {
    PropertyConfigurator.configure(m_props);
    TestEngine testEngine = new TestEngine(m_props);
    m_context = new WikiContext(testEngine, new WikiPage(testEngine, PAGE_NAME));
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) TestEngine(org.apache.wiki.TestEngine) Before(org.junit.Before)

Example 2 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class MetaWeblogHandler method editPost.

/**
 *  Allows the user to edit a post.  It does not allow general
 *   editability of wiki pages, because of the limitations of the
 *  metaWeblog API.
 */
boolean editPost(String postid, String username, String password, Hashtable content, boolean publish) throws XmlRpcException {
    WikiEngine engine = m_context.getEngine();
    log.info("metaWeblog.editPost(" + postid + ") called");
    // FIXME: Is postid correct?  Should we determine it from the page name?
    WikiPage page = engine.getPage(postid);
    checkPermissions(page, username, password, "edit");
    try {
        WikiPage entryPage = (WikiPage) page.clone();
        entryPage.setAuthor(username);
        WikiContext context = new WikiContext(engine, entryPage);
        StringBuilder text = new StringBuilder();
        text.append("!" + content.get("title"));
        text.append("\n\n");
        text.append(content.get("description"));
        log.debug("Updating entry: " + text);
        engine.saveText(context, text.toString());
    } catch (Exception e) {
        log.error("Failed to create weblog entry", e);
        throw new XmlRpcException(0, "Failed to update weblog entry: " + e.getMessage());
    }
    return true;
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) WikiEngine(org.apache.wiki.WikiEngine) XmlRpcException(org.apache.xmlrpc.XmlRpcException) WikiSecurityException(org.apache.wiki.auth.WikiSecurityException) ProviderException(org.apache.wiki.api.exceptions.ProviderException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 3 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class RPCServlet method doPost.

/**
 *  Handle HTTP POST.  This is an XML-RPC call, and we'll just forward
 *  the query to an XmlRpcServer.
 */
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    log.debug("Received POST to RPCServlet");
    try {
        WikiContext ctx = m_engine.createContext(request, WikiContext.NONE);
        XmlRpcContext xmlrpcContext = new WikiXmlRpcContext(m_xmlrpcServer.getHandlerMapping(), ctx);
        byte[] result = m_xmlrpcServer.execute(request.getInputStream(), xmlrpcContext);
        // 
        // I think it's safe to write the output as UTF-8:
        // The XML-RPC standard never creates other than USASCII
        // (which is UTF-8 compatible), and our special UTF-8
        // hack just creates UTF-8.  So in all cases our butt
        // should be covered.
        // 
        response.setContentType("text/xml; charset=utf-8");
        response.setContentLength(result.length);
        OutputStream out = response.getOutputStream();
        out.write(result);
        out.flush();
    // log.debug("Result = "+new String(result) );
    } catch (IOException e) {
        throw new ServletException("Failed to build RPC result", e);
    }
}
Also used : ServletException(javax.servlet.ServletException) WikiContext(org.apache.wiki.WikiContext) XmlRpcContext(org.apache.xmlrpc.XmlRpcContext) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Example 4 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class WikiJSPFilter method doFilter.

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
    WatchDog w = m_engine.getCurrentWatchDog();
    try {
        NDC.push(m_engine.getApplicationName() + ":" + ((HttpServletRequest) request).getRequestURI());
        w.enterState("Filtering for URL " + ((HttpServletRequest) request).getRequestURI(), 90);
        HttpServletResponseWrapper responseWrapper;
        responseWrapper = new MyServletResponseWrapper((HttpServletResponse) response, m_wiki_encoding, useEncoding);
        // fire PAGE_REQUESTED event
        String pagename = DefaultURLConstructor.parsePageFromURL((HttpServletRequest) request, response.getCharacterEncoding());
        fireEvent(WikiPageEvent.PAGE_REQUESTED, pagename);
        super.doFilter(request, responseWrapper, chain);
        try {
            w.enterState("Delivering response", 30);
            WikiContext wikiContext = getWikiContext(request);
            String r = filter(wikiContext, responseWrapper);
            if (useEncoding) {
                OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream(), response.getCharacterEncoding());
                out.write(r);
                out.flush();
                out.close();
            } else {
                response.getWriter().write(r);
            }
            // Clean up the UI messages and loggers
            if (wikiContext != null) {
                wikiContext.getWikiSession().clearMessages();
            }
            // fire PAGE_DELIVERED event
            fireEvent(WikiPageEvent.PAGE_DELIVERED, pagename);
        } finally {
            w.exitState();
        }
    } finally {
        w.exitState();
        NDC.pop();
        NDC.remove();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WikiContext(org.apache.wiki.WikiContext) WatchDog(org.apache.wiki.WatchDog) HttpServletResponseWrapper(javax.servlet.http.HttpServletResponseWrapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) OutputStreamWriter(java.io.OutputStreamWriter)

Example 5 with WikiContext

use of org.apache.wiki.WikiContext in project jspwiki by apache.

the class Preferences method reloadPreferences.

/**
 *  Reloads the preferences from the PageContext into the WikiContext.
 *
 *  @param pageContext The page context.
 */
// FIXME: The way that date preferences are chosen is currently a bit wacky: it all
// gets saved to the cookie based on the browser state with which the user
// happened to first arrive to the site with.  This, unfortunately, means that
// even if the user changes e.g. language preferences (like in a web cafe),
// the old preferences still remain in a site cookie.
public static void reloadPreferences(PageContext pageContext) {
    Preferences prefs = new Preferences();
    Properties props = PropertyReader.loadWebAppProps(pageContext.getServletContext());
    WikiContext ctx = WikiContext.findContext(pageContext);
    prefs.put("SkinName", TextUtil.getStringProperty(props, "jspwiki.defaultprefs.template.skinname", "PlainVanilla"));
    prefs.put("DateFormat", TextUtil.getStringProperty(props, "jspwiki.defaultprefs.template.dateformat", ctx.getEngine().getInternationalizationManager().get(InternationalizationManager.CORE_BUNDLE, getLocale(ctx), "common.datetimeformat")));
    prefs.put("TimeZone", TextUtil.getStringProperty(props, "jspwiki.defaultprefs.template.timezone", java.util.TimeZone.getDefault().getID()));
    prefs.put("Orientation", TextUtil.getStringProperty(props, "jspwiki.defaultprefs.template.orientation", "fav-left"));
    prefs.put("Sidebar", TextUtil.getStringProperty(props, "jspwiki.defaultprefs.template.sidebar", "active"));
    prefs.put("Layout", TextUtil.getStringProperty(props, "jspwiki.defaultprefs.template.layout", "fluid"));
    prefs.put("Language", TextUtil.getStringProperty(props, "jspwiki.defaultprefs.template.language", getLocale(ctx).toString()));
    prefs.put("SectionEditing", TextUtil.getStringProperty(props, "jspwiki.defaultprefs.template.sectionediting", "true"));
    // FIXME: "editor" property does not get registered, may be related with http://bugs.jspwiki.org/show_bug.cgi?id=117
    // disabling it until knowing why it's happening
    // FIXME: editormanager reads jspwiki.editor -- which of both properties should continue
    prefs.put("editor", TextUtil.getStringProperty(props, "jspwiki.defaultprefs.template.editor", "plain"));
    parseJSONPreferences((HttpServletRequest) pageContext.getRequest(), prefs);
    pageContext.getSession().setAttribute(SESSIONPREFS, prefs);
}
Also used : WikiContext(org.apache.wiki.WikiContext) Properties(java.util.Properties)

Aggregations

WikiContext (org.apache.wiki.WikiContext)90 WikiPage (org.apache.wiki.WikiPage)63 Test (org.junit.Test)40 TestEngine (org.apache.wiki.TestEngine)11 StringReader (java.io.StringReader)9 WikiEngine (org.apache.wiki.WikiEngine)9 ProviderException (org.apache.wiki.api.exceptions.ProviderException)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 Before (org.junit.Before)7 BufferedReader (java.io.BufferedReader)6 StringWriter (java.io.StringWriter)6 Collection (java.util.Collection)6 InputStreamReader (java.io.InputStreamReader)5 Date (java.util.Date)5 LinkCollector (org.apache.wiki.LinkCollector)5 Attachment (org.apache.wiki.attachment.Attachment)5 Properties (java.util.Properties)4 MockHttpServletRequest (net.sourceforge.stripes.mock.MockHttpServletRequest)4 WikiDocument (org.apache.wiki.parser.WikiDocument)4