use of com.sun.enterprise.admin.servermgmt.template.TemplateInfoHolder in project Payara by payara.
the class DomainBuilder method initialize.
/**
* Initialize template by loading template jar.
*
* @throws DomainException If exception occurs in initializing the template jar.
*/
// TODO : localization of index.html
private void initialize() throws DomainException {
String templateJarPath = (String) _domainConfig.get(DomainConfig.K_TEMPLATE_NAME);
if (templateJarPath == null || templateJarPath.isEmpty()) {
String defaultTemplateName = Version.getDefaultDomainTemplate();
if (defaultTemplateName == null || defaultTemplateName.isEmpty()) {
throw new DomainException(_strings.get("missingDefaultTemplateName"));
}
Map<String, String> envProperties = new ASenvPropertyReader().getProps();
templateJarPath = envProperties.get(SystemPropertyConstants.INSTALL_ROOT_PROPERTY) + File.separator + DEFAULT_TEMPLATE_RELATIVE_PATH + File.separator + defaultTemplateName;
}
File template = new File(templateJarPath);
if (!template.exists() || !template.getName().endsWith(".jar")) {
throw new DomainException(_strings.get("invalidTemplateJar", template.getAbsolutePath()));
}
try {
_templateJar = new JarFile(new File(templateJarPath));
JarEntry je = _templateJar.getJarEntry("config/" + DomainConstants.DOMAIN_XML_FILE);
if (je == null) {
throw new DomainException(_strings.get("missingMandatoryFile", DomainConstants.DOMAIN_XML_FILE));
}
// Loads template-info.xml
je = _templateJar.getJarEntry(TEMPLATE_INFO_XML);
if (je == null) {
throw new DomainException(_strings.get("missingMandatoryFile", TEMPLATE_INFO_XML));
}
TemplateInfoHolder templateInfoHolder = new TemplateInfoHolder(_templateJar.getInputStream(je), templateJarPath);
_extractedEntries.add(TEMPLATE_INFO_XML);
// Loads string substitution XML.
je = _templateJar.getJarEntry(STRINGSUBS_FILE);
StringSubstitutor stringSubstitutor = null;
if (je != null) {
stringSubstitutor = StringSubstitutionFactory.createStringSubstitutor(_templateJar.getInputStream(je));
List<Property> defaultStringSubsProps = stringSubstitutor.getDefaultProperties(PropertyType.PORT);
for (Property prop : defaultStringSubsProps) {
_defaultPortValues.setProperty(prop.getKey(), prop.getValue());
}
_extractedEntries.add(je.getName());
} else {
_logger.log(Level.WARNING, SLogger.MISSING_FILE, STRINGSUBS_FILE);
}
_domainTempalte = new DomainTemplate(templateInfoHolder, stringSubstitutor, templateJarPath);
// Loads default self signed certificate.
je = _templateJar.getJarEntry("config/" + DomainConstants.KEYSTORE_FILE);
if (je != null) {
_keystoreBytes = new byte[(int) je.getSize()];
InputStream in = null;
int count = 0;
try {
in = _templateJar.getInputStream(je);
count = in.read(_keystoreBytes);
if (count < _keystoreBytes.length) {
throw new DomainException(_strings.get("loadingFailure", je.getName()));
}
} finally {
if (in != null) {
in.close();
}
}
_extractedEntries.add(je.getName());
}
File parentDomainDir = FileUtils.safeGetCanonicalFile(new File(_domainConfig.getRepositoryRoot()));
createDirectory(parentDomainDir);
} catch (Exception e) {
throw new DomainException(e);
}
}
Aggregations