01: /*
02: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
03: * This software was developed by Pentaho Corporation and is provided under the terms
04: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
05: * this file except in compliance with the license. If you need a copy of the license,
06: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
07: *
08: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
09: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
10: * the license for the specific language governing your rights and limitations.
11: *
12: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
13: */
14: package org.pentaho.reportdesigner.crm.report.configuration;
15:
16: import org.gjt.xpp.XmlPullNode;
17: import org.jetbrains.annotations.NotNull;
18: import org.pentaho.reportdesigner.lib.common.xml.XMLConstants;
19: import org.pentaho.reportdesigner.lib.common.xml.XMLContext;
20: import org.pentaho.reportdesigner.lib.common.xml.XMLExternalizable;
21: import org.pentaho.reportdesigner.lib.common.xml.XMLUtils;
22: import org.pentaho.reportdesigner.lib.common.xml.XMLWriter;
23:
24: import java.io.IOException;
25: import java.util.HashMap;
26: import java.util.Set;
27:
28: /**
29: * User: Martin
30: * Date: 17.03.2007
31: * Time: 11:20:28
32: */
33: public class ReportConfiguration implements XMLExternalizable {
34: @NotNull
35: private HashMap<String, String> configProperties;
36:
37: public ReportConfiguration() {
38: configProperties = new HashMap<String, String>();
39: }
40:
41: public ReportConfiguration(@NotNull
42: HashMap<String, String> configProperties) {
43: //noinspection ConstantConditions
44: if (configProperties == null) {
45: throw new IllegalArgumentException(
46: "configProperties must not be null");
47: }
48:
49: this .configProperties = configProperties;
50: }
51:
52: @NotNull
53: public HashMap<String, String> getConfigProperties() {
54: return new HashMap<String, String>(configProperties);
55: }
56:
57: public void externalizeObject(@NotNull
58: XMLWriter xmlWriter, @NotNull
59: XMLContext xmlContext) throws IOException {
60: Set<String> keys = configProperties.keySet();
61: for (String key : keys) {
62: String value = configProperties.get(key);
63: xmlWriter.writeProperty(key, value);
64: }
65: }
66:
67: public void readObject(@NotNull
68: XmlPullNode node, @NotNull
69: XMLContext xmlContext) throws Exception {
70: while (!node.isFinished()) {
71: Object childNodeList = node.readNextChild();
72: if (childNodeList instanceof XmlPullNode) {
73: XmlPullNode child = (XmlPullNode) childNodeList;
74: if (XMLConstants.PROPERTY.equals(child.getRawName())) {
75: String key = child
76: .getAttributeValueFromRawName(XMLConstants.NAME);
77: String value = XMLUtils.readProperty(key, child);
78:
79: configProperties.put(key, value);
80: }
81: }
82: }
83: }
84: }
|