KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.sapia.regis.loader;
2
3 import org.sapia.regis.Node;
4
5 public class LinkTag {
6   
7   public static final String JavaDoc PREPEND = "prepend";
8   public static final String JavaDoc APPEND = "append";
9   
10   private String JavaDoc type = APPEND;
11   private String JavaDoc id, path;
12   
13   public String JavaDoc getRef() {
14     return id;
15   }
16
17   public void setRef(String JavaDoc id) {
18     this.id = id;
19   }
20   
21   public void setPath(String JavaDoc path) {
22     this.path = path;
23   }
24
25   public String JavaDoc getType() {
26     return type;
27   }
28
29   public void setType(String JavaDoc type) {
30     this.type = type;
31   }
32   
33   void create(ConfigContext ctx){
34     if(id == null && path == null){
35       throw new IllegalStateException JavaDoc("include id ref and path not defined");
36     }
37     
38     boolean isPath = path != null;
39     String JavaDoc idOrPath;
40     if(id != null){
41       idOrPath = id;
42     }
43     else{
44       idOrPath = path;
45     }
46     Node node = (Node)ctx.getNodeFor(idOrPath, isPath);
47     if(node == null){
48       throw new IllegalStateException JavaDoc("Invalid link; no node found for id ref or path: " + idOrPath);
49     }
50     if(type.equals(PREPEND)){
51       ctx.getParent().prependLink(node);
52     }
53     else{
54       ctx.getParent().appendLink(node);
55     }
56   }
57
58 }
59
Popular Tags