aboutsummaryrefslogtreecommitdiff
path: root/id.server/src/at/gv
diff options
context:
space:
mode:
authorpeter.danner <peter.danner@d688527b-c9ab-4aba-bd8d-4036d912da1d>2005-10-30 08:37:18 +0000
committerpeter.danner <peter.danner@d688527b-c9ab-4aba-bd8d-4036d912da1d>2005-10-30 08:37:18 +0000
commitfc87e3c437f3ad18362194471303cd86592d89d5 (patch)
tree0c6d651bd36ca8cced94309ecf039a785ad5ae4f /id.server/src/at/gv
parent79be95cea5fea6f101a3f90a03ec3e3bc7fd4894 (diff)
downloadmoa-id-spss-fc87e3c437f3ad18362194471303cd86592d89d5.tar.gz
moa-id-spss-fc87e3c437f3ad18362194471303cd86592d89d5.tar.bz2
moa-id-spss-fc87e3c437f3ad18362194471303cd86592d89d5.zip
prepared for SC-selection new
git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@536 d688527b-c9ab-4aba-bd8d-4036d912da1d
Diffstat (limited to 'id.server/src/at/gv')
-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) {