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