Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
decebals committed Sep 19, 2017
1 parent 310d5b9 commit d4230ea
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,19 @@ public void testControllerWithInterceptor() {
@Interceptor
@Priority(Interceptor.Priority.APPLICATION)
public static class SecuredInterceptor {

@AroundInvoke
public Object doSecured(InvocationContext context) throws Exception {
return context.proceed();
}

}

@Path("/")
@Secured
@Dependent
public static class ControllerWithInterceptor extends Controller {

@GET
public void index() {
// test all controller methods
Expand All @@ -79,14 +82,17 @@ public void index() {
getRequest().getClientIp();
getResponse().send("ok");
}

}

public static class PippoApplication extends ControllerApplication {

@Override
protected void onInit() {
setControllerFactory(new WeldControllerFactory(new Weld().initialize()));
addControllers(ControllerWithInterceptor.class);
}

}

}
Expand Down
47 changes: 33 additions & 14 deletions pippo-core/src/main/java/ro/pippo/core/AbstractTemplateEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public abstract class AbstractTemplateEngine implements TemplateEngine {
private String templatePathPrefix;

/**
* Performs common initialization for template engines
* Performs common initialization for template engines.
*
* Implementations must override this method to do their own template engine specific initialization. To
* use the convenience of this class, implementations must invoke this class's implementation before
* Implementations must override this method to do their own template engine specific initialization.
* To use the convenience of this class, implementations must invoke this class's implementation before
* performing their own initialization.
*
* @param application reference to the Pippo {@link Application} that can be used to retrieve settings
Expand Down Expand Up @@ -75,34 +75,46 @@ public void init(Application application) {
* @see TemplateEngine#setFileExtension(String)
*/
@Override
public final void setFileExtension(String extension) { this.fileExtension = extension; }
public final void setFileExtension(String extension) {
this.fileExtension = extension;
}

/**
* Returns the configured file extension for template resources
* Returns the configured file extension for template resources.
*
* @return String the configured file extension for template resources
*/
protected final String getFileExtension() { return fileExtension; }
protected final String getFileExtension() {
return fileExtension;
}

/**
* @see Application#getLanguages()
*/
protected final Languages getLanguages() { return languages; }
protected final Languages getLanguages() {
return languages;
}

/**
* @see Application#getMessages()
*/
protected final Messages getMessages() { return this.messages; }
protected final Messages getMessages() {
return this.messages;
}

/**
* @see Application#getPippoSettings()
*/
protected final PippoSettings getPippoSettings() { return pippoSettings; }
protected final PippoSettings getPippoSettings() {
return pippoSettings;
}

/**
* @see Languages#getLocaleOrDefault(String)
*/
protected final Locale getLocaleOrDefault(String language) { return languages.getLocaleOrDefault(language); }
protected final Locale getLocaleOrDefault(String language) {
return languages.getLocaleOrDefault(language);
}

/**
* @see Languages#getLocaleOrDefault(RouteContext)
Expand All @@ -114,7 +126,9 @@ protected final Locale getLocaleOrDefault(RouteContext routeContext) {
/**
* @see Languages#getLanguageOrDefault(String)
*/
protected final String getLanguageOrDefault(String language) { return languages.getLanguageOrDefault(language); }
protected final String getLanguageOrDefault(String language) {
return languages.getLanguageOrDefault(language);
}

/**
* @see Languages#getLanguageOrDefault(RouteContext)
Expand All @@ -126,12 +140,17 @@ protected final String getLanguageOrDefault(RouteContext routeContext) {
/**
* @see Application#getRouter()
*/
protected final Router getRouter() { return router; }
protected final Router getRouter() {
return router;
}

/**
* Returns the template path prefix to be used to load template resources
* Returns the template path prefix to be used to load template resources.
*
* @return String the template path prefix for loading template resources
*/
protected final String getTemplatePathPrefix() { return templatePathPrefix; }
protected final String getTemplatePathPrefix() {
return templatePathPrefix;
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright (C) 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ro.pippo.core;

import org.junit.After;
Expand All @@ -15,12 +30,18 @@
import java.util.Map;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class AbstractTemplateEngineTests {
public class AbstractTemplateEngineTest {

private static final String EXPECTED_LANGUAGE = "en_US";
private static final Locale EXPECTED_LOCALE = Locale.forLanguageTag(EXPECTED_LANGUAGE);
Expand Down Expand Up @@ -56,6 +77,12 @@ public void setupApplication() {
when(mockApplication.getRouter()).thenReturn(mockRouter);
}

@After
public void tearDown() {
reset(mockApplication);
reset(mockLanguages);
}

@Test
public void shouldGetLocaleOrDefaultForSpecifiedLanguageFromApplicationLanguages() {
when(mockLanguages.getLocaleOrDefault(EXPECTED_LANGUAGE)).thenReturn(EXPECTED_LOCALE);
Expand Down Expand Up @@ -208,12 +235,6 @@ public void shouldReturnTemplatePathPrefixConfiguredInSettings() {
.getString(eq(PippoConstants.SETTING_TEMPLATE_PATH_PREFIX), eq(TemplateEngine.DEFAULT_PATH_PREFIX));
}

@After
public void tearDown() {
reset(mockApplication);
reset(mockLanguages);
}

private static class TestTemplateEngine extends AbstractTemplateEngine {

@Override
Expand All @@ -223,17 +244,19 @@ public void init(Application application) {

@Override
public void renderString(String templateContent, Map<String, Object> model, Writer writer) {

// do nothing
}

@Override
public void renderResource(String templateName, Map<String, Object> model, Writer writer) {

// do nothing
}

@Override
protected String getDefaultFileExtension() {
return EXPECTED_DEFAULT_FILE_EXTENSION;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,23 @@
*/
package ro.pippo.freemarker;

import java.io.Writer;
import java.util.Locale;
import java.util.Map;

import org.kohsuke.MetaInfServices;
import ro.pippo.core.*;
import ro.pippo.core.route.Router;
import ro.pippo.core.util.StringUtils;
import freemarker.log.Logger;
import freemarker.template.Configuration;
import freemarker.template.SimpleScalar;
import freemarker.template.Template;
import org.kohsuke.MetaInfServices;
import ro.pippo.core.AbstractTemplateEngine;
import ro.pippo.core.Application;
import ro.pippo.core.PippoConstants;
import ro.pippo.core.PippoRuntimeException;
import ro.pippo.core.PippoSettings;
import ro.pippo.core.TemplateEngine;
import ro.pippo.core.route.Router;
import ro.pippo.core.util.StringUtils;

import java.io.Writer;
import java.util.Locale;
import java.util.Map;

/**
* @author Decebal Suiu
Expand Down Expand Up @@ -154,6 +159,12 @@ public void renderResource(String templateName, Map<String, Object> model, Write
}
}

/**
* Override this method if you want to modify the template configuration.
*
* @param application
* @param configuration
*/
protected void init(Application application, Configuration configuration) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@
import groovy.text.Template;
import groovy.text.markup.MarkupTemplateEngine;
import groovy.text.markup.TemplateConfiguration;

import java.io.IOException;
import java.io.Writer;
import java.util.Map;

import org.kohsuke.MetaInfServices;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ro.pippo.core.*;
import ro.pippo.core.AbstractTemplateEngine;
import ro.pippo.core.Application;
import ro.pippo.core.PippoConstants;
import ro.pippo.core.PippoRuntimeException;
import ro.pippo.core.PippoSettings;
import ro.pippo.core.TemplateEngine;
import ro.pippo.core.route.Router;
import ro.pippo.core.util.StringUtils;

import java.io.IOException;
import java.io.Writer;
import java.util.Map;

/**
* Groovy template engine for Pippo.
*
Expand Down Expand Up @@ -125,6 +128,12 @@ public void renderResource(String templateName, Map<String, Object> model, Write
}
}

/**
* Override this method if you want to modify the template configuration.
*
* @param application
* @param configuration
*/
protected void init(Application application, TemplateConfiguration configuration) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
import de.neuland.jade4j.template.ReaderTemplateLoader;
import de.neuland.jade4j.template.TemplateLoader;
import org.kohsuke.MetaInfServices;
import ro.pippo.core.*;
import ro.pippo.core.AbstractTemplateEngine;
import ro.pippo.core.Application;
import ro.pippo.core.PippoConstants;
import ro.pippo.core.PippoRuntimeException;
import ro.pippo.core.PippoSettings;
import ro.pippo.core.TemplateEngine;
import ro.pippo.core.route.Router;
import ro.pippo.core.util.StringUtils;

Expand Down Expand Up @@ -131,6 +136,12 @@ public void renderResource(String templateName, Map<String, Object> model, Write
}
}

/**
* Override this method if you want to modify the template configuration.
*
* @param application
* @param configuration
*/
protected void init(Application application, JadeConfiguration configuration) {
// NO OP
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
import org.kohsuke.MetaInfServices;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ro.pippo.core.*;
import ro.pippo.core.AbstractTemplateEngine;
import ro.pippo.core.Application;
import ro.pippo.core.PippoConstants;
import ro.pippo.core.PippoRuntimeException;
import ro.pippo.core.PippoSettings;
import ro.pippo.core.route.Router;
import ro.pippo.core.util.StringUtils;

Expand Down Expand Up @@ -91,6 +95,12 @@ public void init(Application application) {
engine = builder.build();
}

/**
* Override this method if you want to modify the template configuration.
*
* @param application
* @param configurationTarget
*/
protected void init(Application application, PebbleEngine.Builder configurationTarget) {
// NO OP
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
import org.trimou.handlebars.i18n.DateTimeFormatHelper;
import org.trimou.minify.Minify;
import org.trimou.prettytime.PrettyTimeHelper;
import ro.pippo.core.*;
import ro.pippo.core.AbstractTemplateEngine;
import ro.pippo.core.Application;
import ro.pippo.core.PippoConstants;
import ro.pippo.core.PippoRuntimeException;
import ro.pippo.core.PippoSettings;
import ro.pippo.core.TemplateEngine;
import ro.pippo.core.route.Router;
import ro.pippo.core.util.StringUtils;

Expand Down Expand Up @@ -176,6 +181,12 @@ public void renderResource(String templateName, Map<String, Object> model, Write
}
}

/**
* Override this method if you want to modify the template configuration.
*
* @param application
* @param builder
*/
protected void init(Application application, MustacheEngineBuilder builder) {
}

Expand Down

0 comments on commit d4230ea

Please sign in to comment.