use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.
the class DfClassificationResourceAnalyzer method extractRelatedColumnNameFronTitleLine.
protected AnalyzedTitleLine extractRelatedColumnNameFronTitleLine(String line) {
if (!isTitleLine(line)) {
String msg = "The line should be title line: line=" + line;
throw new IllegalArgumentException(msg);
}
final String connectBeginMark = "[";
final String connectEndMark = "]:";
final String wildCard = "*";
final String prefixMark = DfNameHintUtil.PREFIX_MARK;
final String suffixMark = DfNameHintUtil.SUFFIX_MARK;
if (!Srl.containsAll(line, connectBeginMark, connectEndMark)) {
return null;
}
line = line.trim();
line = removeRearXmlEndIfNeeds(line);
final AnalyzedTitleLine titleLine = new AnalyzedTitleLine();
final ScopeInfo scopeFirst = Srl.extractScopeFirst(line, connectBeginMark, connectEndMark);
if (scopeFirst == null) {
// basically no way
return null;
}
titleLine.setTitle(scopeFirst.getContent().trim());
final String relatedColumnName;
final String option;
{
String pureValue = Srl.substringFirstRear(line, connectEndMark).trim();
if (pureValue.startsWith(wildCard)) {
// *_FLG
pureValue = suffixMark + pureValue.substring(wildCard.length());
} else if (pureValue.endsWith(wildCard)) {
// LD_*
pureValue = pureValue.substring(0, pureValue.lastIndexOf(wildCard));
pureValue = prefixMark + pureValue;
}
if (pureValue.contains("|")) {
relatedColumnName = Srl.substringFirstFront(pureValue, "|").trim();
option = Srl.substringFirstRear(pureValue, "|").trim();
} else {
relatedColumnName = pureValue;
option = null;
}
}
titleLine.setRelatedColumnName(relatedColumnName);
if (Srl.is_NotNull_and_NotTrimmedEmpty(option)) {
final String codeTypeNumber = DfClassificationTop.CODE_TYPE_NUMBER;
if (Srl.containsIgnoreCase(option, codeTypeNumber)) {
titleLine.setCodeType(codeTypeNumber);
}
titleLine.setCheckImplicitSet(Srl.containsIgnoreCase(option, "check"));
}
return titleLine;
}
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 (plainValue != null && plainValue.startsWith(prefix) && plainValue.endsWith(suffix)) {
final ScopeInfo scopeInfo = Srl.extractScopeWide(plainValue, prefix, suffix);
final ProcessBuilder pb = new ProcessBuilder();
final Map<String, String> map = pb.environment();
if (map != null) {
// might be no way, just in case
final String key = scopeInfo.getContent().trim();
final String realValue = map.get(key);
if (realValue != null) {
final DfEnvironmentVariableInfo info = new DfEnvironmentVariableInfo();
info.setEnvName(key);
info.setEnvValue(realValue);
return info;
} else {
throwNotFoundEnvironmentVariableException(propTitle, plainValue, key, map);
}
}
}
return null;
}
use of org.dbflute.util.Srl.ScopeInfo in project lastaflute by lastaflute.
the class RelativeDateScript method resolveHardCodingDate.
public Date resolveHardCodingDate(String relativeDate) {
// $(2014/07/10)
// $(2014/07/10).addDay(1)
// $(2014/07/10 12:34:56)
// $(2014/07/10 12:34:56).addDay(1).moveToDayJust()
// $(2014/07/10).addMonth(3).moveToMonthTerminal()
final ScopeInfo first = Srl.extractScopeFirst(relativeDate, HARD_CODING_BEGIN_MARK, HARD_CODING_END_MARK);
if (first == null) {
throwRelativeDateHandyDateNotFoundException(relativeDate);
}
final String baseDateExp = first.getContent();
final Date date = new HandyDate(Srl.unquoteDouble(baseDateExp)).getDate();
// e.g. .addDay(3)
final String nextExp = first.substringInterspaceToNext();
return resolveRelativeDate(nextExp, date);
}
use of org.dbflute.util.Srl.ScopeInfo in project lastaflute by lastaflute.
the class SimpleTemplateManager method verifyFormat.
// ===================================================================================
// Verify Format
// =============
protected void verifyFormat(String templatePath, String evaluated, String delimiter) {
final String meta = Srl.substringFirstFront(evaluated, delimiter);
if (!meta.endsWith(LF)) {
// also CRLF checked
throwBodyMetaNoIndependentDelimiterException(templatePath, evaluated);
}
final int rearIndex = evaluated.indexOf(delimiter) + delimiter.length();
if (evaluated.length() > rearIndex) {
// just in case (empty template possible?)
final String rearFirstStr = evaluated.substring(rearIndex, rearIndex + 1);
if (!Srl.equalsPlain(rearFirstStr, LF, CR)) {
// e.g. >>> Hello, ...
throwBodyMetaNoIndependentDelimiterException(templatePath, evaluated);
}
}
if (!meta.startsWith(COMMENT_BEGIN)) {
// also leading spaces not allowed
throwTemplateMetaNotStartWithHeaderCommentException(templatePath, evaluated, meta);
}
if (!meta.contains(COMMENT_END)) {
throwBodyMetaHeaderCommentEndMarkNotFoundException(templatePath, evaluated, meta);
}
final String headerComment = Srl.extractScopeFirst(evaluated, COMMENT_BEGIN, COMMENT_END).getContent();
final ScopeInfo titleScope = Srl.extractScopeFirst(headerComment, TITLE_BEGIN, TITLE_END);
if (titleScope == null) {
throwBodyMetaTitleCommentNotFoundException(templatePath, evaluated);
}
final String desc = Srl.substringFirstRear(headerComment, TITLE_END);
if (desc.isEmpty()) {
throwBodyMetaDescriptionCommentNotFoundException(templatePath, evaluated);
}
final String rearMeta = Srl.substringFirstRear(meta, COMMENT_END);
// no way because of already checked
// if (!rearMeta.contains(LF)) {
// }
final List<String> splitList = Srl.splitList(rearMeta, LF);
if (!splitList.get(0).trim().isEmpty()) {
// after '*/'
throwBodyMetaHeaderCommentEndMarkNoIndependentException(templatePath, evaluated);
}
final int nextIndex = 1;
if (splitList.size() > nextIndex) {
// after header comment
final List<String> nextList = splitList.subList(nextIndex, splitList.size());
final int nextSize = nextList.size();
int index = 0;
for (String line : nextList) {
if (index == nextSize - 1) {
// last loop
if (line.isEmpty()) {
// empty line only allowed in last loop
break;
}
}
if (!allowedPrefixList.stream().anyMatch(prefix -> line.startsWith(prefix))) {
throwBodyMetaUnknownLineException(templatePath, evaluated, line);
}
if (line.startsWith(OPTION_LABEL)) {
final String options = Srl.substringFirstRear(line, OPTION_LABEL);
final List<String> optionList = Srl.splitListTrimmed(options, ".");
for (String option : optionList) {
if (!optionSet.contains(option)) {
throwBodyMetaUnknownOptionException(templatePath, evaluated, option);
}
}
}
++index;
}
}
}
use of org.dbflute.util.Srl.ScopeInfo in project lastaflute by lastaflute.
the class SimpleTemplateManager method setupFormatAsValueIfNeeds.
// -----------------------------------------------------
// formatAs()
// ----------
protected void setupFormatAsValueIfNeeds(BoundValue boundValue, String optionDef) {
if (Srl.is_Null_or_TrimmedEmpty(optionDef)) {
return;
}
final Object targetValue = boundValue.getTargetValue();
if (targetValue == null) {
return;
}
if (targetValue instanceof TemporalAccessor) {
// e.g. LocalDate, LocalDateTime
final TemporalAccessor temporal = (TemporalAccessor) targetValue;
final List<String> optionList = Srl.splitListTrimmed(optionDef, "|");
final String formatAsBegin = "formatAs(";
final String formatAsEnd = ")";
optionList.stream().filter(op -> {
return op.startsWith(formatAsBegin) && op.endsWith(formatAsEnd);
}).findFirst().ifPresent(op -> {
// e.g. /*pmb.sea:formatAs('yyyy/MM/dd')*/
final ScopeInfo scope = Srl.extractScopeWide(op, formatAsBegin, formatAsEnd);
final String content = scope.getContent().trim();
if (!Srl.isQuotedSingle(content)) {
throwTemplateFormatAsValueNotQuotedException(optionDef);
}
final String datePattern = Srl.unquoteSingle(content);
final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(datePattern);
boundValue.setTargetValue(formatter.format(temporal));
});
}
}
Aggregations