本文整理汇总了Java中org.alfresco.util.exec.RuntimeExec类的典型用法代码示例。如果您正苦于以下问题:Java RuntimeExec类的具体用法?Java RuntimeExec怎么用?Java RuntimeExec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RuntimeExec类属于org.alfresco.util.exec包,在下文中一共展示了RuntimeExec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateOSNameAttributeForLinux
import org.alfresco.util.exec.RuntimeExec; //导入依赖的package包/类
/**
* Adds a Linux version
*
* @param osName os.name attribute
* @return String
*/
public static String updateOSNameAttributeForLinux(String osName)
{
RuntimeExec exec = new RuntimeExec();
Map<String, String[]> commandMap = new HashMap<String, String[]>(3, 1.0f);
commandMap.put("Linux", new String[] { "lsb_release", "-d" });
exec.setCommandsAndArguments(commandMap);
ExecutionResult ret = exec.execute();
if (ret.getSuccess())
{
osName += " (" + ret.getStdOut().replace("\n", "") + ")";
}
else
{
commandMap.put("Linux", new String[] { "uname", "-a" });
exec.setCommandsAndArguments(commandMap);
ret = exec.execute();
if (ret.getSuccess())
{
osName += " (" + ret.getStdOut().replace("\n", "") + ")";
}
else
{
osName += " (Unknown)";
}
}
return osName;
}
示例2: setUp
import org.alfresco.util.exec.RuntimeExec; //导入依赖的package包/类
@Override
protected void setUp() throws Exception
{
super.setUp();
RuntimeExecutableContentTransformerWorker worker = new RuntimeExecutableContentTransformerWorker();
// the command to execute
RuntimeExec transformCommand = new RuntimeExec();
Map<String, String> commandMap = new HashMap<String, String>(5);
commandMap.put("Mac OS X", "mv -f ${source} ${target}");
commandMap.put("Linux", "mv -f ${source} ${target}");
commandMap.put(".*", "cmd /c copy /Y \"${source}\" \"${target}\"");
transformCommand.setCommandMap(commandMap);
transformCommand.setErrorCodes("1, 2");
worker.setTransformCommand(transformCommand);
worker.setMimetypeService(serviceRegistry.getMimetypeService());
// set the explicit transformations
List<ExplictTransformationDetails> explicitTranformations = new ArrayList<ExplictTransformationDetails>(1);
explicitTranformations.add(
new ExplictTransformationDetails(MimetypeMap.MIMETYPE_TEXT_PLAIN, MimetypeMap.MIMETYPE_XML));
worker.setExplicitTransformations(explicitTranformations);
// initialise so that it doesn't score 0
worker.afterPropertiesSet();
TransformerDebug transformerDebug = (TransformerDebug) ctx.getBean("transformerDebug");
TransformerConfig transformerConfig = (TransformerConfig) ctx.getBean("transformerConfig");
ProxyContentTransformer transformer = new ProxyContentTransformer();
transformer.setMimetypeService(serviceRegistry.getMimetypeService());
transformer.setTransformerDebug(transformerDebug);
transformer.setTransformerConfig(transformerConfig);
transformer.setWorker(worker);
this.transformer = transformer;
}
示例3: transform
import org.alfresco.util.exec.RuntimeExec; //导入依赖的package包/类
public final void transform(ContentReader reader, ContentWriter writer, TransformationOptions options) throws Exception {
try {
String sourceMimetype = getMimetype(reader);
String sourceExtension = mimetypeService.getExtension(sourceMimetype);
File sourceFile = TempFileProvider.createTempFile(getClass().getSimpleName() + "_source_", "." + sourceExtension);
reader.getContent(sourceFile);
String path = sourceFile.getAbsolutePath();
String targetPath = path.substring(0, path.toLowerCase().lastIndexOf(".")) + "_ocr.pdf";
Map<String, String> properties = new HashMap<String, String>(1);
properties.put(VAR_SOURCE, sourceFile.getAbsolutePath());
properties.put(VAR_TARGET, targetPath);
RuntimeExec.ExecutionResult result = obtainExecuter(properties);
if (verbose) {
logger.info("EXIT VALUE: " + result.getExitValue());
logger.info("STDOUT: " + result.getStdOut());
logger.info("STDERR: " + result.getStdErr());
}
if (result.getExitValue() == 143) {
logger.warn(result.getStdErr());
}
else if (result.getExitValue() != 0 && result.getStdErr() != null && result.getStdErr().length() > 0) {
throw new ContentIOException("Failed to perform OCR transformation: \n" + result);
}
File targetFile = new File(targetPath);
writer.putContent(targetFile);
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
示例4: obtainExecuter
import org.alfresco.util.exec.RuntimeExec; //导入依赖的package包/类
private RuntimeExec.ExecutionResult obtainExecuter(Map<String, String> properties){
if (serverOS.equals(SERVER_OS_LINUX)) {
return executerLinux.execute(properties);
} else if (serverOS.equals(SERVER_OS_WINDOWS)) {
return executerWindows.execute(properties);
} else {
throw new ContentIOException("Failed to recognize the operative system: \n" + serverOS);
}
}
示例5: test
import org.alfresco.util.exec.RuntimeExec; //导入依赖的package包/类
protected void test() {
try {
logger.debug("Testing availability");
RuntimeExec.ExecutionResult result = checkCommand.execute();
available=result.getSuccess();
logger.info("Is OCR available? " + available);
}
catch (Exception e) {
available=false;
logger.warn("Check command [" + checkCommand.getCommand() + "] failed. Registering transform as unavailable for the next " + checkFrequencyInSeconds + " seconds");
}
}
示例6: missingTargetBean
import org.alfresco.util.exec.RuntimeExec; //导入依赖的package包/类
@Test
public void missingTargetBean()
{
try (final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"classpath:ImplementationClassReplacingPostProcessorTest/missingTargetBean-context.xml"))
{
final Object testBean = context.getBean("testBean");
Assert.assertFalse("testBean should should have been specialized", testBean instanceof TestDummyBean);
Assert.assertTrue("testBean should have been an instanceof of RuntimeExec", testBean instanceof RuntimeExec);
}
}
示例7: missingReplacementClass
import org.alfresco.util.exec.RuntimeExec; //导入依赖的package包/类
@Test
public void missingReplacementClass()
{
try (final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"classpath:ImplementationClassReplacingPostProcessorTest/missingReplacementClass-context.xml"))
{
final Object testBean = context.getBean("testBean");
Assert.assertFalse("testBean should should have been specialized", testBean instanceof TestDummyBean);
Assert.assertTrue("testBean should have been an instanceof of RuntimeExec", testBean instanceof RuntimeExec);
}
}
示例8: byNameAndClass_disabled
import org.alfresco.util.exec.RuntimeExec; //导入依赖的package包/类
@Test
public void byNameAndClass_disabled()
{
try (final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"classpath:ImplementationClassReplacingPostProcessorTest/byNameAndClass-disabled-context.xml"))
{
final Object testBean = context.getBean("testBean");
Assert.assertFalse("testBean should not have been specialized", testBean instanceof TestDummyBean);
Assert.assertTrue("testBean should have been an instanceof of RuntimeExec", testBean instanceof RuntimeExec);
}
}
示例9: transformInternal
import org.alfresco.util.exec.RuntimeExec; //导入依赖的package包/类
/**
* Transform the image content from the source file to the target file
*/
@Override
protected void transformInternal(File sourceFile, String sourceMimetype,
File targetFile, String targetMimetype, TransformationOptions options) throws Exception
{
Map<String, String> properties = new HashMap<String, String>(5);
// set properties
if (options instanceof ImageTransformationOptions)
{
ImageTransformationOptions imageOptions = (ImageTransformationOptions)options;
CropSourceOptions cropOptions = imageOptions.getSourceOptions(CropSourceOptions.class);
ImageResizeOptions resizeOptions = imageOptions.getResizeOptions();
String commandOptions = imageOptions.getCommandOptions();
if (commandOptions == null)
{
commandOptions = "";
}
// MNT-10882 : JPEG File Format, does not save the alpha (transparency) channel.
if (MimetypeMap.MIMETYPE_IMAGE_JPEG.equalsIgnoreCase(targetMimetype) && isAlphaOptionSupported())
{
commandOptions += " -alpha remove";
}
if (imageOptions.isAutoOrient())
{
commandOptions = commandOptions + " -auto-orient";
}
if (cropOptions != null)
{
commandOptions = commandOptions + " " + getImageCropCommandOptions(cropOptions);
}
if (resizeOptions != null)
{
commandOptions = commandOptions + " " + getImageResizeCommandOptions(resizeOptions);
}
properties.put(KEY_OPTIONS, commandOptions);
}
properties.put(VAR_SOURCE, sourceFile.getAbsolutePath() +
getSourcePageRange(options, sourceMimetype, targetMimetype));
properties.put(VAR_TARGET, targetFile.getAbsolutePath());
// execute the statement
long timeoutMs = options.getTimeoutMs();
RuntimeExec.ExecutionResult result = executer.execute(properties, timeoutMs);
if (result.getExitValue() != 0 && result.getStdErr() != null && result.getStdErr().length() > 0)
{
throw new ContentIOException("Failed to perform ImageMagick transformation: \n" + result);
}
// success
if (logger.isDebugEnabled())
{
logger.debug("ImageMagick executed successfully: \n" + executer);
}
}
示例10: transformInternal
import org.alfresco.util.exec.RuntimeExec; //导入依赖的package包/类
/**
* Transform the pdf content from the source file to the target file
*/
private void transformInternal(File sourceFile, String sourceMimetype, File targetFile, String targetMimetype, TransformationOptions options) throws Exception
{
Map<String, String> properties = new HashMap<String, String>(5);
// set properties
if (options instanceof ImageTransformationOptions)
{
ImageTransformationOptions imageOptions = (ImageTransformationOptions) options;
ImageResizeOptions resizeOptions = imageOptions.getResizeOptions();
String commandOptions = imageOptions.getCommandOptions();
if (commandOptions == null)
{
commandOptions = "";
}
if(resizeOptions != null)
{
if (resizeOptions.getHeight() > -1)
{
commandOptions += " --height=" + resizeOptions.getHeight();
}
if (resizeOptions.getWidth() > -1)
{
commandOptions += " --width=" + resizeOptions.getHeight();
}
if (resizeOptions.getAllowEnlargement())
{
commandOptions += " --allow-enlargement";
}
if (resizeOptions.isMaintainAspectRatio())
{
commandOptions += " --maintain-aspect-ratio";
}
}
commandOptions += " --page=" + getSourcePageRange(imageOptions, sourceMimetype, targetMimetype);
properties.put(KEY_OPTIONS, commandOptions);
}
properties.put(VAR_SOURCE, sourceFile.getAbsolutePath());
properties.put(VAR_TARGET, targetFile.getAbsolutePath());
// execute the statement
long timeoutMs = options.getTimeoutMs();
RuntimeExec.ExecutionResult result = executer.execute(properties, timeoutMs);
if (result.getExitValue() != 0 && result.getStdErr() != null && result.getStdErr().length() > 0)
{
throw new ContentIOException("Failed to perform alfresco-pdf-renderer transformation: \n" + result);
}
// success
if (logger.isDebugEnabled())
{
logger.debug("alfresco-pdf-renderer executed successfully: \n" + executer);
}
}
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:58,代码来源:AlfrescoPdfRendererContentTransformerWorker.java
示例11: OpenOfficeCommandLine
import org.alfresco.util.exec.RuntimeExec; //导入依赖的package包/类
public OpenOfficeCommandLine(String exe, String port, String user) throws IOException
{
File executable = variant.findExecutable(exe);
File officeHome = variant.getOfficeHome(executable);
List<String> command = new ArrayList<String>();
String acceptValue = "socket,host=127.0.0.1,port="+port+";urp;StarOffice.ServiceManager";
String userInstallation = new OpenOfficeURI(user).toString();
command.add(executable == null ? exe : executable.getAbsolutePath());
if (variant.isLibreOffice3Dot5(officeHome))
{
command.add("--accept=" + acceptValue);
if (variant.isMac() && !variant.isLibreOffice3Dot6(officeHome))
{
command.add("--env:UserInstallation=" + userInstallation);
}
else
{
command.add("-env:UserInstallation=" + userInstallation);
}
command.add("--headless");
command.add("--nocrashreport");
//command.add("--nodefault"); included by JOD
command.add("--nofirststartwizard");
//command.add("--nolockcheck"); included by JOD
command.add("--nologo");
command.add("--norestore");
logger.info("Using GNU based LibreOffice "+
(variant.isLibreOffice3Dot6(officeHome) ? "3.6" : "3.5")+" command"+
(variant.isMac() ? " on Mac" : "")+": "+command);
}
else
{
command.add("-accept=" + acceptValue);
command.add("-env:UserInstallation=" + userInstallation);
command.add("-headless");
command.add("-nocrashreport");
//command.add("-nodefault"); included by JOD
command.add("-nofirststartwizard");
//command.add("-nolockcheck"); included by JOD
command.add("-nologo");
command.add("-norestore");
logger.info("Using original OpenOffice command: "+command);
}
map.put(RuntimeExec.KEY_OS_DEFAULT, command);
}
示例12: setCheckCommand
import org.alfresco.util.exec.RuntimeExec; //导入依赖的package包/类
public void setCheckCommand(RuntimeExec checkCommand) {
this.checkCommand = checkCommand;
}
示例13: setExecuterLinux
import org.alfresco.util.exec.RuntimeExec; //导入依赖的package包/类
public void setExecuterLinux(RuntimeExec executerLinux) {
this.executerLinux = executerLinux;
}
示例14: setExecuterWindows
import org.alfresco.util.exec.RuntimeExec; //导入依赖的package包/类
public void setExecuterWindows(RuntimeExec executerWindows) {
this.executerWindows = executerWindows;
}
示例15: setExecuter
import org.alfresco.util.exec.RuntimeExec; //导入依赖的package包/类
/**
* Set the runtime command executer that must be executed in order to run
* <b>ImageMagick</b>. Whether or not this is the full path to the convertCommand
* or just the convertCommand itself depends the environment setup.
* <p>
* The command must contain the variables <code>${source}</code> and
* <code>${target}</code>, which will be replaced by the names of the file to
* be transformed and the name of the output file respectively.
* <pre>
* convert ${source} ${target}
* </pre>
*
* @param executer the system command executer
*/
public void setExecuter(RuntimeExec executer)
{
executer.setProcessProperty(
"MAGICK_TMPDIR", TempFileProvider.getTempDir().getAbsolutePath());
this.executer = executer;
}