# PlantUMLMacroGClass

Last modified by Helge Dahl on 2018/03/07 23:26

#### Export

#### Office Formats

Export as PDF Export as ODT Export as RTF

#### Other Formats

Export as HTML

/* Groovy Class #* */

import net.sourceforge.plantuml.*

class PlantUMLMacroGClass {
def umldoc;
def ctx;
def umltext;
def imageFormat;
def enableImageMap;

void setObjects( doc, context, text, format, imageMap) {
umldoc = doc
ctx = context
umltext = text
imageFormat = format
enableImageMap = imageMap
}

String run( request, response) {
Using umlref, each diagram of the wiki page has its own unique url
def umlref="1"
if (null != ctx.umlref) {
umlref=Integer.toString(Integer.valueOf(ctx.umlref)+1)
}
ctx.put("umlref", umlref)

if("true".equals(request.preview)){
umltext = request.getSession().getAttribute("preview_uml_" + umlref)
request.getSession().removeAttribute("preview_uml_" + umlref)
}

def reader = new SourceStringReader("@startuml\n"+umltext+"\n@enduml")
if ("plain".equals(request.xpage)) {
if( !umlref.equals(request.uml) ){
return "";
}
response.setContentType( "svg".equals(imageFormat) ? "image/svg+xml" : "image/png" )
def img = response.getOutputStream()
def desc = reader.outputImage(img, new FileFormatOption("svg".equals(imageFormat) ? FileFormat.SVG : FileFormat.PNG))
img.close();
return ""
} else if("xpart".equals(request.xpage)) {
return ""
} else {
def preview = false
if("wysiwyginput".equals(request.xpage) || request.getRequestURL().indexOf("/bin/preview/") != -1){
imageFormat = "png"
enableImageMap = true
preview = true
request.getSession().setAttribute("preview_uml_" + umlref, umltext)
}
if("svg".equals(imageFormat)){
return "" + "

" + ""
} else {
if( !enableImageMap ){
return ""
} else {
def imgMapHtml = "<map name=\"umlmap"+umlref+"\">";
String[] mapLines = new String[0];
String map = reader.generateImage(new NullOutputStream(), new FileFormatOption(FileFormat.PNG, false));
String map = reader.getCMapData(0, new FileFormatOption(FileFormat.PNG, false));
if( map != null ){
mapLines = map.split("[
r
n]");
}
for (int i = 1; (i + 1) < mapLines.length; i++) {
imgMapHtml += mapLines[i] + "\n";
}
imgMapHtml += "</map>"
int random = (int)(Math.random() * 100)
return "" + "

" + imgMapHtml + "

" + ""
}
}
}
}
}

/* *# */

Tags:
Created by Helge Dahl on 2011/03/11 08:56

- Comments (0)
- Attachments (1)
- Information

# Applications

# Tips

Did you know that you can improve XWiki? Take 5 minutes to fill this survey and help this open source project!

# Need help?

If you need help with XWiki you can contact:

- Community Support
- Professional Support