@Test public void testCommentWithNewlines() throws Exception { long end = System.currentTimeMillis(); long start = end - (24 * 60 * 60 * 1000); String[] command = new String[] { "--start=" + start, "--end=" + end, "COMMENT:foo\\n" }; String[] command2 = new String[] { "--start=" + start, "--end=" + end, "COMMENT:foo\\n", "COMMENT:foo2\\n" }; RrdGraphDef graphDef = ((JRobinRrdStrategy)m_strategy).createGraphDef(new File(""), command); RrdGraph graph = new RrdGraph(graphDef); assertNotNull("graph object", graph); int firstHeight = graph.getRrdGraphInfo().getHeight(); RrdGraphDef graphDef2 = ((JRobinRrdStrategy)m_strategy).createGraphDef(new File(""), command2); RrdGraph graph2 = new RrdGraph(graphDef2); assertNotNull("second graph object", graph2); int secondHeight = graph2.getRrdGraphInfo().getHeight(); assertFalse("first graph height " + firstHeight + " and second graph height " + secondHeight + " should not be equal... there should be another newline in the second one making it taller", firstHeight == secondHeight); }
protected RrdGraphDef createGraphDef(final File workDir, final String[] inputArray) throws RrdException { RrdGraphDef graphDef = new RrdGraphDef(); graphDef.setImageFormat("PNG"); long start = 0; long end = 0; int height = 100; int width = 400; double lowerLimit = Double.NaN; double upperLimit = Double.NaN; boolean rigid = false; Map<String,List<String>> defs = new LinkedHashMap<String,List<String>>(); final String[] commandArray; if (inputArray[0].contains("rrdtool") && inputArray[1].equals("graph") && inputArray[2].equals("-")) { commandArray = Arrays.copyOfRange(inputArray, 3, inputArray.length); } else { commandArray = inputArray; } log().debug("command array = " + Arrays.toString(commandArray)); for (int i = 0; i < commandArray.length; i++) { String arg = commandArray[i]; if (arg.startsWith("--start=")) { start = Long.parseLong(arg.substring("--start=".length())); log().debug("JRobin start time: " + start); } else if (arg.equals("--start")) { if (i + 1 < commandArray.length) { start = Long.parseLong(commandArray[++i]); log().debug("JRobin start time: " + start); } else { throw new IllegalArgumentException("--start must be followed by a start time"); } } else if (arg.startsWith("--end=")) { end = Long.parseLong(arg.substring("--end=".length())); log().debug("JRobin end time: " + end); } else if (arg.equals("--end")) { if (i + 1 < commandArray.length) { end = Long.parseLong(commandArray[++i]); log().debug("JRobin end time: " + end); } else { throw new IllegalArgumentException("--end must be followed by an end time"); } } else if (arg.startsWith("--title=")) { String[] title = tokenize(arg, "=", true); graphDef.setTitle(title[1]); } else if (arg.equals("--title")) { if (i + 1 < commandArray.length) { graphDef.setTitle(commandArray[++i]); } else { throw new IllegalArgumentException("--title must be followed by a title"); } } else if (arg.startsWith("--color=")) { String[] color = tokenize(arg, "=", true); parseGraphColor(graphDef, color[1]); } else if (arg.equals("--color") || arg.equals("-c")) { if (i + 1 < commandArray.length) { parseGraphColor(graphDef, commandArray[++i]); } else { throw new IllegalArgumentException("--color must be followed by a color"); } } else if (arg.startsWith("--vertical-label=")) { String[] label = tokenize(arg, "=", true); graphDef.setVerticalLabel(label[1]); } else if (arg.equals("--vertical-label")) { if (i + 1 < commandArray.length) { graphDef.setVerticalLabel(commandArray[++i]); } else { throw new IllegalArgumentException("--vertical-label must be followed by a label"); } } else if (arg.startsWith("--height=")) { String[] argParm = tokenize(arg, "=", true); height = Integer.parseInt(argParm[1]); log().debug("JRobin height: "+height); } else if (arg.equals("--height")) { if (i + 1 < commandArray.length) { height = Integer.parseInt(commandArray[++i]); log().debug("JRobin height: "+height); } else { throw new IllegalArgumentException("--height must be followed by a number"); } } else if (arg.startsWith("--width=")) { String[] argParm = tokenize(arg, "=", true); width = Integer.parseInt(argParm[1]); log().debug("JRobin width: "+width); } else if (arg.equals("--width")) { if (i + 1 < commandArray.length) { width = Integer.parseInt(commandArray[++i]); log().debug("JRobin width: "+width); } else { throw new IllegalArgumentException("--width must be followed by a number"); } } else if (arg.startsWith("--units-exponent=")) { String[] argParm = tokenize(arg, "=", true); int exponent = Integer.parseInt(argParm[1]); log().debug("JRobin units exponent: "+exponent); graphDef.setUnitsExponent(exponent); } else if (arg.equals("--units-exponent")) { if (i + 1 < commandArray.length) { int exponent = Integer.parseInt(commandArray[++i]); log().debug("JRobin units exponent: "+exponent); graphDef.setUnitsExponent(exponent); } else { throw new IllegalArgumentException("--units-exponent must be followed by a number"); } } else if (arg.startsWith("--lower-limit=")) { String[] argParm = tokenize(arg, "=", true); lowerLimit = Double.parseDouble(argParm[1]); log().debug("JRobin lower limit: "+lowerLimit); } else if (arg.equals("--lower-limit")) { if (i + 1 < commandArray.length) { lowerLimit = Double.parseDouble(commandArray[++i]); log().debug("JRobin lower limit: "+lowerLimit); } else { throw new IllegalArgumentException("--lower-limit must be followed by a number"); } } else if (arg.startsWith("--upper-limit=")) { String[] argParm = tokenize(arg, "=", true); upperLimit = Double.parseDouble(argParm[1]); log().debug("JRobin upp limit: "+upperLimit); } else if (arg.equals("--upper-limit")) { if (i + 1 < commandArray.length) { upperLimit = Double.parseDouble(commandArray[++i]); log().debug("JRobin upper limit: "+upperLimit); } else { throw new IllegalArgumentException("--upper-limit must be followed by a number"); } } else if (arg.startsWith("--base=")) { String[] argParm = tokenize(arg, "=", true); graphDef.setBase(Double.parseDouble(argParm[1])); } else if (arg.equals("--base")) { if (i + 1 < commandArray.length) { graphDef.setBase(Double.parseDouble(commandArray[++i])); } else { throw new IllegalArgumentException("--base must be followed by a number"); } } else if (arg.startsWith("--font=")) { String[] argParm = tokenize(arg, "=", true); processRrdFontArgument(graphDef, argParm[1]); } else if (arg.equals("--font")) { if (i + 1 < commandArray.length) { processRrdFontArgument(graphDef, commandArray[++i]); } else { throw new IllegalArgumentException("--font must be followed by an argument"); } } else if (arg.startsWith("--imgformat=")) { String[] argParm = tokenize(arg, "=", true); graphDef.setImageFormat(argParm[1]); } else if (arg.equals("--imgformat")) { if (i + 1 < commandArray.length) { graphDef.setImageFormat(commandArray[++i]); } else { throw new IllegalArgumentException("--imgformat must be followed by an argument"); } } else if (arg.equals("--rigid")) { rigid = true; } else if (arg.startsWith("DEF:")) { String definition = arg.substring("DEF:".length()); String[] def = splitDef(definition); String[] ds = def[0].split("="); final String replaced = ds[1].replaceAll("\\\\(.)", "$1"); final File dsFile; File rawPathFile = new File(replaced); if (rawPathFile.isAbsolute()) { dsFile = rawPathFile; } else { dsFile = new File(workDir, replaced); } final String absolutePath = (File.separatorChar == '\\')? dsFile.getAbsolutePath().replace("\\", "\\\\") : dsFile.getAbsolutePath(); graphDef.datasource(ds[0], absolutePath, def[1], def[2]); List<String> defBits = new ArrayList<String>(); defBits.add(absolutePath); defBits.add(def[1]); defBits.add(def[2]); defs.put(ds[0], defBits); } else if (arg.startsWith("CDEF:")) { String definition = arg.substring("CDEF:".length()); String[] cdef = tokenize(definition, "=", true); graphDef.datasource(cdef[0], cdef[1]); List<String> cdefBits = new ArrayList<String>(); cdefBits.add(cdef[1]); defs.put(cdef[0], cdefBits); } else if (arg.startsWith("VDEF:")) { String definition = arg.substring("VDEF:".length()); String[] vdef = tokenize(definition, "=", true); String[] expressionTokens = tokenize(vdef[1], ",", false); addVdefDs(graphDef, vdef[0], expressionTokens, start, end, defs); } else if (arg.startsWith("LINE1:")) { String definition = arg.substring("LINE1:".length()); String[] line1 = tokenize(definition, ":", true); String[] color = tokenize(line1[0], "#", true); graphDef.line(color[0], getColorOrInvisible(color, 1), (line1.length > 1 ? line1[1] : "")); } else if (arg.startsWith("LINE2:")) { String definition = arg.substring("LINE2:".length()); String[] line2 = tokenize(definition, ":", true); String[] color = tokenize(line2[0], "#", true); graphDef.line(color[0], getColorOrInvisible(color, 1), (line2.length > 1 ? line2[1] : ""), 2); } else if (arg.startsWith("LINE3:")) { String definition = arg.substring("LINE3:".length()); String[] line3 = tokenize(definition, ":", true); String[] color = tokenize(line3[0], "#", true); graphDef.line(color[0], getColorOrInvisible(color, 1), (line3.length > 1 ? line3[1] : ""), 3); } else if (arg.startsWith("GPRINT:")) { String definition = arg.substring("GPRINT:".length()); String gprint[] = tokenize(definition, ":", true); String format = gprint[2]; format = format.replaceAll("\\n", "\\\\l"); graphDef.gprint(gprint[0], gprint[1], format); } else if (arg.startsWith("PRINT:")) { String definition = arg.substring("PRINT:".length()); String print[] = tokenize(definition, ":", true); String format = print[2]; format = format.replaceAll("\\n", "\\\\l"); graphDef.print(print[0], print[1], format); } else if (arg.startsWith("COMMENT:")) { String comments[] = tokenize(arg, ":", true); String format = comments[1].replaceAll("\\n", "\\\\l"); graphDef.comment(format); } else if (arg.startsWith("AREA:")) { String definition = arg.substring("AREA:".length()); String area[] = tokenize(definition, ":", true); String[] color = tokenize(area[0], "#", true); if (area.length > 1) { graphDef.area(color[0], getColorOrInvisible(color, 1), area[1]); } else { graphDef.area(color[0], getColorOrInvisible(color, 1)); } } else if (arg.startsWith("STACK:")) { String definition = arg.substring("STACK:".length()); String stack[] = tokenize(definition, ":", true); String[] color = tokenize(stack[0], "#", true); graphDef.stack(color[0], getColor(color[1]), (stack.length > 1 ? stack[1] : "")); } else if (arg.startsWith("HRULE:")) { String definition = arg.substring("HRULE:".length()); String hrule[] = tokenize(definition, ":", true); String[] color = tokenize(hrule[0], "#", true); Double value = Double.valueOf(color[0]); graphDef.hrule(value, getColor(color[1]), (hrule.length > 1 ? hrule[1] : "")); } else if (arg.endsWith("/rrdtool") || arg.equals("graph") || arg.equals("-")) { } else { log().warn("JRobin: Unrecognized graph argument: " + arg); } } graphDef.setTimeSpan(start, end); graphDef.setMinValue(lowerLimit); graphDef.setMaxValue(upperLimit); graphDef.setRigid(rigid); graphDef.setHeight(height); graphDef.setWidth(width); log().debug("JRobin Finished tokenizing checking: start time: " + start + "; end time: " + end); log().debug("large font = " + graphDef.getLargeFont() + ", small font = " + graphDef.getSmallFont()); return graphDef; }
JRobinRrdStrategy implements RrdStrategy<RrdDef,RrdDb> { protected RrdGraphDef createGraphDef(final File workDir, final String[] inputArray) throws RrdException { RrdGraphDef graphDef = new RrdGraphDef(); graphDef.setImageFormat("PNG"); long start = 0; long end = 0; int height = 100; int width = 400; double lowerLimit = Double.NaN; double upperLimit = Double.NaN; boolean rigid = false; Map<String,List<String>> defs = new LinkedHashMap<String,List<String>>(); final String[] commandArray; if (inputArray[0].contains("rrdtool") && inputArray[1].equals("graph") && inputArray[2].equals("-")) { commandArray = Arrays.copyOfRange(inputArray, 3, inputArray.length); } else { commandArray = inputArray; } log().debug("command array = " + Arrays.toString(commandArray)); for (int i = 0; i < commandArray.length; i++) { String arg = commandArray[i]; if (arg.startsWith("--start=")) { start = Long.parseLong(arg.substring("--start=".length())); log().debug("JRobin start time: " + start); } else if (arg.equals("--start")) { if (i + 1 < commandArray.length) { start = Long.parseLong(commandArray[++i]); log().debug("JRobin start time: " + start); } else { throw new IllegalArgumentException("--start must be followed by a start time"); } } else if (arg.startsWith("--end=")) { end = Long.parseLong(arg.substring("--end=".length())); log().debug("JRobin end time: " + end); } else if (arg.equals("--end")) { if (i + 1 < commandArray.length) { end = Long.parseLong(commandArray[++i]); log().debug("JRobin end time: " + end); } else { throw new IllegalArgumentException("--end must be followed by an end time"); } } else if (arg.startsWith("--title=")) { String[] title = tokenize(arg, "=", true); graphDef.setTitle(title[1]); } else if (arg.equals("--title")) { if (i + 1 < commandArray.length) { graphDef.setTitle(commandArray[++i]); } else { throw new IllegalArgumentException("--title must be followed by a title"); } } else if (arg.startsWith("--color=")) { String[] color = tokenize(arg, "=", true); parseGraphColor(graphDef, color[1]); } else if (arg.equals("--color") || arg.equals("-c")) { if (i + 1 < commandArray.length) { parseGraphColor(graphDef, commandArray[++i]); } else { throw new IllegalArgumentException("--color must be followed by a color"); } } else if (arg.startsWith("--vertical-label=")) { String[] label = tokenize(arg, "=", true); graphDef.setVerticalLabel(label[1]); } else if (arg.equals("--vertical-label")) { if (i + 1 < commandArray.length) { graphDef.setVerticalLabel(commandArray[++i]); } else { throw new IllegalArgumentException("--vertical-label must be followed by a label"); } } else if (arg.startsWith("--height=")) { String[] argParm = tokenize(arg, "=", true); height = Integer.parseInt(argParm[1]); log().debug("JRobin height: "+height); } else if (arg.equals("--height")) { if (i + 1 < commandArray.length) { height = Integer.parseInt(commandArray[++i]); log().debug("JRobin height: "+height); } else { throw new IllegalArgumentException("--height must be followed by a number"); } } else if (arg.startsWith("--width=")) { String[] argParm = tokenize(arg, "=", true); width = Integer.parseInt(argParm[1]); log().debug("JRobin width: "+width); } else if (arg.equals("--width")) { if (i + 1 < commandArray.length) { width = Integer.parseInt(commandArray[++i]); log().debug("JRobin width: "+width); } else { throw new IllegalArgumentException("--width must be followed by a number"); } } else if (arg.startsWith("--units-exponent=")) { String[] argParm = tokenize(arg, "=", true); int exponent = Integer.parseInt(argParm[1]); log().debug("JRobin units exponent: "+exponent); graphDef.setUnitsExponent(exponent); } else if (arg.equals("--units-exponent")) { if (i + 1 < commandArray.length) { int exponent = Integer.parseInt(commandArray[++i]); log().debug("JRobin units exponent: "+exponent); graphDef.setUnitsExponent(exponent); } else { throw new IllegalArgumentException("--units-exponent must be followed by a number"); } } else if (arg.startsWith("--lower-limit=")) { String[] argParm = tokenize(arg, "=", true); lowerLimit = Double.parseDouble(argParm[1]); log().debug("JRobin lower limit: "+lowerLimit); } else if (arg.equals("--lower-limit")) { if (i + 1 < commandArray.length) { lowerLimit = Double.parseDouble(commandArray[++i]); log().debug("JRobin lower limit: "+lowerLimit); } else { throw new IllegalArgumentException("--lower-limit must be followed by a number"); } } else if (arg.startsWith("--upper-limit=")) { String[] argParm = tokenize(arg, "=", true); upperLimit = Double.parseDouble(argParm[1]); log().debug("JRobin upp limit: "+upperLimit); } else if (arg.equals("--upper-limit")) { if (i + 1 < commandArray.length) { upperLimit = Double.parseDouble(commandArray[++i]); log().debug("JRobin upper limit: "+upperLimit); } else { throw new IllegalArgumentException("--upper-limit must be followed by a number"); } } else if (arg.startsWith("--base=")) { String[] argParm = tokenize(arg, "=", true); graphDef.setBase(Double.parseDouble(argParm[1])); } else if (arg.equals("--base")) { if (i + 1 < commandArray.length) { graphDef.setBase(Double.parseDouble(commandArray[++i])); } else { throw new IllegalArgumentException("--base must be followed by a number"); } } else if (arg.startsWith("--font=")) { String[] argParm = tokenize(arg, "=", true); processRrdFontArgument(graphDef, argParm[1]); } else if (arg.equals("--font")) { if (i + 1 < commandArray.length) { processRrdFontArgument(graphDef, commandArray[++i]); } else { throw new IllegalArgumentException("--font must be followed by an argument"); } } else if (arg.startsWith("--imgformat=")) { String[] argParm = tokenize(arg, "=", true); graphDef.setImageFormat(argParm[1]); } else if (arg.equals("--imgformat")) { if (i + 1 < commandArray.length) { graphDef.setImageFormat(commandArray[++i]); } else { throw new IllegalArgumentException("--imgformat must be followed by an argument"); } } else if (arg.equals("--rigid")) { rigid = true; } else if (arg.startsWith("DEF:")) { String definition = arg.substring("DEF:".length()); String[] def = splitDef(definition); String[] ds = def[0].split("="); final String replaced = ds[1].replaceAll("\\\\(.)", "$1"); final File dsFile; File rawPathFile = new File(replaced); if (rawPathFile.isAbsolute()) { dsFile = rawPathFile; } else { dsFile = new File(workDir, replaced); } final String absolutePath = (File.separatorChar == '\\')? dsFile.getAbsolutePath().replace("\\", "\\\\") : dsFile.getAbsolutePath(); graphDef.datasource(ds[0], absolutePath, def[1], def[2]); List<String> defBits = new ArrayList<String>(); defBits.add(absolutePath); defBits.add(def[1]); defBits.add(def[2]); defs.put(ds[0], defBits); } else if (arg.startsWith("CDEF:")) { String definition = arg.substring("CDEF:".length()); String[] cdef = tokenize(definition, "=", true); graphDef.datasource(cdef[0], cdef[1]); List<String> cdefBits = new ArrayList<String>(); cdefBits.add(cdef[1]); defs.put(cdef[0], cdefBits); } else if (arg.startsWith("VDEF:")) { String definition = arg.substring("VDEF:".length()); String[] vdef = tokenize(definition, "=", true); String[] expressionTokens = tokenize(vdef[1], ",", false); addVdefDs(graphDef, vdef[0], expressionTokens, start, end, defs); } else if (arg.startsWith("LINE1:")) { String definition = arg.substring("LINE1:".length()); String[] line1 = tokenize(definition, ":", true); String[] color = tokenize(line1[0], "#", true); graphDef.line(color[0], getColorOrInvisible(color, 1), (line1.length > 1 ? line1[1] : "")); } else if (arg.startsWith("LINE2:")) { String definition = arg.substring("LINE2:".length()); String[] line2 = tokenize(definition, ":", true); String[] color = tokenize(line2[0], "#", true); graphDef.line(color[0], getColorOrInvisible(color, 1), (line2.length > 1 ? line2[1] : ""), 2); } else if (arg.startsWith("LINE3:")) { String definition = arg.substring("LINE3:".length()); String[] line3 = tokenize(definition, ":", true); String[] color = tokenize(line3[0], "#", true); graphDef.line(color[0], getColorOrInvisible(color, 1), (line3.length > 1 ? line3[1] : ""), 3); } else if (arg.startsWith("GPRINT:")) { String definition = arg.substring("GPRINT:".length()); String gprint[] = tokenize(definition, ":", true); String format = gprint[2]; format = format.replaceAll("\\n", "\\\\l"); graphDef.gprint(gprint[0], gprint[1], format); } else if (arg.startsWith("PRINT:")) { String definition = arg.substring("PRINT:".length()); String print[] = tokenize(definition, ":", true); String format = print[2]; format = format.replaceAll("\\n", "\\\\l"); graphDef.print(print[0], print[1], format); } else if (arg.startsWith("COMMENT:")) { String comments[] = tokenize(arg, ":", true); String format = comments[1].replaceAll("\\n", "\\\\l"); graphDef.comment(format); } else if (arg.startsWith("AREA:")) { String definition = arg.substring("AREA:".length()); String area[] = tokenize(definition, ":", true); String[] color = tokenize(area[0], "#", true); if (area.length > 1) { graphDef.area(color[0], getColorOrInvisible(color, 1), area[1]); } else { graphDef.area(color[0], getColorOrInvisible(color, 1)); } } else if (arg.startsWith("STACK:")) { String definition = arg.substring("STACK:".length()); String stack[] = tokenize(definition, ":", true); String[] color = tokenize(stack[0], "#", true); graphDef.stack(color[0], getColor(color[1]), (stack.length > 1 ? stack[1] : "")); } else if (arg.startsWith("HRULE:")) { String definition = arg.substring("HRULE:".length()); String hrule[] = tokenize(definition, ":", true); String[] color = tokenize(hrule[0], "#", true); Double value = Double.valueOf(color[0]); graphDef.hrule(value, getColor(color[1]), (hrule.length > 1 ? hrule[1] : "")); } else if (arg.endsWith("/rrdtool") || arg.equals("graph") || arg.equals("-")) { } else { log().warn("JRobin: Unrecognized graph argument: " + arg); } } graphDef.setTimeSpan(start, end); graphDef.setMinValue(lowerLimit); graphDef.setMaxValue(upperLimit); graphDef.setRigid(rigid); graphDef.setHeight(height); graphDef.setWidth(width); log().debug("JRobin Finished tokenizing checking: start time: " + start + "; end time: " + end); log().debug("large font = " + graphDef.getLargeFont() + ", small font = " + graphDef.getSmallFont()); return graphDef; } }
JRobinRrdStrategy implements RrdStrategy<RrdDef,RrdDb> { protected RrdGraphDef createGraphDef(final File workDir, final String[] inputArray) throws RrdException { RrdGraphDef graphDef = new RrdGraphDef(); graphDef.setImageFormat("PNG"); long start = 0; long end = 0; int height = 100; int width = 400; double lowerLimit = Double.NaN; double upperLimit = Double.NaN; boolean rigid = false; Map<String,List<String>> defs = new LinkedHashMap<String,List<String>>(); final String[] commandArray; if (inputArray[0].contains("rrdtool") && inputArray[1].equals("graph") && inputArray[2].equals("-")) { commandArray = Arrays.copyOfRange(inputArray, 3, inputArray.length); } else { commandArray = inputArray; } log().debug("command array = " + Arrays.toString(commandArray)); for (int i = 0; i < commandArray.length; i++) { String arg = commandArray[i]; if (arg.startsWith("--start=")) { start = Long.parseLong(arg.substring("--start=".length())); log().debug("JRobin start time: " + start); } else if (arg.equals("--start")) { if (i + 1 < commandArray.length) { start = Long.parseLong(commandArray[++i]); log().debug("JRobin start time: " + start); } else { throw new IllegalArgumentException("--start must be followed by a start time"); } } else if (arg.startsWith("--end=")) { end = Long.parseLong(arg.substring("--end=".length())); log().debug("JRobin end time: " + end); } else if (arg.equals("--end")) { if (i + 1 < commandArray.length) { end = Long.parseLong(commandArray[++i]); log().debug("JRobin end time: " + end); } else { throw new IllegalArgumentException("--end must be followed by an end time"); } } else if (arg.startsWith("--title=")) { String[] title = tokenize(arg, "=", true); graphDef.setTitle(title[1]); } else if (arg.equals("--title")) { if (i + 1 < commandArray.length) { graphDef.setTitle(commandArray[++i]); } else { throw new IllegalArgumentException("--title must be followed by a title"); } } else if (arg.startsWith("--color=")) { String[] color = tokenize(arg, "=", true); parseGraphColor(graphDef, color[1]); } else if (arg.equals("--color") || arg.equals("-c")) { if (i + 1 < commandArray.length) { parseGraphColor(graphDef, commandArray[++i]); } else { throw new IllegalArgumentException("--color must be followed by a color"); } } else if (arg.startsWith("--vertical-label=")) { String[] label = tokenize(arg, "=", true); graphDef.setVerticalLabel(label[1]); } else if (arg.equals("--vertical-label")) { if (i + 1 < commandArray.length) { graphDef.setVerticalLabel(commandArray[++i]); } else { throw new IllegalArgumentException("--vertical-label must be followed by a label"); } } else if (arg.startsWith("--height=")) { String[] argParm = tokenize(arg, "=", true); height = Integer.parseInt(argParm[1]); log().debug("JRobin height: "+height); } else if (arg.equals("--height")) { if (i + 1 < commandArray.length) { height = Integer.parseInt(commandArray[++i]); log().debug("JRobin height: "+height); } else { throw new IllegalArgumentException("--height must be followed by a number"); } } else if (arg.startsWith("--width=")) { String[] argParm = tokenize(arg, "=", true); width = Integer.parseInt(argParm[1]); log().debug("JRobin width: "+width); } else if (arg.equals("--width")) { if (i + 1 < commandArray.length) { width = Integer.parseInt(commandArray[++i]); log().debug("JRobin width: "+width); } else { throw new IllegalArgumentException("--width must be followed by a number"); } } else if (arg.startsWith("--units-exponent=")) { String[] argParm = tokenize(arg, "=", true); int exponent = Integer.parseInt(argParm[1]); log().debug("JRobin units exponent: "+exponent); graphDef.setUnitsExponent(exponent); } else if (arg.equals("--units-exponent")) { if (i + 1 < commandArray.length) { int exponent = Integer.parseInt(commandArray[++i]); log().debug("JRobin units exponent: "+exponent); graphDef.setUnitsExponent(exponent); } else { throw new IllegalArgumentException("--units-exponent must be followed by a number"); } } else if (arg.startsWith("--lower-limit=")) { String[] argParm = tokenize(arg, "=", true); lowerLimit = Double.parseDouble(argParm[1]); log().debug("JRobin lower limit: "+lowerLimit); } else if (arg.equals("--lower-limit")) { if (i + 1 < commandArray.length) { lowerLimit = Double.parseDouble(commandArray[++i]); log().debug("JRobin lower limit: "+lowerLimit); } else { throw new IllegalArgumentException("--lower-limit must be followed by a number"); } } else if (arg.startsWith("--upper-limit=")) { String[] argParm = tokenize(arg, "=", true); upperLimit = Double.parseDouble(argParm[1]); log().debug("JRobin upp limit: "+upperLimit); } else if (arg.equals("--upper-limit")) { if (i + 1 < commandArray.length) { upperLimit = Double.parseDouble(commandArray[++i]); log().debug("JRobin upper limit: "+upperLimit); } else { throw new IllegalArgumentException("--upper-limit must be followed by a number"); } } else if (arg.startsWith("--base=")) { String[] argParm = tokenize(arg, "=", true); graphDef.setBase(Double.parseDouble(argParm[1])); } else if (arg.equals("--base")) { if (i + 1 < commandArray.length) { graphDef.setBase(Double.parseDouble(commandArray[++i])); } else { throw new IllegalArgumentException("--base must be followed by a number"); } } else if (arg.startsWith("--font=")) { String[] argParm = tokenize(arg, "=", true); processRrdFontArgument(graphDef, argParm[1]); } else if (arg.equals("--font")) { if (i + 1 < commandArray.length) { processRrdFontArgument(graphDef, commandArray[++i]); } else { throw new IllegalArgumentException("--font must be followed by an argument"); } } else if (arg.startsWith("--imgformat=")) { String[] argParm = tokenize(arg, "=", true); graphDef.setImageFormat(argParm[1]); } else if (arg.equals("--imgformat")) { if (i + 1 < commandArray.length) { graphDef.setImageFormat(commandArray[++i]); } else { throw new IllegalArgumentException("--imgformat must be followed by an argument"); } } else if (arg.equals("--rigid")) { rigid = true; } else if (arg.startsWith("DEF:")) { String definition = arg.substring("DEF:".length()); String[] def = splitDef(definition); String[] ds = def[0].split("="); final String replaced = ds[1].replaceAll("\\\\(.)", "$1"); final File dsFile; File rawPathFile = new File(replaced); if (rawPathFile.isAbsolute()) { dsFile = rawPathFile; } else { dsFile = new File(workDir, replaced); } final String absolutePath = (File.separatorChar == '\\')? dsFile.getAbsolutePath().replace("\\", "\\\\") : dsFile.getAbsolutePath(); graphDef.datasource(ds[0], absolutePath, def[1], def[2]); List<String> defBits = new ArrayList<String>(); defBits.add(absolutePath); defBits.add(def[1]); defBits.add(def[2]); defs.put(ds[0], defBits); } else if (arg.startsWith("CDEF:")) { String definition = arg.substring("CDEF:".length()); String[] cdef = tokenize(definition, "=", true); graphDef.datasource(cdef[0], cdef[1]); List<String> cdefBits = new ArrayList<String>(); cdefBits.add(cdef[1]); defs.put(cdef[0], cdefBits); } else if (arg.startsWith("VDEF:")) { String definition = arg.substring("VDEF:".length()); String[] vdef = tokenize(definition, "=", true); String[] expressionTokens = tokenize(vdef[1], ",", false); addVdefDs(graphDef, vdef[0], expressionTokens, start, end, defs); } else if (arg.startsWith("LINE1:")) { String definition = arg.substring("LINE1:".length()); String[] line1 = tokenize(definition, ":", true); String[] color = tokenize(line1[0], "#", true); graphDef.line(color[0], getColorOrInvisible(color, 1), (line1.length > 1 ? line1[1] : "")); } else if (arg.startsWith("LINE2:")) { String definition = arg.substring("LINE2:".length()); String[] line2 = tokenize(definition, ":", true); String[] color = tokenize(line2[0], "#", true); graphDef.line(color[0], getColorOrInvisible(color, 1), (line2.length > 1 ? line2[1] : ""), 2); } else if (arg.startsWith("LINE3:")) { String definition = arg.substring("LINE3:".length()); String[] line3 = tokenize(definition, ":", true); String[] color = tokenize(line3[0], "#", true); graphDef.line(color[0], getColorOrInvisible(color, 1), (line3.length > 1 ? line3[1] : ""), 3); } else if (arg.startsWith("GPRINT:")) { String definition = arg.substring("GPRINT:".length()); String gprint[] = tokenize(definition, ":", true); String format = gprint[2]; format = format.replaceAll("\\n", "\\\\l"); graphDef.gprint(gprint[0], gprint[1], format); } else if (arg.startsWith("PRINT:")) { String definition = arg.substring("PRINT:".length()); String print[] = tokenize(definition, ":", true); String format = print[2]; format = format.replaceAll("\\n", "\\\\l"); graphDef.print(print[0], print[1], format); } else if (arg.startsWith("COMMENT:")) { String comments[] = tokenize(arg, ":", true); String format = comments[1].replaceAll("\\n", "\\\\l"); graphDef.comment(format); } else if (arg.startsWith("AREA:")) { String definition = arg.substring("AREA:".length()); String area[] = tokenize(definition, ":", true); String[] color = tokenize(area[0], "#", true); if (area.length > 1) { graphDef.area(color[0], getColorOrInvisible(color, 1), area[1]); } else { graphDef.area(color[0], getColorOrInvisible(color, 1)); } } else if (arg.startsWith("STACK:")) { String definition = arg.substring("STACK:".length()); String stack[] = tokenize(definition, ":", true); String[] color = tokenize(stack[0], "#", true); graphDef.stack(color[0], getColor(color[1]), (stack.length > 1 ? stack[1] : "")); } else if (arg.startsWith("HRULE:")) { String definition = arg.substring("HRULE:".length()); String hrule[] = tokenize(definition, ":", true); String[] color = tokenize(hrule[0], "#", true); Double value = Double.valueOf(color[0]); graphDef.hrule(value, getColor(color[1]), (hrule.length > 1 ? hrule[1] : "")); } else if (arg.endsWith("/rrdtool") || arg.equals("graph") || arg.equals("-")) { } else { log().warn("JRobin: Unrecognized graph argument: " + arg); } } graphDef.setTimeSpan(start, end); graphDef.setMinValue(lowerLimit); graphDef.setMaxValue(upperLimit); graphDef.setRigid(rigid); graphDef.setHeight(height); graphDef.setWidth(width); log().debug("JRobin Finished tokenizing checking: start time: " + start + "; end time: " + end); log().debug("large font = " + graphDef.getLargeFont() + ", small font = " + graphDef.getSmallFont()); return graphDef; } JRobinRrdStrategy(); }
JRobinRrdStrategy implements RrdStrategy<RrdDef,RrdDb> { protected RrdGraphDef createGraphDef(final File workDir, final String[] inputArray) throws RrdException { RrdGraphDef graphDef = new RrdGraphDef(); graphDef.setImageFormat("PNG"); long start = 0; long end = 0; int height = 100; int width = 400; double lowerLimit = Double.NaN; double upperLimit = Double.NaN; boolean rigid = false; Map<String,List<String>> defs = new LinkedHashMap<String,List<String>>(); final String[] commandArray; if (inputArray[0].contains("rrdtool") && inputArray[1].equals("graph") && inputArray[2].equals("-")) { commandArray = Arrays.copyOfRange(inputArray, 3, inputArray.length); } else { commandArray = inputArray; } log().debug("command array = " + Arrays.toString(commandArray)); for (int i = 0; i < commandArray.length; i++) { String arg = commandArray[i]; if (arg.startsWith("--start=")) { start = Long.parseLong(arg.substring("--start=".length())); log().debug("JRobin start time: " + start); } else if (arg.equals("--start")) { if (i + 1 < commandArray.length) { start = Long.parseLong(commandArray[++i]); log().debug("JRobin start time: " + start); } else { throw new IllegalArgumentException("--start must be followed by a start time"); } } else if (arg.startsWith("--end=")) { end = Long.parseLong(arg.substring("--end=".length())); log().debug("JRobin end time: " + end); } else if (arg.equals("--end")) { if (i + 1 < commandArray.length) { end = Long.parseLong(commandArray[++i]); log().debug("JRobin end time: " + end); } else { throw new IllegalArgumentException("--end must be followed by an end time"); } } else if (arg.startsWith("--title=")) { String[] title = tokenize(arg, "=", true); graphDef.setTitle(title[1]); } else if (arg.equals("--title")) { if (i + 1 < commandArray.length) { graphDef.setTitle(commandArray[++i]); } else { throw new IllegalArgumentException("--title must be followed by a title"); } } else if (arg.startsWith("--color=")) { String[] color = tokenize(arg, "=", true); parseGraphColor(graphDef, color[1]); } else if (arg.equals("--color") || arg.equals("-c")) { if (i + 1 < commandArray.length) { parseGraphColor(graphDef, commandArray[++i]); } else { throw new IllegalArgumentException("--color must be followed by a color"); } } else if (arg.startsWith("--vertical-label=")) { String[] label = tokenize(arg, "=", true); graphDef.setVerticalLabel(label[1]); } else if (arg.equals("--vertical-label")) { if (i + 1 < commandArray.length) { graphDef.setVerticalLabel(commandArray[++i]); } else { throw new IllegalArgumentException("--vertical-label must be followed by a label"); } } else if (arg.startsWith("--height=")) { String[] argParm = tokenize(arg, "=", true); height = Integer.parseInt(argParm[1]); log().debug("JRobin height: "+height); } else if (arg.equals("--height")) { if (i + 1 < commandArray.length) { height = Integer.parseInt(commandArray[++i]); log().debug("JRobin height: "+height); } else { throw new IllegalArgumentException("--height must be followed by a number"); } } else if (arg.startsWith("--width=")) { String[] argParm = tokenize(arg, "=", true); width = Integer.parseInt(argParm[1]); log().debug("JRobin width: "+width); } else if (arg.equals("--width")) { if (i + 1 < commandArray.length) { width = Integer.parseInt(commandArray[++i]); log().debug("JRobin width: "+width); } else { throw new IllegalArgumentException("--width must be followed by a number"); } } else if (arg.startsWith("--units-exponent=")) { String[] argParm = tokenize(arg, "=", true); int exponent = Integer.parseInt(argParm[1]); log().debug("JRobin units exponent: "+exponent); graphDef.setUnitsExponent(exponent); } else if (arg.equals("--units-exponent")) { if (i + 1 < commandArray.length) { int exponent = Integer.parseInt(commandArray[++i]); log().debug("JRobin units exponent: "+exponent); graphDef.setUnitsExponent(exponent); } else { throw new IllegalArgumentException("--units-exponent must be followed by a number"); } } else if (arg.startsWith("--lower-limit=")) { String[] argParm = tokenize(arg, "=", true); lowerLimit = Double.parseDouble(argParm[1]); log().debug("JRobin lower limit: "+lowerLimit); } else if (arg.equals("--lower-limit")) { if (i + 1 < commandArray.length) { lowerLimit = Double.parseDouble(commandArray[++i]); log().debug("JRobin lower limit: "+lowerLimit); } else { throw new IllegalArgumentException("--lower-limit must be followed by a number"); } } else if (arg.startsWith("--upper-limit=")) { String[] argParm = tokenize(arg, "=", true); upperLimit = Double.parseDouble(argParm[1]); log().debug("JRobin upp limit: "+upperLimit); } else if (arg.equals("--upper-limit")) { if (i + 1 < commandArray.length) { upperLimit = Double.parseDouble(commandArray[++i]); log().debug("JRobin upper limit: "+upperLimit); } else { throw new IllegalArgumentException("--upper-limit must be followed by a number"); } } else if (arg.startsWith("--base=")) { String[] argParm = tokenize(arg, "=", true); graphDef.setBase(Double.parseDouble(argParm[1])); } else if (arg.equals("--base")) { if (i + 1 < commandArray.length) { graphDef.setBase(Double.parseDouble(commandArray[++i])); } else { throw new IllegalArgumentException("--base must be followed by a number"); } } else if (arg.startsWith("--font=")) { String[] argParm = tokenize(arg, "=", true); processRrdFontArgument(graphDef, argParm[1]); } else if (arg.equals("--font")) { if (i + 1 < commandArray.length) { processRrdFontArgument(graphDef, commandArray[++i]); } else { throw new IllegalArgumentException("--font must be followed by an argument"); } } else if (arg.startsWith("--imgformat=")) { String[] argParm = tokenize(arg, "=", true); graphDef.setImageFormat(argParm[1]); } else if (arg.equals("--imgformat")) { if (i + 1 < commandArray.length) { graphDef.setImageFormat(commandArray[++i]); } else { throw new IllegalArgumentException("--imgformat must be followed by an argument"); } } else if (arg.equals("--rigid")) { rigid = true; } else if (arg.startsWith("DEF:")) { String definition = arg.substring("DEF:".length()); String[] def = splitDef(definition); String[] ds = def[0].split("="); final String replaced = ds[1].replaceAll("\\\\(.)", "$1"); final File dsFile; File rawPathFile = new File(replaced); if (rawPathFile.isAbsolute()) { dsFile = rawPathFile; } else { dsFile = new File(workDir, replaced); } final String absolutePath = (File.separatorChar == '\\')? dsFile.getAbsolutePath().replace("\\", "\\\\") : dsFile.getAbsolutePath(); graphDef.datasource(ds[0], absolutePath, def[1], def[2]); List<String> defBits = new ArrayList<String>(); defBits.add(absolutePath); defBits.add(def[1]); defBits.add(def[2]); defs.put(ds[0], defBits); } else if (arg.startsWith("CDEF:")) { String definition = arg.substring("CDEF:".length()); String[] cdef = tokenize(definition, "=", true); graphDef.datasource(cdef[0], cdef[1]); List<String> cdefBits = new ArrayList<String>(); cdefBits.add(cdef[1]); defs.put(cdef[0], cdefBits); } else if (arg.startsWith("VDEF:")) { String definition = arg.substring("VDEF:".length()); String[] vdef = tokenize(definition, "=", true); String[] expressionTokens = tokenize(vdef[1], ",", false); addVdefDs(graphDef, vdef[0], expressionTokens, start, end, defs); } else if (arg.startsWith("LINE1:")) { String definition = arg.substring("LINE1:".length()); String[] line1 = tokenize(definition, ":", true); String[] color = tokenize(line1[0], "#", true); graphDef.line(color[0], getColorOrInvisible(color, 1), (line1.length > 1 ? line1[1] : "")); } else if (arg.startsWith("LINE2:")) { String definition = arg.substring("LINE2:".length()); String[] line2 = tokenize(definition, ":", true); String[] color = tokenize(line2[0], "#", true); graphDef.line(color[0], getColorOrInvisible(color, 1), (line2.length > 1 ? line2[1] : ""), 2); } else if (arg.startsWith("LINE3:")) { String definition = arg.substring("LINE3:".length()); String[] line3 = tokenize(definition, ":", true); String[] color = tokenize(line3[0], "#", true); graphDef.line(color[0], getColorOrInvisible(color, 1), (line3.length > 1 ? line3[1] : ""), 3); } else if (arg.startsWith("GPRINT:")) { String definition = arg.substring("GPRINT:".length()); String gprint[] = tokenize(definition, ":", true); String format = gprint[2]; format = format.replaceAll("\\n", "\\\\l"); graphDef.gprint(gprint[0], gprint[1], format); } else if (arg.startsWith("PRINT:")) { String definition = arg.substring("PRINT:".length()); String print[] = tokenize(definition, ":", true); String format = print[2]; format = format.replaceAll("\\n", "\\\\l"); graphDef.print(print[0], print[1], format); } else if (arg.startsWith("COMMENT:")) { String comments[] = tokenize(arg, ":", true); String format = comments[1].replaceAll("\\n", "\\\\l"); graphDef.comment(format); } else if (arg.startsWith("AREA:")) { String definition = arg.substring("AREA:".length()); String area[] = tokenize(definition, ":", true); String[] color = tokenize(area[0], "#", true); if (area.length > 1) { graphDef.area(color[0], getColorOrInvisible(color, 1), area[1]); } else { graphDef.area(color[0], getColorOrInvisible(color, 1)); } } else if (arg.startsWith("STACK:")) { String definition = arg.substring("STACK:".length()); String stack[] = tokenize(definition, ":", true); String[] color = tokenize(stack[0], "#", true); graphDef.stack(color[0], getColor(color[1]), (stack.length > 1 ? stack[1] : "")); } else if (arg.startsWith("HRULE:")) { String definition = arg.substring("HRULE:".length()); String hrule[] = tokenize(definition, ":", true); String[] color = tokenize(hrule[0], "#", true); Double value = Double.valueOf(color[0]); graphDef.hrule(value, getColor(color[1]), (hrule.length > 1 ? hrule[1] : "")); } else if (arg.endsWith("/rrdtool") || arg.equals("graph") || arg.equals("-")) { } else { log().warn("JRobin: Unrecognized graph argument: " + arg); } } graphDef.setTimeSpan(start, end); graphDef.setMinValue(lowerLimit); graphDef.setMaxValue(upperLimit); graphDef.setRigid(rigid); graphDef.setHeight(height); graphDef.setWidth(width); log().debug("JRobin Finished tokenizing checking: start time: " + start + "; end time: " + end); log().debug("large font = " + graphDef.getLargeFont() + ", small font = " + graphDef.getSmallFont()); return graphDef; } JRobinRrdStrategy(); Properties getConfigurationProperties(); void setConfigurationProperties(final Properties configurationParameters); void closeFile(final RrdDb rrdFile); RrdDef createDefinition(final String creator,
			final String directory, final String rrdName, int step,
			final List<RrdDataSource> dataSources, final List<String> rraList); void createFile(final RrdDef rrdDef,  Map<String, String> attributeMappings); RrdDb openFile(final String fileName); void updateFile(final RrdDb rrdFile, final String owner, final String data); Double fetchLastValue(final String fileName, final String ds, final int interval); Double fetchLastValue(final String fileName, final String ds, final String consolidationFunction, final int interval); Double fetchLastValueInRange(final String fileName, final String ds, final int interval, final int range); InputStream createGraph(final String command, final File workDir); RrdGraphDetails createGraphReturnDetails(final String command, final File workDir); void promoteEnqueuedFiles(Collection<String> rrdFiles); String getStats(); int getGraphLeftOffset(); int getGraphRightOffset(); int getGraphTopOffsetWithText(); String getDefaultFileExtension(); static String[] tokenizeWithQuotingAndEscapes(String line, String delims, boolean processQuoted); static String[] tokenizeWithQuotingAndEscapes(final String line, final String delims, final boolean processQuoted, final String tokens); static char[] escapeIfNotPathSepInDEF(final char encountered, final char escaped, final StringBuffer currToken); }
JRobinRrdStrategy implements RrdStrategy<RrdDef,RrdDb> { protected RrdGraphDef createGraphDef(final File workDir, final String[] inputArray) throws RrdException { RrdGraphDef graphDef = new RrdGraphDef(); graphDef.setImageFormat("PNG"); long start = 0; long end = 0; int height = 100; int width = 400; double lowerLimit = Double.NaN; double upperLimit = Double.NaN; boolean rigid = false; Map<String,List<String>> defs = new LinkedHashMap<String,List<String>>(); final String[] commandArray; if (inputArray[0].contains("rrdtool") && inputArray[1].equals("graph") && inputArray[2].equals("-")) { commandArray = Arrays.copyOfRange(inputArray, 3, inputArray.length); } else { commandArray = inputArray; } log().debug("command array = " + Arrays.toString(commandArray)); for (int i = 0; i < commandArray.length; i++) { String arg = commandArray[i]; if (arg.startsWith("--start=")) { start = Long.parseLong(arg.substring("--start=".length())); log().debug("JRobin start time: " + start); } else if (arg.equals("--start")) { if (i + 1 < commandArray.length) { start = Long.parseLong(commandArray[++i]); log().debug("JRobin start time: " + start); } else { throw new IllegalArgumentException("--start must be followed by a start time"); } } else if (arg.startsWith("--end=")) { end = Long.parseLong(arg.substring("--end=".length())); log().debug("JRobin end time: " + end); } else if (arg.equals("--end")) { if (i + 1 < commandArray.length) { end = Long.parseLong(commandArray[++i]); log().debug("JRobin end time: " + end); } else { throw new IllegalArgumentException("--end must be followed by an end time"); } } else if (arg.startsWith("--title=")) { String[] title = tokenize(arg, "=", true); graphDef.setTitle(title[1]); } else if (arg.equals("--title")) { if (i + 1 < commandArray.length) { graphDef.setTitle(commandArray[++i]); } else { throw new IllegalArgumentException("--title must be followed by a title"); } } else if (arg.startsWith("--color=")) { String[] color = tokenize(arg, "=", true); parseGraphColor(graphDef, color[1]); } else if (arg.equals("--color") || arg.equals("-c")) { if (i + 1 < commandArray.length) { parseGraphColor(graphDef, commandArray[++i]); } else { throw new IllegalArgumentException("--color must be followed by a color"); } } else if (arg.startsWith("--vertical-label=")) { String[] label = tokenize(arg, "=", true); graphDef.setVerticalLabel(label[1]); } else if (arg.equals("--vertical-label")) { if (i + 1 < commandArray.length) { graphDef.setVerticalLabel(commandArray[++i]); } else { throw new IllegalArgumentException("--vertical-label must be followed by a label"); } } else if (arg.startsWith("--height=")) { String[] argParm = tokenize(arg, "=", true); height = Integer.parseInt(argParm[1]); log().debug("JRobin height: "+height); } else if (arg.equals("--height")) { if (i + 1 < commandArray.length) { height = Integer.parseInt(commandArray[++i]); log().debug("JRobin height: "+height); } else { throw new IllegalArgumentException("--height must be followed by a number"); } } else if (arg.startsWith("--width=")) { String[] argParm = tokenize(arg, "=", true); width = Integer.parseInt(argParm[1]); log().debug("JRobin width: "+width); } else if (arg.equals("--width")) { if (i + 1 < commandArray.length) { width = Integer.parseInt(commandArray[++i]); log().debug("JRobin width: "+width); } else { throw new IllegalArgumentException("--width must be followed by a number"); } } else if (arg.startsWith("--units-exponent=")) { String[] argParm = tokenize(arg, "=", true); int exponent = Integer.parseInt(argParm[1]); log().debug("JRobin units exponent: "+exponent); graphDef.setUnitsExponent(exponent); } else if (arg.equals("--units-exponent")) { if (i + 1 < commandArray.length) { int exponent = Integer.parseInt(commandArray[++i]); log().debug("JRobin units exponent: "+exponent); graphDef.setUnitsExponent(exponent); } else { throw new IllegalArgumentException("--units-exponent must be followed by a number"); } } else if (arg.startsWith("--lower-limit=")) { String[] argParm = tokenize(arg, "=", true); lowerLimit = Double.parseDouble(argParm[1]); log().debug("JRobin lower limit: "+lowerLimit); } else if (arg.equals("--lower-limit")) { if (i + 1 < commandArray.length) { lowerLimit = Double.parseDouble(commandArray[++i]); log().debug("JRobin lower limit: "+lowerLimit); } else { throw new IllegalArgumentException("--lower-limit must be followed by a number"); } } else if (arg.startsWith("--upper-limit=")) { String[] argParm = tokenize(arg, "=", true); upperLimit = Double.parseDouble(argParm[1]); log().debug("JRobin upp limit: "+upperLimit); } else if (arg.equals("--upper-limit")) { if (i + 1 < commandArray.length) { upperLimit = Double.parseDouble(commandArray[++i]); log().debug("JRobin upper limit: "+upperLimit); } else { throw new IllegalArgumentException("--upper-limit must be followed by a number"); } } else if (arg.startsWith("--base=")) { String[] argParm = tokenize(arg, "=", true); graphDef.setBase(Double.parseDouble(argParm[1])); } else if (arg.equals("--base")) { if (i + 1 < commandArray.length) { graphDef.setBase(Double.parseDouble(commandArray[++i])); } else { throw new IllegalArgumentException("--base must be followed by a number"); } } else if (arg.startsWith("--font=")) { String[] argParm = tokenize(arg, "=", true); processRrdFontArgument(graphDef, argParm[1]); } else if (arg.equals("--font")) { if (i + 1 < commandArray.length) { processRrdFontArgument(graphDef, commandArray[++i]); } else { throw new IllegalArgumentException("--font must be followed by an argument"); } } else if (arg.startsWith("--imgformat=")) { String[] argParm = tokenize(arg, "=", true); graphDef.setImageFormat(argParm[1]); } else if (arg.equals("--imgformat")) { if (i + 1 < commandArray.length) { graphDef.setImageFormat(commandArray[++i]); } else { throw new IllegalArgumentException("--imgformat must be followed by an argument"); } } else if (arg.equals("--rigid")) { rigid = true; } else if (arg.startsWith("DEF:")) { String definition = arg.substring("DEF:".length()); String[] def = splitDef(definition); String[] ds = def[0].split("="); final String replaced = ds[1].replaceAll("\\\\(.)", "$1"); final File dsFile; File rawPathFile = new File(replaced); if (rawPathFile.isAbsolute()) { dsFile = rawPathFile; } else { dsFile = new File(workDir, replaced); } final String absolutePath = (File.separatorChar == '\\')? dsFile.getAbsolutePath().replace("\\", "\\\\") : dsFile.getAbsolutePath(); graphDef.datasource(ds[0], absolutePath, def[1], def[2]); List<String> defBits = new ArrayList<String>(); defBits.add(absolutePath); defBits.add(def[1]); defBits.add(def[2]); defs.put(ds[0], defBits); } else if (arg.startsWith("CDEF:")) { String definition = arg.substring("CDEF:".length()); String[] cdef = tokenize(definition, "=", true); graphDef.datasource(cdef[0], cdef[1]); List<String> cdefBits = new ArrayList<String>(); cdefBits.add(cdef[1]); defs.put(cdef[0], cdefBits); } else if (arg.startsWith("VDEF:")) { String definition = arg.substring("VDEF:".length()); String[] vdef = tokenize(definition, "=", true); String[] expressionTokens = tokenize(vdef[1], ",", false); addVdefDs(graphDef, vdef[0], expressionTokens, start, end, defs); } else if (arg.startsWith("LINE1:")) { String definition = arg.substring("LINE1:".length()); String[] line1 = tokenize(definition, ":", true); String[] color = tokenize(line1[0], "#", true); graphDef.line(color[0], getColorOrInvisible(color, 1), (line1.length > 1 ? line1[1] : "")); } else if (arg.startsWith("LINE2:")) { String definition = arg.substring("LINE2:".length()); String[] line2 = tokenize(definition, ":", true); String[] color = tokenize(line2[0], "#", true); graphDef.line(color[0], getColorOrInvisible(color, 1), (line2.length > 1 ? line2[1] : ""), 2); } else if (arg.startsWith("LINE3:")) { String definition = arg.substring("LINE3:".length()); String[] line3 = tokenize(definition, ":", true); String[] color = tokenize(line3[0], "#", true); graphDef.line(color[0], getColorOrInvisible(color, 1), (line3.length > 1 ? line3[1] : ""), 3); } else if (arg.startsWith("GPRINT:")) { String definition = arg.substring("GPRINT:".length()); String gprint[] = tokenize(definition, ":", true); String format = gprint[2]; format = format.replaceAll("\\n", "\\\\l"); graphDef.gprint(gprint[0], gprint[1], format); } else if (arg.startsWith("PRINT:")) { String definition = arg.substring("PRINT:".length()); String print[] = tokenize(definition, ":", true); String format = print[2]; format = format.replaceAll("\\n", "\\\\l"); graphDef.print(print[0], print[1], format); } else if (arg.startsWith("COMMENT:")) { String comments[] = tokenize(arg, ":", true); String format = comments[1].replaceAll("\\n", "\\\\l"); graphDef.comment(format); } else if (arg.startsWith("AREA:")) { String definition = arg.substring("AREA:".length()); String area[] = tokenize(definition, ":", true); String[] color = tokenize(area[0], "#", true); if (area.length > 1) { graphDef.area(color[0], getColorOrInvisible(color, 1), area[1]); } else { graphDef.area(color[0], getColorOrInvisible(color, 1)); } } else if (arg.startsWith("STACK:")) { String definition = arg.substring("STACK:".length()); String stack[] = tokenize(definition, ":", true); String[] color = tokenize(stack[0], "#", true); graphDef.stack(color[0], getColor(color[1]), (stack.length > 1 ? stack[1] : "")); } else if (arg.startsWith("HRULE:")) { String definition = arg.substring("HRULE:".length()); String hrule[] = tokenize(definition, ":", true); String[] color = tokenize(hrule[0], "#", true); Double value = Double.valueOf(color[0]); graphDef.hrule(value, getColor(color[1]), (hrule.length > 1 ? hrule[1] : "")); } else if (arg.endsWith("/rrdtool") || arg.equals("graph") || arg.equals("-")) { } else { log().warn("JRobin: Unrecognized graph argument: " + arg); } } graphDef.setTimeSpan(start, end); graphDef.setMinValue(lowerLimit); graphDef.setMaxValue(upperLimit); graphDef.setRigid(rigid); graphDef.setHeight(height); graphDef.setWidth(width); log().debug("JRobin Finished tokenizing checking: start time: " + start + "; end time: " + end); log().debug("large font = " + graphDef.getLargeFont() + ", small font = " + graphDef.getSmallFont()); return graphDef; } JRobinRrdStrategy(); Properties getConfigurationProperties(); void setConfigurationProperties(final Properties configurationParameters); void closeFile(final RrdDb rrdFile); RrdDef createDefinition(final String creator,
			final String directory, final String rrdName, int step,
			final List<RrdDataSource> dataSources, final List<String> rraList); void createFile(final RrdDef rrdDef,  Map<String, String> attributeMappings); RrdDb openFile(final String fileName); void updateFile(final RrdDb rrdFile, final String owner, final String data); Double fetchLastValue(final String fileName, final String ds, final int interval); Double fetchLastValue(final String fileName, final String ds, final String consolidationFunction, final int interval); Double fetchLastValueInRange(final String fileName, final String ds, final int interval, final int range); InputStream createGraph(final String command, final File workDir); RrdGraphDetails createGraphReturnDetails(final String command, final File workDir); void promoteEnqueuedFiles(Collection<String> rrdFiles); String getStats(); int getGraphLeftOffset(); int getGraphRightOffset(); int getGraphTopOffsetWithText(); String getDefaultFileExtension(); static String[] tokenizeWithQuotingAndEscapes(String line, String delims, boolean processQuoted); static String[] tokenizeWithQuotingAndEscapes(final String line, final String delims, final boolean processQuoted, final String tokens); static char[] escapeIfNotPathSepInDEF(final char encountered, final char escaped, final StringBuffer currToken);  }