1 16 package org.apache.catalina.storeconfig; 17 18 import java.io.File ; 19 import java.io.IOException ; 20 21 import javax.print.DocPrintJob ; 22 23 import org.apache.catalina.Container; 24 import org.apache.catalina.core.StandardContext; 25 import org.apache.catalina.core.StandardHost; 26 27 33 public class StoreContextAppender extends StoreAppender { 34 35 44 public boolean isPrintValue(Object bean, Object bean2, String attrName, 45 StoreDescription desc) { 46 boolean isPrint = super.isPrintValue(bean, bean2, attrName, desc); 47 if (isPrint) { 48 StandardContext context = ((StandardContext) bean); 49 if ("workDir".equals(attrName)) { 50 String defaultWorkDir = getDefaultWorkDir(context); 51 isPrint = !defaultWorkDir.equals(context.getWorkDir()); 52 } else if ("path".equals(attrName)) { 53 isPrint = desc.isStoreSeparate() 54 && desc.isExternalAllowed() 55 && context.getConfigFile() == null; 56 } else if ("docBase".equals(attrName)) { 57 Container host = context.getParent(); 58 if (host instanceof StandardHost) { 59 File appBase = getAppBase(((StandardHost) host)); 60 File docBase = getDocBase(context,appBase); 61 isPrint = !appBase.equals(docBase.getParentFile()); 62 } 63 } 64 } 65 return isPrint; 66 } 67 68 protected File getAppBase(StandardHost host) { 69 70 File appBase; 71 File file = new File (host.getAppBase()); 72 if (!file.isAbsolute()) 73 file = new File (System.getProperty("catalina.base"), host 74 .getAppBase()); 75 try { 76 appBase = file.getCanonicalFile(); 77 } catch (IOException e) { 78 appBase = file; 79 } 80 return (appBase); 81 82 } 83 84 protected File getDocBase(StandardContext context, File appBase) { 85 86 File docBase; 87 File file = new File (context.getDocBase()); 88 if (!file.isAbsolute()) 89 file = new File (appBase, context.getDocBase()); 90 try { 91 docBase = file.getCanonicalFile(); 92 } catch (IOException e) { 93 docBase = file; 94 } 95 return (docBase); 96 97 } 98 99 105 protected String getDefaultWorkDir(StandardContext context) { 106 String defaultWorkDir = null; 107 String contextPath = context.getPath().length() == 0 ? "_" : context 108 .getPath().substring(1); 109 Container host = context.getParent(); 110 if (host instanceof StandardHost) { 111 String hostWorkDir = ((StandardHost) host).getWorkDir(); 112 if (hostWorkDir != null) { 113 defaultWorkDir = hostWorkDir + File.separator + contextPath; 114 } else { 115 String engineName = context.getParent().getParent().getName(); 116 String hostName = context.getParent().getName(); 117 defaultWorkDir = "work" + File.separator + engineName 118 + File.separator + hostName + File.separator 119 + contextPath; 120 } 121 } 122 return defaultWorkDir; 123 } 124 125 133 public Object defaultInstance(Object bean) throws InstantiationException , 134 IllegalAccessException { 135 if (bean instanceof StandardContext) { 136 StandardContext defaultContext = new StandardContext(); 137 148 return defaultContext; 149 } else 150 return super.defaultInstance(bean); 151 } 152 } | Popular Tags |