KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > regis > loader > IncludeTag


1 package org.sapia.regis.loader;
2
3 import java.util.Iterator JavaDoc;
4
5 import org.sapia.regis.Node;
6
7 public class IncludeTag {
8   
9   private String JavaDoc id, path;
10   
11   public String JavaDoc getRef() {
12     return id;
13   }
14   
15   public void setPath(String JavaDoc path) {
16     this.path = path;
17   }
18   
19
20   public void setRef(String JavaDoc id) {
21     this.id = id;
22   }
23
24   void create(ConfigContext ctx){
25     if(id == null && path == null){
26       throw new IllegalStateException JavaDoc("include id ref and path not defined");
27     }
28     
29     boolean isPath = path != null;
30     String JavaDoc idOrPath;
31     if(id != null){
32       idOrPath = id;
33     }
34     else{
35       idOrPath = path;
36     }
37     
38     if(idOrPath.endsWith("@")){
39       String JavaDoc newId = idOrPath.substring(0, idOrPath.length()-1);
40       Node node = (Node)ctx.getNodeFor(newId, isPath);
41       if(node == null){
42         throw new IllegalStateException JavaDoc("Invalid include; no node found for id ref or path: " + newId);
43       }
44       Iterator JavaDoc itr = node.getChildren().iterator();
45       while(itr.hasNext()){
46         ctx.getParent().addInclude((Node)itr.next());
47       }
48     }
49     else{
50       Node node = (Node)ctx.getNodeFor(idOrPath, isPath);
51       if(node == null){
52         throw new IllegalStateException JavaDoc("Invalid include; no node found for id ref or path: " + idOrPath);
53       }
54       ctx.getParent().addInclude(node);
55     }
56   }
57
58 }
59
Popular Tags