public boolean isURLMapped(final String url) { PrettyUrlMapping mapping = getMappingForUrl(url); return (mapping != null); }
public PrettyConfig build() { final PrettyConfig config = new PrettyConfig(); for (PrettyUrlMapping mapping : mappings) { config.addMapping(mapping); } return config; }
public boolean isMappingId(final String action) { PrettyUrlMapping mapping = getMappingById(action); return mapping instanceof PrettyUrlMapping; }
/** * Loads the Pretty Faces configuration and returns the configuration * object. * * @return Loaded configuration. * @throws IOException * If configuration could not be read. * @throws SAXException * If configuraion could not be parsed. */ public PrettyConfig configure() throws IOException, SAXException { final PrettyConfigBuilder builder = new PrettyConfigBuilder(); // Load configurations from the class path feedClassLoaderConfigs(builder); // Load configurations from the config files configured in the servlet // context feedContextSpecifiedConfig(builder); // Load configuration from the default path feedWebAppConfig(builder); return builder.build(); }
public boolean isViewMapped(String viewId) { if (viewId != null) { viewId = viewId.trim(); PrettyUrlMapping needle = new PrettyUrlMapping(); needle.setViewId(viewId); if (viewId.startsWith("/")) { if (getMappings().contains(needle)) { return true; } needle.setViewId(viewId.substring(1)); } return getMappings().contains(needle); } return false; }
private void feedClassLoaderConfigs(final PrettyConfigBuilder builder) throws IOException, SAXException final Enumeration<URL> urls = getResourceLoader().getResources(PRETTY_CONFIG_RESOURCE); if (urls != null) try is = openStream(url); configParser.parse(builder, is);
public PrettyUrlMapping getMappingForUrl(final String url) { for (PrettyUrlMapping mapping : getMappings()) { String urlPattern = mapping.getPattern(); UrlPatternParser um = new UrlPatternParser(urlPattern); if (um.matches(url)) { return mapping; } } return null; }
/** * This method accepts a mapping id (with or without prefix) * * @param id Mapping id * @return PrettyUrlMapping Corresponding mapping */ public PrettyUrlMapping getMappingById(String id) { if (id != null) { if (id.startsWith(PrettyContext.PRETTY_PREFIX)) { id = id.substring(PrettyContext.PRETTY_PREFIX.length()); } for (PrettyUrlMapping mapping : getMappings()) { if (mapping.getId().equals(id)) { return mapping; } } } return null; } }
private void feedContextSpecifiedConfig(final PrettyConfigBuilder builder) throws IOException, SAXException final List<String> configFilesList = getConfigFilesList(); for (final String systemId : configFilesList) configParser.parse(builder, is);
/** * Load and cache configurations */ public void init(final FilterConfig filterConfig) throws ServletException { final PrettyConfigurator configurator = new PrettyConfigurator(filterConfig.getServletContext()); try { log.info("PrettyFilter starting up..."); PrettyConfig config = configurator.configure(); servletContext = filterConfig.getServletContext(); setConfig(config); log.info("PrettyFilter initialized."); } catch (IOException ioex) { throw new ServletException("Error configuring Pretty Faces, could not load the configuration.", ioex); } catch (SAXException saxex) { throw new ServletException("Error configuring Pretty Faces, could not parse the configuration.", saxex); } }
PrettyUrlMapping mapping = config.getMappingById(action); if (mapping != null) log.info("Redirecting to mappingId [" + mapping.getId() + "], [" + url + "]"); externalContext.redirect(externalContext.encodeActionURL(url));
/** * Return true if the given URL corresponds to one or more mappings in the * current configuration. Strips context path information if necessary. */ public boolean isURLMapped(final String url) { return getConfig().isURLMapped(stripContextPath(url)); }
/** * Constructs a new configurator. * * @param servletContext * servlet context, must not be <code>null</code>. */ public PrettyConfigurator(final ServletContext servletContext) { if (servletContext == null) { throw new IllegalArgumentException("Servlet context must not be null."); } this.servletContext = servletContext; configParser = new DigesterPrettyConfigParser(); }
private boolean isPrettyNavigationCase(final String action) { PrettyContext prettyContext = PrettyContext.getCurrentInstance(); PrettyConfig config = prettyContext.getConfig(); return action != null && config.isMappingId(action) && action.trim().startsWith(PrettyContext.PRETTY_PREFIX); } }
public void parse(final PrettyConfigBuilder builder, final InputStream resource) throws IOException, SAXException { if (builder == null) { throw new IllegalArgumentException("Builder must not be null."); } if (resource == null) { throw new IllegalArgumentException("Input stream must not be null."); } final Digester digester = configureDigester(new Digester()); digester.push(builder); digester.parse(resource); }
private void feedWebAppConfig(final PrettyConfigBuilder builder) throws IOException, SAXException { final InputStream is = servletContext.getResourceAsStream(DEFAULT_PRETTY_FACES_CONFIG); if (is != null) { if (log.isInfoEnabled()) { log.info("Reading config [" + DEFAULT_PRETTY_FACES_CONFIG + "]."); } try { configParser.parse(builder, is); } finally { try { is.close(); } catch (IOException ignored) { } } } }
private void injectParams(final FacesContext context, final String url, final PrettyUrlMapping mapping, final UrlPatternParser parser) { Map<String, String> params = parser.getMappedParameters(url); if (params != null) { for (Map.Entry<String, String> param : params.entrySet()) { String el = param.getKey(); String value = param.getValue(); try { elUtils.setValue(context, el, value); } catch (Exception e) { throw new PrettyException("PrettyFaces: Exception occurred while processing <" + mapping.getId() + ":" + el + "> for URL <" + url + ">", e); } } } }
public void injectParameters(final FacesContext context) { PrettyContext prettyContext = PrettyContext.getCurrentInstance(); String url = prettyContext.stripContextPath(prettyContext.getOriginalUri()); for (PrettyUrlMapping mapping : prettyContext.getConfig().getMappings()) { UrlPatternParser parser = new UrlPatternParser(mapping.getPattern()); if (parser.matches(url)) { injectParams(context, url, mapping, parser); injectQueryParams(context, mapping); } } }
public String buildMappedUrl(final UIComponent component) { String mappingId = (String) component.getAttributes().get("mappingId"); if (mappingId == null) { throw new PrettyException("Mapping id was null when attempting to build URL for component: " + component.toString() + " <" + component.getClientId(FacesContext.getCurrentInstance()) + ">"); } PrettyContext prettyContext = PrettyContext.getCurrentInstance(); PrettyConfig prettyConfig = prettyContext.getConfig(); PrettyUrlMapping urlMapping = prettyConfig.getMappingById(mappingId); return buildMappedUrl(urlMapping, extractParameters(component)); }
/** * Determine if this request URL is mapped by PrettyFaces */ public boolean isPrettyRequest() { return getConfig().isURLMapped(stripContextPath(originalUri)); }