Search in sources :

Example 1 with Archive

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

the class ArchiveEntryWrapperImpl method extract.

/**
 * Extract all the substitutable entries for an archive.
 * It also takes care of extracting substitutable entries
 * from nested archives.
 *
 * @throws IOException If any IO error occurs during extraction.
 */
private void extract() throws IOException {
    for (Object object : _archive.getArchiveOrMemberEntry()) {
        String extratFilePath = _extractDir.getAbsolutePath() + File.separator;
        if (object instanceof Archive) {
            Archive archive = (Archive) object;
            File file = new File(extratFilePath + archive.getName());
            try {
                extractEntry(archive.getName(), file);
            } catch (IllegalArgumentException e) {
                continue;
            }
            _extractedEntries.put(archive.getName(), file);
            new ArchiveEntryWrapperImpl(archive, extratFilePath, this);
            _noOfExtractedEntries.incrementAndGet();
        } else if (object instanceof MemberEntry) {
            MemberEntry entry = (MemberEntry) object;
            File file = new File(extratFilePath + entry.getName());
            try {
                extractEntry(entry.getName(), file);
            } catch (IllegalArgumentException e) {
                continue;
            }
            _extractedEntries.put(entry.getName(), file);
            getAllArchiveMemberList().add(new ArchiveMemberHandler(file, this));
            _noOfExtractedEntries.incrementAndGet();
        } else {
            _logger.log(Level.WARNING, SLogger.INVALID_ARCHIVE_ENTRY, new Object[] { object, _archive.getName() });
        }
    }
}
Also used : Archive(com.sun.enterprise.admin.servermgmt.xml.stringsubs.Archive) JarFile(java.util.jar.JarFile) File(java.io.File) MemberEntry(com.sun.enterprise.admin.servermgmt.xml.stringsubs.MemberEntry)

Example 2 with Archive

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

the class StringSubstitutionEngine method doSubstitution.

/**
 * Perform's string substitution for a given group.
 *
 * @param groups Groups for which the string substitution
 *  has to be performed.
 * @throws StringSubstitutionException If any error occurs during
 *  substitution.
 */
private void doSubstitution(Group group) throws StringSubstitutionException {
    List<? extends FileEntry> fileList = group.getFileEntry();
    List<? extends Archive> archiveList = group.getArchive();
    if (!isValid(fileList) && !isValid(archiveList)) {
        if (_logger.isLoggable(Level.FINER)) {
            _logger.log(Level.FINER, _strings.get("noSubstitutableGroupEntry", group.getId()));
        }
        return;
    }
    List<? extends ChangePairRef> refList = group.getChangePairRef();
    if (!isValid(refList)) {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, _strings.get("noChangePairForGroup", group.getId()));
        }
        return;
    }
    String groupMode = null;
    ModeType modeType = group.getMode();
    if (modeType != null) {
        groupMode = modeType.value();
    }
    buildChangePairsMap();
    Map<String, String> substitutionMap = new HashMap<String, String>();
    for (ChangePairRef ref : refList) {
        String name = ref.getName();
        String localMode = ref.getMode();
        // then inherit the mode of the group
        if (localMode == null || localMode.length() == 0) {
            localMode = groupMode;
        }
        Pair pair = _changePairsMap.get(name);
        if (pair == null) {
            _logger.log(Level.INFO, SLogger.MISSING_CHANGE_PAIR, new Object[] { name, group.getId() });
            continue;
        }
        String beforeString = pair.getBefore();
        String afterString = pair.getAfter();
        if (localMode == null || localMode.length() == 0) {
            if (_logger.isLoggable(Level.FINEST)) {
                _logger.log(Level.FINEST, _strings.get("noModeValue", group.getId()));
            }
        } else {
            try {
                afterString = ModeProcessor.processModeType(ModeType.fromValue(localMode), afterString);
            } catch (Exception e) {
                _logger.log(Level.WARNING, SLogger.INVALID_MODE_TYPE, localMode);
            }
        }
        substitutionMap.put(beforeString, afterString);
    }
    SubstitutionAlgorithm algorithm = new SubstitutionAlgorithmFactory().getAlgorithm(substitutionMap);
    for (FileEntry fileEntry : fileList) {
        fileEntry.setName(_attrPreprocessor.substitutePath(fileEntry.getName()));
        List<? extends Substitutable> substituables = _substitutableFactory.getFileEntrySubstituables(fileEntry);
        for (Substitutable substituable : substituables) {
            algorithm.substitute(substituable);
            substituable.finish();
        }
    }
    for (Archive archive : archiveList) {
        if (archive == null || archive.getName().isEmpty()) {
            continue;
        }
        try {
            archive.setName(_attrPreprocessor.substitutePath(archive.getName()));
            List<? extends Substitutable> substituables = _substitutableFactory.getArchiveEntrySubstitutable(archive);
            if (!isValid(substituables)) {
                continue;
            }
            for (Substitutable substituable : substituables) {
                algorithm.substitute(substituable);
                substituable.finish();
            }
        } catch (Exception e) {
            LogHelper.log(_logger, Level.WARNING, SLogger.ERR_ARCHIVE_SUBSTITUTION, e, archive.getName());
        }
    }
}
Also used : Archive(com.sun.enterprise.admin.servermgmt.xml.stringsubs.Archive) HashMap(java.util.HashMap) ChangePairRef(com.sun.enterprise.admin.servermgmt.xml.stringsubs.ChangePairRef) StringSubstitutionException(com.sun.enterprise.admin.servermgmt.stringsubs.StringSubstitutionException) SubstitutionAlgorithm(com.sun.enterprise.admin.servermgmt.stringsubs.SubstitutionAlgorithm) ModeType(com.sun.enterprise.admin.servermgmt.xml.stringsubs.ModeType) Substitutable(com.sun.enterprise.admin.servermgmt.stringsubs.Substitutable) FileEntry(com.sun.enterprise.admin.servermgmt.xml.stringsubs.FileEntry) ChangePair(com.sun.enterprise.admin.servermgmt.xml.stringsubs.ChangePair)

Aggregations

Archive (com.sun.enterprise.admin.servermgmt.xml.stringsubs.Archive)2 StringSubstitutionException (com.sun.enterprise.admin.servermgmt.stringsubs.StringSubstitutionException)1 Substitutable (com.sun.enterprise.admin.servermgmt.stringsubs.Substitutable)1 SubstitutionAlgorithm (com.sun.enterprise.admin.servermgmt.stringsubs.SubstitutionAlgorithm)1 ChangePair (com.sun.enterprise.admin.servermgmt.xml.stringsubs.ChangePair)1 ChangePairRef (com.sun.enterprise.admin.servermgmt.xml.stringsubs.ChangePairRef)1 FileEntry (com.sun.enterprise.admin.servermgmt.xml.stringsubs.FileEntry)1 MemberEntry (com.sun.enterprise.admin.servermgmt.xml.stringsubs.MemberEntry)1 ModeType (com.sun.enterprise.admin.servermgmt.xml.stringsubs.ModeType)1 File (java.io.File)1 HashMap (java.util.HashMap)1 JarFile (java.util.jar.JarFile)1