optimise imports, reformat and remove dead code
This commit is contained in:
@@ -2,52 +2,43 @@ package com.atlassian.plugins.confluence.markdown;
|
|||||||
|
|
||||||
import com.atlassian.confluence.content.render.xhtml.ConversionContext;
|
import com.atlassian.confluence.content.render.xhtml.ConversionContext;
|
||||||
import com.atlassian.confluence.content.render.xhtml.DefaultConversionContext;
|
import com.atlassian.confluence.content.render.xhtml.DefaultConversionContext;
|
||||||
import com.atlassian.confluence.content.render.xhtml.XhtmlException;
|
|
||||||
import com.atlassian.confluence.macro.Macro;
|
import com.atlassian.confluence.macro.Macro;
|
||||||
import com.atlassian.confluence.macro.MacroExecutionException;
|
import com.atlassian.confluence.macro.MacroExecutionException;
|
||||||
import com.atlassian.confluence.xhtml.api.MacroDefinition;
|
|
||||||
import com.atlassian.confluence.xhtml.api.MacroDefinitionHandler;
|
|
||||||
import com.atlassian.confluence.xhtml.api.XhtmlContent;
|
import com.atlassian.confluence.xhtml.api.XhtmlContent;
|
||||||
|
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.atlassian.renderer.RenderContext;
|
import com.atlassian.renderer.RenderContext;
|
||||||
import com.atlassian.renderer.v2.RenderMode;
|
import com.atlassian.renderer.v2.RenderMode;
|
||||||
import com.atlassian.renderer.v2.macro.BaseMacro;
|
import com.atlassian.renderer.v2.macro.BaseMacro;
|
||||||
import com.atlassian.renderer.v2.macro.MacroException;
|
import com.atlassian.renderer.v2.macro.MacroException;
|
||||||
|
|
||||||
//import com.atlassian.plugin.spring.scanner.annotation.component.Scanned;
|
|
||||||
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
|
|
||||||
import com.atlassian.webresource.api.assembler.PageBuilderService;
|
import com.atlassian.webresource.api.assembler.PageBuilderService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
|
|
||||||
import com.vladsch.flexmark.ast.Node;
|
import com.vladsch.flexmark.ast.Node;
|
||||||
import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughSubscriptExtension;
|
|
||||||
import com.vladsch.flexmark.ext.tables.TablesExtension;
|
|
||||||
import com.vladsch.flexmark.ext.ins.InsExtension;
|
|
||||||
import com.vladsch.flexmark.ext.definition.DefinitionExtension;
|
|
||||||
import com.vladsch.flexmark.ext.gfm.tasklist.TaskListExtension;
|
|
||||||
import com.vladsch.flexmark.ext.footnotes.FootnoteExtension;
|
|
||||||
import com.vladsch.flexmark.ext.wikilink.WikiLinkExtension;
|
|
||||||
import com.vladsch.flexmark.ext.autolink.AutolinkExtension;
|
|
||||||
import com.vladsch.flexmark.ext.anchorlink.AnchorLinkExtension;
|
import com.vladsch.flexmark.ext.anchorlink.AnchorLinkExtension;
|
||||||
import com.vladsch.flexmark.superscript.SuperscriptExtension;
|
import com.vladsch.flexmark.ext.autolink.AutolinkExtension;
|
||||||
|
import com.vladsch.flexmark.ext.definition.DefinitionExtension;
|
||||||
|
import com.vladsch.flexmark.ext.footnotes.FootnoteExtension;
|
||||||
|
import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughSubscriptExtension;
|
||||||
|
import com.vladsch.flexmark.ext.gfm.tasklist.TaskListExtension;
|
||||||
|
import com.vladsch.flexmark.ext.ins.InsExtension;
|
||||||
|
import com.vladsch.flexmark.ext.tables.TablesExtension;
|
||||||
|
import com.vladsch.flexmark.ext.wikilink.WikiLinkExtension;
|
||||||
import com.vladsch.flexmark.ext.youtube.embedded.YouTubeLinkExtension;
|
import com.vladsch.flexmark.ext.youtube.embedded.YouTubeLinkExtension;
|
||||||
import com.vladsch.flexmark.html.HtmlRenderer;
|
import com.vladsch.flexmark.html.HtmlRenderer;
|
||||||
import com.vladsch.flexmark.parser.Parser;
|
import com.vladsch.flexmark.parser.Parser;
|
||||||
|
import com.vladsch.flexmark.superscript.SuperscriptExtension;
|
||||||
import com.vladsch.flexmark.util.options.MutableDataSet;
|
import com.vladsch.flexmark.util.options.MutableDataSet;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
import java.net.*;
|
public class MarkdownFromURLMacro extends BaseMacro implements Macro {
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
//@Scanned
|
|
||||||
public class MarkdownFromURLMacro extends BaseMacro implements Macro
|
|
||||||
{
|
|
||||||
|
|
||||||
private final XhtmlContent xhtmlUtils;
|
private final XhtmlContent xhtmlUtils;
|
||||||
|
|
||||||
@@ -59,26 +50,19 @@ public class MarkdownFromURLMacro extends BaseMacro implements Macro
|
|||||||
this.xhtmlUtils = xhtmlUtils;
|
this.xhtmlUtils = xhtmlUtils;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public MarkdownFromURLMacro(XhtmlContent xhtmlUtils)
|
|
||||||
// {
|
|
||||||
// this.xhtmlUtils = xhtmlUtils;
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BodyType getBodyType()
|
public BodyType getBodyType() {
|
||||||
{
|
|
||||||
return BodyType.PLAIN_TEXT;
|
return BodyType.PLAIN_TEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OutputType getOutputType()
|
public OutputType getOutputType() {
|
||||||
{
|
|
||||||
return OutputType.BLOCK;
|
return OutputType.BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String execute(Map<String, String> parameters, String bodyContent, ConversionContext conversionContext) throws MacroExecutionException
|
public String execute(Map<String, String> parameters, String bodyContent, ConversionContext conversionContext) throws MacroExecutionException {
|
||||||
{
|
|
||||||
|
|
||||||
if (bodyContent != null) {
|
if (bodyContent != null) {
|
||||||
pageBuilderService.assembler().resources().requireWebResource("com.atlassian.plugins.confluence.markdown.confluence-markdown-macro:highlightjs");
|
pageBuilderService.assembler().resources().requireWebResource("com.atlassian.plugins.confluence.markdown.confluence-markdown-macro:highlightjs");
|
||||||
@@ -132,30 +116,25 @@ public class MarkdownFromURLMacro extends BaseMacro implements Macro
|
|||||||
toParse = toParse.trim();
|
toParse = toParse.trim();
|
||||||
if (toParse.startsWith("<html>\n<head>\n <title>OpenID transaction in progress</title>")) {
|
if (toParse.startsWith("<html>\n<head>\n <title>OpenID transaction in progress</title>")) {
|
||||||
throw new privateRepositoryException("Cannot import from private repository.");
|
throw new privateRepositoryException("Cannot import from private repository.");
|
||||||
}else {
|
} else {
|
||||||
Node document = parser.parse(toParse);
|
Node document = parser.parse(toParse);
|
||||||
html = renderer.render(document) + highlightjs;
|
html = renderer.render(document) + highlightjs;
|
||||||
}
|
}
|
||||||
}
|
} catch (MalformedURLException u) {
|
||||||
catch (MalformedURLException u) {
|
|
||||||
exceptionsToReturn = exceptionsToReturn + "<strong>Error with Markdown From URL macro: Invalid URL.</strong><br>Please enter a valid URL. If you are not trying to import markdown from a URL, use the Markdown macro instead of the Markdown from URL macro.<br>For support <a href='https://community.atlassian.com/t5/tag/addon-com.atlassian.plugins.confluence.markdown.confluence-markdown-macro/tg-p'>visit our Q&A in the Atlassian Community</a>. You can ask a new question by clicking the \"Create\" button on the top right of the Q&A.<br>";
|
exceptionsToReturn = exceptionsToReturn + "<strong>Error with Markdown From URL macro: Invalid URL.</strong><br>Please enter a valid URL. If you are not trying to import markdown from a URL, use the Markdown macro instead of the Markdown from URL macro.<br>For support <a href='https://community.atlassian.com/t5/tag/addon-com.atlassian.plugins.confluence.markdown.confluence-markdown-macro/tg-p'>visit our Q&A in the Atlassian Community</a>. You can ask a new question by clicking the \"Create\" button on the top right of the Q&A.<br>";
|
||||||
}
|
} catch (privateRepositoryException p) {
|
||||||
catch (privateRepositoryException p) {
|
|
||||||
exceptionsToReturn = exceptionsToReturn + "<strong>Error with Markdown From URL macro: Importing from private Bitbucket repositories is not supported.</strong><br>Please make your repository public before importing. Alternatively, you can copy and paste your markdown into the Markdown macro.<br>If you are allowed access, you can find the markdown file <a href='" + bodyContent + "'>here</a>.<br>For support <a href='https://community.atlassian.com/t5/tag/addon-com.atlassian.plugins.confluence.markdown.confluence-markdown-macro/tg-p'>visit our Q&A in the Atlassian Community</a>. You can ask a new question by clicking the \"Create\" button on the top right of the Q&A.<br>";
|
exceptionsToReturn = exceptionsToReturn + "<strong>Error with Markdown From URL macro: Importing from private Bitbucket repositories is not supported.</strong><br>Please make your repository public before importing. Alternatively, you can copy and paste your markdown into the Markdown macro.<br>If you are allowed access, you can find the markdown file <a href='" + bodyContent + "'>here</a>.<br>For support <a href='https://community.atlassian.com/t5/tag/addon-com.atlassian.plugins.confluence.markdown.confluence-markdown-macro/tg-p'>visit our Q&A in the Atlassian Community</a>. You can ask a new question by clicking the \"Create\" button on the top right of the Q&A.<br>";
|
||||||
}
|
} catch (FileNotFoundException f) {
|
||||||
catch (FileNotFoundException f) {
|
|
||||||
exceptionsToReturn = exceptionsToReturn + "<strong>Error with Markdown From URL macro: URL does not exist.</strong><br>" + bodyContent + "<br>Please double check your URL. Perhaps you made a typo or perhaps the page has been moved.<br>This can also be caused by changing the Github repository containing the file from public to private. If this is the case go back to the raw file and re-copy the link.<br>For support <a href='https://community.atlassian.com/t5/tag/addon-com.atlassian.plugins.confluence.markdown.confluence-markdown-macro/tg-p'>visit our Q&A in the Atlassian Community</a>. You can ask a new question by clicking the \"Create\" button on the top right of the Q&A.<br>";
|
exceptionsToReturn = exceptionsToReturn + "<strong>Error with Markdown From URL macro: URL does not exist.</strong><br>" + bodyContent + "<br>Please double check your URL. Perhaps you made a typo or perhaps the page has been moved.<br>This can also be caused by changing the Github repository containing the file from public to private. If this is the case go back to the raw file and re-copy the link.<br>For support <a href='https://community.atlassian.com/t5/tag/addon-com.atlassian.plugins.confluence.markdown.confluence-markdown-macro/tg-p'>visit our Q&A in the Atlassian Community</a>. You can ask a new question by clicking the \"Create\" button on the top right of the Q&A.<br>";
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e) {
|
|
||||||
exceptionsToReturn = exceptionsToReturn + "<strong>Error with Markdown From URL macro: Unexpected error.</strong><br>" + e.toString() + "<br>For support <a href='https://community.atlassian.com/t5/tag/addon-com.atlassian.plugins.confluence.markdown.confluence-markdown-macro/tg-p'>visit our Q&A in the Atlassian Community</a>. You can ask a new question by clicking the \"Create\" button on the top right of the Q&A.<br>";
|
exceptionsToReturn = exceptionsToReturn + "<strong>Error with Markdown From URL macro: Unexpected error.</strong><br>" + e.toString() + "<br>For support <a href='https://community.atlassian.com/t5/tag/addon-com.atlassian.plugins.confluence.markdown.confluence-markdown-macro/tg-p'>visit our Q&A in the Atlassian Community</a>. You can ask a new question by clicking the \"Create\" button on the top right of the Q&A.<br>";
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
if (exceptionsToReturn != "") {
|
if (exceptionsToReturn != "") {
|
||||||
html = "<p style='background: #ffe0e0; border-radius: 5px; padding: 10px;'>" + exceptionsToReturn + "</p>";
|
html = "<p style='background: #ffe0e0; border-radius: 5px; padding: 10px;'>" + exceptionsToReturn + "</p>";
|
||||||
}
|
}
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,7 +154,7 @@ public class MarkdownFromURLMacro extends BaseMacro implements Macro
|
|||||||
try {
|
try {
|
||||||
return execute(map, s, new DefaultConversionContext(renderContext));
|
return execute(map, s, new DefaultConversionContext(renderContext));
|
||||||
} catch (MacroExecutionException e) {
|
} catch (MacroExecutionException e) {
|
||||||
throw new MacroException(e.getMessage(),e);
|
throw new MacroException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,48 +2,36 @@ package com.atlassian.plugins.confluence.markdown;
|
|||||||
|
|
||||||
import com.atlassian.confluence.content.render.xhtml.ConversionContext;
|
import com.atlassian.confluence.content.render.xhtml.ConversionContext;
|
||||||
import com.atlassian.confluence.content.render.xhtml.DefaultConversionContext;
|
import com.atlassian.confluence.content.render.xhtml.DefaultConversionContext;
|
||||||
import com.atlassian.confluence.content.render.xhtml.XhtmlException;
|
|
||||||
import com.atlassian.confluence.macro.Macro;
|
import com.atlassian.confluence.macro.Macro;
|
||||||
import com.atlassian.confluence.macro.MacroExecutionException;
|
import com.atlassian.confluence.macro.MacroExecutionException;
|
||||||
import com.atlassian.confluence.xhtml.api.MacroDefinition;
|
|
||||||
import com.atlassian.confluence.xhtml.api.MacroDefinitionHandler;
|
|
||||||
import com.atlassian.confluence.xhtml.api.XhtmlContent;
|
import com.atlassian.confluence.xhtml.api.XhtmlContent;
|
||||||
|
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.atlassian.renderer.RenderContext;
|
import com.atlassian.renderer.RenderContext;
|
||||||
import com.atlassian.renderer.v2.RenderMode;
|
import com.atlassian.renderer.v2.RenderMode;
|
||||||
import com.atlassian.renderer.v2.macro.BaseMacro;
|
import com.atlassian.renderer.v2.macro.BaseMacro;
|
||||||
import com.atlassian.renderer.v2.macro.MacroException;
|
import com.atlassian.renderer.v2.macro.MacroException;
|
||||||
|
|
||||||
//import com.atlassian.plugin.spring.scanner.annotation.component.Scanned;
|
|
||||||
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
|
|
||||||
import com.atlassian.webresource.api.assembler.PageBuilderService;
|
import com.atlassian.webresource.api.assembler.PageBuilderService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import com.vladsch.flexmark.ast.Node;
|
import com.vladsch.flexmark.ast.Node;
|
||||||
import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughSubscriptExtension;
|
|
||||||
import com.vladsch.flexmark.ext.tables.TablesExtension;
|
|
||||||
import com.vladsch.flexmark.ext.ins.InsExtension;
|
|
||||||
import com.vladsch.flexmark.ext.definition.DefinitionExtension;
|
|
||||||
import com.vladsch.flexmark.ext.gfm.tasklist.TaskListExtension;
|
|
||||||
import com.vladsch.flexmark.ext.footnotes.FootnoteExtension;
|
|
||||||
import com.vladsch.flexmark.ext.wikilink.WikiLinkExtension;
|
|
||||||
import com.vladsch.flexmark.ext.autolink.AutolinkExtension;
|
|
||||||
import com.vladsch.flexmark.ext.anchorlink.AnchorLinkExtension;
|
import com.vladsch.flexmark.ext.anchorlink.AnchorLinkExtension;
|
||||||
import com.vladsch.flexmark.superscript.SuperscriptExtension;
|
import com.vladsch.flexmark.ext.autolink.AutolinkExtension;
|
||||||
|
import com.vladsch.flexmark.ext.definition.DefinitionExtension;
|
||||||
|
import com.vladsch.flexmark.ext.footnotes.FootnoteExtension;
|
||||||
|
import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughSubscriptExtension;
|
||||||
|
import com.vladsch.flexmark.ext.gfm.tasklist.TaskListExtension;
|
||||||
|
import com.vladsch.flexmark.ext.ins.InsExtension;
|
||||||
|
import com.vladsch.flexmark.ext.tables.TablesExtension;
|
||||||
|
import com.vladsch.flexmark.ext.wikilink.WikiLinkExtension;
|
||||||
import com.vladsch.flexmark.ext.youtube.embedded.YouTubeLinkExtension;
|
import com.vladsch.flexmark.ext.youtube.embedded.YouTubeLinkExtension;
|
||||||
import com.vladsch.flexmark.html.HtmlRenderer;
|
import com.vladsch.flexmark.html.HtmlRenderer;
|
||||||
import com.vladsch.flexmark.parser.Parser;
|
import com.vladsch.flexmark.parser.Parser;
|
||||||
|
import com.vladsch.flexmark.superscript.SuperscriptExtension;
|
||||||
import com.vladsch.flexmark.util.options.MutableDataSet;
|
import com.vladsch.flexmark.util.options.MutableDataSet;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
//@Scanned
|
public class MarkdownMacro extends BaseMacro implements Macro {
|
||||||
public class MarkdownMacro extends BaseMacro implements Macro
|
|
||||||
{
|
|
||||||
|
|
||||||
private final XhtmlContent xhtmlUtils;
|
private final XhtmlContent xhtmlUtils;
|
||||||
|
|
||||||
@@ -55,26 +43,18 @@ public class MarkdownMacro extends BaseMacro implements Macro
|
|||||||
this.xhtmlUtils = xhtmlUtils;
|
this.xhtmlUtils = xhtmlUtils;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public MarkdownMacro(XhtmlContent xhtmlUtils)
|
|
||||||
// {
|
|
||||||
// this.xhtmlUtils = xhtmlUtils;
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BodyType getBodyType()
|
public BodyType getBodyType() {
|
||||||
{
|
|
||||||
return BodyType.PLAIN_TEXT;
|
return BodyType.PLAIN_TEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OutputType getOutputType()
|
public OutputType getOutputType() {
|
||||||
{
|
|
||||||
return OutputType.BLOCK;
|
return OutputType.BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String execute(Map<String, String> parameters, String bodyContent, ConversionContext conversionContext) throws MacroExecutionException
|
public String execute(Map<String, String> parameters, String bodyContent, ConversionContext conversionContext) throws MacroExecutionException {
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
pageBuilderService.assembler().resources().requireWebResource("com.atlassian.plugins.confluence.markdown.confluence-markdown-macro:highlightjs");
|
pageBuilderService.assembler().resources().requireWebResource("com.atlassian.plugins.confluence.markdown.confluence-markdown-macro:highlightjs");
|
||||||
@@ -107,7 +87,7 @@ public class MarkdownMacro extends BaseMacro implements Macro
|
|||||||
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
|
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
|
||||||
|
|
||||||
Node document = parser.parse(bodyContent);
|
Node document = parser.parse(bodyContent);
|
||||||
String html = renderer.render(document ) + highlightjs; // "<p>This is <em>Sparta</em></p>\n"
|
String html = renderer.render(document) + highlightjs; // "<p>This is <em>Sparta</em></p>\n"
|
||||||
return html;
|
return html;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -127,7 +107,7 @@ public class MarkdownMacro extends BaseMacro implements Macro
|
|||||||
try {
|
try {
|
||||||
return execute(map, s, new DefaultConversionContext(renderContext));
|
return execute(map, s, new DefaultConversionContext(renderContext));
|
||||||
} catch (MacroExecutionException e) {
|
} catch (MacroExecutionException e) {
|
||||||
throw new MacroException(e.getMessage(),e);
|
throw new MacroException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user