KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > woody > datatype > FlowJXPathSelectionListBuilder


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 org.apache.cocoon.woody.datatype;
17
18 import org.apache.avalon.framework.context.Context;
19 import org.apache.avalon.framework.context.ContextException;
20 import org.apache.avalon.framework.context.Contextualizable;
21 import org.apache.cocoon.woody.util.DomHelper;
22 import org.w3c.dom.Element JavaDoc;
23
24 /**
25  * Builds a selection list that will take its values from the flow page data. The items list and,
26  * for each item, its value and label, are fetched using JXPath expressions.
27  * <p>
28  * If an item has no label, its value is used as the label.
29  * <p>
30  * Example:
31  * <pre>
32  * &lt;wd:selection-list type="flow-jxpath"
33  * list-path="selectList" value-path="value" label-path="label"/gt;
34  * </pre>
35  * Flow script:
36  * <pre>
37  * var data = {
38  * selectList: [{value:3, label:"three"}, {value:4}]
39  * };
40  * form.showForm("form.html", data);
41  * </pre>
42  *
43  * @see org.apache.cocoon.woody.datatype.FlowJXPathSelectionList
44  * @author <a HREF="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
45  * @version CVS $Id: FlowJXPathSelectionListBuilder.java 30932 2004-07-29 17:35:38Z vgritsenko $
46  */

47 public class FlowJXPathSelectionListBuilder implements SelectionListBuilder, Contextualizable {
48
49     private Context context;
50     
51     public void contextualize(Context context) throws ContextException {
52         this.context = context;
53     }
54
55     public SelectionList build(Element JavaDoc selectionListElement, Datatype datatype) throws Exception JavaDoc {
56         
57         String JavaDoc listPath = DomHelper.getAttribute(selectionListElement, "list-path");
58         String JavaDoc keyPath = DomHelper.getAttribute(selectionListElement, "value-path");
59         String JavaDoc valuePath = DomHelper.getAttribute(selectionListElement, "label-path");
60         
61         return new FlowJXPathSelectionList(context, listPath, keyPath, valuePath, datatype);
62     }
63
64 }
65
Popular Tags