diff options
author | Alexander Marsalek <amarsalek@iaik.tugraz.at> | 2021-04-10 15:07:10 +0200 |
---|---|---|
committer | Alexander Marsalek <amarsalek@iaik.tugraz.at> | 2021-04-10 15:07:10 +0200 |
commit | 0bc55a19b8c7b2aa53c74fee08f6bf97017ef586 (patch) | |
tree | a12d2f6c74e6fc4eb2381aaade9eab10e2bf8e44 /pdf-as-lib/src | |
parent | 0af9cdc6ddaa103fecb928f1d2c1bc030534d590 (diff) | |
download | pdf-as-4-0bc55a19b8c7b2aa53c74fee08f6bf97017ef586.tar.gz pdf-as-4-0bc55a19b8c7b2aa53c74fee08f6bf97017ef586.tar.bz2 pdf-as-4-0bc55a19b8c7b2aa53c74fee08f6bf97017ef586.zip |
extend valueresolver
Diffstat (limited to 'pdf-as-lib/src')
3 files changed, 45 insertions, 18 deletions
diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/RequestParameterResolver.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/RequestParameterResolver.java index 1d8d4638..4b2a8f10 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/RequestParameterResolver.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/RequestParameterResolver.java @@ -16,15 +16,22 @@ public class RequestParameterResolver implements IResolver { private OgnlContext ctx; public RequestParameterResolver(Map<String, String> requestParameters) { + +// this.ctx = new OgnlContext(memberAccess, null, null, requestParameters); MemberAccess memberAccess = new AbstractMemberAccess() { - @Override - public boolean isAccessible(Map context, Object target, Member member, String propertyName) { - int modifiers = member.getModifiers(); - return Modifier.isPublic(modifiers); - } - }; - - this.ctx = new OgnlContext(memberAccess, null, null, requestParameters); + @Override + public boolean isAccessible(Map context, Object target, Member member, String propertyName) { + int modifiers = member.getModifiers(); + return Modifier.isPublic(modifiers); + } + }; + + this.ctx = new OgnlContext(null, null, memberAccess); + this.ctx.put("dynamic", requestParameters); +// for(String key : requestParameters.keySet()) { +// this.ctx.put(key, requestParameters.get(key)); +// } + } @Override diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/ValueResolver.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/ValueResolver.java index c6cddc9e..e5905c22 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/ValueResolver.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/stamping/ValueResolver.java @@ -35,7 +35,6 @@ import org.slf4j.LoggerFactory; import java.nio.charset.Charset; import java.text.SimpleDateFormat; import java.util.Calendar; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.TimeZone; @@ -61,19 +60,27 @@ public class ValueResolver implements IProfileConstants, IResolver { private static final Charset UTF_8 = Charset.forName("UTF-8"); - private IResolver internalResolver; - + private IResolver internalCertificateResolver; + private IResolver internalRequestParameterResolver; public ValueResolver(ICertificateProvider certProvider, OperationStatus operationStatus) { - internalResolver = new CertificateResolver( + internalCertificateResolver = new CertificateResolver( certProvider.getCertificate(), operationStatus); + Map<String, String> test = new HashMap<>(); + test.put("schoolNameRand", RandomStringUtils.randomAlphabetic(5)); + test.put("schoolName", "EGIZ testschule"); + + test.put("subject","bbbbb"); + internalRequestParameterResolver = new RequestParameterResolver(test); } public ValueResolver(OperationStatus operationStatus) { Map<String, String> test = new HashMap<>(); test.put("schoolNameRand", RandomStringUtils.randomAlphabetic(5)); - test.put("schoolName", "EGIZ testschule"); - internalResolver = new RequestParameterResolver(test); - + test.put("schoolName", "EGIZ testschule"); + + test.put("subject","bbbbb"); + internalRequestParameterResolver = new RequestParameterResolver(test); + } public String resolve(String key, String value, @@ -115,10 +122,17 @@ public class ValueResolver implements IProfileConstants, IResolver { do { int idx = matcher.start(0); int idxe = matcher.end(0); - result += value.substring(curidx, idx); + String tmp1 = value.substring(curidx, idx); + result += tmp1; curidx = idxe; - result += internalResolver.resolve(key, - matcher.group(1), settings); + String tmpValue = matcher.group(1); + if(!tmpValue.contains("dynamic")) { + String tmp = internalCertificateResolver.resolve(key, tmpValue, settings); + result += tmp; + }else { + String tmp2 = internalRequestParameterResolver.resolve(key, tmpValue, settings); + result += tmp2; + } } while (matcher.find()); } else { result = value; diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java index ecdddfa1..08dcd249 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/impl/status/OperationStatus.java @@ -56,6 +56,8 @@ public class OperationStatus implements Serializable { private PDFASBackend backend; private Map<String, String> metaInformations = new HashMap<String, String>(); + private HashMap<String, String> requestParameters = new HashMap<String, String>(); + public OperationStatus(ISettings configuration, SignParameter signParameter, PDFASBackend backend) { this.configuration = configuration; this.signParamter = signParameter; @@ -174,4 +176,8 @@ public class OperationStatus implements Serializable { public Map<String, String> getMetaInformations() { return metaInformations; } + + public HashMap<String, String> getRequestParameters() { + return requestParameters; + } } |