-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
149 additions
and
329 deletions.
There are no files selected for viewing
85 changes: 0 additions & 85 deletions
85
src/main/java/io/github/alaugks/spring/messagesource/base/BaseTranslationMessageSource.java
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
src/main/java/io/github/alaugks/spring/messagesource/base/CatalogMessageSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package io.github.alaugks.spring.messagesource.base; | ||
|
||
import io.github.alaugks.spring.messagesource.base.catalog.CatalogInterface; | ||
import io.github.alaugks.spring.messagesource.base.records.TransUnitCatalog; | ||
import java.text.MessageFormat; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import org.springframework.context.support.AbstractMessageSource; | ||
import org.springframework.util.Assert; | ||
|
||
public class CatalogMessageSource extends AbstractMessageSource { | ||
|
||
public static final String DEFAULT_DOMAIN = "messages"; | ||
|
||
private final CatalogInterface catalog; | ||
|
||
private CatalogMessageSource(CatalogInterface catalog) { | ||
this.catalog = catalog; | ||
} | ||
|
||
public static Builder builder(CatalogInterface catalog) { | ||
return new Builder(catalog); | ||
} | ||
|
||
public static final class Builder { | ||
|
||
private CatalogInterface catalog; | ||
private CatalogInterface catalogCache; | ||
|
||
public Builder(CatalogInterface catalog) { | ||
Assert.notNull(catalog, "Argument catalog must not be null"); | ||
this.catalog = catalog; | ||
} | ||
|
||
public Builder catalogCache(CatalogInterface cacheCatalog) { | ||
Assert.notNull(cacheCatalog, "Argument cacheCatalog must not be null"); | ||
this.catalogCache = cacheCatalog; | ||
return this; | ||
} | ||
|
||
public CatalogMessageSource build() { | ||
if (catalogCache != null) { | ||
this.catalog = catalogCache.nextHandler(this.catalog); | ||
} | ||
|
||
catalog.build(); | ||
return new CatalogMessageSource(this.catalog); | ||
} | ||
} | ||
|
||
public List<TransUnitCatalog> getAll() { | ||
return this.catalog.getAll(); | ||
} | ||
|
||
public String get(Locale locale, String code) { | ||
return this.catalog.resolve(locale, code); | ||
} | ||
|
||
@Override | ||
protected MessageFormat resolveCode(String code, Locale locale) { | ||
try { | ||
return new MessageFormat(this.get(locale, code), locale); | ||
} catch (Exception e) { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 0 additions & 75 deletions
75
src/main/java/io/github/alaugks/spring/messagesource/base/catalog/CatalogHandler.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...ain/java/io/github/alaugks/spring/messagesource/base/catalog/CatalogHandlerInterface.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.