mirror of
https://github.com/octoleo/plantuml.git
synced 2024-11-25 22:37:33 +00:00
Add reading remote style files from URLs (Fix #1470)
This commit is contained in:
parent
1ef8dd39f9
commit
d92242ec35
@ -37,6 +37,8 @@ package net.sourceforge.plantuml.style;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
import net.sourceforge.plantuml.FileSystem;
|
import net.sourceforge.plantuml.FileSystem;
|
||||||
import net.sourceforge.plantuml.TitledDiagram;
|
import net.sourceforge.plantuml.TitledDiagram;
|
||||||
@ -80,23 +82,32 @@ public class CommandStyleImport extends SingleLineCommand2<TitledDiagram> {
|
|||||||
protected CommandExecutionResult executeArg(TitledDiagram diagram, LineLocation location, RegexResult arg) {
|
protected CommandExecutionResult executeArg(TitledDiagram diagram, LineLocation location, RegexResult arg) {
|
||||||
final String path = arg.get("PATH", 0);
|
final String path = arg.get("PATH", 0);
|
||||||
try {
|
try {
|
||||||
final SFile f = FileSystem.getInstance().getFile(path);
|
|
||||||
BlocLines lines = null;
|
BlocLines lines = null;
|
||||||
if (f.exists()) {
|
if (path.startsWith("http")) {
|
||||||
lines = BlocLines.load(f, location);
|
URL url = new URL(path);
|
||||||
|
try (InputStream remoteInputStream = url.openStream()) {
|
||||||
|
lines = BlocLines.load(remoteInputStream, location);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
final InputStream internalIs = StyleLoader.class.getResourceAsStream("/skin/" + path);
|
final SFile styleFile = FileSystem.getInstance().getFile(path);
|
||||||
if (internalIs != null)
|
if (styleFile.exists()) {
|
||||||
lines = BlocLines.load(internalIs, location);
|
lines = BlocLines.load(styleFile, location);
|
||||||
|
} else {
|
||||||
|
final InputStream internalIs = StyleLoader.class.getResourceAsStream("/skin/" + path);
|
||||||
|
if (internalIs != null)
|
||||||
|
lines = BlocLines.load(internalIs, location);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (lines == null)
|
|
||||||
|
if (lines == null || lines.size() == 0)
|
||||||
return CommandExecutionResult.error("Cannot read: " + path);
|
return CommandExecutionResult.error("Cannot read: " + path);
|
||||||
|
|
||||||
final StyleBuilder styleBuilder = diagram.getSkinParam().getCurrentStyleBuilder();
|
final StyleBuilder styleBuilder = diagram.getSkinParam().getCurrentStyleBuilder();
|
||||||
for (Style modifiedStyle : StyleParser.parse(lines, styleBuilder))
|
for (Style modifiedStyle : StyleParser.parse(lines, styleBuilder))
|
||||||
diagram.getSkinParam().muteStyle(modifiedStyle);
|
diagram.getSkinParam().muteStyle(modifiedStyle);
|
||||||
|
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
return CommandExecutionResult.error("Invalid URL to style definition: " + e.getMessage());
|
||||||
} catch (StyleParsingException e) {
|
} catch (StyleParsingException e) {
|
||||||
return CommandExecutionResult.error("Error in style definition: " + e.getMessage());
|
return CommandExecutionResult.error("Error in style definition: " + e.getMessage());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user