Skip to content

Commit

Permalink
1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrninistrator committed Dec 25, 2024
1 parent 8e2af33 commit 14ecdfb
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*.txt
src/test/resources/formatted_html
src/test/resources/error_html
src/test/resources/error_text_file
src/test/resources/raw_html
src/test/resources/text_file
src/test/java/test/usddi/local
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ lifeline.box.width
lifeline.box.height
```

- 1.0.3

返回消息支持为空

# 3. 示例

## 3.1. 示例 - 基本
Expand Down Expand Up @@ -129,7 +133,7 @@ sh run.sh [文本文件路径]
- Gradle

```
testImplementation 'com.github.adrninistrator:uml-sequence-diagram-drawio:1.0.2'
testImplementation 'com.github.adrninistrator:uml-sequence-diagram-drawio:1.0.3'
```

- Maven
Expand All @@ -138,7 +142,7 @@ testImplementation 'com.github.adrninistrator:uml-sequence-diagram-drawio:1.0.2'
<dependency>
<groupId>com.github.adrninistrator</groupId>
<artifactId>uml-sequence-diagram-drawio</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>
<type>provided</type>
</dependency>
```
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'java'
apply plugin: 'java-library'

group 'com.github.adrninistrator'
version = "1.0.2"
version = "1.0.3"
def projectName = "uml-sequence-diagram-drawio"
description = "${projectName}"
sourceCompatibility = 1.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class USDDIConstants {
public static final BigDecimal LIFELINE_BOX_WIDTH_HEIGHT_MULTIPLE = BigDecimal.valueOf(2);

// Lifeline方框与文字的间距,横向
public static final BigDecimal LIFELINE_BOX_BORDER_TEXT_SPACE_HORIZONTAL = BigDecimal.valueOf(2);
public static final BigDecimal LIFELINE_BOX_BORDER_TEXT_SPACE_HORIZONTAL = BigDecimal.valueOf(4);

// 消息宽度最大允许占用开始与结束的生命线之间水平间距的比例
public static final BigDecimal MESSAGE_MAX_WIDTH_PERCENTAGE_LIFELINE = BigDecimal.valueOf(0.7D);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/adrninistrator/usddi/conf/ConfManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.adrninistrator.usddi.common.USDDIConstants;
import com.adrninistrator.usddi.exceptions.ConfException;
import com.adrninistrator.usddi.util.USDDIUtil;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -114,7 +115,7 @@ public boolean handleStyleConf() {
* @throws ConfException
*/
private boolean checkBlank(String value, String key, String configFilePath, boolean allowEmpty) throws ConfException {
if (USDDIUtil.isStrEmpty(value)) {
if (StringUtils.isBlank(value)) {
if (!allowEmpty) {
throw new ConfException("配置文件中未指定参数: " + configFilePath + " " + key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.adrninistrator.usddi.handler.base.BaseHandler;
import com.adrninistrator.usddi.html.HtmlHandler;
import com.adrninistrator.usddi.logger.DebugLogger;
import com.adrninistrator.usddi.util.USDDIUtil;
import org.apache.commons.lang3.StringUtils;

/**
* @author adrninistrator
Expand Down Expand Up @@ -52,7 +52,7 @@ public boolean handleDescription(String text) {
// 处理当前处理到的y坐标,加上描述的高度
usedVariables.addCurrentY(this.getClass(), "加上描述的高度", USDDIConstants.DESCRIPTION_HEIGHT);

if (!USDDIUtil.isStrEmpty(link)) {
if (StringUtils.isNotBlank(link)) {
// 未指定链接
descriptionInfo.setLink(link);
// 处理当前处理到的y坐标,加上描述与生命线的间距
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.adrninistrator.usddi.jaxb.dto.MxRoot;
import com.adrninistrator.usddi.jaxb.dto.UserObject;
import com.adrninistrator.usddi.jaxb.util.JAXBUtil;
import com.adrninistrator.usddi.util.USDDIUtil;
import org.apache.commons.lang3.StringUtils;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -395,10 +395,10 @@ private String getLifelineStyle() {
if (confStyleInfo.getLineWidthOfLifeline() != null) {
map.put("strokeWidth", confStyleInfo.getLineWidthOfLifeline().toPlainString());
}
if (!USDDIUtil.isStrEmpty(confStyleInfo.getLineColorOfLifeline())) {
if (StringUtils.isNotBlank(confStyleInfo.getLineColorOfLifeline())) {
map.put("strokeColor", confStyleInfo.getLineColorOfLifeline());
}
if (!USDDIUtil.isStrEmpty(confStyleInfo.getBoxColorOfLifeline())) {
if (StringUtils.isNotBlank(confStyleInfo.getBoxColorOfLifeline())) {
map.put("fillColor", confStyleInfo.getBoxColorOfLifeline());
}

Expand All @@ -414,10 +414,10 @@ private String getActivationStyle() {
if (confStyleInfo.getLineWidthOfActivation() != null) {
map.put("strokeWidth", confStyleInfo.getLineWidthOfActivation().toPlainString());
}
if (!USDDIUtil.isStrEmpty(confStyleInfo.getLineColorOfActivation())) {
if (StringUtils.isNotBlank(confStyleInfo.getLineColorOfActivation())) {
map.put("strokeColor", confStyleInfo.getLineColorOfActivation());
}
if (!USDDIUtil.isStrEmpty(confStyleInfo.getBoxColorOfActivation())) {
if (StringUtils.isNotBlank(confStyleInfo.getBoxColorOfActivation())) {
map.put("fillColor", confStyleInfo.getBoxColorOfActivation());
}

Expand All @@ -430,7 +430,7 @@ private Map<String, String> getMessageStyle() {
if (confStyleInfo.getLineWidthOfMessage() != null) {
map.put("strokeWidth", confStyleInfo.getLineWidthOfMessage().toPlainString());
}
if (!USDDIUtil.isStrEmpty(confStyleInfo.getLineColorOfMessage())) {
if (StringUtils.isNotBlank(confStyleInfo.getLineColorOfMessage())) {
map.put("strokeColor", confStyleInfo.getLineColorOfMessage());
}
return map;
Expand Down Expand Up @@ -494,13 +494,13 @@ private String getStyleStringFromMap(Map<String, String> map) {
// 处理文字及字体
private String handleTextWithFont(String text, String textFont, Integer textSize, String textColor) {
StringBuilder textStyle = new StringBuilder();
if (!USDDIUtil.isStrEmpty(textFont)) {
if (StringUtils.isNotBlank(textFont)) {
textStyle.append(" ").append("face=\"").append(textFont).append("\"");
}
if (textSize != null) {
textStyle.append(" ").append("style=\"font-size: ").append(textSize).append("px\"");
}
if (!USDDIUtil.isStrEmpty(textColor)) {
if (StringUtils.isNotBlank(textColor)) {
textStyle.append(" ").append("color=\"").append(textColor).append("\"");
}
if (textStyle.length() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.adrninistrator.usddi.common.USDDIConstants;
import com.adrninistrator.usddi.dto.lifeline.LifelineName;
import com.adrninistrator.usddi.enums.MessageTypeEnum;
import com.adrninistrator.usddi.util.USDDIUtil;
import org.apache.commons.lang3.StringUtils;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -77,13 +77,13 @@ public void writeDescription(String description, String link) throws IOException
}
writeDescriptionDone = true;

if (USDDIUtil.isStrEmpty(description)) {
if (StringUtils.isBlank(description)) {
throw new RuntimeException("描述为空");
}

writer.write(USDDIConstants.DESCRIPTION_FLAG);
writer.write(description);
if (!USDDIUtil.isStrEmpty(link)) {
if (StringUtils.isNotBlank(link)) {
writer.write(USDDIConstants.LINK_FLAG);
writer.write(link);
}
Expand Down Expand Up @@ -215,13 +215,13 @@ private String addLifeline(String lifeline) {
private void addMessage(MessageTypeEnum messageTypeEnum, String startLifeline, String endLifeline, String message, String link) {
checkStage();

if (USDDIUtil.isStrEmpty(startLifeline)) {
if (StringUtils.isBlank(startLifeline)) {
throw new RuntimeException("起点生命线为空");
}
if (USDDIUtil.isStrEmpty(endLifeline)) {
if (StringUtils.isBlank(endLifeline)) {
throw new RuntimeException("终点生命线为空");
}
if (USDDIUtil.isStrEmpty(message)) {
if (StringUtils.isBlank(message)) {
throw new RuntimeException("消息内容为空");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ private void handleLifeLineAfter(Counter lifelineBoxMaxWidth, Counter lifelineBo
lifelineBoxWidth = USDDIUtil.minBigDecimal(lifelineBoxHeightMultiple, lifelineBoxMaxAllowedWidth);
}

// Lifeline方框使用的宽度需要再加2
// Lifeline方框使用的宽度需要再加一些,加2可能不够,使用加4
usedVariables.setLifelineBoxActualWidth(lifelineBoxWidth.add(USDDIConstants.LIFELINE_BOX_BORDER_TEXT_SPACE_HORIZONTAL));
usedVariables.setLifelineBoxActualWidthHalf(USDDIUtil.getHalfBigDecimal(usedVariables.getLifelineBoxActualWidth()));

Expand Down
20 changes: 11 additions & 9 deletions src/main/java/com/adrninistrator/usddi/util/USDDIUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.adrninistrator.usddi.enums.MessageTypeEnum;
import com.adrninistrator.usddi.handler.base.BaseMessageHandler;
import com.adrninistrator.usddi.logger.DebugLogger;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.math.BigDecimal;
Expand All @@ -33,10 +34,6 @@ public class USDDIUtil {

private static final String CLASS_PATH = USDDIUtil.class.getResource("/").getPath();

public static boolean isStrEmpty(String str) {
return str == null || str.trim().isEmpty();
}

public static File findFile(String filePath) throws URISyntaxException {
File file = new File(filePath);
if (file.exists()) {
Expand Down Expand Up @@ -165,10 +162,6 @@ public static MessageInText genMessageInText(String text, UsedVariables usedVari
// 未指定链接
messageText = text.substring(messageTextIndex + USDDIConstants.MESSAGE_TEXT_FLAG.length()).trim();
}
if (messageText.isEmpty()) {
System.err.println("当前消息文字为空: " + text);
return null;
}

String endLifelineName = text.substring(messageFlagIndex.getIndex() + messageFlagIndex.getFlag().length(), messageTextIndex).trim();
if (endLifelineName.isEmpty()) {
Expand All @@ -194,15 +187,24 @@ public static MessageInText genMessageInText(String text, UsedVariables usedVari
messageInText.setEndLifelineSeq(endLifelineSeq);
}
messageInText.setMessageText(messageText);

boolean rspMessage = false;
if (USDDIConstants.MESSAGE_REQ_FLAG.equals(messageFlagIndex.getFlag())) {
messageInText.setMessageType(startLifelineSeq.equals(endLifelineSeq) ? MessageTypeEnum.MTE_SELF : MessageTypeEnum.MTE_REQ);
} else if (USDDIConstants.MESSAGE_RSP_FLAG.equals(messageFlagIndex.getFlag())) {
messageInText.setMessageType(MessageTypeEnum.MTE_RSP);
rspMessage = true;
} else if (USDDIConstants.MESSAGE_ASYNC_FLAG.equals(messageFlagIndex.getFlag())) {
messageInText.setMessageType(MessageTypeEnum.MTE_ASYNC);
}

if (!isStrEmpty(link)) {
if (messageText.isEmpty() && !rspMessage) {
// 只有返回消息允许为空
System.err.println("当前消息文字为空: " + text);
return null;
}

if (StringUtils.isNotBlank(link)) {
messageInText.setLink(link);
}

Expand Down

0 comments on commit 14ecdfb

Please sign in to comment.