
org.zodiac.ureport.console.endpoint.BaseEndpoint Maven / Gradle / Ivy
package org.zodiac.ureport.console.endpoint;
import java.net.URLDecoder;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zodiac.commons.constants.CharsetConstants;
public abstract class BaseEndpoint implements ConsoleEndpoint {
protected final Logger logger = LoggerFactory.getLogger(getClass());
public BaseEndpoint() {
}
protected Throwable buildRootException(Throwable throwable) {
if (throwable.getCause() == null) {
return throwable;
}
return buildRootException(throwable.getCause());
}
protected String decode(String value) {
if (value == null) {
return value;
}
try {
value = URLDecoder.decode(value, CharsetConstants.UTF_8_NAME);
value = URLDecoder.decode(value, CharsetConstants.UTF_8_NAME);
return value;
} catch (Exception ex) {
return value;
}
}
protected String decodeContent(String content) {
if (content == null) {
return content;
}
try {
content = URLDecoder.decode(content, CharsetConstants.UTF_8_NAME);
return content;
} catch (Exception ex) {
return content;
}
}
protected String buildDownloadFileName(String reportFileName, String fileName, String extName) {
if (StringUtils.isNotBlank(fileName)) {
fileName = decode(fileName);
if (!fileName.toLowerCase().endsWith(extName)) {
fileName = fileName + extName;
}
return fileName;
} else {
int pos = reportFileName.indexOf(":");
if (pos > 0) {
reportFileName = reportFileName.substring(pos + 1, reportFileName.length());
}
pos = reportFileName.toLowerCase().indexOf(".ureport.xml");
if (pos > 0) {
reportFileName = reportFileName.substring(0, pos);
}
return "ureport-" + reportFileName + extName;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy