aboutsummaryrefslogtreecommitdiff
path: root/id.server/src/at/gv/egovernment/moa/id
diff options
context:
space:
mode:
Diffstat (limited to 'id.server/src/at/gv/egovernment/moa/id')
-rw-r--r--id.server/src/at/gv/egovernment/moa/id/auth/builder/Builder.java33
-rw-r--r--id.server/src/at/gv/egovernment/moa/id/auth/builder/CertInfoVerifyXMLSignatureRequestBuilder.java5
2 files changed, 27 insertions, 11 deletions
diff --git a/id.server/src/at/gv/egovernment/moa/id/auth/builder/Builder.java b/id.server/src/at/gv/egovernment/moa/id/auth/builder/Builder.java
index 29e0badc7..a5d87ef83 100644
--- a/id.server/src/at/gv/egovernment/moa/id/auth/builder/Builder.java
+++ b/id.server/src/at/gv/egovernment/moa/id/auth/builder/Builder.java
@@ -12,21 +12,36 @@ import at.gv.egovernment.moa.util.StringUtils;
public class Builder {
/**
- * Replaces oll occurrences of a special tag in an XML or HTML template by a value.
+ * Replaces a given number of occurences of a special tag in an XML or HTML template by a value.
* @param htmlTemplate template
* @param tag special tag
* @param value value replacing the tag
+ * @param maxreplacements: -1 to replace each occurence of tag, or limit replacements by a given positive number
* @return XML or HTML code, the tag replaced
* @throws BuildException when template does not contain the tag
*/
- protected String replaceTag(String template, String tag, String value) throws BuildException {
- int index = template.indexOf(tag);
- if (index < 0)
- throw new BuildException(
- "builder.01",
- new Object[] {"&lt;" + tag.substring(1, tag.length() - 1) + "&gt;"});
- return StringUtils.replaceAll(template, tag, value);
-// return template.substring(0, index) + value + template.substring(index + tag.length());
+ protected String replaceTag(String template, String tag, String value, int maxreplacements) throws BuildException {
+ String result = template;
+ int index = result.indexOf(tag);
+ if (index < 0) {
+ // Substring not found but should
+ throw new BuildException(
+ "builder.01",
+ new Object[] {"&lt;" + tag.substring(1, tag.length() - 1) + "&gt;"});
+ } else {
+ // replace each occurence
+ if (maxreplacements == -1) {
+ return StringUtils.replaceAll(template, tag, value);
+ } else {
+ int found = 1;
+ while (index > -1 && (found <= maxreplacements)) {
+ result = result.substring(0, index) + value + result.substring(index + tag.length());
+ index = result.indexOf(tag);
+ if (index > -1) found += 1;
+ }
+ }
+ }
+ return result;
}
}
diff --git a/id.server/src/at/gv/egovernment/moa/id/auth/builder/CertInfoVerifyXMLSignatureRequestBuilder.java b/id.server/src/at/gv/egovernment/moa/id/auth/builder/CertInfoVerifyXMLSignatureRequestBuilder.java
index 5150001ca..03895a38e 100644
--- a/id.server/src/at/gv/egovernment/moa/id/auth/builder/CertInfoVerifyXMLSignatureRequestBuilder.java
+++ b/id.server/src/at/gv/egovernment/moa/id/auth/builder/CertInfoVerifyXMLSignatureRequestBuilder.java
@@ -21,7 +21,8 @@ public class CertInfoVerifyXMLSignatureRequestBuilder extends Builder implements
/** private static String nl contains the NewLine representation in Java*/
private static final String nl = "\n";
- /**
+
+ /**
* XML template for the CertInfoVerifyXMLSignatureRequest to be built
*/
static final String CERTINFO_REQUEST =
@@ -72,7 +73,7 @@ public class CertInfoVerifyXMLSignatureRequestBuilder extends Builder implements
try {
String dsigSignature = FileUtils.readResource(resDsigSignature, "UTF-8");
- certInfoRequest = replaceTag(certInfoRequest, SIGNATURE_TAG, dsigSignature);
+ certInfoRequest = replaceTag(certInfoRequest, SIGNATURE_TAG, dsigSignature, 1);
return certInfoRequest;
}
catch (IOException ex) {