-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PLANTUML-15 Allow setting output format for generated diagram #2
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,19 @@ | |
@Role | ||
public interface PlantUMLGenerator | ||
{ | ||
/** | ||
* Generate the image in the passed output parameter, using PlantUML. | ||
* | ||
* @param input the textual definition input | ||
* @param output the stream into which the generated image will be written to | ||
* @param serverURL the optional plantUML server URL (e.g. {@code http://www.plantuml.com/plantuml}. If not an | ||
* empty string or not null then the URL is called to get the generated image. Otherwise PlantUML works in | ||
* embedded mode (requires installation of Graphviz locally for most diagram types, and the {@code | ||
* GRAPHVIZ_DOT} environment variable must be set to point to the path of the GraphViz executable). | ||
* @throws IOException when there's a generation or writing error | ||
*/ | ||
void outputImage(String input, OutputStream output, String serverURL) throws IOException; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will break backward compatibility. Revapi should fail. Also note that the javadoc formatting is not following our best practices but that should be easy to fix. See https://dev.xwiki.org/xwiki/bin/view/Community/CodeStyle/JavaCodeStyle/ To make this not break backward compatibiilty, just make it a default method. BTW the javadoc is not correct as it doesn't explain what's the difference with Are you sure we need this when we can already specify the format? Why is it needed? Thx |
||
|
||
/** | ||
* Generate the image in the passed output parameter, using PlantUML. | ||
* | ||
|
@@ -42,7 +55,8 @@ public interface PlantUMLGenerator | |
* empty string or not null then the URL is called to get the generated image. Otherwise PlantUML works in | ||
* embedded mode (requires installation of Graphviz locally for most diagram types, and the {@code | ||
* GRAPHVIZ_DOT} environment variable must be set to point to the path of the GraphViz executable). | ||
* @param format sets the output format from the PlantUML server | ||
* @throws IOException when there's a generation or writing error | ||
*/ | ||
void outputImage(String input, OutputStream output, String serverURL) throws IOException; | ||
void outputImage(String input, OutputStream output, String serverURL, String format) throws IOException; | ||
xumix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,8 @@ public class PlantUMLMacroParameters | |
{ | ||
private String serverURL; | ||
|
||
private String format; | ||
|
||
/** | ||
* @param serverURL see {@link #getServer()} | ||
*/ | ||
|
@@ -42,6 +44,16 @@ public void setServer(String serverURL) | |
this.serverURL = serverURL; | ||
} | ||
|
||
/** | ||
* @param format see {@link #getFormat()}. Valid values: svg, png, txt | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be improved. Best is to use: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also missing a |
||
*/ | ||
@PropertyDescription("the PlantUML output format") | ||
xumix marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing examples here. This is is important for users since this is what they'll see in the WYSIWYG macro UI |
||
public void setFormat(String format) | ||
{ | ||
this.format = format; | ||
} | ||
|
||
/** | ||
* @return the (optional) PlantUML server URL (e.g. {@code http://www.plantuml.com/plantuml}) | ||
*/ | ||
|
@@ -50,6 +62,14 @@ public String getServer() | |
return this.serverURL; | ||
} | ||
|
||
/** | ||
* @return the (optional) PlantUML output format, png by default. Valid values: svg, png, txt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. No need to dupicate. Better put a |
||
*/ | ||
public String getFormat() | ||
{ | ||
return this.format; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) | ||
{ | ||
|
@@ -65,6 +85,7 @@ public boolean equals(Object object) | |
PlantUMLMacroParameters rhs = (PlantUMLMacroParameters) object; | ||
return new EqualsBuilder() | ||
.append(getServer(), rhs.getServer()) | ||
.append(getFormat(), rhs.getFormat()) | ||
.isEquals(); | ||
} | ||
|
||
|
@@ -73,6 +94,7 @@ public int hashCode() | |
{ | ||
return new HashCodeBuilder(5, 37) | ||
.append(getServer()) | ||
.append(getFormat()) | ||
.toHashCode(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,4 +56,16 @@ public String getPlantUMLServerURL() | |
} | ||
return serverURL; | ||
} | ||
|
||
@Override | ||
public String getDefaultOutputFormat() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. formatting is not following our best practices, see above. |
||
String format = this.plantUMLConfigurationSource.getProperty("format"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see a |
||
// The returned value can be null if no xobject has been defined on the wiki config page. | ||
if (format == null) { | ||
// Fallback to xwiki.properties | ||
format = this.xwikiPropertiesConfigurationSource.getProperty("plantuml.format", "png"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: my previous feedback was not applied. You can write:
|
||
} | ||
xumix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return format; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,12 @@ public class DefaultPlantUMLGenerator implements PlantUMLGenerator | |
|
||
@Override | ||
public void outputImage(String input, OutputStream outputStream, String serverURL) throws IOException | ||
{ | ||
outputImage(input, outputStream, serverURL, "png"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like some unnecessary code duplication since we allow to pass null to default to the default configuration. See |
||
} | ||
|
||
@Override | ||
public void outputImage(String input, OutputStream outputStream, String serverURL, String format) throws IOException | ||
{ | ||
if (StringUtils.isEmpty(serverURL)) { | ||
new SourceStringReader(input).outputImage(outputStream); | ||
|
@@ -65,7 +71,7 @@ public void outputImage(String input, OutputStream outputStream, String serverUR | |
// https://plantuml.com/text-encoding | ||
String compressedInput = this.asciiEncoder.encode( | ||
this.compressor.compress(input.getBytes(StandardCharsets.UTF_8))); | ||
String fullURL = String.format("%s/png/~1%s", StringUtils.removeEnd(serverURL, "/"), compressedInput); | ||
String fullURL = String.format("%s/%s/~1%s", StringUtils.removeEnd(serverURL, "/"), format, compressedInput); | ||
// Call the server and get the response | ||
try (CloseableHttpClient httpclient = HttpClients.createDefault()) { | ||
HttpGet httpGet = new HttpGet(fullURL); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The since doesn't seem correct. This is the version of this extension when this changes will be in. Right now the pom says
2.1.2-SNAPSHOT
, so I'd say it should be2.2
since you're making non bug-fixing changes, hence we'll increase the minor version by 1.