1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.onehippo.forge.gallerymagick.core.command;
17
18 import org.apache.commons.exec.CommandLine;
19 import org.apache.commons.lang.StringUtils;
20
21
22
23
24 public class ImageMagickCommand extends AbstractMagickCommand {
25
26
27
28
29 public static final String PROP_EXECUTABLE_CONVERT = "org.onehippo.forge.gallerymagick.core.command.im.convert";
30
31
32
33
34 public static final String PROP_EXECUTABLE_IDENTIFY = "org.onehippo.forge.gallerymagick.core.command.im.identify";
35
36
37
38
39
40
41
42
43 public ImageMagickCommand(final String executable, final String subCommand) {
44 super(StringUtils.defaultIfBlank(getExecutableFromSystemProperty(subCommand), executable),
45 StringUtils.defaultIfBlank(subCommand, DEFAULT_SUBCOMMAND_CONVERT));
46 }
47
48
49
50
51 @Override
52 protected CommandLine createCommandLine() {
53 String executable = getExecutable();
54
55 if (StringUtils.isBlank(executable)) {
56 executable = getSubCommand();
57 }
58
59 CommandLine cmdLine = new CommandLine(executable);
60
61 for (String argument : getArguments()) {
62 cmdLine.addArgument(argument);
63 }
64
65 return cmdLine;
66 }
67
68
69
70
71
72
73 static String getExecutableFromSystemProperty(final String subCommand) {
74 String executable = null;
75
76 if (StringUtils.equals("convert", subCommand)) {
77 final String value = System.getProperty(PROP_EXECUTABLE_CONVERT);
78 if (StringUtils.isNotBlank(value)) {
79 executable = value;
80 }
81 } else if (StringUtils.equals("identify", subCommand)) {
82 final String value = System.getProperty(PROP_EXECUTABLE_IDENTIFY);
83 if (StringUtils.isNotBlank(value)) {
84 executable = value;
85 }
86 }
87
88 return executable;
89 }
90
91 }