Skip to content

Commit

Permalink
Fix ContentTypeEngine initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
gitblit committed May 22, 2015
1 parent cbb8863 commit a3d22ac
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### [Unreleased][unreleased] ### [Unreleased][unreleased]


#### Fixed #### Fixed
- ContentTypeEngines were not properly initialized during the discovery/registration process

#### Changed #### Changed
#### Added #### Added
#### Removed #### Removed
Expand Down
11 changes: 4 additions & 7 deletions pippo-core/src/main/java/ro/pippo/core/Application.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -191,19 +191,16 @@ public boolean hasContentTypeEngine(String contentType) {
} }


public void registerContentTypeEngine(Class<? extends ContentTypeEngine> engineClass) { public void registerContentTypeEngine(Class<? extends ContentTypeEngine> engineClass) {
engines.registerContentTypeEngine(engineClass); ContentTypeEngine engine = engines.registerContentTypeEngine(engineClass);
if (engine != null) {
engine.init(this);
}
} }


public ContentTypeEngine getContentTypeEngine(String contentType) { public ContentTypeEngine getContentTypeEngine(String contentType) {
return engines.getContentTypeEngine(contentType); return engines.getContentTypeEngine(contentType);
} }


public void setContentTypeEngine(ContentTypeEngine engine) {
engine.init(this);

engines.setContentTypeEngine(engine);
}

public Router getRouter() { public Router getRouter() {
if (router == null) { if (router == null) {
router = new DefaultRouter(); router = new DefaultRouter();
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ public List<String> getContentTypes() {
* for the content type. * for the content type.
* *
* @param engineClass * @param engineClass
* @return the engine instance, if it is registered
*/ */
public void registerContentTypeEngine(Class<? extends ContentTypeEngine> engineClass) { public ContentTypeEngine registerContentTypeEngine(Class<? extends ContentTypeEngine> engineClass) {
ContentTypeEngine engine = null; ContentTypeEngine engine = null;
try { try {
engine = engineClass.newInstance(); engine = engineClass.newInstance();
Expand All @@ -83,9 +84,11 @@ public void registerContentTypeEngine(Class<? extends ContentTypeEngine> engineC
} }
if (!engines.containsKey(engine.getContentType())) { if (!engines.containsKey(engine.getContentType())) {
setContentTypeEngine(engine); setContentTypeEngine(engine);
return engine;
} else { } else {
log.debug("'{}' content engine already registered, ignoring '{}'", engine.getContentType(), log.debug("'{}' content engine already registered, ignoring '{}'", engine.getContentType(),
engineClass.getName()); engineClass.getName());
return null;
} }
} }


Expand Down

0 comments on commit a3d22ac

Please sign in to comment.