Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package org.litesoft.servlet;

import java.io.*;

public class WebInfLocator
{
    // e.g.: file:/C:/zDev/litesoft/GWT_Sandbox/UIdesign/war/WEB-INF/lib/LocationAnchor.jar
    public static String getLocationAnchorPathFrom( ClassLoader pClassLoader )
    {
        try
        {
            Class<?> zClass = pClassLoader.loadClass( "org.litesoft.locationanchor.LocationAnchor" );
            return zClass.newInstance().toString();
        }
        catch ( Exception e )
        {
            e.printStackTrace();
            return null;
        }
    }

    // e.g.: file:/C:/zDev/litesoft/GWT_Sandbox/UIdesign/war/WEB-INF/lib/LocationAnchor.jar
    public static String getLocationAnchorPathFrom( Class<?> pForClassLoader )
    {
        try
        {
            return getLocationAnchorPathFrom( pForClassLoader.getClassLoader() );
        }
        catch ( Exception e )
        {
            e.printStackTrace();
            return null;
        }
    }

    // e.g.: file:/C:/zDev/litesoft/GWT_Sandbox/UIdesign/war/WEB-INF/lib/LocationAnchor.jar
    public static String getLocationAnchorPath()
    {
        return getLocationAnchorPathFrom( WebInfLocator.class );
    }

    // e.g.: file:/C:/zDev/litesoft/GWT_Sandbox/UIdesign/war/WEB-INF/lib/LocationAnchor.jar
    public static String getLocationAnchorPath( Object pForClassLoader )
    {
        try
        {
            return getLocationAnchorPathFrom( pForClassLoader.getClass() );
        }
        catch ( Exception e )
        {
            e.printStackTrace();
            return null;
        }
    }

    public static File extractDir( String pLocationAnchorPath ) // e.g.: file:/C:/zDev/litesoft/GWT_Sandbox/UIdesign/war/WEB-INF/lib/LocationAnchor.jar
    { // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .01234
        if ( pLocationAnchorPath == null )
        {
            System.out.println( "WebInfLocator.extractDir: No Path?" );
            return null;
        }
        int at = pLocationAnchorPath.indexOf( "/WEB-INF/" ); // . . . . . . . . . . . . . . . . .0123456
        if ( (at <= 6) /* . . . . . . . . .. . 012345678 */ || !pLocationAnchorPath.startsWith( "file:/" ) )
        {
            System.out.println( "WebInfLocator.extractDir: Path? '" + pLocationAnchorPath + "'" );
            return null;
        }
        String zPath = pLocationAnchorPath.substring( 5, at + 8 );
        if ( Character.isLetter( zPath.charAt( 1 ) ) && ":/".equals( zPath.substring( 2, 4 ) ) ) // Stupid Windows
        {
            zPath = zPath.substring( 1 ); // Drop the leading slash, leaving the start as the drive reference
        }
        File zDir = new File( zPath );
        if ( !zDir.isDirectory() )
        {
            System.out.println( "WebInfLocator.extractDir, Not a Directory: " + zDir.getPath() );
            return null;
        }
        try
        {
            return zDir.getCanonicalFile();
        }
        catch ( IOException e )
        {
            System.out.println( "WebInfLocator.extractDir, Could not Canonicalize: " + zDir.getPath() );
            return null;
        }
    }

    public static File getDir( Object pForClassLoader )
    {
        return extractDir( getLocationAnchorPath( pForClassLoader ) );
    }
}

Commits for litesoft/trunk/Java/VersionedStaticContentFilter/src/org/litesoft/servlet/WebInfLocator.java

Diff revisions: vs.
Revision Author Commited Message
917 Diff Diff GeorgeS picture GeorgeS Sun 08 Dec, 2013 20:49:56 +0000

1.7 prep & VersionedStaticContentFilter upgrade to new “/ver” model!

466 GeorgeS picture GeorgeS Thu 25 Aug, 2011 12:47:41 +0000