From fc87e3c437f3ad18362194471303cd86592d89d5 Mon Sep 17 00:00:00 2001 From: "peter.danner" Date: Sun, 30 Oct 2005 08:37:18 +0000 Subject: prepared for SC-selection new git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@536 d688527b-c9ab-4aba-bd8d-4036d912da1d --- .../egovernment/moa/id/auth/builder/Builder.java | 33 ++++++++++++++++------ .../CertInfoVerifyXMLSignatureRequestBuilder.java | 5 ++-- 2 files changed, 27 insertions(+), 11 deletions(-) (limited to 'id.server/src/at/gv/egovernment') 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[] {"<" + tag.substring(1, tag.length() - 1) + ">"}); - 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[] {"<" + tag.substring(1, tag.length() - 1) + ">"}); + } 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) { -- cgit v1.2.3