Search in sources :

Example 1 with TemplateInfoHolder

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);
    }
}
Also used : DomainException(com.sun.enterprise.admin.servermgmt.DomainException) InputStream(java.io.InputStream) TemplateInfoHolder(com.sun.enterprise.admin.servermgmt.template.TemplateInfoHolder) ASenvPropertyReader(com.sun.enterprise.universal.glassfish.ASenvPropertyReader) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) DomainException(com.sun.enterprise.admin.servermgmt.DomainException) RepositoryException(com.sun.enterprise.admin.servermgmt.RepositoryException) StringSubstitutor(com.sun.enterprise.admin.servermgmt.stringsubs.StringSubstitutor) JarFile(java.util.jar.JarFile) File(java.io.File) Property(com.sun.enterprise.admin.servermgmt.xml.stringsubs.Property)

Aggregations

DomainException (com.sun.enterprise.admin.servermgmt.DomainException)1 RepositoryException (com.sun.enterprise.admin.servermgmt.RepositoryException)1 StringSubstitutor (com.sun.enterprise.admin.servermgmt.stringsubs.StringSubstitutor)1 TemplateInfoHolder (com.sun.enterprise.admin.servermgmt.template.TemplateInfoHolder)1 Property (com.sun.enterprise.admin.servermgmt.xml.stringsubs.Property)1 ASenvPropertyReader (com.sun.enterprise.universal.glassfish.ASenvPropertyReader)1 File (java.io.File)1 InputStream (java.io.InputStream)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1