use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class WikiEngineTest method testAttachmentRefs3.
/**
* Checks, if ReferenceManager is informed if a link to an attachment is added.
*/
@Test
public void testAttachmentRefs3() throws Exception {
final ReferenceManager refMgr = m_engine.getManager(ReferenceManager.class);
final AttachmentManager attMgr = m_engine.getManager(AttachmentManager.class);
m_engine.saveText(NAME1, "fooBar");
final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "TestAtt.txt");
att.setAuthor("FirstPost");
attMgr.storeAttachment(att, m_engine.makeAttachmentFile());
m_engine.saveText(NAME1, " [" + NAME1 + "/TestAtt.txt] ");
// and check post-conditions
Collection<String> c = refMgr.findUncreated();
Assertions.assertTrue(c == null || c.size() == 0, "attachment exists");
c = refMgr.findUnreferenced();
Assertions.assertEquals(c.size(), 1, "unreferenced count");
Assertions.assertEquals(NAME1, c.iterator().next(), "unreferenced");
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class DefaultPageRenamer method getReferencesToChange.
private Set<String> getReferencesToChange(final Page fromPage, final Engine engine) {
final Set<String> referrers = new TreeSet<>();
final Collection<String> r = engine.getManager(ReferenceManager.class).findReferrers(fromPage.getName());
if (r != null) {
referrers.addAll(r);
}
try {
final List<Attachment> attachments = engine.getManager(AttachmentManager.class).listAttachments(fromPage);
for (final Attachment att : attachments) {
final Collection<String> c = engine.getManager(ReferenceManager.class).findReferrers(att.getName());
if (c != null) {
referrers.addAll(c);
}
}
} catch (final ProviderException e) {
// We will continue despite this error
log.error("Provider error while fetching attachments for rename", e);
}
return referrers;
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class LinkTag method doEndTag.
@Override
public int doEndTag() {
try {
final Engine engine = m_wikiContext.getEngine();
final JspWriter out = pageContext.getOut();
final String url = figureOutURL();
final StringBuilder sb = new StringBuilder(20);
sb.append((m_cssClass != null) ? "class=\"" + m_cssClass + "\" " : "");
sb.append((m_style != null) ? "style=\"" + m_style + "\" " : "");
sb.append((m_target != null) ? "target=\"" + m_target + "\" " : "");
sb.append((m_title != null) ? "title=\"" + m_title + "\" " : "");
sb.append((m_rel != null) ? "rel=\"" + m_rel + "\" " : "");
sb.append((m_accesskey != null) ? "accesskey=\"" + m_accesskey + "\" " : "");
sb.append((m_tabindex != null) ? "tabindex=\"" + m_tabindex + "\" " : "");
if (engine.getManager(PageManager.class).getPage(m_pageName) instanceof Attachment) {
sb.append(engine.getManager(AttachmentManager.class).forceDownload(m_pageName) ? "download " : "");
}
switch(m_format) {
case URL:
out.print(url);
break;
default:
case ANCHOR:
out.print("<a " + sb + " href=\"" + url + "\">");
break;
}
// Add any explicit body content. This is not the intended use of LinkTag, but happens to be the way it has worked previously.
if (m_bodyContent != null) {
final String linktext = m_bodyContent.getString().trim();
out.write(linktext);
}
// Finish off by closing opened anchor
if (m_format == ANCHOR)
out.print("</a>");
} catch (final Exception e) {
// Yes, we want to catch all exceptions here, including RuntimeExceptions
log.error("Tag failed", e);
}
return EVAL_PAGE;
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class LinkToTag method doWikiStartTag.
@Override
public int doWikiStartTag() throws IOException {
String pageName = m_pageName;
boolean isattachment = false;
if (m_pageName == null) {
final Page p = m_wikiContext.getPage();
if (p != null) {
pageName = p.getName();
isattachment = p instanceof Attachment;
} else {
return SKIP_BODY;
}
}
final JspWriter out = pageContext.getOut();
final String url;
final String linkclass;
String forceDownload = "";
if (isattachment) {
url = m_wikiContext.getURL(ContextEnum.PAGE_ATTACH.getRequestContext(), pageName, (getVersion() != null) ? "version=" + getVersion() : null);
linkclass = "attachment";
if (m_wikiContext.getEngine().getManager(AttachmentManager.class).forceDownload(pageName)) {
forceDownload = "download ";
}
} else {
final StringBuilder params = new StringBuilder();
if (getVersion() != null) {
params.append("version=").append(getVersion());
}
if (getTemplate() != null) {
params.append(params.length() > 0 ? "&" : "").append("skin=").append(getTemplate());
}
url = m_wikiContext.getURL(ContextEnum.PAGE_VIEW.getRequestContext(), pageName, params.toString());
linkclass = "wikipage";
}
switch(m_format) {
case ANCHOR:
out.print("<a class=\"" + linkclass + "\" href=\"" + url + "\" accesskey=\"" + m_accesskey + "\" title=\"" + m_title + "\" " + forceDownload + ">");
break;
case URL:
out.print(url);
break;
}
return EVAL_BODY_INCLUDE;
}
use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.
the class AttachmentsIteratorTag method doAfterBody.
/**
* {@inheritDoc}
*/
@Override
public final int doAfterBody() {
if (bodyContent != null) {
try {
final JspWriter out = getPreviousOut();
out.print(bodyContent.getString());
bodyContent.clearBody();
} catch (final IOException e) {
log.error("Unable to get inner tag text", e);
// FIXME: throw something?
}
}
if (m_iterator != null && m_iterator.hasNext()) {
final Attachment att = (Attachment) m_iterator.next();
final Context context = m_wikiContext.clone();
context.setPage(att);
pageContext.setAttribute(Context.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
pageContext.setAttribute(getId(), att);
return EVAL_BODY_BUFFERED;
}
return SKIP_BODY;
}
Aggregations