package at.gv.egovernment.moa.id.auth.builder;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import at.gv.egovernment.moa.id.BuildException;
/**
* Builder for HTML form requesting the security layer implementation
* to get the identity link from smartcard by a <InfoboxReadRequest>
.
*
* @author Paul Ivancsics
* @version $Id$
*/
public class GetIdentityLinkFormBuilder extends Builder {
/** private static String NL contains the NewLine representation in Java*/
private static final String nl = "\n";
/** special tag in the HTML template to be substituted for the BKU URL */
private static final String BKU_TAG = "";
/** special tag in the HTML template to be substituted for the XML request */
private static final String XMLREQUEST_TAG = "";
/** special tag in the HTML template to be substituted for the data URL */
private static final String DATAURL_TAG = "";
/** special tag in the HTML template to be substituted for certificate info XML request */
private static final String CERTINFO_XMLREQUEST_TAG = "";
/** special tag in the HTML template to be substituted for the certificate info data URL */
private static final String CERTINFO_DATAURL_TAG = "";
/** special tag in the HTML template to be substituted for the infoboxes to be pushed from the BKU */
private static final String PUSHINFOBOX_TAG = "";
/** private static int all contains the representation to replace all tags*/
private static final int ALL = -1;
/** default HTML template */
private static final String DEFAULT_HTML_TEMPLATE =
"" + nl +
"" + nl +
"" + nl +
"Anmeldung mit Bürgerkarte" + nl +
"" + nl +
"" + nl +
"" + nl +
"" + nl +
"" + nl +
"";
/**
* Constructor for GetIdentityLinkFormBuilder.
*/
public GetIdentityLinkFormBuilder() {
super();
}
/**
* Builds the HTML form, including XML Request and data URL as parameters.
*
* @param htmlTemplate template to be used for the HTML form;
* may be null
, in this case a default layout will be produced
* @param xmlRequest XML Request to be sent as a parameter in the form
* @param bkuURL URL of the "Bürgerkartenumgebung" the form will be submitted to;
* may be null
, in this case the default URL will be used
* @param dataURL DataURL to be sent as a parameter in the form
*/
public String build(
String htmlTemplate,
String bkuURL,
String xmlRequest,
String dataURL,
String certInfoXMLRequest,
String certInfoDataURL,
String pushInfobox)
throws BuildException
{
String htmlForm = htmlTemplate == null ? DEFAULT_HTML_TEMPLATE : htmlTemplate;
// String bku = bkuURL == null ? DEFAULT_BKU : bkuURL;
htmlForm = replaceTag(htmlForm, BKU_TAG, bkuURL, true, ALL);
htmlForm = replaceTag(htmlForm, XMLREQUEST_TAG, encodeParameter(xmlRequest), true, ALL);
htmlForm = replaceTag(htmlForm, DATAURL_TAG, dataURL, true, ALL);
htmlForm = replaceTag(htmlForm, PUSHINFOBOX_TAG, pushInfobox, false, ALL);
//new:wird oben mitreplaced htmlForm = replaceTag(htmlForm, BKU_TAG, bkuURL);
htmlForm = replaceTag(htmlForm, CERTINFO_XMLREQUEST_TAG, encodeParameter(certInfoXMLRequest), true, ALL);
htmlForm = replaceTag(htmlForm, CERTINFO_DATAURL_TAG, certInfoDataURL, true, ALL);
return htmlForm;
}
/**
* Encodes a string for inclusion as a parameter in the form.
* Double quotes are substituted by """
.
* @param s the string to be encoded
* @return the string encoded
* @throws BuildException on any exception encountered
*/
public static String encodeParameter(String s) throws BuildException {
StringReader in = new StringReader(s);
StringWriter out = new StringWriter();
try {
for (int ch = in.read(); ch >= 0; ch = in.read()) {
if (ch == '"')
out.write(""");
else if (ch == '<')
out.write("<");
else if (ch == '>')
out.write(">");
else if (ch == 'ä')
out.write("ä");
else if (ch == 'ö')
out.write("ö");
else if (ch == 'ü')
out.write("ü");
else if (ch == 'Ä')
out.write("Ä");
else if (ch == 'Ö')
out.write("Ö");
else if (ch == 'Ü')
out.write("Ü");
else if (ch == 'ß')
out.write("ß");
else
out.write(ch);
}
}
catch (IOException ex) {
throw new BuildException("builder.00", new Object[] {"GetIdentityLinkForm", ex.toString()});
}
return out.toString();
}
}