MCPcopy Create free account
hub / github.com/apache/tomcat / fixDocBase

Method fixDocBase

java/org/apache/catalina/startup/ContextConfig.java:837–940  ·  view source on GitHub ↗

Adjust docBase. @throws IOException cannot access the context base path

()

Source from the content-addressed store, hash-verified

835 * @throws IOException cannot access the context base path
836 */
837 protected void fixDocBase() throws IOException {
838
839 Host host = (Host) context.getParent();
840 File appBase = host.getAppBaseFile();
841
842 // This could be blank, relative, absolute or canonical
843 String docBaseConfigured = context.getDocBase();
844 // If there is no explicit docBase, derive it from the path and version
845 if (docBaseConfigured == null) {
846 // Trying to guess the docBase according to the path
847 String path = context.getPath();
848 if (path == null) {
849 return;
850 }
851 ContextName cn = new ContextName(path, context.getWebappVersion());
852 docBaseConfigured = cn.getBaseName();
853 }
854
855 // Obtain the absolute docBase in String and File form
856 String docBaseAbsolute;
857 File docBaseConfiguredFile = new File(docBaseConfigured);
858 if (!docBaseConfiguredFile.isAbsolute()) {
859 docBaseAbsolute = (new File(appBase, docBaseConfigured)).getAbsolutePath();
860 } else {
861 docBaseAbsolute = docBaseConfiguredFile.getAbsolutePath();
862 }
863 File docBaseAbsoluteFile = new File(docBaseAbsolute);
864 String originalDocBase = docBaseAbsolute;
865
866 ContextName cn = new ContextName(context.getPath(), context.getWebappVersion());
867 String pathName = cn.getBaseName();
868
869 boolean unpackWARs = true;
870 if (host instanceof StandardHost) {
871 unpackWARs = ((StandardHost) host).isUnpackWARs();
872 if (unpackWARs && context instanceof StandardContext) {
873 unpackWARs = ((StandardContext) context).getUnpackWAR();
874 }
875 }
876
877 // At this point we need to determine if we have a WAR file in the
878 // appBase that needs to be expanded. Therefore, we consider the absolute
879 // docBase NOT the canonical docBase. This is because some users symlink
880 // WAR files into the appBase and we want this to work correctly.
881 boolean docBaseAbsoluteInAppBase = docBaseAbsolute.startsWith(appBase.getPath() + File.separatorChar);
882 if (docBaseAbsolute.toLowerCase(Locale.ENGLISH).endsWith(".war") && !docBaseAbsoluteFile.isDirectory()) {
883 URL war = UriUtil.buildJarUrl(docBaseAbsoluteFile);
884 if (unpackWARs) {
885 docBaseAbsolute = ExpandWar.expand(host, war, pathName);
886 docBaseAbsoluteFile = new File(docBaseAbsolute);
887 if (context instanceof StandardContext) {
888 ((StandardContext) context).setOriginalDocBase(originalDocBase);
889 }
890 } else {
891 ExpandWar.validate(host, war, pathName);
892 }
893 } else {
894 File docBaseAbsoluteFileWar = new File(docBaseAbsolute + ".war");

Callers 1

beforeStartMethod · 0.95

Calls 15

getAppBaseFileMethod · 0.95
getBaseNameMethod · 0.95
buildJarUrlMethod · 0.95
expandMethod · 0.95
validateMethod · 0.95
getUnpackWARMethod · 0.80
endsWithMethod · 0.80
setOriginalDocBaseMethod · 0.80
lengthMethod · 0.80
getParentMethod · 0.65
getDocBaseMethod · 0.65
getPathMethod · 0.65

Tested by

no test coverage detected