use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class CalendarTag method doWikiStartTag.
/**
* {@inheritDoc}
*/
@Override
public final int doWikiStartTag() throws IOException, ProviderException {
WikiEngine engine = m_wikiContext.getEngine();
JspWriter out = pageContext.getOut();
Calendar cal = Calendar.getInstance();
Calendar prevCal = Calendar.getInstance();
Calendar nextCal = Calendar.getInstance();
//
// Check if there is a parameter in the request to set the date.
//
String calendarDate = pageContext.getRequest().getParameter("calendar.date");
if (calendarDate == null) {
calendarDate = pageContext.getRequest().getParameter("weblog.startDate");
}
if (calendarDate != null) {
try {
Date d = m_dateFormat.parse(calendarDate);
cal.setTime(d);
prevCal.setTime(d);
nextCal.setTime(d);
} catch (ParseException e) {
log.warn("date format wrong: " + calendarDate);
}
}
// First, set to first day of month
cal.set(Calendar.DATE, 1);
prevCal.set(Calendar.DATE, 1);
nextCal.set(Calendar.DATE, 1);
// Now move to first day of previous month
prevCal.add(Calendar.MONTH, -1);
// Now move to first day of next month
nextCal.add(Calendar.MONTH, 1);
out.write("<table class=\"calendar\">\n");
HttpServletRequest httpServletRequest = m_wikiContext.getHttpRequest();
String queryString = engine.safeGetQueryString(httpServletRequest);
out.write("<tr>" + getMonthNaviLink(prevCal, "<<", queryString) + "<td colspan=5 class=\"month\">" + getMonthLink(cal) + "</td>" + getMonthNaviLink(nextCal, ">>", queryString) + "</tr>\n");
int month = cal.get(Calendar.MONTH);
// Then, find the first day of the week.
cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
out.write("<tr><td class=\"weekdays\">Mon</td>" + "<td class=\"weekdays\">Tue</td>" + "<td class=\"weekdays\">Wed</td>" + "<td class=\"weekdays\">Thu</td>" + "<td class=\"weekdays\">Fri</td>" + "<td class=\"weekdays\">Sat</td>" + "<td class=\"weekdays\">Sun</td></tr>\n");
boolean noMoreDates = false;
while (!noMoreDates) {
out.write("<tr>");
for (int i = 0; i < 7; i++) {
int mth = cal.get(Calendar.MONTH);
if (mth != month) {
out.write("<td class=\"othermonth\">" + cal.get(Calendar.DATE) + "</td>");
} else {
out.write(getDayLink(cal));
}
cal.add(Calendar.DATE, 1);
}
if (cal.get(Calendar.MONTH) != month) {
noMoreDates = true;
}
out.write("</tr>\n");
}
out.write("</table>\n");
return EVAL_BODY_INCLUDE;
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class CheckVersionTag method doWikiStartTag.
/**
* {@inheritDoc}
*/
@Override
public final int doWikiStartTag() throws IOException, ProviderException {
WikiEngine engine = m_wikiContext.getEngine();
WikiPage page = m_wikiContext.getPage();
if (page != null && engine.pageExists(page.getName())) {
int version = page.getVersion();
boolean include = false;
WikiPage latest = engine.getPage(page.getName());
switch(m_mode) {
case LATEST:
include = (version < 0) || (latest.getVersion() == version);
break;
case NOTLATEST:
include = (version > 0) && (latest.getVersion() != version);
break;
case FIRST:
include = (version == 1) || (version < 0 && latest.getVersion() == 1);
break;
case NOTFIRST:
include = version > 1;
break;
default:
throw new InternalWikiException("Mode which is not available!");
}
if (include) {
// log.debug("INCLD");
return EVAL_BODY_INCLUDE;
}
}
return SKIP_BODY;
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class SessionsPlugin method execute.
/**
* {@inheritDoc}
*/
public String execute(WikiContext context, Map<String, String> params) throws PluginException {
WikiEngine engine = context.getEngine();
String prop = params.get(PARAM_PROP);
if ("users".equals(prop)) {
Principal[] principals = WikiSession.userPrincipals(engine);
StringBuilder s = new StringBuilder();
for (int i = 0; i < principals.length; i++) {
s.append(principals[i].getName() + ", ");
}
// remove the last comma and blank :
return s.substring(0, s.length() - (s.length() > 2 ? 2 : 0));
}
// number of sessions for each user)
if ("distinctUsers".equals(prop)) {
Principal[] principals = WikiSession.userPrincipals(engine);
// we do not assume that the principals are sorted, so first count
// them :
HashMap<String, Integer> distinctPrincipals = new HashMap<String, Integer>();
for (int i = 0; i < principals.length; i++) {
String principalName = principals[i].getName();
if (distinctPrincipals.containsKey(principalName)) {
// we already have an entry, increase the counter:
int numSessions = distinctPrincipals.get(principalName).intValue();
// store the new value:
distinctPrincipals.put(principalName, ++numSessions);
} else {
// first time we see this entry, add entry to HashMap with value 1
distinctPrincipals.put(principalName, 1);
}
}
//
//
StringBuilder s = new StringBuilder();
Iterator<Map.Entry<String, Integer>> entries = distinctPrincipals.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry<String, Integer> entry = entries.next();
s.append(entry.getKey() + "(" + entry.getValue().toString() + "), ");
}
// remove the last comma and blank :
if (s.length() >= 2)
return s.substring(0, s.length() - 2);
}
return String.valueOf(WikiSession.sessions(engine));
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class LinkTag method makeBasicURL.
private String makeBasicURL(String context, String page, String parms, boolean absolute) {
String url;
WikiEngine engine = m_wikiContext.getEngine();
if (context.equals(WikiContext.DIFF)) {
int r1 = 0;
int r2 = 0;
if (DiffLinkTag.VER_LATEST.equals(getVersion())) {
WikiPage latest = engine.getPage(page, WikiProvider.LATEST_VERSION);
r1 = latest.getVersion();
} else if (DiffLinkTag.VER_PREVIOUS.equals(getVersion())) {
r1 = m_wikiContext.getPage().getVersion() - 1;
r1 = (r1 < 1) ? 1 : r1;
} else if (DiffLinkTag.VER_CURRENT.equals(getVersion())) {
r1 = m_wikiContext.getPage().getVersion();
} else {
r1 = Integer.parseInt(getVersion());
}
if (DiffLinkTag.VER_LATEST.equals(m_compareToVersion)) {
WikiPage latest = engine.getPage(page, WikiProvider.LATEST_VERSION);
r2 = latest.getVersion();
} else if (DiffLinkTag.VER_PREVIOUS.equals(m_compareToVersion)) {
r2 = m_wikiContext.getPage().getVersion() - 1;
r2 = (r2 < 1) ? 1 : r2;
} else if (DiffLinkTag.VER_CURRENT.equals(m_compareToVersion)) {
r2 = m_wikiContext.getPage().getVersion();
} else {
r2 = Integer.parseInt(m_compareToVersion);
}
parms = "r1=" + r1 + "&r2=" + r2;
}
// url = m_wikiContext.getURL( m_context, m_pageName, parms );
url = engine.getURL(m_context, m_pageName, parms, m_absolute);
return url;
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class LinkTag method figureOutURL.
/**
* This method figures out what kind of an URL should be output. It mirrors heavily
* on JSPWikiMarkupParser.handleHyperlinks();
*
* @return the URL
* @throws ProviderException
*/
private String figureOutURL() throws ProviderException {
String url = null;
WikiEngine engine = m_wikiContext.getEngine();
if (m_pageName == null) {
WikiPage page = m_wikiContext.getPage();
if (page != null) {
m_pageName = page.getName();
}
}
if (m_templatefile != null) {
String params = addParamsForRecipient(null, m_containedParams);
String template = engine.getTemplateDir();
url = engine.getURL(WikiContext.NONE, "templates/" + template + "/" + m_templatefile, params, false);
} else if (m_jsp != null) {
String params = addParamsForRecipient(null, m_containedParams);
// url = m_wikiContext.getURL( WikiContext.NONE, m_jsp, params );
url = engine.getURL(WikiContext.NONE, m_jsp, params, m_absolute);
} else if (m_ref != null) {
int interwikipoint;
if (new LinkParsingOperations(m_wikiContext).isExternalLink(m_ref)) {
url = m_ref;
} else if ((interwikipoint = m_ref.indexOf(":")) != -1) {
String extWiki = m_ref.substring(0, interwikipoint);
String wikiPage = m_ref.substring(interwikipoint + 1);
url = engine.getInterWikiURL(extWiki);
if (url != null) {
url = TextUtil.replaceString(url, "%s", wikiPage);
}
} else if (m_ref.startsWith("#")) {
// Local link
} else if (TextUtil.isNumber(m_ref)) {
// Reference
} else {
int hashMark = -1;
String parms = (m_version != null) ? "version=" + getVersion() : null;
//
// Internal wiki link, but is it an attachment link?
//
WikiPage p = engine.getPage(m_pageName);
if (p instanceof Attachment) {
url = m_wikiContext.getURL(WikiContext.ATTACH, m_pageName);
} else if ((hashMark = m_ref.indexOf('#')) != -1) {
// It's an internal Wiki link, but to a named section
String namedSection = m_ref.substring(hashMark + 1);
String reallink = m_ref.substring(0, hashMark);
reallink = MarkupParser.cleanLink(reallink);
String matchedLink;
String sectref = "";
if ((matchedLink = engine.getFinalPageName(reallink)) != null) {
sectref = "section-" + engine.encodeName(matchedLink) + "-" + namedSection;
sectref = "#" + sectref.replace('%', '_');
} else {
matchedLink = reallink;
}
url = makeBasicURL(m_context, matchedLink, parms, m_absolute) + sectref;
} else {
String reallink = MarkupParser.cleanLink(m_ref);
url = makeBasicURL(m_context, reallink, parms, m_absolute);
}
}
} else if (m_pageName != null && m_pageName.length() > 0) {
WikiPage p = engine.getPage(m_pageName);
String parms = (m_version != null) ? "version=" + getVersion() : null;
parms = addParamsForRecipient(parms, m_containedParams);
if (p instanceof Attachment) {
String ctx = m_context;
// attachment, but don't override the context setting otherwise
if (m_context == null || m_context.equals(WikiContext.VIEW)) {
ctx = WikiContext.ATTACH;
}
url = engine.getURL(ctx, m_pageName, parms, m_absolute);
// url = m_wikiContext.getURL( ctx, m_pageName, parms );
} else {
url = makeBasicURL(m_context, m_pageName, parms, m_absolute);
}
} else {
String page = engine.getFrontPage();
url = makeBasicURL(m_context, page, null, m_absolute);
}
return url;
}
Aggregations