1 17 18 package com.finalist.jag.template; 19 20 21 import com.finalist.jag.template.parser.*; 22 23 import java.util.*; 24 25 26 33 public class TemplateHeaderFactory implements JagParserConstants { 34 35 36 private TemplateHeaderCollection headers = null; 37 38 39 46 public TemplateHeaderCollection getHeaderCollection() { 47 return headers; 48 } 49 50 51 60 public TemplateHeaderCollection create(JagBlockCollection jagblocks) { 61 62 headers = null; 63 64 Collection headerLines = new ArrayList(); 65 JagBlock childBlock[] = {jagblocks.getFirstChild(), null, null}; 66 67 for (; childBlock[0] != null; childBlock[0] = childBlock[0].getNextSibling()) { 68 if (childBlock[0].getType() != HEADERDEF_BEGIN) { 69 continue; 70 } 71 72 Collection identList = new ArrayList(); 73 Collection paramList = new ArrayList(); 74 75 childBlock[1] = childBlock[0].getFirstChild(); 76 77 while (childBlock[1] != null) { 78 if (childBlock[1].getType() == PARAMDEF) { 79 String ident = null, value = null; 80 81 childBlock[2] = childBlock[1].getFirstChild(); 82 83 while (childBlock[2] != null) { 84 if (childBlock[2].getType() == IDENT) { 85 ident = childBlock[2].getText(); 86 } 87 else if (childBlock[2].getType() == STRING) { 88 value = childBlock[2].getText(); 89 } 90 91 childBlock[2] = childBlock[2].getNextSibling(); 92 } 93 94 if ((ident != null) && (value != null)) { 95 paramList.add(new JagParameter(ident, value)); 96 } 97 } 98 else if (childBlock[1].getType() == IDENT) { 99 identList.add(childBlock[1].getText()); 100 } 101 102 childBlock[1] = childBlock[1].getNextSibling(); 103 } 104 105 String [] identArray = (String []) identList.toArray(new String [identList.size()]); 106 JagParameter[] paramArray = (JagParameter[]) paramList.toArray(new JagParameter[paramList.size()]); 107 108 headerLines.add(create(identArray, paramArray)); 109 } 110 111 headers = new TemplateHeaderCollection((HeaderLine[]) headerLines 112 .toArray(new HeaderLine[headerLines.size()])); 113 114 return headers; 115 } 116 117 118 128 protected HeaderLine create(String [] identArray, 129 JagParameter[] paramArray) { 130 131 HeaderLine headerLine = null; 132 133 for (int i = 0; i < identArray.length; i++) { 134 String ident = identArray[i]; 135 136 if (ident.equals("taglib")) { 137 headerLine = createUrlHeaderLine(identArray, paramArray); 138 139 if (headerLine != null) { 140 return headerLine; 141 } 142 } 143 } 144 145 if (headerLine == null) { 146 headerLine = new HeaderLine(identArray, paramArray); 147 } 148 149 return headerLine; 150 } 151 152 153 163 protected HeaderLine createUrlHeaderLine(String [] identArray, 164 JagParameter[] paramArray) { 165 166 String url = null; 168 String prefix = null; 169 170 for (int i = 0; i < paramArray.length; i++) { 171 if ((url == null) && paramArray[i].getIdent().equals("uri")) { 172 url = paramArray[i].getValue(); 173 } 174 else if ((prefix == null) && paramArray[i].getIdent().equals("prefix")) { 175 prefix = paramArray[i].getValue(); 176 } 177 } 178 179 return ((url != null) && (prefix != null)) 180 ? new UrlHeaderLine(identArray, paramArray, url, prefix) 181 : null; 182 } 183 } | Popular Tags |