/** * Returns a list of all .def-file entries in this Component. * @return A list of .def-file entries. */ private List<DefEntry> findDefEntries() { List<DefEntry> defEntries = new ArrayList<>(); ZipEntry defDir = jarFile.getEntry(DEFPATH); if ((defDir == null) || !defDir.isDirectory()) return defEntries; for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) { JarEntry entry = entries.nextElement(); String name = entry.getName(); if (name.endsWith(".def")) { if (name.matches("^" + DEFPATH + ".*\\.def$")) { defEntries.add(new DefEntry(this, entry)); } else { log.info("Config definition file '" + name + "' in component '" + jarFile.getName() + "' will not be used. Files must reside in the '" + DEFPATH + "' directory in the .jar file"); } } } return defEntries; }
/** * @param bundle The bundle this def entry belongs to. * @param zipEntry The ZipEntry representing the def-file. */ public DefEntry(Bundle bundle, ZipEntry zipEntry) { this.bundle = bundle; this.zipEntry = zipEntry; String entryName = zipEntry.getName(); Tuple2<String, String> nameAndNamespace = ConfigUtils.getNameAndNamespaceFromString(entryName.substring(DEFPATH.length(), entryName.indexOf(".def"))); defName = nameAndNamespace.first; defNamespace = getNamespace(); if (defNamespace.isEmpty()) throw new IllegalArgumentException("Config definition '" + defName + "' is missing a package (or namespace)"); contents = getContents(); }
private String getContents() { StringBuilder ret = new StringBuilder(""); BufferedReader reader = new BufferedReader(getReader()); try { String str = reader.readLine(); while (str != null){ ret.append(str); str = reader.readLine(); if (str != null) { ret.append("\n"); } } reader.close(); } catch (IOException e) { throw new IllegalArgumentException("Failed reading contents of def-file '" + defName + ".def in component " + bundle.jarFile.getName(),e); } return ret.toString(); }
/** * Returns the namespace of the .def-file, as given by the "namespace=" statement inside the given entry. * @return The namespace string, or "" (empty string) if no namespace exists */ private String getNamespace() { return ConfigUtils.getDefNamespace(getReader()); }