@Test public void doActionTwoParamsCtx() throws Exception { final Shop shop = this.context.mock(Shop.class); ApplicationDirector.setCurrentShop(shop); this.context.checking(new Expectations() {{ allowing(shop).getDefaultShopPreferredUrl(); will(returnValue("https: }}); final ApiUrlTemplateFunctionProviderImpl func = new ApiUrlTemplateFunctionProviderImpl("/ctx", "one", "two"); assertEquals("https: assertEquals("https: assertEquals("https: assertEquals("https: assertEquals("https: assertEquals("https: }
@Override public Object doAction(final Object... params) { final Shop shop = ApplicationDirector.getCurrentShop(); final String defaultUrl = shop.getDefaultShopPreferredUrl(); final StringBuilder url = new StringBuilder(defaultUrl); if (defaultUrl.endsWith("/")) { url.append(contextPath.substring(1)); } else { url.append(contextPath); } if (params != null && params.length >= 1) { final List sections; if (params[0] instanceof Collection) { sections = new ArrayList((Collection) params[0]); } else if (params[0] != null) { sections = Collections.singletonList(String.valueOf(params[0])); } else { sections = Collections.emptyList(); } final int pLength = this.paramName != null ? this.paramName.length : 0; if (pLength <= sections.size()) { for (int i = 0; i < pLength; i++) { final String sec = (String) sections.get(i); if (StringUtils.isNotBlank(sec)) { url.append('/').append(this.paramName[i]).append('/').append(sec); } } for (int i = pLength; i < sections.size(); i++) { final String sec = (String) sections.get(i); if (StringUtils.isNotBlank(sec)) { url.append('/').append(sec); } } } } if (url.length() == 0) { return "/"; } return url.toString(); }
ApiUrlTemplateFunctionProviderImpl implements TemplateProcessor.FunctionProvider { @Override public Object doAction(final Object... params) { final Shop shop = ApplicationDirector.getCurrentShop(); final String defaultUrl = shop.getDefaultShopPreferredUrl(); final StringBuilder url = new StringBuilder(defaultUrl); if (defaultUrl.endsWith("/")) { url.append(contextPath.substring(1)); } else { url.append(contextPath); } if (params != null && params.length >= 1) { final List sections; if (params[0] instanceof Collection) { sections = new ArrayList((Collection) params[0]); } else if (params[0] != null) { sections = Collections.singletonList(String.valueOf(params[0])); } else { sections = Collections.emptyList(); } final int pLength = this.paramName != null ? this.paramName.length : 0; if (pLength <= sections.size()) { for (int i = 0; i < pLength; i++) { final String sec = (String) sections.get(i); if (StringUtils.isNotBlank(sec)) { url.append('/').append(this.paramName[i]).append('/').append(sec); } } for (int i = pLength; i < sections.size(); i++) { final String sec = (String) sections.get(i); if (StringUtils.isNotBlank(sec)) { url.append('/').append(sec); } } } } if (url.length() == 0) { return "/"; } return url.toString(); } }
ApiUrlTemplateFunctionProviderImpl implements TemplateProcessor.FunctionProvider { @Override public Object doAction(final Object... params) { final Shop shop = ApplicationDirector.getCurrentShop(); final String defaultUrl = shop.getDefaultShopPreferredUrl(); final StringBuilder url = new StringBuilder(defaultUrl); if (defaultUrl.endsWith("/")) { url.append(contextPath.substring(1)); } else { url.append(contextPath); } if (params != null && params.length >= 1) { final List sections; if (params[0] instanceof Collection) { sections = new ArrayList((Collection) params[0]); } else if (params[0] != null) { sections = Collections.singletonList(String.valueOf(params[0])); } else { sections = Collections.emptyList(); } final int pLength = this.paramName != null ? this.paramName.length : 0; if (pLength <= sections.size()) { for (int i = 0; i < pLength; i++) { final String sec = (String) sections.get(i); if (StringUtils.isNotBlank(sec)) { url.append('/').append(this.paramName[i]).append('/').append(sec); } } for (int i = pLength; i < sections.size(); i++) { final String sec = (String) sections.get(i); if (StringUtils.isNotBlank(sec)) { url.append('/').append(sec); } } } } if (url.length() == 0) { return "/"; } return url.toString(); } ApiUrlTemplateFunctionProviderImpl();  ApiUrlTemplateFunctionProviderImpl(final String contextPath, final String ... paramName); }
ApiUrlTemplateFunctionProviderImpl implements TemplateProcessor.FunctionProvider { @Override public Object doAction(final Object... params) { final Shop shop = ApplicationDirector.getCurrentShop(); final String defaultUrl = shop.getDefaultShopPreferredUrl(); final StringBuilder url = new StringBuilder(defaultUrl); if (defaultUrl.endsWith("/")) { url.append(contextPath.substring(1)); } else { url.append(contextPath); } if (params != null && params.length >= 1) { final List sections; if (params[0] instanceof Collection) { sections = new ArrayList((Collection) params[0]); } else if (params[0] != null) { sections = Collections.singletonList(String.valueOf(params[0])); } else { sections = Collections.emptyList(); } final int pLength = this.paramName != null ? this.paramName.length : 0; if (pLength <= sections.size()) { for (int i = 0; i < pLength; i++) { final String sec = (String) sections.get(i); if (StringUtils.isNotBlank(sec)) { url.append('/').append(this.paramName[i]).append('/').append(sec); } } for (int i = pLength; i < sections.size(); i++) { final String sec = (String) sections.get(i); if (StringUtils.isNotBlank(sec)) { url.append('/').append(sec); } } } } if (url.length() == 0) { return "/"; } return url.toString(); } ApiUrlTemplateFunctionProviderImpl();  ApiUrlTemplateFunctionProviderImpl(final String contextPath, final String ... paramName); @Override Object doAction(final Object... params); }
ApiUrlTemplateFunctionProviderImpl implements TemplateProcessor.FunctionProvider { @Override public Object doAction(final Object... params) { final Shop shop = ApplicationDirector.getCurrentShop(); final String defaultUrl = shop.getDefaultShopPreferredUrl(); final StringBuilder url = new StringBuilder(defaultUrl); if (defaultUrl.endsWith("/")) { url.append(contextPath.substring(1)); } else { url.append(contextPath); } if (params != null && params.length >= 1) { final List sections; if (params[0] instanceof Collection) { sections = new ArrayList((Collection) params[0]); } else if (params[0] != null) { sections = Collections.singletonList(String.valueOf(params[0])); } else { sections = Collections.emptyList(); } final int pLength = this.paramName != null ? this.paramName.length : 0; if (pLength <= sections.size()) { for (int i = 0; i < pLength; i++) { final String sec = (String) sections.get(i); if (StringUtils.isNotBlank(sec)) { url.append('/').append(this.paramName[i]).append('/').append(sec); } } for (int i = pLength; i < sections.size(); i++) { final String sec = (String) sections.get(i); if (StringUtils.isNotBlank(sec)) { url.append('/').append(sec); } } } } if (url.length() == 0) { return "/"; } return url.toString(); } ApiUrlTemplateFunctionProviderImpl();  ApiUrlTemplateFunctionProviderImpl(final String contextPath, final String ... paramName); @Override Object doAction(final Object... params);  }