Search in sources :

Example 1 with ScopeInfo

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;
}
Also used : ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

Example 2 with ScopeInfo

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;
}
Also used : ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

Example 3 with ScopeInfo

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);
}
Also used : HandyDate(org.dbflute.helper.HandyDate) ScopeInfo(org.dbflute.util.Srl.ScopeInfo) Date(java.util.Date) HandyDate(org.dbflute.helper.HandyDate)

Example 4 with ScopeInfo

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;
        }
    }
}
Also used : TemplateFileParseFailureException(org.lastaflute.core.template.exception.TemplateFileParseFailureException) SqlAnalyzer(org.dbflute.twowaysql.SqlAnalyzer) DfCollectionUtil(org.dbflute.util.DfCollectionUtil) Arrays(java.util.Arrays) EmbeddedVariableNode(org.dbflute.twowaysql.node.EmbeddedVariableNode) NodeAdviceFactory(org.dbflute.twowaysql.factory.NodeAdviceFactory) Set(java.util.Set) ScopeInfo(org.dbflute.util.Srl.ScopeInfo) BoundValue(org.dbflute.twowaysql.node.BoundValue) TemporalAccessor(java.time.temporal.TemporalAccessor) CommandContextCreator(org.dbflute.twowaysql.context.CommandContextCreator) ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfResourceUtil(org.dbflute.util.DfResourceUtil) CommandContext(org.dbflute.twowaysql.context.CommandContext) SimpleMapPmb(org.dbflute.twowaysql.pmbean.SimpleMapPmb) List(java.util.List) Node(org.dbflute.twowaysql.node.Node) DateTimeFormatter(java.time.format.DateTimeFormatter) Map(java.util.Map) PostConstruct(javax.annotation.PostConstruct) FileTextIO(org.dbflute.helper.filesystem.FileTextIO) Collections(java.util.Collections) Srl(org.dbflute.util.Srl) InputStream(java.io.InputStream) ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

Example 5 with ScopeInfo

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));
        });
    }
}
Also used : TemporalAccessor(java.time.temporal.TemporalAccessor) ScopeInfo(org.dbflute.util.Srl.ScopeInfo) DateTimeFormatter(java.time.format.DateTimeFormatter)

Aggregations

ScopeInfo (org.dbflute.util.Srl.ScopeInfo)42 File (java.io.File)7 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 LinkedHashMap (java.util.LinkedHashMap)6 List (java.util.List)6 FileTextIO (org.dbflute.helper.filesystem.FileTextIO)6 FileInputStream (java.io.FileInputStream)4 FileNotFoundException (java.io.FileNotFoundException)4 LinkedHashSet (java.util.LinkedHashSet)4 IOException (java.io.IOException)3 Arrays (java.util.Arrays)3 Set (java.util.Set)3 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)3 DateTimeFormatter (java.time.format.DateTimeFormatter)2 TemporalAccessor (java.time.temporal.TemporalAccessor)2 DfBuildProperties (org.dbflute.DfBuildProperties)2 DfIllegalPropertySettingException (org.dbflute.exception.DfIllegalPropertySettingException)2 StringKeyMap (org.dbflute.helper.StringKeyMap)2 FileHierarchyTracer (org.dbflute.helper.filesystem.FileHierarchyTracer)2