Search in sources :

Example 1 with Property

use of com.sun.enterprise.admin.servermgmt.xml.stringsubs.Property in project Payara by payara.

the class StringSubstitutionEngine method buildChangePairsMap.

/**
 * Build's a HashMap containing an entry for each <change-pair> in the string-subs
 * configuration file. The HashMap is created so that <change-pair> elements do not
 * need to be re-analyzed each time they're referenced.
 */
private void buildChangePairsMap() {
    if (_changePairsMap == null || _changePairsMap.isEmpty()) {
        Defaults defaults = _root.getDefaults();
        if (defaults != null) {
            List<Property> properties = defaults.getProperty();
            if (!properties.isEmpty()) {
                _defaultProperties = new HashMap<String, Property>(properties.size(), 1);
                for (Property prop : properties) {
                    _defaultProperties.put(prop.getKey(), prop);
                }
            }
        }
        List<? extends ChangePair> changePairList = _root.getChangePair();
        _changePairsMap = new HashMap<String, Pair>(changePairList.size());
        for (ChangePair pair : _root.getChangePair()) {
            String id = pair.getId();
            String beforeValue = pair.getBefore();
            String afterValue = pair.getAfter();
            if (id == null || beforeValue == null || afterValue == null) {
                _logger.log(Level.INFO, SLogger.EMPTY_CHANGE_PAIR);
                continue;
            }
            beforeValue = _attrPreprocessor.substituteBefore(beforeValue);
            afterValue = _attrPreprocessor.substituteAfter(afterValue);
            _changePairsMap.put(id, new Pair(beforeValue, afterValue));
        }
    }
}
Also used : Defaults(com.sun.enterprise.admin.servermgmt.xml.stringsubs.Defaults) ChangePair(com.sun.enterprise.admin.servermgmt.xml.stringsubs.ChangePair) Property(com.sun.enterprise.admin.servermgmt.xml.stringsubs.Property) ChangePair(com.sun.enterprise.admin.servermgmt.xml.stringsubs.ChangePair)

Example 2 with Property

use of com.sun.enterprise.admin.servermgmt.xml.stringsubs.Property in project Payara by payara.

the class StringSubstitutionEngine method getDefaultProperties.

@Override
public List<Property> getDefaultProperties(PropertyType type) {
    Defaults defaults = _root.getDefaults();
    if (defaults == null) {
        return Collections.emptyList();
    }
    if (type == null) {
        return defaults.getProperty();
    }
    List<Property> props = new ArrayList<Property>();
    for (Property prop : defaults.getProperty()) {
        if (prop.getType().equals(type)) {
            props.add(prop);
        }
    }
    return props;
}
Also used : Defaults(com.sun.enterprise.admin.servermgmt.xml.stringsubs.Defaults) ArrayList(java.util.ArrayList) Property(com.sun.enterprise.admin.servermgmt.xml.stringsubs.Property)

Example 3 with Property

use of com.sun.enterprise.admin.servermgmt.xml.stringsubs.Property 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

Property (com.sun.enterprise.admin.servermgmt.xml.stringsubs.Property)3 Defaults (com.sun.enterprise.admin.servermgmt.xml.stringsubs.Defaults)2 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 ChangePair (com.sun.enterprise.admin.servermgmt.xml.stringsubs.ChangePair)1 ASenvPropertyReader (com.sun.enterprise.universal.glassfish.ASenvPropertyReader)1 File (java.io.File)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1