use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.
the class DfMailFluteTableLoader method doLoad.
protected Map<String, Map<String, Object>> doLoad(String targetDir, String targetExt, String targetKeyword, List<String> exceptPathList, Map<String, Object> tableMap) {
final List<File> fileList = DfCollectionUtil.newArrayList();
final File baseDir = new File(targetDir);
collectFile(fileList, targetExt, targetKeyword, exceptPathList, baseDir);
final Map<String, Map<String, Object>> schemaMap = DfCollectionUtil.newLinkedHashMap();
final FileTextIO textIO = new FileTextIO().encodeAsUTF8().removeUTF8Bom().replaceCrLfToLf();
for (File bodyFile : fileList) {
final Map<String, Object> table = DfCollectionUtil.newHashMap();
final String fileName = bodyFile.getName();
table.put("fileName", fileName);
final String className = Srl.camelize(Srl.substringLastFront(fileName, targetExt)) + "Postcard";
// used as output file name
table.put("className", className);
table.put("camelizedName", className);
final String addedPkg = deriveAdditionalPackage(tableMap, baseDir, bodyFile);
if (Srl.is_NotNull_and_NotEmpty(addedPkg)) {
table.put("additionalPackage", addedPkg);
}
final String domainPath = buildDomainPath(bodyFile, targetDir);
// e.g. /member/member_registration.dfmail
table.put("domainPath", domainPath);
// e.g. member/member_registration.dfmail
table.put("resourcePath", Srl.ltrim(domainPath, "/"));
table.put("defName", buildUpperSnakeName(domainPath));
{
final String dirPath = Srl.substringLastFront(domainPath, "/");
final String snakeCase = buildPlainSnakeName(dirPath);
final String camelizedName = Srl.camelize(snakeCase);
table.put("camelizedDir", camelizedName);
table.put("capCamelDir", Srl.initCap(camelizedName));
table.put("uncapCamelDir", Srl.initUncap(camelizedName));
}
{
final String snakeCase = buildPlainSnakeName(fileName);
final String camelizedName = Srl.camelize(snakeCase);
table.put("camelizedFile", camelizedName);
table.put("capCamelFile", Srl.initCap(camelizedName));
table.put("uncapCamelFile", Srl.initUncap(camelizedName));
}
final String plainText = readText(textIO, toPath(bodyFile));
final String delimiter = META_DELIMITER;
if (!plainText.contains(delimiter)) {
throwBodyMetaNotFoundException(toPath(bodyFile), plainText);
}
verifyFormat(toPath(bodyFile), plainText, delimiter);
final String headerComment = Srl.extractScopeFirst(plainText, COMMENT_BEGIN, COMMENT_END).getContent();
final ScopeInfo titleScope = Srl.extractScopeFirst(headerComment, TITLE_BEGIN, TITLE_END);
final String desc = Srl.substringFirstRear(headerComment, TITLE_END);
table.put("headerComment", headerComment);
table.put("title", titleScope.getContent());
table.put("description", desc);
final String bodyMeta = Srl.substringFirstFront(plainText, delimiter);
final boolean hasOptionPlusHtml = hasOptionPlusHtml(bodyMeta, delimiter);
table.put("hasOptionPlusHtml", hasOptionPlusHtml);
final String htmlFilePath = deriveHtmlFilePath(toPath(bodyFile));
if (new File(htmlFilePath).exists()) {
if (!hasOptionPlusHtml) {
throwNoPlusHtmlButHtmlTemplateExistsException(toPath(bodyFile), htmlFilePath, bodyMeta);
}
verifyMailHtmlTemplateTextFormat(htmlFilePath, readText(textIO, htmlFilePath));
} else {
if (hasOptionPlusHtml) {
throwNoHtmlTemplateButPlusHtmlExistsException(toPath(bodyFile), htmlFilePath, bodyMeta);
}
}
final Map<String, String> propertyNameTypeMap = new LinkedHashMap<String, String>();
final Map<String, String> propertyNameOptionMap = new LinkedHashMap<String, String>();
final Set<String> propertyNameSet = new LinkedHashSet<String>();
processAutoDetect(plainText, propertyNameTypeMap, propertyNameOptionMap, propertyNameSet);
processSpecifiedDetect(plainText, propertyNameTypeMap, propertyNameOptionMap, propertyNameSet);
final List<Map<String, String>> propertyList = new ArrayList<Map<String, String>>();
final StringBuilder commaSb = new StringBuilder();
for (String propertyName : propertyNameSet) {
final Map<String, String> property = new LinkedHashMap<String, String>();
property.put("propertyName", propertyName);
property.put("capCalemName", Srl.initCap(propertyName));
property.put("uncapCalemName", Srl.initUncap(propertyName));
// exists
property.put("propertyType", propertyNameTypeMap.get(propertyName));
propertyList.add(property);
if (commaSb.length() > 0) {
commaSb.append(", ");
}
commaSb.append("\"").append(propertyName).append("\"");
}
table.put("propertyList", propertyList);
table.put("propertyNameCommaString", commaSb.toString());
schemaMap.put(fileName, table);
}
return schemaMap;
}
use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.
the class DfCraftDiffAssertProvider method processBasicEquals.
protected DfCraftDiffAssertHandler processBasicEquals(File sqlFile, String plainSql, final String resolvedSql) {
// space after '--' has been resolved here
final String keyPrefix = "--#df:assertEquals(";
final String keySuffix = ")#";
final ScopeInfo scopeFirst = Srl.extractScopeFirst(resolvedSql, keyPrefix, keySuffix);
if (scopeFirst == null) {
// not found
return null;
}
final String craftTitle = scopeFirst.getContent().trim();
if (Srl.is_Null_or_TrimmedEmpty(craftTitle)) {
throwCraftDiffCraftTitleNotFoundException(sqlFile, plainSql);
}
// *unsupported envType on assert definition
return new DfCraftDiffAssertHandler(_craftMetaDir, _nextDirection, craftTitle);
}
use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.
the class DfArrangeQueryDocSetupper method analyzeArrangeQueryLineList.
protected List<DfArrangeQueryMethod> analyzeArrangeQueryLineList(String tableDbName, List<String> lineList) {
// #hope jflute should use Java parser? (2018/12/31)
final List<DfArrangeQueryMethod> methodList = new ArrayList<DfArrangeQueryMethod>();
String javadocTitle = null;
boolean inJavaDoc = false;
for (String line : lineList) {
final String trimmedLine = Srl.trim(line);
if (Srl.equalsPlain(trimmedLine, "/**")) {
inJavaDoc = true;
javadocTitle = null;
} else if (Srl.contains(trimmedLine, "*/")) {
inJavaDoc = false;
} else if (inJavaDoc && Srl.startsWith(trimmedLine, "*")) {
if (javadocTitle == null) {
// to use first line
javadocTitle = Srl.substringFirstRear(line, "*").trim();
}
} else if (trimmedLine.isEmpty()) {
// empty line
// may be different
javadocTitle = null;
} else if (trimmedLine.startsWith("//")) {
// line comment line
// may be different
javadocTitle = null;
} else if (Srl.containsAny(line, "public", "protected", "private") && !Srl.contains(line, METHOD_PREFIX)) {
// other field or method
javadocTitle = null;
}
if (isArrangeQueryMethodFirstLine(line, trimmedLine)) {
final ScopeInfo scopeFirst = Srl.extractScopeFirst(line, METHOD_PREFIX, "(");
if (scopeFirst == null) {
// basically no way, but just in case
continue;
}
final String businessName = scopeFirst.getContent();
if (businessName.isEmpty()) {
// e.g. arrange(), may be in TemplateClass
continue;
}
final String methodName = METHOD_PREFIX + businessName;
final DfArrangeQueryMethod method = new DfArrangeQueryMethod(tableDbName, methodName);
if (javadocTitle != null) {
method.setTitle(javadocTitle);
}
methodList.add(method);
}
}
return methodList;
}
use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.
the class DfTableXlsReader method resolveLargeDataIfNeeds.
protected String resolveLargeDataIfNeeds(DfDataTable table, int columnIndex, Row row, String str) {
if (str == null) {
return null;
}
final String refPrefix = LDATA_REF_PREFIX;
final String refSuffix = LDATA_REF_SUFFIX;
if (_largeDataMap != null && str.startsWith(refPrefix) && str.endsWith(refSuffix)) {
final ScopeInfo scopeInfo = Srl.extractScopeFirst(str, refPrefix, refSuffix);
final String dataKey = scopeInfo.getContent();
final DfDataColumn column = table.getColumn(columnIndex);
final String columnTitle = table.getTableDbName() + "." + column.getColumnDbName();
final Map<String, String> dataMap = _largeDataMap.get(columnTitle);
if (dataMap != null) {
final String largeData = dataMap.get(dataKey);
if (largeData != null) {
return largeData;
} else {
throwLargeDataReferenceDataNotFoundException(table, columnIndex, row, str, dataKey);
}
} else {
throwLargeDataReferenceDataNotFoundException(table, columnIndex, row, str, dataKey);
}
}
return str;
}
use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.
the class DfDispatchVariableResolver method handleEnvironmentVariable.
// -----------------------------------------------------
// Environment Variable
// --------------------
protected DfEnvironmentVariableInfo handleEnvironmentVariable(String propTitle, String plainValue) {
final String prefix = "$$env:";
final String suffix = "$$";
if (!existsEnvironmentVariable(propTitle, plainValue, prefix, suffix)) {
return null;
}
// e.g. $$env:DBFLUTE_MAIHAMADB_JDBC_URL$$
final Map<String, String> envMap = extractEnvironmentMap();
final ScopeInfo scopeInfo = Srl.extractScopeFirst(plainValue, prefix, suffix);
// e.g. DBFLUTE_MAIHAMADB_JDBC_URL
final String envKey = scopeInfo.getContent().trim();
final String envValue = envMap.get(envKey);
final String realValue;
if (envValue != null) {
// switch variable to value
final String front = Srl.ltrim(scopeInfo.substringInterspaceToPrevious());
final String rear = Srl.rtrim(Srl.substringFirstFront(scopeInfo.substringInterspaceToNext(), "|"));
realValue = front + envValue + rear;
} else {
// no environment
final String interspaceToNext = scopeInfo.substringInterspaceToNext().trim();
if (interspaceToNext.contains("|")) {
// e.g. $$env:DBFLUTE_MAIHAMADB_JDBC_URL$$ | jdbc:mysql://localhost:3306/maihamadb
realValue = Srl.substringFirstRear(interspaceToNext, "|").trim();
} else {
throwNotFoundEnvironmentVariableException(propTitle, plainValue, envKey, envMap);
// unreachable
return null;
}
}
final DfEnvironmentVariableInfo info = new DfEnvironmentVariableInfo();
info.setEnvName(envKey);
info.setEnvValue(realValue);
return info;
}
Aggregations