1 11 package org.apache.catalina.ssi; 12 13 14 import java.io.PrintWriter ; 15 24 public class SSIEcho implements SSICommand { 25 protected final static String DEFAULT_ENCODING = "entity"; 26 protected final static String MISSING_VARIABLE_VALUE = "(none)"; 27 28 29 32 public long process(SSIMediator ssiMediator, String commandName, 33 String [] paramNames, String [] paramValues, PrintWriter writer) { 34 long lastModified = 0; 35 String encoding = DEFAULT_ENCODING; 36 String errorMessage = ssiMediator.getConfigErrMsg(); 37 for (int i = 0; i < paramNames.length; i++) { 38 String paramName = paramNames[i]; 39 String paramValue = paramValues[i]; 40 if (paramName.equalsIgnoreCase("var")) { 41 String variableValue = ssiMediator.getVariableValue( 42 paramValue, encoding); 43 if (variableValue == null) { 44 variableValue = MISSING_VARIABLE_VALUE; 45 } 46 writer.write(variableValue); 47 lastModified = System.currentTimeMillis(); 48 } else if (paramName.equalsIgnoreCase("encoding")) { 49 if (isValidEncoding(paramValue)) { 50 encoding = paramValue; 51 } else { 52 ssiMediator.log("#echo--Invalid encoding: " + paramValue); 53 writer.write(errorMessage); 54 } 55 } else { 56 ssiMediator.log("#echo--Invalid attribute: " + paramName); 57 writer.write(errorMessage); 58 } 59 } 60 return lastModified; 61 } 62 63 64 protected boolean isValidEncoding(String encoding) { 65 return encoding.equalsIgnoreCase("url") 66 || encoding.equalsIgnoreCase("entity") 67 || encoding.equalsIgnoreCase("none"); 68 } 69 } | Popular Tags |