Get URL configuration for target page. If this is invalid or not available, get it from adaptable.
@param adaptable Adaptable (request or resource)
@param targetPage Target page (may be null)
@return Url config (never null)
324350
protected UrlConfig getUrlConfigForTarget(Adaptable adaptable, Page targetPage) {
    Resource targetResource = null;
    if (targetPage != null) {
      targetResource = targetPage.adaptTo(Resource.class);
    }
    return getUrlConfigForTarget(adaptable, targetResource);
  }
1278297
public static ConfigurationOptionBuilder<List<URL>> urlsOption() {
		return new ConfigurationOptionBuilder<List<URL>>(new ListValueConverter<URL>(UrlValueConverter.INSTANCE), List.class)
				.defaultValue(Collections.<URL>emptyList());
	}
580516
public static String getUrl(final String url) throws Exception {
        return getUrl(new URL(url), null, null);
    }
351754
@Override
    public String url() {
        String url = "";
        if (!StringUtils.isEmpty(baseUrl())) {
            url = baseUrl() + path();
        } else {
            if (!StringUtils.isEmpty(properties.getProperty(Constants.DEFAULT_PROPERTY_URL))) {
                url = properties.getProperty(Constants.DEFAULT_PROPERTY_URL);
            }
            if (testConfig != null && (!StringUtils.isEmpty(testConfig.url()))) {
                url = testConfig.url();
            }
            if (!StringUtils.isEmpty(JvmUtil.getJvmProperty(Constants.JVM_CONDUCTOR_URL))) {
                url = JvmUtil.getJvmProperty(Constants.JVM_CONDUCTOR_URL);
            }
        }
        return url;
    }
172236
private static Page findPage(
		ServletContext servletContext,
		HttpServletRequest req,
		HttpServletResponse resp,
		SemanticCMS semanticCMS
	) throws ServletException, IOException {
		// Path extra info not allowed
		if(req.getPathInfo() != null) {
			return null;
		}
		// Query string not allowed
		if(req.getQueryString() != null) {
			return null;
		}
		String basePath;
		{
			String servletPath = req.getServletPath();
			// Must end in expected extension
			if(!servletPath.endsWith(RssUtils.EXTENSION)) {
				return null;
			}
			basePath = servletPath.substring(0, servletPath.length() - RssUtils.EXTENSION.length());
		}
		// Try to find the page, jspx, then jsp, then direct URL without extension
		String pagePath = null;
		for (String extension : RssUtils.getResourceExtensions()) {
			pagePath = basePath + extension;
			try {
				if(
					!RssUtils.isProtectedExtension(pagePath)
					&& ServletContextCache.getResource(servletContext, pagePath) != null
				) {
					break;
				}
			} catch(MalformedURLException e) {
				// Assume does not exist
			}
		}
		assert pagePath != null : "The last extension should be the default if none matched";
		if(RssUtils.isProtectedExtension(pagePath)) {
			return null;
		}
		// Find book and path
		PageRef pageRef;
		{
			Book book = semanticCMS.getPublishedBook(pagePath);
			if(book == null || !book.isAccessible()) {
				return null;
			}
			BookRef bookRef = book.getBookRef();
			try {
				pageRef = new PageRef(
					bookRef,
					Path.valueOf(pagePath.substring(bookRef.getPrefix().length()))
				);
			} catch(ValidationException e) {
				return null;
			}
		}
		// Capture the page
		return CapturePage.capturePage(
			servletContext,
			req,
			resp,
			pageRef,
			CaptureLevel.META
		);
	}
976772
private static URL discoverConfigFileUrl(String configFileName, String customConfigPropertyName) {
        URL rval;

        // User Defined
        ///////////////////////////////////
        String userConfig = System.getProperty(customConfigPropertyName);
        if (userConfig != null) {
            // Treat it as a URL
            try {
                rval = new URL(userConfig);
                return rval;
            } catch (Exception t) {
            }
            // Treat it as a file
            try {
                File f = new File(userConfig);
                if (f.isFile()) {
                    rval = f.toURI().toURL();
                    return rval;
                }
            } catch (Exception t) {
            }
            throw new RuntimeException("Apiman configuration provided at [" + userConfig + "] but could not be loaded."); //$NON-NLS-1$ //$NON-NLS-2$
        }
        
        // Wildfly/EAP
        ///////////////////////////////////
        String jbossConfigDir = System.getProperty("jboss.server.config.dir"); //$NON-NLS-1$
        String jbossConfigUrl = System.getProperty("jboss.server.config.url"); //$NON-NLS-1$
        if (jbossConfigDir != null) {
            File dirFile = new File(jbossConfigDir);
            rval = findConfigUrlInDirectory(dirFile, configFileName);
            if (rval != null) {
                return rval;
            }
        }
        if (jbossConfigUrl != null) {
            File dirFile = new File(jbossConfigUrl);
            rval = findConfigUrlInDirectory(dirFile, configFileName);
            if (rval != null) {
                return rval;
            }
        }

        // Apache Tomcat
        ///////////////////////
        String tomcatHomeDir = System.getProperty("catalina.home"); //$NON-NLS-1$
        if (tomcatHomeDir != null) {
            File dirFile = new File(tomcatHomeDir, "conf"); //$NON-NLS-1$
            rval = findConfigUrlInDirectory(dirFile, configFileName);
            if (rval != null) {
                return rval;
            }
        }

        // If not found, use an empty file.
        ////////////////////////////////////////
        return ConfigFileConfiguration.class.getResource("empty.properties"); //$NON-NLS-1$
    }
579707
protected Optional<ProviderLoginPageConfiguration> buildProviderConfiguration(final IndirectClient client, final WebContext webContext,
                                                                                  final WebApplicationService service) {
        val name = client.getName();
        val matcher = PAC4J_CLIENT_SUFFIX_PATTERN.matcher(client.getClass().getSimpleName());
        val type = matcher.replaceAll(StringUtils.EMPTY).toLowerCase();
        val uriBuilder = UriComponentsBuilder
            .fromUriString(DelegatedClientNavigationController.ENDPOINT_REDIRECT)
            .queryParam(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER, name);

        if (service != null) {
            val sourceParam = service.getSource();
            val serviceParam = service.getOriginalUrl();
            if (StringUtils.isNotBlank(sourceParam) && StringUtils.isNotBlank(serviceParam)) {
                uriBuilder.queryParam(sourceParam, serviceParam);
            }
        }

        val methodParam = webContext.getRequestParameter(CasProtocolConstants.PARAMETER_METHOD);
        if (StringUtils.isNotBlank(methodParam)) {
            uriBuilder.queryParam(CasProtocolConstants.PARAMETER_METHOD, methodParam);
        }
        val localeParam = webContext.getRequestParameter(this.localeParamName);
        if (StringUtils.isNotBlank(localeParam)) {
            uriBuilder.queryParam(this.localeParamName, localeParam);
        }
        val themeParam = webContext.getRequestParameter(this.themeParamName);
        if (StringUtils.isNotBlank(themeParam)) {
            uriBuilder.queryParam(this.themeParamName, themeParam);
        }
        val redirectUrl = uriBuilder.toUriString();
        val autoRedirect = (Boolean) client.getCustomProperties().getOrDefault(ClientCustomPropertyConstants.CLIENT_CUSTOM_PROPERTY_AUTO_REDIRECT, Boolean.FALSE);
        val p = new ProviderLoginPageConfiguration(name, redirectUrl, type, getCssClass(name), autoRedirect);
        return Optional.of(p);
    }
1258077
def create_url_adapter(self, request: Optional[BaseRequestWebsocket]) -> Optional[MapAdapter]:
        
        if request is not None:
            host = request.host
            return self.url_map.bind_to_request(
                request.scheme, host, request.method, request.path, request.query_string,
            )

        if self.config['SERVER_NAME'] is not None:
            return self.url_map.bind(
                self.config['PREFERRED_URL_SCHEME'], self.config['SERVER_NAME'],
            )
        return None
742504
public static <C extends Page> String absoluteUrlFor(final Class<C> page,
		final PageParameters parameters, final boolean withServerPort)
	{
		final StringBuilder url = new StringBuilder();
		url.append(WicketUrlExtensions.getDomainUrl(withServerPort));
		url.append(WicketUrlExtensions.getBaseUrl(page, parameters).canonical().toString());
		return url.toString();
	}
593869
public static URLTemplatesFactory getURLTemplatesFactory( ServletContext servletContext )
    {
        assert servletContext != null : "The ServletContext cannot be null.";

        if ( servletContext == null )
        {
            throw new IllegalArgumentException( "The ServletContext cannot be null." );
        }

        return ( URLTemplatesFactory ) servletContext.getAttribute( URL_TEMPLATE_FACTORY_ATTR );
    }
498203
public org.opencms.ade.containerpage.client.ui.CmsContainerPageContainer getContainerTarget(String containerName) {

        return m_targetContainers.get(containerName);
    }
795461
@SuppressWarnings("null")
  protected final JSONObject getPage(Page page) throws JSONException {
    Resource resource = page.adaptTo(Resource.class);

    JSONObject pageObject = new JSONObject();

    // node name
    pageObject.put("name", page.getName());

    // node title text
    String title = page.getTitle();
    if (StringUtils.isEmpty(title)) {
      title = page.getName();
    }
    pageObject.put("text", title);

    // resource type
    pageObject.put("type", resource.getResourceType());

    // template
    String template = page.getProperties().get(NameConstants.PN_TEMPLATE, String.class);
    if (StringUtils.isNotEmpty(template)) {
      pageObject.put("template", template);
    }

    // css class for icon
    pageObject.put("cls", "page");

    return pageObject;
  }
1374351
protected static Properties loadConfig(URL url) {
    InputStream is = null;
    try {
      URLConnection connection = url.openConnection();
      if(connection instanceof HttpURLConnection) {
        ((HttpURLConnection)connection).setConnectTimeout(2000);
      }
      is = connection.getInputStream();
      return loadConfig(url.toString(), is);     
    } catch (Exception ex) {
      throw new IllegalArgumentException("Failed to load configuration from [" + url + "]");
    }finally {
      if(is!=null) try { is.close(); } catch (Exception ex) { /* No Op */ }
    }
  }
141889
public static BindingConfiguration load(URL location) throws IllegalStateException {
    	
        Document doc;
        try {
            doc = loadDocument(location);
        } catch (IOException e) {
            throw new IllegalStateException("Cannot load " + location.toExternalForm(), e);
        } catch (ParserConfigurationException e) {
            throw new IllegalStateException("Cannot initialise parser for " + location.toExternalForm(), e);
        } catch (SAXException e) {
            throw new IllegalStateException("Cannot parse " + location.toExternalForm(), e);
        }
        BindingConfiguration configuration = parseDocument(doc);
        return configuration;
    }
562110
public static URL url(final String url) {
        if (url == null) {
            return null;
        }
        try {
            if (url.startsWith("classpath:")) {
                return new URL(null, url, new ClasspathURLStreamHandler());
            }
            return new URL(url);
        } catch (final MalformedURLException ex) {
            throw new IllegalArgumentException("Invalid URL: " + url, ex);
        }
    }
1148934
public static MavenPluginGeneratedConfigOption mavenConfiguration( String url )
    {
        validateNotEmpty( url, "specified configuration url must not be empty " );
        try
        {
            return mavenConfiguration( new URL( url ) );
        } catch( MalformedURLException mE )
        {
            throw new IllegalArgumentException( "url " + url + " is not a valid url", mE );
        }
    }
803821
public static Url getPageUrl(final Page page, final PageParameters parameters)
	{
		return getPageUrl(page.getPageClass(), parameters);
	}