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());
}
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());
}
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();
}
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;
}
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;
}
Aggregations