01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.xml.export;
19:
20: import java.io.IOException;
21: import java.io.Writer;
22: import java.util.Collection;
23: import java.util.Iterator;
24:
25: import de.finix.contelligent.core.security.Role;
26: import de.finix.contelligent.xml.DTDCatalog;
27:
28: public class DefaultPrincipalDataXMLPolicy implements
29: PrincipalDataXMLPolicy {
30:
31: public void writeXMLHeader(Writer writer, String groupId)
32: throws IOException {
33: DTDCatalog dtdCatalog = DTDCatalog.getInstance();
34: StringBuffer output = new StringBuffer(160);
35: output
36: .append(
37: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE ")
38: .append(DTDCatalog.PRINCIPAL_DATA)
39: .append(" PUBLIC \"")
40: .append(
41: dtdCatalog
42: .getPublicId(DTDCatalog.PRINCIPAL_DATA))
43: .append("\" \"")
44: .append(DTDCatalog.PUBLICID_URLPREFIX)
45: .append(
46: dtdCatalog
47: .getFileName(DTDCatalog.PRINCIPAL_DATA))
48: .append("\">\n\n").append("<").append(
49: DTDCatalog.PRINCIPAL_DATA).append(">\n");
50: writer.write(output.toString());
51: }
52:
53: public void writeXMLFooter(Writer writer) throws IOException {
54: writer.write("</" + DTDCatalog.PRINCIPAL_DATA + ">");
55: }
56:
57: public void writeUser(String userId, String alias,
58: String displayName, String password, Collection roles,
59: Writer writer) throws IOException {
60: writer.write("\t<user name=\"");
61: writer.write(userId);
62: writer.write("\" displayName=\"");
63: writer.write(displayName);
64: if (password != null) {
65: writer.write("\" password=\"");
66: writer.write(password);
67: }
68: if (alias != null) {
69: writer.write("\" alias=\"");
70: writer.write(alias);
71: }
72: writer.write("\">\n");
73: Iterator iterator = roles.iterator();
74:
75: while (iterator.hasNext()) {
76: Role role = (Role) iterator.next();
77: writer.write("\t\t<hasRole name=\"");
78: writer.write(role.getName());
79: writer.write("\" group=\"");
80: writer.write(role.getGroupId());
81: writer.write("\"/>\n");
82: }
83: writer.write("\t</user>\n");
84: }
85:
86: public void writeRole(String roleId, String displayName,
87: Writer writer) throws IOException {
88: writer.write("\t<role name=\"");
89: writer.write(roleId);
90: writer.write("\" displayName=\"");
91: writer.write(displayName);
92: writer.write("\"/>\n");
93: }
94: }
|