• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / thymeleaf-scripting / #1164

pending completion
#1164

Pull #189

github

web-flow
Merge e930cb29c into 34bbfca66
Pull Request #189: Update dependency org.mybatis:mybatis-parent to v38

611 of 621 relevant lines covered (98.39%)

0.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/main/java/org/mybatis/scripting/thymeleaf/processor/MyBatisBindTagProcessor.java
1
/*
2
 *    Copyright 2018-2022 the original author or authors.
3
 *
4
 *    Licensed under the Apache License, Version 2.0 (the "License");
5
 *    you may not use this file except in compliance with the License.
6
 *    You may obtain a copy of the License at
7
 *
8
 *       https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 *    Unless required by applicable law or agreed to in writing, software
11
 *    distributed under the License is distributed on an "AS IS" BASIS,
12
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *    See the License for the specific language governing permissions and
14
 *    limitations under the License.
15
 */
16
package org.mybatis.scripting.thymeleaf.processor;
17

18
import java.util.List;
19
import java.util.Objects;
20

21
import org.mybatis.scripting.thymeleaf.MyBatisBindingContext;
22
import org.thymeleaf.context.ITemplateContext;
23
import org.thymeleaf.engine.AttributeName;
24
import org.thymeleaf.exceptions.TemplateProcessingException;
25
import org.thymeleaf.model.IProcessableElementTag;
26
import org.thymeleaf.processor.element.AbstractAttributeTagProcessor;
27
import org.thymeleaf.processor.element.IElementTagStructureHandler;
28
import org.thymeleaf.standard.expression.Assignation;
29
import org.thymeleaf.standard.expression.AssignationSequence;
30
import org.thymeleaf.standard.expression.AssignationUtils;
31
import org.thymeleaf.standard.expression.IStandardExpression;
32
import org.thymeleaf.templatemode.TemplateMode;
33
import org.thymeleaf.util.StringUtils;
34

35
/**
36
 * The processor class for handling the {@code mybatis:bind} tag. <br>
37
 * This processor register an any value to the MyBatis’s bind variables (similar to that of the {@code <bind>} provided
38
 * by MyBatis core module) This class's implementation was inspired with the {@code StandardWithTagProcessor} provide by
39
 * Thymeleaf.
40
 *
41
 * @author Kazuki Shimizu
42
 *
43
 * @version 1.0.0
44
 *
45
 * @see org.thymeleaf.standard.processor.StandardWithTagProcessor
46
 */
47
public class MyBatisBindTagProcessor extends AbstractAttributeTagProcessor {
48

49
  private static final int PRECEDENCE = 600;
50
  private static final String ATTR_NAME = "bind";
51

52
  /**
53
   * Constructor that can be specified the template mode and dialect prefix.
54
   *
55
   * @param templateMode
56
   *          A target template mode
57
   * @param prefix
58
   *          A target dialect prefix
59
   */
60
  public MyBatisBindTagProcessor(final TemplateMode templateMode, final String prefix) {
61
    super(templateMode, prefix, null, false, ATTR_NAME, true, PRECEDENCE, true);
1✔
62
  }
1✔
63

64
  /**
65
   * {@inheritDoc}
66
   */
67
  @Override
68
  protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName,
69
      String attributeValue, IElementTagStructureHandler structureHandler) {
70
    AssignationSequence assignations = AssignationUtils.parseAssignationSequence(context, attributeValue, false);
1✔
71

72
    List<Assignation> assignationValues = assignations.getAssignations();
1✔
73
    assignationValues.forEach(assignation -> {
1✔
74
      IStandardExpression nameExp = assignation.getLeft();
1✔
75
      Object name = nameExp.execute(context);
1✔
76
      IStandardExpression valueExp = assignation.getRight();
1✔
77
      Object value = valueExp.execute(context);
1✔
78

79
      if (Objects.isNull(name) || StringUtils.isEmpty(name.toString())) {
1✔
80
        throw new TemplateProcessingException(
1✔
81
            "Variable name expression evaluated as null or empty: \"" + nameExp + "\"");
82
      }
83

84
      MyBatisBindingContext bindingContext = MyBatisBindingContext.load(context);
1✔
85
      bindingContext.setCustomBindVariable(name.toString(), value);
1✔
86
    });
1✔
87
  }
1✔
88

89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc