use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class AbstractForm method doExportXml.
@Override
public void doExportXml(boolean saveAs) {
// export search parameters
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
Writer w = new OutputStreamWriter(bos, StandardCharsets.UTF_8)) {
XmlUtility.wellformDocument(storeToXml(), w);
BinaryResource res = new BinaryResource("form.xml", bos.toByteArray());
getDesktop().openUri(res, OpenUriAction.DOWNLOAD);
} catch (Exception e) {
BEANS.get(ExceptionHandler.class).handle(new ProcessingException(TEXTS.get("FormExportXml") + " " + getTitle(), e));
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class AbstractFormField method loadFromXmlString.
@Override
public final void loadFromXmlString(String xml) {
if (xml == null) {
return;
}
try {
Document doc = XmlUtility.getXmlDocument(xml);
Element root = doc.getDocumentElement();
loadFromXml(root);
} catch (Exception e) {
throw new ProcessingException("Error in AbstractFormField.setXML: ", e);
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class AbstractColorField method parseValueInternal.
@Override
protected String parseValueInternal(String text) {
// hex
if (StringUtility.isNullOrEmpty(text)) {
return null;
}
try {
// try to parse hex
Matcher matcher = ColorUtility.HEX_COLOR_PATTERN.matcher(text);
if (matcher.matches()) {
return "#" + matcher.group(2);
}
// try to parse any kind of RGB
matcher = RGB_COLOR_PATTERN.matcher(text);
if (matcher.matches()) {
int r = Integer.parseInt(matcher.group(1));
int g = Integer.parseInt(matcher.group(2));
int b = Integer.parseInt(matcher.group(3));
if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
throw new ProcessingException(TEXTS.get("InvalidValueMessageX", text));
}
String hexValue = ColorUtility.rgbToText(r, g, b).toUpperCase();
return hexValue;
}
} catch (Exception e) {
throw new ProcessingException(TEXTS.get("InvalidValueMessageX", text), e);
}
throw new ProcessingException(TEXTS.get("InvalidValueMessageX", text));
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class AbstractValueField method parseAndSetValue.
/**
* Parses and sets either the value or an errorStatus, if parsing or validation fails.
*/
@Override
public final void parseAndSetValue(String text) {
if (isValueParsing()) {
LOG.warn("Loop detection in [{}] with text {}", getClass().getName(), text);
return;
}
try {
setFieldChanging(true);
setValueParsing(true);
setDisplayText(text);
removeErrorStatus(ParsingFailedStatus.class);
VALUE parsedValue = interceptParseValue(text);
setValue(parsedValue);
return;
} catch (ProcessingException pe) {
addErrorStatus(new ParsingFailedStatus(pe, text));
return;
} catch (Exception e) {
LOG.error("Unexpected Error: ", e);
ProcessingException pe = new ProcessingException(TEXTS.get("InvalidValueMessageX", text), e);
addErrorStatus(new ParsingFailedStatus(pe, text));
return;
} finally {
setValueParsing(false);
setFieldChanging(false);
}
}
use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.
the class FormDataStatementBuilder method createSqlPart.
/**
* Create sql text, makes bind names unique, and adds all binds to the bind map
* <p>
* To use no operator use {@link DataModelConstants#OPERATOR_NONE} and null for binds and values, stm will be
* decorated and is the result itself
* <p>
* To use no aggregation use {@link DataModelConstants#AGGREGATION_NONE}
*/
@SuppressWarnings("bsiRulesDefinition:htmlInString")
public String createSqlPart(final Integer aggregationType, String sql, final int operation, List<String> bindNames, List<Object> bindValues, final boolean plainBind, Map<String, String> parentAliasMap) {
if (sql == null) {
sql = "";
}
if (bindNames == null) {
bindNames = new ArrayList<String>(0);
}
if (bindValues == null) {
bindValues = new ArrayList<Object>(0);
}
// by default
if (sql.indexOf("<attribute>") < 0) {
sql = "<attribute>" + sql + "</attribute>";
}
// convenience: automatically add missing alias on plain attributes, but only if the parent entity has at most 1 alias mapping
Matcher m = PLAIN_ATTRIBUTE_PATTERN.matcher(sql);
if (m.find()) {
if (parentAliasMap.size() == 0) {
// nop
} else if (parentAliasMap.size() == 1) {
sql = m.replaceAll("$1@parent." + parentAliasMap.keySet().iterator().next() + "@.$2$3");
} else {
throw new ProcessingException("root attribute with " + sql + " uses no @...@ alias prefix, but parent has more than 1 alias: " + parentAliasMap);
}
}
// resolve aliases
sql = m_aliasMapper.replaceMarkersByAliases(sql, parentAliasMap, parentAliasMap);
// generate unique bind names
final ArrayList<String> newBindNames = new ArrayList<String>(2);
for (int i = 0; i < bindNames.size(); i++) {
String o = bindNames.get(i);
String n = localizeBindName(o, "__");
newBindNames.add(n);
sql = localizeStatement(sql, o, n);
}
// part decoration
final List<Object> valuesFinal = bindValues;
ITagProcessor processor = new ITagProcessor() {
@Override
public String processTag(String tagName, String a) {
return createSqlOpValuePart(aggregationType, a, operation, newBindNames, valuesFinal, plainBind);
}
};
return StringUtility.replaceTags(sql, "attribute", processor);
}
Aggregations