Java tutorial
/******************************************************************************* * Copyright 2013 Sarbyn * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ package com.sarbyn.ath.explorer; import java.io.File; import java.io.FileFilter; import java.io.FilenameFilter; import org.apache.commons.io.filefilter.RegexFileFilter; import com.sarbyn.ath.main.Logger; /** * Analyze a framework application folder, searching for all * the strings.xml file in the "res" folder * * @author sarbyn * */ public class AppAnalyzer { private File appFolder; private String appName; private File resFolder; private static final String TRANSLATION_PARENT_FOLDER = "res"; private static final String DEFAULT_TRANSLATION_FOLDER = "values"; /** * Default constructor * * @param f Application folder */ public AppAnalyzer(File f) { appFolder = f; appName = f.getName(); resFolder = getResFolder(); } /** * Start the analysis * * @param languageFilter - the language filter (if any) */ public void start(String languageFilter) { Logger.debug("*** Scanning application " + appName); if (resFolder == null || !resFolder.exists()) { Logger.error("The application " + appName + " does not have RES folder!"); return; } Logger.debug("**** Res folder is " + resFolder); File defaultTranslationFolder = findDefaultResFolder(resFolder); if (defaultTranslationFolder == null) { Logger.error("The application " + appName + " does not have default translation folder!"); return; } Logger.debug("**** Default translation folder is " + defaultTranslationFolder.getAbsolutePath()); File[] translationsFolder = resFolder.listFiles((FileFilter) new RegexFileFilter("^values-(\\w*)(-\\w*)?")); Logger.debug("SIZE " + translationsFolder.length); for (File f : translationsFolder) { TranslationFileParser parser = new TranslationFileParser(appName, defaultTranslationFolder, f); parser.compare(languageFilter); } } private File getResFolder() { File[] searchForResFolder = appFolder.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return TRANSLATION_PARENT_FOLDER.equals(name); } }); return searchForResFolder[0]; } private File findDefaultResFolder(File resFolder) { File[] f = resFolder.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return DEFAULT_TRANSLATION_FOLDER.equals(name); } }); if (f.length == 0) return null; return f[0]; } }