Search in sources :

Example 71 with WikiContext

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

the class RPCHandler method listLinks.

public Vector listLinks(String pagename) throws XmlRpcException {
    pagename = parsePageCheckCondition(pagename);
    WikiPage page = m_engine.getPage(pagename);
    String pagedata = m_engine.getPureText(page);
    LinkCollector localCollector = new LinkCollector();
    LinkCollector extCollector = new LinkCollector();
    LinkCollector attCollector = new LinkCollector();
    WikiContext context = new WikiContext(m_engine, page);
    context.setVariable(WikiEngine.PROP_REFSTYLE, "absolute");
    m_engine.textToHTML(context, pagedata, localCollector, extCollector, attCollector);
    Vector<Hashtable<String, String>> result = new Vector<Hashtable<String, String>>();
    // 
    for (Iterator<String> i = localCollector.getLinks().iterator(); i.hasNext(); ) {
        String link = i.next();
        Hashtable<String, String> ht = new Hashtable<String, String>();
        ht.put("page", toRPCString(link));
        ht.put("type", LINK_LOCAL);
        if (m_engine.pageExists(link)) {
            ht.put("href", context.getURL(WikiContext.VIEW, link));
        } else {
            ht.put("href", context.getURL(WikiContext.EDIT, link));
        }
        result.add(ht);
    }
    // 
    for (Iterator<String> i = attCollector.getLinks().iterator(); i.hasNext(); ) {
        String link = i.next();
        Hashtable<String, String> ht = new Hashtable<String, String>();
        ht.put("page", toRPCString(link));
        ht.put("type", LINK_LOCAL);
        ht.put("href", context.getURL(WikiContext.ATTACH, link));
        result.add(ht);
    }
    for (Iterator<String> i = extCollector.getLinks().iterator(); i.hasNext(); ) {
        String link = i.next();
        Hashtable<String, String> ht = new Hashtable<String, String>();
        ht.put("page", link);
        ht.put("type", LINK_EXTERNAL);
        ht.put("href", link);
        result.add(ht);
    }
    return result;
}
Also used : WikiContext(org.apache.wiki.WikiContext) Hashtable(java.util.Hashtable) WikiPage(org.apache.wiki.WikiPage) LinkCollector(org.apache.wiki.LinkCollector) Vector(java.util.Vector)

Example 72 with WikiContext

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

the class RPCHandlerUTF8 method listLinks.

public Vector listLinks(String pagename) throws XmlRpcException {
    pagename = parsePageCheckCondition(pagename);
    WikiPage page = m_engine.getPage(pagename);
    String pagedata = m_engine.getPureText(page);
    LinkCollector localCollector = new LinkCollector();
    LinkCollector extCollector = new LinkCollector();
    LinkCollector attCollector = new LinkCollector();
    WikiContext context = new WikiContext(m_engine, page);
    context.setVariable(WikiEngine.PROP_REFSTYLE, "absolute");
    m_engine.textToHTML(context, pagedata, localCollector, extCollector, attCollector);
    Vector<Hashtable<String, String>> result = new Vector<Hashtable<String, String>>();
    // 
    for (Iterator<String> i = localCollector.getLinks().iterator(); i.hasNext(); ) {
        String link = i.next();
        Hashtable<String, String> ht = new Hashtable<String, String>();
        ht.put("page", link);
        ht.put("type", LINK_LOCAL);
        if (m_engine.pageExists(link)) {
            ht.put("href", context.getViewURL(link));
        } else {
            ht.put("href", context.getURL(WikiContext.EDIT, link));
        }
        result.add(ht);
    }
    // 
    for (String link : attCollector.getLinks()) {
        Hashtable<String, String> ht = new Hashtable<String, String>();
        ht.put("page", link);
        ht.put("type", LINK_LOCAL);
        ht.put("href", context.getURL(WikiContext.ATTACH, link));
        result.add(ht);
    }
    for (String link : extCollector.getLinks()) {
        Hashtable<String, String> ht = new Hashtable<String, String>();
        ht.put("page", link);
        ht.put("type", LINK_EXTERNAL);
        ht.put("href", link);
        result.add(ht);
    }
    return result;
}
Also used : WikiContext(org.apache.wiki.WikiContext) Hashtable(java.util.Hashtable) WikiPage(org.apache.wiki.WikiPage) LinkCollector(org.apache.wiki.LinkCollector) Vector(java.util.Vector)

Example 73 with WikiContext

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

the class JSPWikiMarkupParserTest method translate.

private String translate(WikiEngine e, WikiPage p, String src) throws IOException, NoRequiredPropertyException, ServletException {
    WikiContext context = new WikiContext(e, testEngine.newHttpRequest(), p);
    JSPWikiMarkupParser tr = new JSPWikiMarkupParser(context, new BufferedReader(new StringReader(src)));
    XHTMLRenderer conv = new XHTMLRenderer(context, tr.parse());
    return conv.getString();
}
Also used : WikiContext(org.apache.wiki.WikiContext) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) XHTMLRenderer(org.apache.wiki.render.XHTMLRenderer)

Example 74 with WikiContext

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

the class CounterPluginTest method translate.

private String translate(String src) throws IOException, NoRequiredPropertyException, ServletException {
    WikiContext context = new WikiContext(testEngine, new WikiPage(testEngine, "TestPage"));
    MarkupParser p = new JSPWikiMarkupParser(context, new StringReader(src));
    WikiDocument dom = p.parse();
    WikiRenderer r = new XHTMLRenderer(context, dom);
    return r.getString();
}
Also used : WikiContext(org.apache.wiki.WikiContext) JSPWikiMarkupParser(org.apache.wiki.parser.JSPWikiMarkupParser) WikiPage(org.apache.wiki.WikiPage) StringReader(java.io.StringReader) WikiRenderer(org.apache.wiki.render.WikiRenderer) XHTMLRenderer(org.apache.wiki.render.XHTMLRenderer) WikiDocument(org.apache.wiki.parser.WikiDocument) MarkupParser(org.apache.wiki.parser.MarkupParser) JSPWikiMarkupParser(org.apache.wiki.parser.JSPWikiMarkupParser)

Example 75 with WikiContext

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

the class PageRenamerTest method testReferrerNoWikiName.

@Test
public void testReferrerNoWikiName() throws Exception {
    m_engine.saveText("Test", "foo");
    m_engine.saveText("TestPage2", "[Test] [Test#anchor] test Test [test] [link|test] [link|test]");
    WikiPage p = m_engine.getPage("TestPage");
    WikiContext context = new WikiContext(m_engine, p);
    m_engine.renamePage(context, "Test", "TestPage", true);
    String data = m_engine.getPureText("TestPage2", WikiProvider.LATEST_VERSION);
    Assert.assertEquals("wrong data", "[TestPage] [TestPage#anchor] test Test [TestPage] [link|TestPage] [link|TestPage]", data.trim());
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

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