1 34 35 36 package com.micronova.jsp.tag; 37 38 import java.util.*; 39 import java.io.*; 40 import com.micronova.util.*; 41 42 public class SystemTag extends MapTag 43 { 44 public final static String COMMAND = "command"; 45 public final static String STDIN = "stdin"; 46 public final static String STDOUT = "stdout"; 47 public final static String STDERR = "stderr"; 48 public final static String RC = "rc"; 49 50 private static final String DEFAULTEXPORT = "${" + VALUEVAR + "." + STDOUT + "}"; 51 52 public void init() 53 { 54 super.init(); 55 56 _export = DEFAULTEXPORT; 57 } 58 59 public Object processValue(Object tagValue) throws Exception 60 { 61 NestedMap map = _map; 62 63 String command = (String )map.get(COMMAND); 64 String stdin = (String )map.get(STDIN); 65 66 if (stdin == null) 67 { 68 stdin = ""; 69 } 70 71 if (command != null) 72 { 73 ByteArrayInputStream bIn = new ByteArrayInputStream(stdin.getBytes()); 74 ByteArrayOutputStream bOut = new ByteArrayOutputStream(); 75 ByteArrayOutputStream bErr = new ByteArrayOutputStream(); 76 77 Process p = Runtime.getRuntime().exec(command); 78 79 Shell shell = new Shell(p, bIn, bOut, bErr); 80 81 int rc = shell.exec(); 82 83 map.put(RC, new Integer (rc)); 84 85 map.put(STDOUT, bOut.toString("iso-8859-1")); 86 87 map.put(STDERR, bErr.toString("iso-8859-1")); 88 } 89 90 return tagValue; 91 } 92 93 public void setCommand(Object expression) throws Exception 94 { 95 _map.put(COMMAND, evaluateAttribute(COMMAND, expression, String .class)); 96 } 97 98 public void setStdin(Object expression) throws Exception 99 { 100 _map.put(STDIN, evaluateAttribute(STDIN, expression, String .class)); 101 } 102 } 103 | Popular Tags |