@Test public void decode_compoent_event_request_with_slash_in_context_path() throws Exception { ComponentClassResolver resolver = mockComponentClassResolver(); Request request = mockRequest(); Response response = mockResponse(); LocalizationSetter ls = mockLocalizationSetter(); MetaDataLocator metaDataLocator = neverWhitelistProtected(); expect(ls.isSupportedLocaleName("page.component:event")).andReturn(false); train_getParameter(request, InternalConstants.PAGE_CONTEXT_NAME, null); train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, null); train_getLocale(request, Locale.ENGLISH); ls.setNonPersistentLocaleFromLocaleName("en"); train_getPath(request, "/foo/bar/page.component:event"); train_isPageName(resolver, "page", true); train_canonicalizePageName(resolver, "page", "Page"); replay(); ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "foo/bar", metaDataLocator, null); ComponentEventRequestParameters parameters = linkEncoder.decodeComponentEventRequest(request); assertNotNull(parameters); assertEquals(parameters.getActivePageName(), "Page"); assertEquals(parameters.getEventType(), "event"); verify(); }
public ComponentEventRequestParameters decodeComponentEventRequest(Request request) { String explicitLocale = null; String requestPath = request.getPath(); if (applicationFolderPrefix != null) { requestPath = removeApplicationPrefix(requestPath); } List<String> path = splitPath(requestPath); if (path.isEmpty()) { return null; } String potentialLocale = path.get(0); if (localizationSetter.isSupportedLocaleName(potentialLocale)) { explicitLocale = potentialLocale; path.remove(0); } StringBuilder pageName = new StringBuilder(100); String sep = ""; while (!path.isEmpty()) { String name = path.remove(0); String eventType = EventConstants.ACTION; String nestedComponentId = ""; boolean found = false; int colonx = name.lastIndexOf(':'); if (colonx > 0) { found = true; eventType = name.substring(colonx + 1); name = name.substring(0, colonx); } int dotx = name.indexOf('.'); if (dotx > 0) { found = true; nestedComponentId = name.substring(dotx + 1); name = name.substring(0, dotx); } pageName.append(sep).append(name); if (found) { ComponentEventRequestParameters result = validateAndConstructComponentEventRequest(request, pageName.toString(), nestedComponentId, eventType, path); if (result == null) { return result; } if (explicitLocale == null) { setLocaleFromRequest(request); } else { localizationSetter.setLocaleFromLocaleName(explicitLocale); } return result; } sep = "/"; } return null; }
ComponentEventLinkEncoderImpl implements ComponentEventLinkEncoder { public ComponentEventRequestParameters decodeComponentEventRequest(Request request) { String explicitLocale = null; String requestPath = request.getPath(); if (applicationFolderPrefix != null) { requestPath = removeApplicationPrefix(requestPath); } List<String> path = splitPath(requestPath); if (path.isEmpty()) { return null; } String potentialLocale = path.get(0); if (localizationSetter.isSupportedLocaleName(potentialLocale)) { explicitLocale = potentialLocale; path.remove(0); } StringBuilder pageName = new StringBuilder(100); String sep = ""; while (!path.isEmpty()) { String name = path.remove(0); String eventType = EventConstants.ACTION; String nestedComponentId = ""; boolean found = false; int colonx = name.lastIndexOf(':'); if (colonx > 0) { found = true; eventType = name.substring(colonx + 1); name = name.substring(0, colonx); } int dotx = name.indexOf('.'); if (dotx > 0) { found = true; nestedComponentId = name.substring(dotx + 1); name = name.substring(0, dotx); } pageName.append(sep).append(name); if (found) { ComponentEventRequestParameters result = validateAndConstructComponentEventRequest(request, pageName.toString(), nestedComponentId, eventType, path); if (result == null) { return result; } if (explicitLocale == null) { setLocaleFromRequest(request); } else { localizationSetter.setLocaleFromLocaleName(explicitLocale); } return result; } sep = "/"; } return null; } }
ComponentEventLinkEncoderImpl implements ComponentEventLinkEncoder { public ComponentEventRequestParameters decodeComponentEventRequest(Request request) { String explicitLocale = null; String requestPath = request.getPath(); if (applicationFolderPrefix != null) { requestPath = removeApplicationPrefix(requestPath); } List<String> path = splitPath(requestPath); if (path.isEmpty()) { return null; } String potentialLocale = path.get(0); if (localizationSetter.isSupportedLocaleName(potentialLocale)) { explicitLocale = potentialLocale; path.remove(0); } StringBuilder pageName = new StringBuilder(100); String sep = ""; while (!path.isEmpty()) { String name = path.remove(0); String eventType = EventConstants.ACTION; String nestedComponentId = ""; boolean found = false; int colonx = name.lastIndexOf(':'); if (colonx > 0) { found = true; eventType = name.substring(colonx + 1); name = name.substring(0, colonx); } int dotx = name.indexOf('.'); if (dotx > 0) { found = true; nestedComponentId = name.substring(dotx + 1); name = name.substring(0, dotx); } pageName.append(sep).append(name); if (found) { ComponentEventRequestParameters result = validateAndConstructComponentEventRequest(request, pageName.toString(), nestedComponentId, eventType, path); if (result == null) { return result; } if (explicitLocale == null) { setLocaleFromRequest(request); } else { localizationSetter.setLocaleFromLocaleName(explicitLocale); } return result; } sep = "/"; } return null; } ComponentEventLinkEncoderImpl(ComponentClassResolver componentClassResolver,
                                         ContextPathEncoder contextPathEncoder, LocalizationSetter localizationSetter,
                                         Response response, RequestSecurityManager requestSecurityManager, BaseURLSource baseURLSource,
                                         PersistentLocale persistentLocale,
                                         @Symbol(SymbolConstants.ENCODE_LOCALE_INTO_PATH)
                                         boolean encodeLocaleIntoPath,
                                         @Symbol(SymbolConstants.CONTEXT_PATH)
                                         String contextPath,
                                         @Symbol(SymbolConstants.APPLICATION_FOLDER) String applicationFolder,
                                         MetaDataLocator metaDataLocator,
                                         ClientWhitelist clientWhitelist); }
ComponentEventLinkEncoderImpl implements ComponentEventLinkEncoder { public ComponentEventRequestParameters decodeComponentEventRequest(Request request) { String explicitLocale = null; String requestPath = request.getPath(); if (applicationFolderPrefix != null) { requestPath = removeApplicationPrefix(requestPath); } List<String> path = splitPath(requestPath); if (path.isEmpty()) { return null; } String potentialLocale = path.get(0); if (localizationSetter.isSupportedLocaleName(potentialLocale)) { explicitLocale = potentialLocale; path.remove(0); } StringBuilder pageName = new StringBuilder(100); String sep = ""; while (!path.isEmpty()) { String name = path.remove(0); String eventType = EventConstants.ACTION; String nestedComponentId = ""; boolean found = false; int colonx = name.lastIndexOf(':'); if (colonx > 0) { found = true; eventType = name.substring(colonx + 1); name = name.substring(0, colonx); } int dotx = name.indexOf('.'); if (dotx > 0) { found = true; nestedComponentId = name.substring(dotx + 1); name = name.substring(0, dotx); } pageName.append(sep).append(name); if (found) { ComponentEventRequestParameters result = validateAndConstructComponentEventRequest(request, pageName.toString(), nestedComponentId, eventType, path); if (result == null) { return result; } if (explicitLocale == null) { setLocaleFromRequest(request); } else { localizationSetter.setLocaleFromLocaleName(explicitLocale); } return result; } sep = "/"; } return null; } ComponentEventLinkEncoderImpl(ComponentClassResolver componentClassResolver,
                                         ContextPathEncoder contextPathEncoder, LocalizationSetter localizationSetter,
                                         Response response, RequestSecurityManager requestSecurityManager, BaseURLSource baseURLSource,
                                         PersistentLocale persistentLocale,
                                         @Symbol(SymbolConstants.ENCODE_LOCALE_INTO_PATH)
                                         boolean encodeLocaleIntoPath,
                                         @Symbol(SymbolConstants.CONTEXT_PATH)
                                         String contextPath,
                                         @Symbol(SymbolConstants.APPLICATION_FOLDER) String applicationFolder,
                                         MetaDataLocator metaDataLocator,
                                         ClientWhitelist clientWhitelist); Link createPageRenderLink(PageRenderRequestParameters parameters); Link createComponentEventLink(ComponentEventRequestParameters parameters, boolean forForm); ComponentEventRequestParameters decodeComponentEventRequest(Request request); PageRenderRequestParameters decodePageRenderRequest(Request request); void appendContext(boolean seperatorRequired, EventContext context, StringBuilder builder); }
ComponentEventLinkEncoderImpl implements ComponentEventLinkEncoder { public ComponentEventRequestParameters decodeComponentEventRequest(Request request) { String explicitLocale = null; String requestPath = request.getPath(); if (applicationFolderPrefix != null) { requestPath = removeApplicationPrefix(requestPath); } List<String> path = splitPath(requestPath); if (path.isEmpty()) { return null; } String potentialLocale = path.get(0); if (localizationSetter.isSupportedLocaleName(potentialLocale)) { explicitLocale = potentialLocale; path.remove(0); } StringBuilder pageName = new StringBuilder(100); String sep = ""; while (!path.isEmpty()) { String name = path.remove(0); String eventType = EventConstants.ACTION; String nestedComponentId = ""; boolean found = false; int colonx = name.lastIndexOf(':'); if (colonx > 0) { found = true; eventType = name.substring(colonx + 1); name = name.substring(0, colonx); } int dotx = name.indexOf('.'); if (dotx > 0) { found = true; nestedComponentId = name.substring(dotx + 1); name = name.substring(0, dotx); } pageName.append(sep).append(name); if (found) { ComponentEventRequestParameters result = validateAndConstructComponentEventRequest(request, pageName.toString(), nestedComponentId, eventType, path); if (result == null) { return result; } if (explicitLocale == null) { setLocaleFromRequest(request); } else { localizationSetter.setLocaleFromLocaleName(explicitLocale); } return result; } sep = "/"; } return null; } ComponentEventLinkEncoderImpl(ComponentClassResolver componentClassResolver,
                                         ContextPathEncoder contextPathEncoder, LocalizationSetter localizationSetter,
                                         Response response, RequestSecurityManager requestSecurityManager, BaseURLSource baseURLSource,
                                         PersistentLocale persistentLocale,
                                         @Symbol(SymbolConstants.ENCODE_LOCALE_INTO_PATH)
                                         boolean encodeLocaleIntoPath,
                                         @Symbol(SymbolConstants.CONTEXT_PATH)
                                         String contextPath,
                                         @Symbol(SymbolConstants.APPLICATION_FOLDER) String applicationFolder,
                                         MetaDataLocator metaDataLocator,
                                         ClientWhitelist clientWhitelist); Link createPageRenderLink(PageRenderRequestParameters parameters); Link createComponentEventLink(ComponentEventRequestParameters parameters, boolean forForm); ComponentEventRequestParameters decodeComponentEventRequest(Request request); PageRenderRequestParameters decodePageRenderRequest(Request request); void appendContext(boolean seperatorRequired, EventContext context, StringBuilder builder);  }