01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.woody.datatype;
18:
19: import org.apache.avalon.framework.context.Context;
20: import org.apache.avalon.framework.context.ContextException;
21: import org.apache.avalon.framework.context.Contextualizable;
22: import org.apache.cocoon.woody.util.DomHelper;
23: import org.w3c.dom.Element;
24:
25: /**
26: * Builds a selection list that will take its values from the flow page data. The items list and,
27: * for each item, its value and label, are fetched using JXPath expressions.
28: * <p>
29: * If an item has no label, its value is used as the label.
30: * <p>
31: * Example:
32: * <pre>
33: * <wd:selection-list type="flow-jxpath"
34: * list-path="selectList" value-path="value" label-path="label"/gt;
35: * </pre>
36: * Flow script:
37: * <pre>
38: * var data = {
39: * selectList: [{value:3, label:"three"}, {value:4}]
40: * };
41: * form.showForm("form.html", data);
42: * </pre>
43: *
44: * @see org.apache.cocoon.woody.datatype.FlowJXPathSelectionList
45: * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
46: * @version CVS $Id: FlowJXPathSelectionListBuilder.java 433543 2006-08-22 06:22:54Z crossley $
47: */
48: public class FlowJXPathSelectionListBuilder implements
49: SelectionListBuilder, Contextualizable {
50:
51: private Context context;
52:
53: public void contextualize(Context context) throws ContextException {
54: this .context = context;
55: }
56:
57: public SelectionList build(Element selectionListElement,
58: Datatype datatype) throws Exception {
59:
60: String listPath = DomHelper.getAttribute(selectionListElement,
61: "list-path");
62: String keyPath = DomHelper.getAttribute(selectionListElement,
63: "value-path");
64: String valuePath = DomHelper.getAttribute(selectionListElement,
65: "label-path");
66:
67: return new FlowJXPathSelectionList(context, listPath, keyPath,
68: valuePath, datatype);
69: }
70:
71: }
|