1 18 package org.apache.beehive.netui.core.urltemplates; 19 20 import org.apache.beehive.netui.util.logging.Logger; 21 22 import javax.servlet.ServletContext ; 23 import java.util.Arrays ; 24 import java.util.List ; 25 26 30 public class URLTemplateDescriptor 31 { 32 private static final Logger _log = new Logger( URLTemplateDescriptor.class ); 34 35 private static URLTemplateDescriptor instance = new URLTemplateDescriptor(); 37 38 public static final String DEFAULT_TEMPLATE = "default"; 40 public static final String SECURE_DEFAULT_TEMPLATE = "secure-default"; 41 public static final String ACTION_TEMPLATE = "action"; 42 public static final String SECURE_ACTION_TEMPLATE = "secure-action"; 43 public static final String RESOURCE_TEMPLATE = "resource"; 44 public static final String SECURE_RESOURCE_TEMPLATE = "secure-resource"; 45 public static final String RENDER_TEMPLATE = "render"; 46 public static final String SECURE_RENDER_TEMPLATE = "secure-render"; 47 48 public static final String SCHEME_TOKEN = "{url:scheme}"; 50 public static final String DOMAIN_TOKEN = "{url:domain}"; 51 public static final String PORT_TOKEN = "{url:port}"; 52 public static final String PATH_TOKEN = "{url:path}"; 53 public static final String QUERY_STRING_TOKEN = "{url:queryString}"; 54 public static final String FRAGMENT_TOKEN = "{url:fragment}"; 55 56 private static final List KNOWN_TEMPLATE_TOKENS = 57 Arrays.asList( new String []{ SCHEME_TOKEN, DOMAIN_TOKEN, PORT_TOKEN, FRAGMENT_TOKEN } ); 58 59 private static final List REQUIRED_TEMPLATE_TOKENS = 60 Arrays.asList( new String []{ PATH_TOKEN, QUERY_STRING_TOKEN } ); 61 62 private URLTemplates _urlTemplates = new URLTemplates(); 64 65 private boolean _loaded = false; 66 67 70 protected URLTemplateDescriptor() 71 { 72 } 73 74 80 public URLTemplate getURLTemplate( String name ) 81 { 82 return _urlTemplates.getTemplate( name ); 83 } 84 85 92 public String getURLTemplateRef( String refGroupName, String key ) 93 { 94 String ref = _urlTemplates.getTemplateNameByRef( refGroupName, key ); 95 if ( ref == null ) 96 { 97 if ( key.equals( SECURE_RENDER_TEMPLATE ) || 100 key.equals( SECURE_ACTION_TEMPLATE ) || 101 key.equals( SECURE_RESOURCE_TEMPLATE ) ) 102 { 103 ref = _urlTemplates.getTemplateNameByRef( refGroupName, SECURE_DEFAULT_TEMPLATE ); 104 } 105 } 106 107 return ref; 108 } 109 110 115 public static URLTemplateDescriptor getInstance() 116 { 117 return instance; 118 } 119 120 public synchronized void load( ServletContext servletContext ) 121 { 122 if ( _loaded ) 123 { 124 return; 125 } 126 127 URLTemplatesFactory urlTemplatesFactory = new URLTemplatesFactory(); 128 urlTemplatesFactory.setKnownTokens( KNOWN_TEMPLATE_TOKENS ); 129 urlTemplatesFactory.setRequiredTokens( REQUIRED_TEMPLATE_TOKENS ); 130 _urlTemplates = urlTemplatesFactory.getTemplates( servletContext ); 131 132 _loaded = true; 133 } 134 } 135 | Popular Tags |