Search in sources :

Example 1 with JavaPropertiesResult

use of org.dbflute.helper.jprop.JavaPropertiesResult 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;
}
Also used : JavaPropertiesResult(org.dbflute.helper.jprop.JavaPropertiesResult) JavaPropertiesReader(org.dbflute.helper.jprop.JavaPropertiesReader) JavaPropertiesProperty(org.dbflute.helper.jprop.JavaPropertiesProperty) File(java.io.File)

Example 2 with JavaPropertiesResult

use of org.dbflute.helper.jprop.JavaPropertiesResult 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);
}
Also used : JavaPropertiesResult(org.dbflute.helper.jprop.JavaPropertiesResult) JavaPropertiesReader(org.dbflute.helper.jprop.JavaPropertiesReader) DfFreeGenRequest(org.dbflute.logic.manage.freegen.DfFreeGenRequest) Map(java.util.Map)

Aggregations

JavaPropertiesReader (org.dbflute.helper.jprop.JavaPropertiesReader)2 JavaPropertiesResult (org.dbflute.helper.jprop.JavaPropertiesResult)2 File (java.io.File)1 Map (java.util.Map)1 JavaPropertiesProperty (org.dbflute.helper.jprop.JavaPropertiesProperty)1 DfFreeGenRequest (org.dbflute.logic.manage.freegen.DfFreeGenRequest)1