01: /*
02: * ReportTableGrants.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.db.report;
13:
14: import java.util.Collection;
15: import java.util.Collections;
16: import workbench.db.TableGrant;
17: import workbench.db.TableIdentifier;
18: import workbench.db.WbConnection;
19: import workbench.util.StrBuffer;
20:
21: /**
22: * Generate XML report information about table grants.
23: *
24: * @see workbench.db.DbMetadata#getTableGrants(workbench.db.TableIdentifier)
25: * @author support@sql-workbench.net
26: */
27: public class ReportTableGrants {
28: public static final String TAG_GRANT = "grant";
29: public static final String TAG_GRANT_GRANTEE = "grantee";
30: public static final String TAG_GRANT_PRIV = "privilege";
31: public static final String TAG_GRANT_GRANTABLE = "grantable";
32: private Collection<TableGrant> grants;
33: private String namespace;
34:
35: public ReportTableGrants(WbConnection con, TableIdentifier tbl) {
36: grants = con.getMetadata().getTableGrants(tbl);
37: }
38:
39: public ReportTableGrants(Collection<TableGrant> tableGrants) {
40: this .grants = tableGrants;
41: }
42:
43: public void appendXml(StrBuffer result, StrBuffer indent) {
44: if (grants.size() == 0)
45: return;
46:
47: TagWriter tagWriter = new TagWriter();
48: tagWriter.setNamespace(this .namespace);
49:
50: StrBuffer indent1 = new StrBuffer(indent);
51: indent1.append(" ");
52:
53: for (TableGrant grant : grants) {
54: tagWriter.appendOpenTag(result, indent, TAG_GRANT);
55: result.append('\n');
56: tagWriter.appendTag(result, indent1, TAG_GRANT_PRIV, grant
57: .getPrivilege());
58: tagWriter.appendTag(result, indent1, TAG_GRANT_GRANTEE,
59: grant.getGrantee());
60: tagWriter.appendTag(result, indent1, TAG_GRANT_GRANTABLE,
61: grant.isGrantable());
62: tagWriter.appendCloseTag(result, indent, TAG_GRANT);
63: }
64:
65: return;
66: }
67:
68: public Collection<TableGrant> getGrants() {
69: return Collections.unmodifiableCollection(grants);
70: }
71:
72: public void setNamespace(String namespace) {
73: this.namespace = namespace;
74: }
75: }
|