Search in sources :

Example 36 with ProcessingException

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));
    }
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) VetoException(org.eclipse.scout.rt.platform.exception.VetoException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 37 with ProcessingException

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);
    }
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 38 with ProcessingException

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));
}
Also used : Matcher(java.util.regex.Matcher) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 39 with ProcessingException

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);
    }
}
Also used : ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) IOException(java.io.IOException) VetoException(org.eclipse.scout.rt.platform.exception.VetoException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 40 with ProcessingException

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);
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) ITagProcessor(org.eclipse.scout.rt.platform.util.StringUtility.ITagProcessor) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Aggregations

ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)142 IOException (java.io.IOException)48 MessagingException (javax.mail.MessagingException)21 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)17 File (java.io.File)14 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)12 Folder (javax.mail.Folder)10 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)9 RemoteFile (org.eclipse.scout.rt.shared.services.common.file.RemoteFile)9 NoSuchProviderException (java.security.NoSuchProviderException)8 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)8 FileInputStream (java.io.FileInputStream)7 InputStream (java.io.InputStream)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 FileOutputStream (java.io.FileOutputStream)6 Message (javax.mail.Message)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 OutputStream (java.io.OutputStream)5 HashMap (java.util.HashMap)5