I18nContentProcessor.java 2.39 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.jcr.Node
 *  org.apache.sling.api.resource.ResourceResolver
 */
package com.adobe.cq.wcm.translation.impl;

import com.adobe.cq.wcm.translation.impl.I18nStringExtractor;
import java.util.HashMap;
import java.util.HashSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.jcr.Node;
import org.apache.sling.api.resource.ResourceResolver;

public abstract class I18nContentProcessor {
    protected I18nStringExtractor i18nStringExtractor;
    protected HashSet<String> existingI18nStringSet;
    protected ResourceResolver resourceResolver;

    public I18nContentProcessor(I18nStringExtractor i18nStringExtractor, HashSet<String> existingI18nStringSet, ResourceResolver resourceResolver) {
        this.i18nStringExtractor = i18nStringExtractor;
        this.existingI18nStringSet = existingI18nStringSet;
        this.resourceResolver = resourceResolver;
    }

    private void addI18nString(String i18nString, String comment, HashMap<String, String> i18nStringMap) {
        String i18nKey = i18nString;
        if (comment != null) {
            i18nKey = i18nString + " ((" + comment + "))";
        }
        if (!this.existingI18nStringSet.contains(i18nKey)) {
            i18nStringMap.put(i18nKey, i18nString);
        }
    }

    protected boolean searchAndAddI18nString(String content, HashMap<String, String> i18nStringMap, String regEx, int stringGroup) {
        boolean bSave = false;
        Pattern pattern = Pattern.compile(regEx);
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()) {
            this.addI18nString(matcher.group(stringGroup), null, i18nStringMap);
            bSave = true;
        }
        return bSave;
    }

    protected boolean searchAndAddI18nStringWithComment(String content, HashMap<String, String> i18nStringMap, String regEx, int stringGroup, int commentGroup) {
        boolean bSave = false;
        Pattern pattern = Pattern.compile(regEx);
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()) {
            this.addI18nString(matcher.group(stringGroup), matcher.group(commentGroup), i18nStringMap);
            bSave = true;
        }
        return bSave;
    }

    abstract boolean processFileForI18nStrings(Node var1, HashMap<String, String> var2);

    abstract boolean processFileForIncludes(Node var1);
}