Search in sources :

Example 36 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.

the class DfLanguagePropertyPackageResolver method processListType.

protected String processListType(String typeName, boolean exceptUtil, String listPkg, String listName) {
    final String listBegin = listName + "<";
    final String listEnd = ">";
    if (typeName.startsWith(listBegin) && typeName.endsWith(listEnd)) {
        final ScopeInfo scope = Srl.extractScopeWide(typeName, listBegin, listEnd);
        final String content = scope.getContent();
        final String resolvedContent = doResolvePackageName(content, exceptUtil);
        return listPkg + "." + listBegin + resolvedContent + listEnd;
    } else {
        return null;
    }
}
Also used : ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

Example 37 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.

the class DfMailFluteTableLoader method verifyFormat.

// *very similar logic also exists on MailFlute
// ===================================================================================
// Verify Format
// =============
protected void verifyFormat(String bodyFile, String plainText, String delimiter) {
    final String meta = Srl.substringFirstFront(plainText, delimiter);
    if (!meta.endsWith(LF)) {
        // also CRLF checked
        throwBodyMetaNoIndependentDelimiterException(bodyFile, plainText);
    }
    final int rearIndex = plainText.indexOf(delimiter) + delimiter.length();
    if (plainText.length() > rearIndex) {
        // just in case (empty mail possible?)
        final String rearFirstStr = plainText.substring(rearIndex, rearIndex + 1);
        if (!Srl.equalsPlain(rearFirstStr, LF, CR)) {
            // e.g. >>> Hello, ...
            throwBodyMetaNoIndependentDelimiterException(bodyFile, plainText);
        }
    }
    if (!meta.startsWith(COMMENT_BEGIN)) {
        // also leading spaces not allowed
        throwBodyMetaNotStartWithHeaderCommentException(bodyFile, plainText, meta);
    }
    if (!meta.contains(COMMENT_END)) {
        throwBodyMetaHeaderCommentEndMarkNotFoundException(bodyFile, plainText, meta);
    }
    final String headerComment = Srl.extractScopeFirst(plainText, COMMENT_BEGIN, COMMENT_END).getContent();
    final ScopeInfo titleScope = Srl.extractScopeFirst(headerComment, TITLE_BEGIN, TITLE_END);
    if (titleScope == null) {
        throwBodyMetaTitleCommentNotFoundException(bodyFile, plainText);
    }
    final String desc = Srl.substringFirstRear(headerComment, TITLE_END);
    if (desc.isEmpty()) {
        throwBodyMetaDescriptionCommentNotFoundException(bodyFile, plainText);
    }
    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(bodyFile, plainText);
    }
    if (!splitList.get(1).startsWith(SUBJECT_LABEL)) {
        // also leading spaces not allowed
        throwBodyMetaSubjectNotFoundException(bodyFile, plainText);
    }
    final int nextIndex = 2;
    if (splitList.size() > nextIndex) {
        // after subject
        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(bodyFile, plainText, line);
            }
            // option check is not here because it can be added in MailFlute
            // 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(bodyFile, plainText, option);
            // }
            // }
            // }
            ++index;
        }
    }
}
Also used : Arrays(java.util.Arrays) DfFreeGenMapProp(org.dbflute.logic.manage.freegen.DfFreeGenMapProp) DfFreeGenTableLoader(org.dbflute.logic.manage.freegen.DfFreeGenTableLoader) ScopeInfo(org.dbflute.util.Srl.ScopeInfo) DfBasicProperties(org.dbflute.properties.DfBasicProperties) DfParameterAutoDetectAssist(org.dbflute.logic.sql2entity.analyzer.DfParameterAutoDetectAssist) ArrayList(java.util.ArrayList) DfLanguageDependency(org.dbflute.logic.generate.language.DfLanguageDependency) LinkedHashMap(java.util.LinkedHashMap) ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) Map(java.util.Map) FileHierarchyTracer(org.dbflute.helper.filesystem.FileHierarchyTracer) Srl(org.dbflute.util.Srl) LinkedHashSet(java.util.LinkedHashSet) DfCollectionUtil(org.dbflute.util.DfCollectionUtil) Set(java.util.Set) DfParameterAutoDetectProcess(org.dbflute.logic.sql2entity.analyzer.DfParameterAutoDetectProcess) DfNameHintUtil(org.dbflute.util.DfNameHintUtil) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) DfBuildProperties(org.dbflute.DfBuildProperties) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) DfFreeGenMetaData(org.dbflute.logic.manage.freegen.DfFreeGenMetaData) List(java.util.List) DfSql2EntityMarkAnalyzer(org.dbflute.logic.sql2entity.analyzer.DfSql2EntityMarkAnalyzer) DfParameterAutoDetectBindNode(org.dbflute.logic.sql2entity.analyzer.DfParameterAutoDetectBindNode) IfNode(org.dbflute.twowaysql.node.IfNode) FileHierarchyTracingHandler(org.dbflute.helper.filesystem.FileHierarchyTracingHandler) DfLanguagePropertyPackageResolver(org.dbflute.logic.generate.language.pkgstyle.DfLanguagePropertyPackageResolver) DfFreeGenResource(org.dbflute.logic.manage.freegen.DfFreeGenResource) FileTextIO(org.dbflute.helper.filesystem.FileTextIO) DfSql2EntityMark(org.dbflute.logic.sql2entity.analyzer.DfSql2EntityMark) ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

Example 38 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.

the class DfRefreshMan method detectEclipseProjectName.

protected String detectEclipseProjectName() {
    // e.g.
    // PROJECT_ROOT
    // |-dbflute_maihamadb
    // |-mydbflute
    // |-...
    // |-.project
    final File projectFile = new File("../.project");
    if (!projectFile.exists()) {
        return null;
    }
    final Set<String> resultSet = new HashSet<String>();
    try {
        new FileTextIO().encodeAsUTF8().readFilteringLine(new FileInputStream(projectFile), new FileTextLineFilter() {

            boolean _found = false;

            public String filter(String line) {
                if (_found || !line.contains("<name>")) {
                    return null;
                }
                ScopeInfo scopeInfo = Srl.extractScopeFirst(line, "<name>", "</name>");
                if (scopeInfo == null) {
                    // basically no way, just in case
                    return null;
                }
                final String content = scopeInfo.getContent().trim();
                resultSet.add(content);
                _found = true;
                return null;
            }
        });
    } catch (FileNotFoundException ignored) {
        // no way because of already checked, just in case
        return null;
    }
    if (resultSet.isEmpty()) {
        _log.info("*The .project file exists but not found project name: " + projectFile);
        return null;
    }
    return resultSet.iterator().next();
}
Also used : FileTextIO(org.dbflute.helper.filesystem.FileTextIO) FileNotFoundException(java.io.FileNotFoundException) FileTextLineFilter(org.dbflute.helper.filesystem.FileTextLineFilter) ScopeInfo(org.dbflute.util.Srl.ScopeInfo) File(java.io.File) FileInputStream(java.io.FileInputStream) HashSet(java.util.HashSet)

Example 39 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.

the class JavaPropertiesReader method reflectToVariableList.

protected void reflectToVariableList(String key, List<ScopeInfo> variableScopeList, List<Integer> variableNumberList, List<String> variableStringList) {
    for (ScopeInfo scopeInfo : variableScopeList) {
        final String content = scopeInfo.getContent();
        final Integer variableNumber = valueOfVariableNumber(key, content);
        if (variableNumber != null) {
            // for non-number option
            variableNumberList.add(variableNumber);
        }
        // contains all elements
        variableStringList.add(content);
    }
}
Also used : ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

Example 40 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.

the class SubQueryIndentProcessor method moveSubQueryEndToRear.

// should be checked before calling if on last line
public static String moveSubQueryEndToRear(String exp) {
    final String sqend = END_MARK_PREFIX;
    final String idterm = IDENTITY_TERMINAL;
    final ScopeInfo lastScope = Srl.extractScopeLast(exp, sqend, idterm);
    final String scopeStr = lastScope.getScope();
    final String front = exp.substring(0, lastScope.getBeginIndex());
    final String rear = exp.substring(lastScope.getEndIndex());
    return front + rear + scopeStr;
}
Also used : ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

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