1 36 37 package com.caucho.doc.javadoc; 38 39 import com.caucho.config.ConfigException; 40 import com.caucho.log.Log; 41 import com.caucho.util.CharBuffer; 42 import com.caucho.util.Crc64; 43 import com.caucho.util.L10N; 44 import com.caucho.vfs.Path; 45 import com.caucho.vfs.Vfs; 46 47 import java.util.ArrayList ; 48 import java.util.logging.Logger ; 49 50 import java.io.FileNotFoundException ; 51 52 55 public class Api { 56 static protected final Logger log = Log.open(Api.class); 57 static final L10N L = new L10N(Api.class); 58 59 private String _id; 60 private String _name; 61 private String _description; 62 private String _location; 63 private String _indexString; 64 private ArrayList <Path> _index = new ArrayList <Path>(); 65 66 private Path _locationPath; 67 private boolean _isLocal; 68 private boolean _isLocalAbsolute; 69 70 73 public void setId(String id) 74 throws ConfigException 75 { 76 for (int i = 0; i < id.length(); i++) { 77 if (!Character.isJavaIdentifierPart(id.charAt(i))) 78 throw new ConfigException(L.l("illegal character in `{0}': {1}","id",id.charAt(i))); 79 } 80 _id = id; 81 } 82 83 86 public String getId() 87 { 88 return _id; 89 } 90 91 94 public void setName(String name) 95 { 96 _name = name; 97 } 98 99 102 public String getName() 103 { 104 return _name; 105 } 106 107 110 public void setDescription(String description) 111 { 112 _description = description; 113 } 114 115 118 public String getDescription() 119 { 120 return _description; 121 } 122 123 132 public void setLocation(String location) 133 { 134 if (!location.endsWith("/")) { 135 CharBuffer cb = CharBuffer.allocate(); 136 cb.append(location); 137 cb.append('/'); 138 _location = cb.close(); 139 } 140 else 141 _location = location; 142 } 143 144 147 public String getLocation() 148 { 149 return _location; 150 } 151 152 155 Path getLocationPath() 156 { 157 return _locationPath; 158 } 159 160 164 public void setIndex(String index) 165 { 166 _indexString = index; 167 } 168 169 public void init() 170 throws ConfigException 171 { 172 if (_id == null) 173 throw new ConfigException(L.l("`{0}' is required","id")); 174 175 if (_location == null) 176 throw new ConfigException(L.l("`{0}' is required","location")); 177 178 if (_name == null) 179 _name = _location.toString(); 180 181 if (_indexString == null) 182 _indexString = "index-all.html"; 183 184 _locationPath = Vfs.lookup(_location); 185 186 int split = _indexString.indexOf('#'); 187 188 if (split > -1) { 189 CharBuffer before = new CharBuffer(_indexString.substring(0,split)); 190 CharBuffer after = new CharBuffer(_indexString.substring(split + 1)); 191 CharBuffer index = CharBuffer.allocate(); 192 193 boolean isIndex = false; 194 195 for (int i = 1; i <= 27; i++) { 196 index.append(before); 197 index.append(i); 198 index.append(after); 199 200 Path indexPath = _locationPath.lookup(index.toString()); 201 202 if (indexPath.exists()) { 203 isIndex = true; 204 _index.add(indexPath); 205 } 206 207 index.clear(); 208 } 209 210 if (!isIndex) { 211 throw new ConfigException(L.l("`{0}' not found", _locationPath.lookup(_indexString))); 212 } 213 } 214 else 215 _index.add(_locationPath.lookup(_indexString)); 216 217 if (_locationPath.getScheme().equals("file")) { 218 _isLocal = true; 219 Path pwd = Vfs.getPwd(); 220 221 if (!_locationPath.getPath().startsWith(pwd.getPath())) 222 _isLocalAbsolute = true; 223 } 224 } 225 226 long generateCrc64(long crc) 227 { 228 crc = Crc64.generate(crc,_location); 229 return Crc64.generate(crc,_index.toString()); 230 } 231 232 235 public ArrayList <Path> getIndexes() 236 { 237 return _index; 238 } 239 240 241 244 public boolean isLocal() 245 { 246 return _isLocal; 247 } 248 249 253 public boolean isLocalAbsolute() 254 { 255 return _isLocalAbsolute; 256 } 257 258 262 263 String getLocationHref(String file) 264 { 265 CharBuffer cb = CharBuffer.allocate(); 266 267 if (_isLocalAbsolute) { 268 cb.append(_id); 269 cb.append('/'); 270 } 271 else { 272 cb.append(_location); 273 } 274 275 cb.append(file); 276 277 return cb.close(); 278 } 279 } 280 281 282 | Popular Tags |