use of org.dbflute.helper.jprop.JavaPropertiesReader in project dbflute-core by dbflute.
the class DfPropHtmlManager method doSetupFamilyProperty.
protected Map<String, DfPropHtmlFileAttribute> doSetupFamilyProperty(DfPropHtmlRequest request, Map<String, Object> requestMap, String propertiesFile, String envType, Map<String, DfPropHtmlFileAttribute> defaultEnvMap) {
final List<File> familyFileList = extractFamilyFileList(request.getRequestName(), requestMap, propertiesFile);
if (familyFileList.isEmpty()) {
return DfCollectionUtil.emptyMap();
}
final String specifiedPureFileName = Srl.substringLastRear(propertiesFile, "/");
final Map<String, DfPropHtmlFileAttribute> attributeMap = DfCollectionUtil.newLinkedHashMap();
DfPropHtmlFileAttribute rootAttribute = null;
if (defaultEnvMap != null) {
// when specified environment
for (DfPropHtmlFileAttribute attribute : defaultEnvMap.values()) {
if (attribute.isRootFile()) {
// always exists here
rootAttribute = attribute;
}
}
}
final DfPropHtmlRequest extendsRequest = getExtendsRequest(request);
for (final File familyFile : familyFileList) {
final String langType = extractLangType(familyFile.getName());
final String fileKey = buildFileKey(envType, familyFile);
final String title = fileKey + ":" + familyFile.getPath();
final JavaPropertiesReader reader = createReader(request, title, familyFile);
final DfPropHtmlFileAttribute extendsAttribute = findExtendsAttribute(extendsRequest, envType, langType);
if (extendsAttribute != null) {
prepareExtendsProperties(request, reader, extendsAttribute);
}
_log.info("...Reading properties family file: " + fileKey);
final JavaPropertiesResult jpropResult = reader.read();
// only base-point properties are target here
// extends properties are used only for override
final List<JavaPropertiesProperty> jpropList = jpropResult.getPropertyBasePointOnlyList();
final Set<String> propertyKeySet = DfCollectionUtil.newLinkedHashSet();
for (JavaPropertiesProperty jprop : jpropList) {
request.addProperty(envType, langType, jprop);
propertyKeySet.add(jprop.getPropertyKey());
}
final DfPropHtmlFileAttribute attribute = new DfPropHtmlFileAttribute(familyFile, envType, langType);
attribute.addPropertyKeyAll(propertyKeySet);
attribute.setKeyCount(jpropList.size());
attribute.setExtendsAttribute(extendsAttribute);
attribute.addDuplicateKeyAll(jpropResult.getDuplicateKeyList());
if (defaultEnvMap != null) {
// when specified environment
if (rootAttribute != null) {
// always true
// every files compare with root file here
attribute.setStandardAttribute(rootAttribute);
} else {
// no way but just in case
final DfPropHtmlFileAttribute standardAttribute = defaultEnvMap.get(langType);
if (standardAttribute != null) {
// same language on standard environment is my standard here
attribute.setStandardAttribute(standardAttribute);
}
// if standard not found, the file exists only in the environment
}
} else {
// when default environment
attribute.toBeDefaultEnv();
if (familyFile.getName().equals(specifiedPureFileName)) {
_log.info(" -> root file: " + specifiedPureFileName + " (" + envType + ")");
attribute.toBeRootFile();
// save for relation to root
rootAttribute = attribute;
}
}
request.addFileAttribute(attribute);
attributeMap.put(langType, attribute);
}
if (rootAttribute != null) {
for (DfPropHtmlFileAttribute attribute : attributeMap.values()) {
if (attribute.isDefaultEnv() && !attribute.isRootFile()) {
attribute.setStandardAttribute(rootAttribute);
}
}
}
return attributeMap;
}
use of org.dbflute.helper.jprop.JavaPropertiesReader in project dbflute-core by dbflute.
the class DfPropTableLoader method createReader.
// ===================================================================================
// Properties Reader
// =================
protected JavaPropertiesReader createReader(String requestName, DfFreeGenResource resource, Map<String, Object> tableMap, Map<String, DfFreeGenRequest> requestMap) {
final String resourceFile = resource.getResourceFile();
final String title = requestName + ":" + resourceFile;
final JavaPropertiesReader reader = new JavaPropertiesReader(title, new JavaPropertiesStreamProvider() {
public InputStream provideStream() throws IOException {
return new FileInputStream(new File(resourceFile));
}
}).encodeAsUTF8();
final String extendsPropRequestKey = "extendsPropRequest";
String extendsPropRequest = (String) tableMap.get(extendsPropRequestKey);
final List<String> extendsPropFileList;
if (extendsPropRequest != null) {
extendsPropFileList = new ArrayList<String>();
while (true) {
final DfFreeGenRequest extendsRequest = requestMap.get(extendsPropRequest);
if (extendsRequest == null) {
throwFreeGenPropExtendsRequestNotFoundException(requestName, extendsPropRequest, requestMap);
}
if (!extendsRequest.isResourceTypeProp()) {
throwFreeGenPropExtendsRequestNotPropException(requestName, extendsPropRequest, extendsRequest);
}
final String extendsFile = extendsRequest.getResource().getResourceFile();
extendsPropFileList.add(extendsFile);
final Map<String, Object> extendsTableMap = extendsRequest.getOptionMap();
extendsPropRequest = (String) extendsTableMap.get(extendsPropRequestKey);
if (extendsPropRequest == null) {
break;
}
}
} else {
// for compatible
@SuppressWarnings("unchecked") final List<String> castList = (List<String>) tableMap.get("extendsPropFileList");
extendsPropFileList = castList;
}
if (extendsPropFileList != null && !extendsPropFileList.isEmpty()) {
for (String extendsPropFile : extendsPropFileList) {
final String resolvedFile = resource.resolveBaseDir(extendsPropFile);
final String extendsTitle = requestName + ":" + extendsPropFile;
reader.extendsProperties(extendsTitle, new JavaPropertiesStreamProvider() {
public InputStream provideStream() throws IOException {
return new FileInputStream(new File(resolvedFile));
}
});
}
}
if (isProperty("isCheckImplicitOverride", tableMap)) {
reader.checkImplicitOverride();
}
if (isProperty("isUseNonNumberVariable", tableMap)) {
reader.useNonNumberVariable();
}
@SuppressWarnings("unchecked") final List<String> variableExceptList = (List<String>) tableMap.get("variableExceptList");
if (variableExceptList != null) {
reader.useVariableExcept(DfCollectionUtil.newHashSet(variableExceptList));
}
if (isProperty("isSuppressVariableOrder", tableMap) || getLittleAdjustmentProperties().isCompatibleFreeGenPropVariableNotOrdered()) {
reader.suppressVariableOrder();
}
return reader;
}
use of org.dbflute.helper.jprop.JavaPropertiesReader in project dbflute-core by dbflute.
the class DfPropTableLoader method loadTable.
// ===================================================================================
// Load Table
// ==========
// ; resourceMap = map:{
// ; resourceType = PROP
// ; resourceFile = ../../../sea.properties
// }
// ; outputMap = map:{
// ; templateFile = MessageDef.vm
// ; outputDirectory = ../src/main/java
// ; package = org.dbflute...
// ; className = MessageDef
// }
// ; optionMap = map:{
// ; exceptKeyList = list:{ prefix:config. }
// ; groupingKeyMap = map:{ label = prefix:label. }
// ; extendsPropRequest = FooProp
// ; extendsPropFileList = list:{ ../../../bar.properties }
// ; isCheckImplicitOverride = false
// }
@Override
public DfFreeGenMetaData loadTable(String requestName, DfFreeGenResource resource, DfFreeGenMapProp mapProp) {
final Map<String, Object> tableMap = mapProp.getOptionMap();
final Map<String, DfFreeGenRequest> requestMap = mapProp.getRequestMap();
final JavaPropertiesReader reader = createReader(requestName, resource, tableMap, requestMap);
final JavaPropertiesResult result;
try {
result = reader.read();
} catch (RuntimeException e) {
final Map<String, Map<String, String>> mappingMap = mapProp.getMappingMap();
throwFreeGenPropReadFailureException(requestName, resource, tableMap, mappingMap, e);
// unreachable
return null;
}
final String resourceFile = resource.getResourceFile();
// #for_now used?
final String tableName = buildTableName(resourceFile);
final List<Map<String, Object>> columnList = toMapList(result, tableMap);
return DfFreeGenMetaData.asOnlyOne(tableMap, tableName, columnList);
}
Aggregations