01: /*
02: * Copyright 2001-2007 Hippo (www.hippo.nl)
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package nl.hippo.cms.editor.flow;
17:
18: import java.util.ArrayList;
19: import java.util.Iterator;
20:
21: import org.w3c.dom.Document;
22: import org.w3c.dom.Element;
23: import org.w3c.dom.Text;
24:
25: public class FlowDocumentProperties extends
26: AbstractFlowContextComponent {
27:
28: public FlowDocumentProperties(Configuration conf, FlowHelper fh) {
29: super (conf, fh);
30: }
31:
32: public void update() {
33: m_values = helper.getDocumentProperties(editorConfiguration
34: .getDocumentType(), editorConfiguration
35: .getDocumentPath());
36: }
37:
38: public String getComponentKey() {
39: return "properties";
40: }
41:
42: public ArrayList valuesToXML(Document d) {
43: ArrayList valueElements = new ArrayList();
44:
45: Iterator it = m_values.keySet().iterator();
46: Element propertyEl;
47: Text propertyValue;
48: while (it.hasNext()) {
49: String key = (String) it.next();
50: int nsSep = key.lastIndexOf(":");
51: if (nsSep > 0 && nsSep < key.length() - 1) {
52: String elQName = key.substring(nsSep + 1);
53: String elNamespaceURI = key.substring(0, nsSep);
54:
55: propertyEl = d.createElement("property");
56:
57: propertyEl.setAttribute("namespace", elNamespaceURI);
58: propertyEl.setAttribute("name", elQName);
59:
60: propertyValue = d.createTextNode((String) m_values
61: .get(key));
62: propertyEl.appendChild(propertyValue);
63:
64: valueElements.add(propertyEl);
65: }
66: }
67:
68: return valueElements;
69: }
70:
71: public ArrayList componentsToXML() {
72: // no subcomponents
73: return new ArrayList();
74: }
75:
76: }
|