in doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java [75:153]
public void execute(Sink sink, MacroRequest request) throws MacroExecutionException {
String id = (String) request.getParameter("id");
String urlParam = (String) request.getParameter("url");
String fileParam = (String) request.getParameter("file");
String debugParam = (String) request.getParameter("debug");
if (debugParam != null) {
this.debug = Boolean.parseBoolean(debugParam);
}
String ignoreDownloadErrorParam = (String) request.getParameter("ignoreDownloadError");
if (ignoreDownloadErrorParam != null) {
this.ignoreDownloadError = Boolean.parseBoolean(ignoreDownloadErrorParam);
}
boolean verbatim = true;
String verbatimParam = (String) request.getParameter("verbatim");
if (verbatimParam != null && !"".equals(verbatimParam)) {
verbatim = Boolean.valueOf(verbatimParam);
}
boolean source = true;
String sourceParam = (String) request.getParameter("source");
if (sourceParam != null && !"".equals(sourceParam)) {
source = Boolean.valueOf(sourceParam);
}
String encoding = (String) request.getParameter("encoding");
URL url;
if (!(urlParam == null || urlParam.isEmpty())) {
try {
url = new URL(urlParam);
} catch (MalformedURLException e) {
throw new IllegalArgumentException(urlParam + " is a malformed URL", e);
}
} else if (!(fileParam == null || fileParam.isEmpty())) {
File f = new File(fileParam);
if (!f.isAbsolute()) {
f = new File(request.getBasedir(), fileParam);
}
try {
url = f.toURI().toURL();
} catch (MalformedURLException e) {
throw new IllegalArgumentException(fileParam + " is a malformed URL", e);
}
} else {
throw new IllegalArgumentException("Either the 'url' or the 'file' param has to be provided");
}
StringBuffer snippet;
try {
snippet = getSnippet(url, encoding, id);
} catch (IOException e) {
throw new MacroExecutionException("Error reading snippet", e);
}
if (verbatim) {
sink.verbatim(source ? SinkEventAttributeSet.SOURCE : null);
sink.text(snippet.toString());
sink.verbatim_();
} else {
sink.rawText(snippet.toString());
}
}