de.fichtelmax.mojo.messagebundle.generate.MessageResourceParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of messagebundle-maven-plugin Show documentation
Show all versions of messagebundle-maven-plugin Show documentation
A Maven plugin that generates enumerations for message bundles
package de.fichtelmax.mojo.messagebundle.generate;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import de.fichtelmax.mojo.messagebundle.model.MessageBundleInfo;
import de.fichtelmax.mojo.messagebundle.model.MessagePropertyInfo;
public class MessageResourceParser {
public MessageBundleInfo parse(File baseDir, File file) throws IOException {
String packagePath = baseDir.toURI().relativize(file.getParentFile().toURI()).getPath();
if (packagePath.endsWith(File.separator)) {
packagePath = packagePath.substring(0, packagePath.length() - 1);
}
String packageName = packagePath.replace(File.separatorChar, '.');
try (InputStream in = new FileInputStream(file)) {
Properties properties = new Properties();
properties.load(in);
MessageBundleInfo info = new MessageBundleInfo();
info.setBundleFileName(packagePath + File.separatorChar + file.getName());
info.setPackageName(packageName);
info.setName(file.getName().replaceAll("\\..*$", ""));
for (String property : properties.stringPropertyNames()) {
MessagePropertyInfo propertyInfo = new MessagePropertyInfo();
propertyInfo.setPropertyName(property);
propertyInfo.setValue(properties.getProperty(property));
info.getPropertyInfos().add(propertyInfo);
}
return info;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy