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

import com.adobe.cq.wcm.translation.impl.I18nContentProcessor;
import com.adobe.cq.wcm.translation.impl.I18nStringExtractor;
import java.util.HashMap;
import java.util.HashSet;
import javax.jcr.Node;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class I18nJavaScriptProcessor
extends I18nContentProcessor {
    private static Logger logger = LoggerFactory.getLogger(I18nJavaScriptProcessor.class);

    public I18nJavaScriptProcessor(I18nStringExtractor i18nStringExtractor, HashSet<String> existingI18nStringSet, ResourceResolver resourceResolver) {
        super(i18nStringExtractor, existingI18nStringSet, resourceResolver);
    }

    @Override
    boolean processFileForI18nStrings(Node node, HashMap<String, String> i18nStringMap) {
        String regEx;
        boolean bSave = false;
        String fileContent = I18nStringExtractor.getFileContentsFromNode(node);
        try {
            logger.trace("In function: processFileForI18nStrings for {}", (Object)node.getPath());
            regEx = "((CQ)|(Granite))\\.I18n.((get)|(getMessage))\\(\\s*['\"]([^,]*?)['\"]\\)";
            if (this.searchAndAddI18nString(fileContent, i18nStringMap, regEx, 7)) {
                bSave = true;
            }
        }
        catch (Exception ignored) {
            // empty catch block
        }
        try {
            regEx = "((CQ)|(Granite))\\.I18n.((get)|(getMessage))\\(\\s*['\"]([^,]*?)['\"]\\s*,\\s*.*?[^'\"]\\s*\\)";
            if (this.searchAndAddI18nString(fileContent, i18nStringMap, regEx, 7)) {
                bSave = true;
            }
        }
        catch (Exception ignored) {
            // empty catch block
        }
        try {
            regEx = "((CQ)|(Granite))\\.I18n\\.((get)|(getMessage))\\(\\s*[\"'](.*?)[\"'],.*?\\s*[\"'](.*?)['\"]\\s*\\)";
            if (this.searchAndAddI18nStringWithComment(fileContent, i18nStringMap, regEx, 7, 8)) {
                bSave = true;
            }
        }
        catch (Exception ignored) {
            // empty catch block
        }
        return bSave;
    }

    @Override
    boolean processFileForIncludes(Node node) {
        return false;
    }
}