1 package org.sapia.regis.loader; 2 3 import org.sapia.regis.Node; 4 5 public class LinkTag { 6 7 public static final String PREPEND = "prepend"; 8 public static final String APPEND = "append"; 9 10 private String type = APPEND; 11 private String id, path; 12 13 public String getRef() { 14 return id; 15 } 16 17 public void setRef(String id) { 18 this.id = id; 19 } 20 21 public void setPath(String path) { 22 this.path = path; 23 } 24 25 public String getType() { 26 return type; 27 } 28 29 public void setType(String type) { 30 this.type = type; 31 } 32 33 void create(ConfigContext ctx){ 34 if(id == null && path == null){ 35 throw new IllegalStateException ("include id ref and path not defined"); 36 } 37 38 boolean isPath = path != null; 39 String 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 ("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 |