KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > forms > formmodel > ImportDefinitionBuilder


1 /*
2  * Copyright 2005 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.forms.formmodel;
17
18 import org.apache.cocoon.forms.formmodel.library.Library;
19 import org.apache.cocoon.forms.util.DomHelper;
20 import org.w3c.dom.Element JavaDoc;
21
22
23 /**
24  * @version $Id: ImportDefinitionBuilder.java 289538 2005-09-16 13:46:22Z sylvain $
25  */

26 public class ImportDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
27
28     public static final String JavaDoc PREFIX_ATTRIBUTE = "prefix";
29     public static final String JavaDoc URI_ATTRIBUTE = "uri";
30     
31     /**
32      * Imports a new library
33      */

34     public WidgetDefinition buildWidgetDefinition(Element JavaDoc widgetElement)
35             throws Exception JavaDoc {
36         
37         if(this.context == null || this.context.getLocalLibrary() == null)
38             throw new Exception JavaDoc("Import statement seen and context is empty! (at "+DomHelper.getLocation(widgetElement)+")");
39             
40         Library lib = this.context.getLocalLibrary();
41         String JavaDoc prefix = DomHelper.getAttribute(widgetElement, PREFIX_ATTRIBUTE);
42         String JavaDoc uri = DomHelper.getAttribute(widgetElement, URI_ATTRIBUTE);
43         
44         if(!lib.includeAs(prefix,uri))
45             throw new Exception JavaDoc("Import statement did not succeed (probably used ':' in the prefix?)! (at "+DomHelper.getLocation(widgetElement)+")");
46         
47         return null;
48     }
49
50 }
51
Popular Tags