提交 124e84c8 编写于 作者: O o2sword

多语言国际化3

上级 b9f11aad
exception_accessDenied=\u7528\u6237:{} \u6743\u9650\u4E0D\u8DB3.
exception_accessDenied_1=\u7528\u6237:{} \u8BBF\u95EE\u5BF9\u8C61 class:{}, id:{}, \u6743\u9650\u4E0D\u8DB3.
exception_accessDeniedOrEntityNotExist=\u7528\u6237:{} \u6743\u9650\u4E0D\u8DB3\u6216\u8005\u5BF9\u8C61\u4E0D\u5B58\u5728.
exception_accessDeniedOrEntityNotExist_1=\u7528\u6237:{} \u6743\u9650\u4E0D\u8DB3\u6216\u8005\u5BF9\u8C61\u4E0D\u5B58\u5728, {}.
exception_entityNotExist=\u6807\u8BC6\u4E3A:{} \u7684 {} \u5BF9\u8C61\u4E0D\u5B58\u5728.
exception_entityNotExist_1=\u6807\u8BC6\u4E3A:{} \u7684\u5BF9\u8C61\u4E0D\u5B58\u5728.
exception_entityNotExist_2=\u7C7B\u578B\u4E3A: {} \u7684\u5BF9\u8C61\u4E0D\u5B58\u5728.
com.x.base.core.project.exception.ExceptionAccessDenied=\u7528\u6237:{} \u6743\u9650\u4E0D\u8DB3.
com.x.base.core.project.exception.ExceptionAccessDenied_1=\u7528\u6237:{} \u8BBF\u95EE\u5BF9\u8C61 class:{}, id:{}, \u6743\u9650\u4E0D\u8DB3.
com.x.base.core.project.exception.ExceptionAccessDeniedOrEntityNotExist=\u7528\u6237:{} \u6743\u9650\u4E0D\u8DB3\u6216\u8005\u5BF9\u8C61\u4E0D\u5B58\u5728.
com.x.base.core.project.exception.ExceptionAccessDeniedOrEntityNotExist_1=\u7528\u6237:{} \u6743\u9650\u4E0D\u8DB3\u6216\u8005\u5BF9\u8C61\u4E0D\u5B58\u5728, {}.
com.x.base.core.project.exception.ExceptionEntityNotExist=\u6807\u8BC6\u4E3A:{} \u7684 {} \u5BF9\u8C61\u4E0D\u5B58\u5728.
com.x.base.core.project.exception.ExceptionEntityNotExist_1=\u6807\u8BC6\u4E3A:{} \u7684\u5BF9\u8C61\u4E0D\u5B58\u5728.
com.x.base.core.project.exception.ExceptionEntityNotExist_2=\u7C7B\u578B\u4E3A: {} \u7684\u5BF9\u8C61\u4E0D\u5B58\u5728.
exception_accessDenied=User :{} Insufficient permissions.
exception_accessDenied_1=User :{} access object class:{}, id:{}, insufficient permission.
exception_accessDeniedOrEntityNotExist=User :{} Insufficient permissions or the object does not exist.
exception_accessDeniedOrEntityNotExist_1=User :{} Insufficient permission or object does not exist, {}.
exception_entityNotExist=The {2} object identified as :{1} does not exist.
exception_entityNotExist_1=The object identified as :{} does not exist.
exception_entityNotExist_2=Object of type: {} does not exist.
com.x.base.core.project.exception.ExceptionAccessDenied=User :{} Insufficient permissions.
com.x.base.core.project.exception.ExceptionAccessDenied_1=User :{} access object class:{}, id:{}, insufficient permission.
com.x.base.core.project.exception.ExceptionAccessDeniedOrEntityNotExist=User :{} Insufficient permissions or the object does not exist.
com.x.base.core.project.exception.ExceptionAccessDeniedOrEntityNotExist_1=User :{} Insufficient permission or object does not exist, {}.
com.x.base.core.project.exception.ExceptionEntityNotExist=The {2} object identified as :{1} does not exist.
com.x.base.core.project.exception.ExceptionEntityNotExist_1=The object identified as :{} does not exist.
com.x.base.core.project.exception.ExceptionEntityNotExist_2=Object of type: {} does not exist.
exception_accessDenied=\u7528\u6237:{} \u6743\u9650\u4E0D\u8DB3.
exception_accessDenied_1=\u7528\u6237:{} \u8BBF\u95EE\u5BF9\u8C61 class:{}, id:{}, \u6743\u9650\u4E0D\u8DB3.
exception_accessDeniedOrEntityNotExist=\u7528\u6237:{} \u6743\u9650\u4E0D\u8DB3\u6216\u8005\u5BF9\u8C61\u4E0D\u5B58\u5728.
exception_accessDeniedOrEntityNotExist_1=\u7528\u6237:{} \u6743\u9650\u4E0D\u8DB3\u6216\u8005\u5BF9\u8C61\u4E0D\u5B58\u5728, {}.
exception_entityNotExist=\u6807\u8BC6\u4E3A:{} \u7684 {} \u5BF9\u8C61\u4E0D\u5B58\u5728.
exception_entityNotExist_1=\u6807\u8BC6\u4E3A:{} \u7684\u5BF9\u8C61\u4E0D\u5B58\u5728.
exception_entityNotExist_2=\u7C7B\u578B\u4E3A: {} \u7684\u5BF9\u8C61\u4E0D\u5B58\u5728.
com.x.base.core.project.exception.ExceptionAccessDenied=\u7528\u6237:{} \u6743\u9650\u4E0D\u8DB3.
com.x.base.core.project.exception.ExceptionAccessDenied_1=\u7528\u6237:{} \u8BBF\u95EE\u5BF9\u8C61 class:{}, id:{}, \u6743\u9650\u4E0D\u8DB3.
com.x.base.core.project.exception.ExceptionAccessDeniedOrEntityNotExist=\u7528\u6237:{} \u6743\u9650\u4E0D\u8DB3\u6216\u8005\u5BF9\u8C61\u4E0D\u5B58\u5728.
com.x.base.core.project.exception.ExceptionAccessDeniedOrEntityNotExist_1=\u7528\u6237:{} \u6743\u9650\u4E0D\u8DB3\u6216\u8005\u5BF9\u8C61\u4E0D\u5B58\u5728, {}.
com.x.base.core.project.exception.ExceptionEntityNotExist=\u6807\u8BC6\u4E3A:{} \u7684 {} \u5BF9\u8C61\u4E0D\u5B58\u5728.
com.x.base.core.project.exception.ExceptionEntityNotExist_1=\u6807\u8BC6\u4E3A:{} \u7684\u5BF9\u8C61\u4E0D\u5B58\u5728.
com.x.base.core.project.exception.ExceptionEntityNotExist_2=\u7C7B\u578B\u4E3A: {} \u7684\u5BF9\u8C61\u4E0D\u5B58\u5728.
exception_accessDenied=\u7528\u6236:{} \u6B0A\u9650\u4E0D\u8DB3.
exception_accessDenied_1=\u7528\u6236:{} \u8A2A\u554F\u5C0D\u8C61 class:{}, id:{}, \u6B0A\u9650\u4E0D\u8DB3.
exception_accessDeniedOrEntityNotExist=\u7528\u6236:{} \u6B0A\u9650\u4E0D\u8DB3\u6216\u8005\u5C0D\u8C61\u4E0D\u5B58\u5728.
exception_accessDeniedOrEntityNotExist_1=\u7528\u6236:{} \u6B0A\u9650\u4E0D\u8DB3\u6216\u8005\u5C0D\u8C61\u4E0D\u5B58\u5728, {}.
exception_entityNotExist=\u6A19\u8B58\u70BA:{} \u7684 {} \u5C0D\u8C61\u4E0D\u5B58\u5728.
exception_entityNotExist_1=\u6A19\u8B58\u70BA:{} \u7684\u5C0D\u8C61\u4E0D\u5B58\u5728.
exception_entityNotExist_2=\u985E\u578B\u70BA: {} \u7684\u5C0D\u8C61\u4E0D\u5B58\u5728.
......@@ -6,25 +6,29 @@ import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.LanguageTools;
public class ExceptionAccessDenied extends PromptException {
public class ExceptionAccessDenied extends LanguagePromptException {
private static final long serialVersionUID = -7354813827434276962L;
public static String defaultMessage = "用户:{} 权限不足.";
public ExceptionAccessDenied(String person) {
super(LanguageTools.getValue("exception_accessDenied"), person);
super(defaultMessage, person);
}
public ExceptionAccessDenied(EffectivePerson effectivePerson) {
super(LanguageTools.getValue("exception_accessDenied"), effectivePerson.getDistinguishedName());
super(defaultMessage, effectivePerson.getDistinguishedName());
this.setLanguageKey(this.getClass().getName());
}
public ExceptionAccessDenied(EffectivePerson effectivePerson, JpaObject jpa) {
super(LanguageTools.getValue("exception_accessDenied_1"), effectivePerson.getDistinguishedName(),
super("用户:{} 访问对象 class:{}, id:{}, 权限不足.", effectivePerson.getDistinguishedName(),
(null == jpa) ? null : jpa.getClass().getName(), (null == jpa) ? null : jpa.getId());
this.setLanguageKey(this.getClass().getName()+"_1");
}
public ExceptionAccessDenied(EffectivePerson effectivePerson, String message) {
super(LanguageTools.getValue("exception_accessDenied"), effectivePerson.getDistinguishedName(), Objects.toString(message, ""));
super(defaultMessage, effectivePerson.getDistinguishedName(), Objects.toString(message, ""));
}
}
......@@ -5,20 +5,23 @@ import java.util.Objects;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.LanguageTools;
public class ExceptionAccessDeniedOrEntityNotExist extends PromptException {
public class ExceptionAccessDeniedOrEntityNotExist extends LanguagePromptException {
private static final long serialVersionUID = -7354813827434276962L;
public static String defaultMessage = "用户:{} 权限不足或者对象不存在.";
public ExceptionAccessDeniedOrEntityNotExist(String person) {
super(LanguageTools.getValue("exception_accessDeniedOrEntityNotExist"), person);
super(defaultMessage, person);
}
public ExceptionAccessDeniedOrEntityNotExist(EffectivePerson effectivePerson) {
super(LanguageTools.getValue("exception_accessDeniedOrEntityNotExist"), effectivePerson.getDistinguishedName());
super(defaultMessage, effectivePerson.getDistinguishedName());
}
public ExceptionAccessDeniedOrEntityNotExist(EffectivePerson effectivePerson, String message) {
super(LanguageTools.getValue("exception_accessDeniedOrEntityNotExist_1"), effectivePerson.getDistinguishedName(), Objects.toString(message, ""));
super("用户:{} 权限不足或者对象不存在, {}.", effectivePerson.getDistinguishedName(), Objects.toString(message, ""));
this.setLanguageKey(this.getClass().getName()+"_1");
}
}
......@@ -7,33 +7,37 @@ import org.apache.commons.lang3.StringUtils;
import com.x.base.core.entity.JpaObject;
public class ExceptionEntityNotExist extends PromptException {
public class ExceptionEntityNotExist extends LanguagePromptException {
private static final long serialVersionUID = -7354813827434276962L;
public static String defaultMessage = "标识为:{} 的 {} 对象不存在.";
public ExceptionEntityNotExist(String flag, JpaObject jpa) {
super(LanguageTools.getValue("exception_entityNotExist"), flag, (null == jpa) ? null : jpa.nameOfEntity());
super(defaultMessage, flag, (null == jpa) ? null : jpa.nameOfEntity());
}
public <T extends JpaObject> ExceptionEntityNotExist(String flag, Class<T> cls) {
super(LanguageTools.getValue("exception_entityNotExist"), flag, (null == cls) ? null : cls.getSimpleName());
super(defaultMessage, flag, (null == cls) ? null : cls.getSimpleName());
}
public <T extends JpaObject> ExceptionEntityNotExist(List<String> ids, Class<T> cls) {
super(LanguageTools.getValue("exception_entityNotExist"), (null == ids) ? null : StringUtils.join(ids, ","),
super(defaultMessage, (null == ids) ? null : StringUtils.join(ids, ","),
(null == cls) ? null : cls.getSimpleName());
}
public <T extends JpaObject> ExceptionEntityNotExist(String flag, String name) {
super(LanguageTools.getValue("exception_entityNotExist"), flag, name);
super(defaultMessage, flag, name);
}
public <T extends JpaObject> ExceptionEntityNotExist(String flag) {
super(LanguageTools.getValue("exception_entityNotExist_1"), flag);
super("标识为:{} 的对象不存在.", flag);
this.setLanguageKey(this.getClass().getName()+"_1");
}
public <T extends JpaObject> ExceptionEntityNotExist(Class<T> cls) {
super(LanguageTools.getValue("exception_entityNotExist_2"), cls.getSimpleName());
super("类型为: {} 的对象不存在.", cls.getSimpleName());
this.setLanguageKey(this.getClass().getName()+"_2");
}
}
package com.x.base.core.project.exception;
import com.x.base.core.project.logger.MessageFormatter;
import com.x.base.core.project.tools.LanguageTools;
import org.apache.commons.lang3.StringUtils;
public abstract class LanguagePromptException extends PromptException {
private static final long serialVersionUID = -1212029031489695352L;
private Object[] argArray = null;
private String languageKey = null;
public LanguagePromptException() {
super();
}
public LanguagePromptException(String message) {
super(message);
}
public LanguagePromptException(String message, Object... os) {
super(format(message, os));
this.argArray = os;
}
public LanguagePromptException(Throwable cause) {
super(cause);
}
public LanguagePromptException(Throwable cause, String message) {
super(message, cause);
}
public LanguagePromptException(Throwable cause, String message, Object... os) {
super(format(message, os), cause);
this.argArray = os;
}
public String getFormatMessage(String key, String language){
if(StringUtils.isNotBlank(language)){
language = StringUtils.split(language, ",")[0].trim();
}
if(StringUtils.isNotBlank(this.languageKey)){
key = this.languageKey;
}
String languageString = LanguageTools.getValue(key, language);
if(this.argArray!=null && StringUtils.isNotBlank(languageString)){
languageString = MessageFormatter.arrayFormat(languageString, this.argArray).getMessage();
}
return languageString;
}
public String getLanguageKey() {
return languageKey;
}
public void setLanguageKey(String languageKey) {
this.languageKey = languageKey;
}
}
......@@ -9,6 +9,7 @@ import javax.ws.rs.core.CacheControl;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.Response;
import com.x.base.core.project.exception.LanguagePromptException;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jetty.http.HttpHeader;
......@@ -26,6 +27,8 @@ public class ResponseFactory {
public static final String Accept_Ranges = "Accept-Ranges";
public static final String Content_Type = "Content-Type";
public static final String Content_Length = "Content-Length";
public static final String Accept_Language = "Accept-Language";
public static <T> Response getDefaultActionResultResponse(ActionResult<T> result) {
if (result.getType().equals(ActionResult.Type.error)) {
......@@ -73,6 +76,10 @@ public class ResponseFactory {
public static <T> Response getEntityTagActionResultResponse(HttpServletRequest request, ActionResult<T> result) {
if (result.getType().equals(ActionResult.Type.error)) {
if ((result.throwable instanceof LanguagePromptException)) {
LanguagePromptException e = (LanguagePromptException)result.throwable;
result.setMessage((e.getFormatMessage(result.getPrompt(), request.getHeader(Accept_Language))));
}
if ((result.throwable instanceof CallbackPromptException)) {
return Response.ok(callbackError(result)).build();
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册