/** * @param bundle * @param templateLocation */ @SuppressWarnings({"nls", "boxing", "unchecked"}) public void initializeFrom(Bundle bundle, String templateLocation) { Enumeration<String> list = bundle.getEntryPaths(templateLocation); if (list == null) { return; } // got some elements, look for "template.properties" int count = 0; while (list.hasMoreElements()) { String nextRoot = list.nextElement(); if (nextRoot.endsWith(BUNDLE_DIRECTORY) == false) { continue; } String nextEntry = nextRoot + TEMPLATE_PROPERTIES; // found another template URL nextURL = bundle.getEntry(nextEntry); if (nextURL == null) { // no such thing continue; } // looks like we have properties count += 1; Properties props = new Properties(); InputStream is = null; try { is = nextURL.openStream(); props.load(is); } catch (IOException e) { BPELUIPlugin.log(e); // skip to the next entry continue; } finally { try { is.close(); } catch (Throwable t) { } } String name = props.getProperty(PROPERTY_NAME); // No name, no game. if (name == null) { continue; } String enc = props.getProperty(PROPERTY_ENCODING, DEFAULT_ENCODING); String desc = props.getProperty(PROPERTY_DESCRIPTION, EMPTY); // add any namespaces we are supplying ... mNamespaceNames.addAll(findProperties(props, "namespace.{0}")); Template template = new Template(); template.mName = name; template.mDescription = desc; template.mProperties = (Map) props; mTemplateByName.put(name, template); String id = props.getProperty(PROPERTY_KEY); if (id != null) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=330813 // https://jira.jboss.org/browse/JBIDE-7165 template.mKey = id; mTemplateByKey.put(id, template); } int hole = 3; for (int i = 0; hole >= 0; i++) { String key = MessageFormat.format("resource.{0}", i); String resourceName = props.getProperty(key); if (resourceName == null) { hole--; continue; } hole = 3; key = MessageFormat.format("resource.{0}.name", i); String nameTemplate = props.getProperty(key); String entryLoc = nextRoot + resourceName; TemplateResource resource = new TemplateResource(); resource.mName = resourceName; resource.mContent = slurpContent(bundle.getEntry(entryLoc), enc); resource.mNameTemplate = nameTemplate; // add the resource which makes up this "template" template.add(resource); } } }