Search in sources :

Example 76 with WikiContext

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

the class PageRenamerTest method testSimpleRename.

@Test
public void testSimpleRename() throws Exception {
    // Count the numberof existing references
    int refCount = m_engine.getReferenceManager().findCreated().size();
    m_engine.saveText("TestPage", "the big lazy dog thing");
    WikiPage p = m_engine.getPage("TestPage");
    WikiContext context = new WikiContext(m_engine, p);
    m_engine.renamePage(context, "TestPage", "FooTest", false);
    WikiPage newpage = m_engine.getPage("FooTest");
    Assert.assertNotNull("no new page", newpage);
    Assert.assertNull("old page not gone", m_engine.getPage("TestPage"));
    // Refmgr
    Collection<String> refs = m_engine.getReferenceManager().findCreated();
    Assert.assertTrue("FooTest does not exist", refs.contains("FooTest"));
    Assert.assertFalse("TestPage exists", refs.contains("TestPage"));
    Assert.assertEquals("wrong list size", refCount + 1, refs.size());
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 77 with WikiContext

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

the class PageRenamerTest method testReferrerChangeAnchor.

@Test
public void testReferrerChangeAnchor() throws Exception {
    m_engine.saveText("TestPage", "foofoo");
    m_engine.saveText("TestPage2", "[TestPage#heading1]");
    WikiPage p = m_engine.getPage("TestPage");
    WikiContext context = new WikiContext(m_engine, p);
    m_engine.renamePage(context, "TestPage", "FooTest", true);
    String data = m_engine.getPureText("TestPage2", WikiProvider.LATEST_VERSION);
    Assert.assertEquals("no rename", "[FooTest#heading1]", data.trim());
    Collection<String> refs = m_engine.getReferenceManager().findReferrers("TestPage");
    Assert.assertNull("oldpage", refs);
    refs = m_engine.getReferenceManager().findReferrers("FooTest");
    Assert.assertEquals("new size", 1, refs.size());
    Assert.assertEquals("wrong ref", "TestPage2", (String) refs.iterator().next());
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 78 with WikiContext

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

the class SpamFilter method insertInputFields.

/**
 * This helper method adds all the input fields to your editor that the SpamFilter requires
 * to check for spam.  This <i>must</i> be in your editor form if you intend to use the SpamFilter.
 *
 * @param pageContext The PageContext
 * @return A HTML string which contains input fields for the SpamFilter.
 */
public static final String insertInputFields(PageContext pageContext) {
    WikiContext ctx = WikiContext.findContext(pageContext);
    WikiEngine engine = ctx.getEngine();
    StringBuilder sb = new StringBuilder();
    if (engine.getContentEncoding().equals("UTF-8")) {
        sb.append("<input name='encodingcheck' type='hidden' value='\u3041' />\n");
    }
    return sb.toString();
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiEngine(org.apache.wiki.WikiEngine)

Example 79 with WikiContext

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

the class WikiServletFilter method getWikiContext.

/**
 *  Figures out the wiki context from the request.  This method does not create the
 *  context if it does not exist.
 *
 *  @param request The request to examine
 *  @return A valid WikiContext value (or null, if the context could not be located).
 */
protected WikiContext getWikiContext(ServletRequest request) {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    WikiContext ctx = (WikiContext) httpRequest.getAttribute(WikiTagBase.ATTR_CONTEXT);
    return ctx;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WikiContext(org.apache.wiki.WikiContext)

Example 80 with WikiContext

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

the class TemplateManager method listTimeFormats.

/**
 * List all available timeformats, read from the jspwiki.properties
 *
 * @param pageContext
 * @return map of TimeFormats
 * @since 2.7.x
 */
public Map listTimeFormats(PageContext pageContext) {
    WikiContext context = WikiContext.findContext(pageContext);
    Properties props = m_engine.getWikiProperties();
    ArrayList<String> tfArr = new ArrayList<String>(40);
    LinkedHashMap<String, String> resultMap = new LinkedHashMap<String, String>();
    /* filter timeformat properties */
    for (Enumeration e = props.propertyNames(); e.hasMoreElements(); ) {
        String name = (String) e.nextElement();
        if (name.startsWith(TIMEFORMATPROPERTIES)) {
            tfArr.add(name);
        }
    }
    /* fetch actual formats */
    if (tfArr.size() == 0) /*
                                 * no props found - make sure some default
                                 * formats are avail
                                 */
    {
        tfArr.add("dd-MMM-yy");
        tfArr.add("d-MMM-yyyy");
        tfArr.add("EEE, dd-MMM-yyyy, zzzz");
    } else {
        Collections.sort(tfArr);
        for (int i = 0; i < tfArr.size(); i++) {
            tfArr.set(i, props.getProperty(tfArr.get(i)));
        }
    }
    String prefTimeZone = Preferences.getPreference(context, "TimeZone");
    // TimeZone tz = TimeZone.getDefault();
    TimeZone tz = TimeZone.getTimeZone(prefTimeZone);
    /*try
        {
            tz.setRawOffset(Integer.parseInt(prefTimeZone));
        }
        catch (Exception e)
        {
        }*/
    // current date
    Date d = new Date();
    try {
        // dummy format pattern
        SimpleDateFormat fmt = Preferences.getDateFormat(context, TimeFormat.DATETIME);
        fmt.setTimeZone(tz);
        for (int i = 0; i < tfArr.size(); i++) {
            try {
                String f = tfArr.get(i);
                fmt.applyPattern(f);
                resultMap.put(f, fmt.format(d));
            } catch (IllegalArgumentException e) {
            }
        // skip parameter
        }
    } catch (IllegalArgumentException e) {
    }
    return resultMap;
}
Also used : WikiContext(org.apache.wiki.WikiContext) Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) TimeZone(java.util.TimeZone) SimpleDateFormat(java.text.SimpleDateFormat)

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