use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class LinkTag method makeBasicURL.
private String makeBasicURL(final String context, final String page, String parms) {
final Engine engine = m_wikiContext.getEngine();
if (context.equals(ContextEnum.PAGE_DIFF.getRequestContext())) {
int r1;
int r2;
if (DiffLinkTag.VER_LATEST.equals(getVersion())) {
final Page latest = engine.getManager(PageManager.class).getPage(page, WikiProvider.LATEST_VERSION);
r1 = latest.getVersion();
} else if (DiffLinkTag.VER_PREVIOUS.equals(getVersion())) {
r1 = m_wikiContext.getPage().getVersion() - 1;
r1 = Math.max(r1, 1);
} else if (DiffLinkTag.VER_CURRENT.equals(getVersion())) {
r1 = m_wikiContext.getPage().getVersion();
} else {
r1 = Integer.parseInt(getVersion());
}
if (DiffLinkTag.VER_LATEST.equals(m_compareToVersion)) {
final Page latest = engine.getManager(PageManager.class).getPage(page, WikiProvider.LATEST_VERSION);
r2 = latest.getVersion();
} else if (DiffLinkTag.VER_PREVIOUS.equals(m_compareToVersion)) {
r2 = m_wikiContext.getPage().getVersion() - 1;
r2 = Math.max(r2, 1);
} else if (DiffLinkTag.VER_CURRENT.equals(m_compareToVersion)) {
r2 = m_wikiContext.getPage().getVersion();
} else {
r2 = Integer.parseInt(m_compareToVersion);
}
parms = "r1=" + r1 + "&r2=" + r2;
}
return engine.getURL(m_context, m_pageName, parms);
}
use of org.apache.wiki.api.core.Engine 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;
final Engine engine = m_wikiContext.getEngine();
if (m_pageName == null) {
final Page page = m_wikiContext.getPage();
if (page != null) {
m_pageName = page.getName();
}
}
if (m_templatefile != null) {
final String params = addParamsForRecipient(null, m_containedParams);
final String template = engine.getTemplateDir();
url = engine.getURL(ContextEnum.PAGE_NONE.getRequestContext(), "templates/" + template + "/" + m_templatefile, params);
} else if (m_jsp != null) {
final String params = addParamsForRecipient(null, m_containedParams);
// url = m_wikiContext.getURL( ContextEnum.PAGE_NONE.getRequestContext(), m_jsp, params );
url = engine.getURL(ContextEnum.PAGE_NONE.getRequestContext(), m_jsp, params);
} else if (m_ref != null) {
final int interwikipoint;
if (new LinkParsingOperations(m_wikiContext).isExternalLink(m_ref)) {
url = m_ref;
} else if ((interwikipoint = m_ref.indexOf(":")) != -1) {
final String extWiki = m_ref.substring(0, interwikipoint);
final 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 {
final int hashMark;
final String parms = (m_version != null) ? "version=" + getVersion() : null;
// Internal wiki link, but is it an attachment link?
final Page p = engine.getManager(PageManager.class).getPage(m_pageName);
if (p instanceof Attachment) {
url = m_wikiContext.getURL(ContextEnum.PAGE_ATTACH.getRequestContext(), m_pageName);
} else if ((hashMark = m_ref.indexOf('#')) != -1) {
// It's an internal Wiki link, but to a named section
final 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) + sectref;
} else {
final String reallink = MarkupParser.cleanLink(m_ref);
url = makeBasicURL(m_context, reallink, parms);
}
}
} else if (m_pageName != null && !m_pageName.isEmpty()) {
final Page p = engine.getManager(PageManager.class).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(ContextEnum.PAGE_VIEW.getRequestContext())) {
ctx = ContextEnum.PAGE_ATTACH.getRequestContext();
}
url = engine.getURL(ctx, m_pageName, parms);
// url = m_wikiContext.getURL( ctx, m_pageName, parms );
} else {
url = makeBasicURL(m_context, m_pageName, parms);
}
} else {
final String page = engine.getFrontPage();
url = makeBasicURL(m_context, page, null);
}
return url;
}
use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class HasAttachmentsTag method doWikiStartTag.
@Override
public final int doWikiStartTag() {
final Engine engine = m_wikiContext.getEngine();
final Page page = m_wikiContext.getPage();
final AttachmentManager mgr = engine.getManager(AttachmentManager.class);
try {
if (page != null && engine.getManager(PageManager.class).wikiPageExists(page) && mgr.attachmentsEnabled()) {
if (mgr.hasAttachments(page)) {
return EVAL_BODY_INCLUDE;
}
}
} catch (final ProviderException e) {
log.fatal("Provider failed while trying to check for attachements", e);
// FIXME: THrow something.
}
return SKIP_BODY;
}
use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class RSS20Feed method getItems.
private List<Element> getItems() {
final ArrayList<Element> list = new ArrayList<>();
final SimpleDateFormat fmt = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'");
final Engine engine = m_wikiContext.getEngine();
ServletContext servletContext = null;
if (m_wikiContext.getHttpRequest() != null)
servletContext = m_wikiContext.getHttpRequest().getSession().getServletContext();
for (final Entry e : m_entries) {
final Page p = e.getPage();
final String url = e.getURL();
final Element item = new Element("item");
item.addContent(new Element("link").setText(url));
item.addContent(new Element("title").setText(e.getTitle()));
item.addContent(new Element("description").setText(e.getContent()));
//
if (engine.getManager(AttachmentManager.class).hasAttachments(p) && servletContext != null) {
try {
final List<Attachment> c = engine.getManager(AttachmentManager.class).listAttachments(p);
for (final Attachment att : c) {
final Element attEl = new Element("enclosure");
attEl.setAttribute("url", engine.getURL(ContextEnum.PAGE_ATTACH.getRequestContext(), att.getName(), null));
attEl.setAttribute("length", Long.toString(att.getSize()));
attEl.setAttribute("type", getMimeType(servletContext, att.getFileName()));
item.addContent(attEl);
}
} catch (final ProviderException ex) {
// FIXME: log.info("Can't get attachment data",ex);
}
}
//
// Modification date.
//
final Calendar cal = Calendar.getInstance();
cal.setTime(p.getLastModified());
cal.add(Calendar.MILLISECOND, -(cal.get(Calendar.ZONE_OFFSET) + (cal.getTimeZone().inDaylightTime(p.getLastModified()) ? cal.get(Calendar.DST_OFFSET) : 0)));
item.addContent(new Element("pubDate").setText(fmt.format(cal.getTime())));
list.add(item);
}
return list;
}
use of org.apache.wiki.api.core.Engine in project jspwiki by apache.
the class AuthorTag method doWikiStartTag.
/**
* {@inheritDoc}
*/
@Override
public final int doWikiStartTag() throws IOException {
final Engine engine = m_wikiContext.getEngine();
final Page page = m_wikiContext.getPage();
String author = page.getAuthor();
if (author != null && !author.isEmpty()) {
author = TextUtil.replaceEntities(author);
if (engine.getManager(PageManager.class).wikiPageExists(author) && !("plain".equalsIgnoreCase(m_format))) {
// FIXME: It's very boring to have to do this. Slow, too.
final RenderingManager mgr = engine.getManager(RenderingManager.class);
final MarkupParser p = mgr.getParser(m_wikiContext, "[" + author + "|" + author + "]");
final WikiDocument d = p.parse();
author = mgr.getHTML(m_wikiContext, d);
}
pageContext.getOut().print(author);
} else {
pageContext.getOut().print(Preferences.getBundle(m_wikiContext, InternationalizationManager.CORE_BUNDLE).getString("common.unknownauthor"));
}
return SKIP_BODY;
}
Aggregations