use of org.apache.commons.io.LineIterator in project pratilipi by Pratilipi.
the class I18n method getStrings.
@SuppressWarnings("unchecked")
public static Map<String, String> getStrings(Language language) {
Map<String, String> strings = LANG_STRINGS_MAP.get(language);
if (strings == null) {
strings = language == Language.ENGLISH ? new HashMap<String, String>() : (Map<String, String>) ((HashMap<String, String>) getStrings(Language.ENGLISH)).clone();
try {
File langFile = new File(I18n.class.getResource("language." + language.getCode()).toURI());
LineIterator it = FileUtils.lineIterator(langFile, "UTF-8");
while (it.hasNext()) {
String line = it.nextLine();
if (line.indexOf('=') != -1) {
String key = line.substring(0, line.indexOf('=')).trim();
String value = line.substring(line.indexOf('=') + 1).trim();
if (language == Language.ENGLISH || strings.get(key) != null)
strings.put(key, value);
}
}
LineIterator.closeQuietly(it);
LANG_STRINGS_MAP.put(language, strings);
} catch (NullPointerException | URISyntaxException | IOException e) {
logger.log(Level.SEVERE, "Exception while reading from " + language + " language file.", e);
}
}
return strings;
}
use of org.apache.commons.io.LineIterator in project pratilipi by Pratilipi.
the class PratilipiSite method isEligibleForPWA.
private boolean isEligibleForPWA(String email, Language language) {
if (email == null || language == null)
return false;
List<String> lines = new ArrayList<>();
String file = "data/pwa-user-list." + language.getCode();
try {
InputStream inputStream = getClass().getResource(file).openStream();
LineIterator it = IOUtils.lineIterator(inputStream, "UTF-8");
while (it.hasNext()) lines.add(it.next().trim().toLowerCase());
LineIterator.closeQuietly(it);
} catch (NullPointerException | IOException e) {
logger.log(Level.SEVERE, "Exception in reading file: " + file, e);
}
for (String line : lines) {
if (line.isEmpty())
continue;
if (email.equals(line))
return true;
}
return false;
}
use of org.apache.commons.io.LineIterator in project pratilipi by Pratilipi.
the class EmailUtil method sendMail.
@Deprecated
public static void sendMail(String name, String email, String templateName, Language language, Map<String, String> dataModel) throws UnexpectedServerException {
dataModel.put("user_display_name", name);
String senderName = null;
Pattern senderNamePattern = Pattern.compile("<#-- SENDER_NAME:(.+?)-->");
String senderEmail = null;
Pattern senderEmailPattern = Pattern.compile("<#-- SENDER_EMAIL:(.+?)-->");
String subject = null;
Pattern subjectPattern = Pattern.compile("<#-- SUBJECT:(.+?)-->");
String body = FreeMarkerUtil.processTemplate(dataModel, filePath + templateName + "." + language.getCode() + ".ftl");
try {
File file = new File(EmailUtil.class.getResource("template/" + templateName + "." + language.getCode() + ".ftl").toURI());
LineIterator it = FileUtils.lineIterator(file, "UTF-8");
Matcher m = null;
String line = null;
while (it.hasNext()) {
line = it.nextLine().trim();
if (line.isEmpty())
continue;
else if (senderName == null && (m = senderNamePattern.matcher(line)).find())
senderName = m.group(1).trim();
else if (senderEmail == null && (m = senderEmailPattern.matcher(line)).find())
senderEmail = m.group(1).trim();
else if (subject == null && (m = subjectPattern.matcher(line)).find())
subject = m.group(1).trim();
else if (senderName != null && senderEmail != null && subject != null)
break;
}
sendMail(senderName, senderEmail, name, email, subject, body);
} catch (IOException | URISyntaxException e1) {
logger.log(Level.SEVERE, "Failed to process \"" + templateName + "." + language.getCode() + "\" email template.", e1);
throw new UnexpectedServerException();
}
}
use of org.apache.commons.io.LineIterator in project pratilipi by Pratilipi.
the class PratilipiSite method getListTitle.
private String getListTitle(String listName, Language lang) {
String listTitle = null;
try {
String fileName = "list." + lang.getCode() + "." + listName;
InputStream inputStream = DataAccessor.class.getResource("curated/" + fileName).openStream();
LineIterator it = IOUtils.lineIterator(inputStream, "UTF-8");
listTitle = it.nextLine().trim();
LineIterator.closeQuietly(it);
} catch (NullPointerException | IOException e) {
logger.log(Level.SEVERE, "Exception while reading from data file.", e);
}
return listTitle;
}
use of org.apache.commons.io.LineIterator in project pratilipi by Pratilipi.
the class PratilipiSite method createDataModelForStaticPage.
public Map<String, Object> createDataModelForStaticPage(String pageName, Language lang) throws UnexpectedServerException {
StringBuilder content = new StringBuilder();
String staticTitle = null;
try {
String fileName = "static." + (lang == null ? "" : lang.getCode() + ".") + pageName;
File file = new File(getClass().getResource(dataFilePrefix + fileName).toURI());
LineIterator it = FileUtils.lineIterator(file, "UTF-8");
if (it.hasNext())
staticTitle = it.nextLine().trim();
while (it.hasNext()) content.append(it.nextLine() + "<br/>");
LineIterator.closeQuietly(it);
} catch (NullPointerException e) {
return null;
} catch (URISyntaxException | IOException e) {
logger.log(Level.SEVERE, "Exception while reading from data file.", e);
throw new UnexpectedServerException();
}
Map<String, Object> dataModel = new HashMap<String, Object>();
dataModel.put("title", SEOTitleUtil.getStaticPageTitle(pageName, lang));
dataModel.put("staticTitle", staticTitle);
dataModel.put("content", content.toString());
return dataModel;
}
Aggregations