Example usage for java.lang Throwable getLocalizedMessage

List of usage examples for java.lang Throwable getLocalizedMessage

Introduction

In this page you can find the example usage for java.lang Throwable getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:com.amalto.workbench.utils.Util.java

public static boolean handleConnectionException(final Shell shell, Throwable t, String title) {
    if (null == t) {
        return false;
    }/*  www  . jav  a  2s.  com*/
    String message = null;
    if (t instanceof com.sun.xml.internal.ws.client.ClientTransportException) {
        String key = ((com.sun.xml.internal.ws.client.ClientTransportException) t).getKey();
        if (null == title) {
            title = Messages.ConnectFailedTitle;
        }

        if (CONNECT_FAIL.equals(key)) {
            message = Messages.ConnectFailed;
        } else if (UNAUTHORIZE.equals(key)) {
            message = Messages.ConnectUnauthorized;
        } else if (NOT_FOUND.equals(key)) {
            message = Messages.ConnectNotFound;
        } else {
            return false;
        }

        return true;
    } else if (t instanceof ConnectException) {
        message = t.getLocalizedMessage();
    }
    if (t instanceof XtentisException) {
        return handleConnectionException(shell, t.getCause(), title);
    }
    if (message != null) {
        if (null == Display.getCurrent()) {
            final String fTitle = title;
            final String fMessage = message;
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    MessageDialog.openWarning(shell, fTitle, fMessage);
                }
            });
        } else {
            MessageDialog.openWarning(shell, title, message);
        }
        return true;
    }
    return false;
}

From source file:org.opencms.xml.CmsXmlEntityResolver.java

/**
 * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String)
 *//*from   ww w  .j a  v a 2 s.  c  om*/
public InputSource resolveEntity(String publicId, String systemId) {

    // lookup the system id caches first
    byte[] content;
    systemId = translateLegacySystemId(systemId);
    content = m_cachePermanent.get(systemId);
    if (content != null) {

        // permanent cache contains system id
        return new InputSource(new ByteArrayInputStream(content));
    } else if (systemId.equals(CmsXmlPage.XMLPAGE_XSD_SYSTEM_ID)) {

        // XML page XSD reference
        try {
            InputStream stream = getClass().getClassLoader().getResourceAsStream(XMLPAGE_XSD_LOCATION);
            content = CmsFileUtil.readFully(stream);
            // cache the XML page DTD
            m_cachePermanent.put(systemId, content);
            return new InputSource(new ByteArrayInputStream(content));
        } catch (Throwable t) {
            LOG.error(
                    Messages.get().getBundle().key(Messages.LOG_XMLPAGE_XSD_NOT_FOUND_1, XMLPAGE_XSD_LOCATION),
                    t);
        }

    } else if (systemId.equals(XMLPAGE_OLD_DTD_SYSTEM_ID_1) || systemId.endsWith(XMLPAGE_OLD_DTD_SYSTEM_ID_2)) {

        // XML page DTD reference
        try {
            InputStream stream = getClass().getClassLoader().getResourceAsStream(XMLPAGE_OLD_DTD_LOCATION);
            // cache the XML page DTD
            content = CmsFileUtil.readFully(stream);
            m_cachePermanent.put(systemId, content);
            return new InputSource(new ByteArrayInputStream(content));
        } catch (Throwable t) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_XMLPAGE_DTD_NOT_FOUND_1,
                    XMLPAGE_OLD_DTD_LOCATION), t);
        }
    } else if ((m_cms != null) && systemId.startsWith(OPENCMS_SCHEME)) {

        // opencms:// VFS reference
        String cacheSystemId = systemId.substring(OPENCMS_SCHEME.length() - 1);
        String cacheKey = getCacheKey(cacheSystemId,
                m_cms.getRequestContext().getCurrentProject().isOnlineProject());
        // look up temporary cache
        content = m_cacheTemporary.get(cacheKey);
        if (content != null) {
            return new InputSource(new ByteArrayInputStream(content));
        }
        String storedSiteRoot = m_cms.getRequestContext().getSiteRoot();
        try {
            // content not cached, read from VFS
            m_cms.getRequestContext().setSiteRoot("/");
            CmsFile file = m_cms.readFile(cacheSystemId, CmsResourceFilter.IGNORE_EXPIRATION);
            content = file.getContents();
            // store content in cache
            m_cacheTemporary.put(cacheKey, content);
            if (LOG.isDebugEnabled()) {
                LOG.debug(Messages.get().getBundle().key(Messages.LOG_ERR_CACHED_SYS_ID_1, cacheKey));
            }
            return new InputSource(new ByteArrayInputStream(content));
        } catch (Throwable t) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_ENTITY_RESOLVE_FAILED_1, systemId), t);
        } finally {
            m_cms.getRequestContext().setSiteRoot(storedSiteRoot);
        }

    } else if (systemId.startsWith(INTERNAL_SCHEME)) {
        String location = systemId.substring(INTERNAL_SCHEME.length());
        try {
            InputStream stream = getClass().getClassLoader().getResourceAsStream(location);
            content = CmsFileUtil.readFully(stream);
            m_cachePermanent.put(systemId, content);
            return new InputSource(new ByteArrayInputStream(content));
        } catch (Throwable t) {
            LOG.error(t.getLocalizedMessage(), t);
        }

    } else if (systemId.substring(0, systemId.lastIndexOf("/") + 1)
            .equalsIgnoreCase(CmsConfigurationManager.DEFAULT_DTD_PREFIX)) {
        // default DTD location in the org.opencms.configuration package
        String location = null;
        try {
            String dtdFilename = systemId.substring(systemId.lastIndexOf("/") + 1);
            location = CmsConfigurationManager.DEFAULT_DTD_LOCATION + dtdFilename;
            InputStream stream = getClass().getClassLoader().getResourceAsStream(location);
            content = CmsFileUtil.readFully(stream);
            // cache the DTD
            m_cachePermanent.put(systemId, content);
            return new InputSource(new ByteArrayInputStream(content));
        } catch (Throwable t) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_DTD_NOT_FOUND_1, location), t);
        }
    }
    // use the default behaviour (i.e. resolve through external URL)
    return null;
}

From source file:org.opencms.importexport.CmsImportVersion10.java

/**
 * Sets the membership information that could not been set immediately,
 * because of import order issues.<p>
 *///w  w  w.  j  ava 2s . c  om
public void setMembership() {

    if ((m_orgUnit == null) || (m_membership == null)) {
        return;
    }

    // get the membership data to set
    Map<String, Map<String, String>> membership = m_membership.get(m_orgUnit.getName());
    if (membership == null) {
        return;
    }

    // set group membership
    Map<String, String> groups = membership.get(I_CmsPrincipal.PRINCIPAL_GROUP);
    if (groups != null) {
        Iterator<Entry<String, String>> it = groups.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, String> entry = it.next();
            String userName = entry.getKey();
            String groupName = entry.getValue();

            // set the users group
            try {
                getCms().addUserToGroup(userName, groupName);
            } catch (Throwable e) {
                getReport().println(Messages.get().container(Messages.RPT_USER_COULDNT_BE_ADDED_TO_GROUP_2,
                        userName, groupName), I_CmsReport.FORMAT_WARNING);
                if (LOG.isDebugEnabled()) {
                    LOG.debug(e.getLocalizedMessage(), e);
                }
            }
        }
    }

    // set role membership
    Map<String, String> roles = membership.get(I_CmsPrincipal.PRINCIPAL_USER);
    if (roles != null) {
        Iterator<Entry<String, String>> it = roles.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, String> entry = it.next();
            String userName = entry.getKey();
            String roleName = entry.getValue();

            // set the users roles
            CmsRole role = CmsRole.valueOfRoleName(roleName);
            try {
                // set the user role
                OpenCms.getRoleManager().addUserToRole(getCms(), role, userName);
                return;
            } catch (Throwable e) {
                getReport().println(Messages.get().container(Messages.RPT_USER_COULDNT_BE_ADDED_TO_ROLE_2,
                        userName, roleName), I_CmsReport.FORMAT_WARNING);
                if (LOG.isDebugEnabled()) {
                    LOG.debug(e.getLocalizedMessage(), e);
                }
            }
        }
    }
}

From source file:org.opencms.importexport.CmsImportVersion7.java

/**
 * Rewrites all parseable files, to assure link check.<p>
 * /* w w  w.  j a  v a2 s.  c  om*/
 * This is a global process, that is executed only once at the 
 * end of the import to be sure that all link targets are 
 * available.<p>
 * 
 * @see #addXmlDigesterRules(Digester)
 */
public void rewriteParseables() {

    if (m_parseables.isEmpty()) {
        return;
    }

    I_CmsReport report = getReport();
    CmsObject cms = getCms();
    cms.getRequestContext().setAttribute(CmsLogEntry.ATTR_LOG_ENTRY, Boolean.FALSE);

    report.println(Messages.get().container(Messages.RPT_START_PARSE_LINKS_0), I_CmsReport.FORMAT_HEADLINE);

    int i = 0;
    Iterator<String> it = m_parseables.iterator();
    while (it.hasNext()) {
        String resName = it.next();

        report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_SUCCESSION_2,
                String.valueOf(i + 1), String.valueOf(m_parseables.size())), I_CmsReport.FORMAT_NOTE);

        report.print(Messages.get().container(Messages.RPT_PARSE_LINKS_FOR_1, resName),
                I_CmsReport.FORMAT_NOTE);
        report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0));

        try {
            CmsFile file = cms.readFile(resName);
            // make sure the date last modified is kept...
            file.setDateLastModified(file.getDateLastModified());
            // make sure the file is locked
            CmsLock lock = cms.getLock(file);
            if (lock.isUnlocked()) {
                cms.lockResource(resName);
            } else if (!lock.isDirectlyOwnedInProjectBy(cms)) {
                cms.changeLock(resName);
            }
            // rewrite the file
            cms.writeFile(file);

            report.println(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0),
                    I_CmsReport.FORMAT_OK);
        } catch (Throwable e) {
            report.addWarning(e);
            report.println(
                    org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_FAILED_0),
                    I_CmsReport.FORMAT_ERROR);
            if (LOG.isWarnEnabled()) {
                LOG.warn(Messages.get().getBundle().key(Messages.LOG_IMPORTEXPORT_REWRITING_1, resName));
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug(e.getLocalizedMessage(), e);
            }
        }
        i++;
    }
    cms.getRequestContext().removeAttribute(CmsLogEntry.ATTR_LOG_ENTRY);

    report.println(Messages.get().container(Messages.RPT_END_PARSE_LINKS_0), I_CmsReport.FORMAT_HEADLINE);
    m_parseables = null;
}

From source file:cl.gisred.android.MantCatastroActivity.java

private void cerrarFormMant(boolean bSave, View v) {
    if (bSave) {//from  w  w w.  ja v  a  2 s .  c o m

        final AtomicReference<String> resp = new AtomicReference<>("");

        if (!validarForm(v)) {
            DialogoConfirmacion oDialog = new DialogoConfirmacion();
            oDialog.show(getFragmentManager(), "tagAlert");
            return;
        } else {
            View vAction = getLayoutValidate(v);
            Map<String, Object> objectMap = new HashMap<>();
            for (View view : vAction.getTouchables()) {

                if (view.getClass().getGenericSuperclass().equals(Spinner.class)) {
                    Spinner oSpinner = (Spinner) view;
                    String sValue = oSpinner.getSelectedItem().toString();

                    if (oSpinner.getId() == R.id.spinnerElement)
                        objectMap.put("elemento", sValue);
                    else if (oSpinner.getId() == R.id.spinnerDiagnostic)
                        objectMap.put("diagnostico", sValue);
                    else if (oSpinner.getId() == R.id.spinnerMaterial)
                        objectMap.put("material", sValue);
                    else if (oSpinner.getId() == R.id.spinnerCriticidad)
                        objectMap.put("criticidad", sValue);
                }
            }

            objectMap.put("id_padre", idNodo);
            objectMap.put("rotulo", rotulo);
            objectMap.put("empresa", empresa);
            objectMap.put("estado", "Informado");

            Graphic newFeatureGraphic = new Graphic(oUbicacionForm, null, objectMap);
            Graphic[] adds = { newFeatureGraphic };
            LyAddMantCatastro.applyEdits(adds, null, null, new CallbackListener<FeatureEditResult[][]>() {
                @Override
                public void onCallback(FeatureEditResult[][] featureEditResults) {
                    if (featureEditResults[0] != null) {
                        if (featureEditResults[0][0] != null && featureEditResults[0][0].isSuccess()) {

                            resp.set("Guardado Correctamente Id: " + featureEditResults[0][0].getObjectId());

                            runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    Util.showConfirmation(MantCatastroActivity.this, resp.get());
                                }
                            });
                        }
                    }
                }

                @Override
                public void onError(Throwable throwable) {
                    resp.set("Error al ingresar: " + throwable.getLocalizedMessage());
                    Log.w("onError", resp.get());

                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            Toast.makeText(MantCatastroActivity.this, resp.get(), Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            });
        }
    }

    bMapTap = false;
    oUbicacionForm = null;

    if (mBusquedaLayer != null && myMapView.getLayerByID(mBusquedaLayer.getID()) != null)
        myMapView.removeLayer(mBusquedaLayer);

    if (mUbicacionLayer != null && myMapView.getLayerByID(mUbicacionLayer.getID()) != null)
        myMapView.removeLayer(mUbicacionLayer);

    if (mSeleccionLayer != null && myMapView.getLayerByID(mSeleccionLayer.getID()) != null)
        myMapView.removeLayer(mSeleccionLayer);

    if (bVerCapas)
        toogleCapas(fabVerCapas);

    if (bIngCliente)
        menuMultipleActions.setVisibility(View.VISIBLE);

    fabShowForm.setVisibility(View.GONE);
    formMant.dismiss();

    if (LyAddMantCatastro != null)
        LyAddMantCatastro.setVisible(true);
}

From source file:cl.gisred.android.MantCatastroActivity.java

private void cerrarDialogCrear(boolean bSave, @Nullable View viewDialog) {
    final AtomicReference<String> resp = new AtomicReference<>("");

    if (bSave) {//w  w w.j  a  va  2s .c o  m
        if (!validarVista(viewDialog)) {
            DialogoConfirmacion oDialog = new DialogoConfirmacion();
            oDialog.show(getFragmentManager(), "tagAlert");
            return;
        } else {
            switch (idResLayoutSelect) {
            case R.layout.dialog_poste:
                oLyAddGraphs = LyAddPoste;
                break;
            case R.layout.dialog_direccion:
                oLyAddGraphs = LyAddDireccion;
                break;
            case R.layout.dialog_cliente:
                oLyAddGraphs = LyAddCliente;
                break;
            case R.layout.dialog_cliente_cnr:
                oLyAddGraphs = LyAddClienteCnr;
                break;
            }

            if (oLyAddGraphs != null) {
                View oView = getLayoutValidate(viewDialog);
                Util oUtil = new Util(oUbicacion);

                ArrayList<Map<String, Object>> oAttrToSave = oUtil.getAttrAddByView(oView, idResLayoutSelect,
                        empresa);

                Map<String, Object> attributes = oAttrToSave.get(0);
                Graphic newFeatureGraphic = new Graphic(oUbicacion, null, attributes);
                Graphic[] adds = { newFeatureGraphic };

                if (idResLayoutSelect == R.layout.dialog_cliente_cnr
                        || idResLayoutSelect == R.layout.dialog_cliente) {
                    addsUnion = Util.addAttrUnionPoint(oAttrToSave, oUbicacion);
                }

                oLyAddGraphs.applyEdits(adds, null, null, new CallbackListener<FeatureEditResult[][]>() {

                    @Override
                    public void onCallback(FeatureEditResult[][] featureEditResults) {
                        if (featureEditResults[0] != null) {
                            if (featureEditResults[0][0] != null && featureEditResults[0][0].isSuccess()) {

                                resp.set(
                                        "Guardado Correctamente Id: " + featureEditResults[0][0].getObjectId());

                                if (idResLayoutSelect == R.layout.dialog_cliente_cnr
                                        || idResLayoutSelect == R.layout.dialog_cliente)
                                    LyAddUnion.applyEdits(addsUnion, null, null, callBackUnion());

                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        Util.showConfirmation(MantCatastroActivity.this, resp.get());
                                    }
                                });
                            }
                        }
                    }

                    @Override
                    public void onError(Throwable throwable) {
                        resp.set("Error al grabar: " + throwable.getLocalizedMessage());
                        Log.w("onError", resp.get());

                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(MantCatastroActivity.this, resp.get(), Toast.LENGTH_SHORT)
                                        .show();
                            }
                        });
                    }

                });
            }
        }
    } else {
        resp.set("Cancelado");
        Toast.makeText(MantCatastroActivity.this, resp.get(), Toast.LENGTH_LONG).show();
    }

    bMapTap = false;

    if (mBusquedaLayer != null && myMapView.getLayerByID(mBusquedaLayer.getID()) != null)
        myMapView.removeLayer(mBusquedaLayer);

    if (mUbicacionLayer != null && myMapView.getLayerByID(mUbicacionLayer.getID()) != null)
        myMapView.removeLayer(mUbicacionLayer);

    if (mSeleccionLayer != null && myMapView.getLayerByID(mSeleccionLayer.getID()) != null)
        myMapView.removeLayer(mSeleccionLayer);

    oUbicacion = null;
    if (bVerCapas)
        toogleCapas(fabVerCapas);
    //setLayerAddToggle(false);
    if (bIngCliente)
        menuMultipleActions.setVisibility(View.VISIBLE);
    fabShowDialog.setVisibility(View.GONE);
    dialogCrear.dismiss();
    if (oLyAddGraphs != null)
        oLyAddGraphs.setVisible(true);
}

From source file:cl.gisred.android.RegEquipoActivity.java

private void cerrarFormLimit(boolean bSave, View v) {
    // TODO Usar Layer Indicada
    bSave = false;/*www  .j av a 2  s  .  co  m*/
    if (bSave) {

        final AtomicReference<String> resp = new AtomicReference<>("");

        if (!validarZoneLimit(v)) {
            DialogoConfirmacion oDialog = new DialogoConfirmacion();
            oDialog.show(getFragmentManager(), "tagAlert");
            return;
        } else {
            View vAction = getLayoutValidate(v);
            Map<String, Object> objectMap = new HashMap<>();
            for (View view : vAction.getTouchables()) {

                if (view.getClass().equals(GisEditText.class)) {
                    GisEditText oText = (GisEditText) view;

                    if (oText.getText() != null && !oText.getText().toString().isEmpty()) {
                        if (oText.getId() == R.id.txtPoste) {
                            objectMap.put("id_poste", oText.getIdObjeto());
                            oUbicacion = oText.getPoint();
                        } else if (oText.getId() == R.id.txtTramoBt) {
                            objectMap.put("id_tramo", oText.getText().toString());
                        }
                    }
                }
            }

            objectMap.put("empresa", empresa);
            objectMap.put("modulo", modulo);

            Graphic newFeatureGraphic = new Graphic(oUbicacion, null, objectMap);
            Graphic[] adds = { newFeatureGraphic };
            LyRetRegEquipo.applyEdits(adds, null, null, new CallbackListener<FeatureEditResult[][]>() {
                @Override
                public void onCallback(FeatureEditResult[][] featureEditResults) {
                    if (featureEditResults[0] != null) {
                        if (featureEditResults[0][0] != null && featureEditResults[0][0].isSuccess()) {

                            resp.set("Guardado Correctamente Id: " + featureEditResults[0][0].getObjectId());

                            runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    Util.showConfirmation(RegEquipoActivity.this, resp.get());
                                }
                            });
                        }
                    }
                }

                @Override
                public void onError(Throwable throwable) {
                    resp.set("Error al ingresar: " + throwable.getLocalizedMessage());
                    Log.w("onError", resp.get());

                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            Toast.makeText(RegEquipoActivity.this, resp.get(), Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            });
        }
    }

    bMapTap = false;
    oUbicacion = null;

    if (mBusquedaLayer != null && myMapView.getLayerByID(mBusquedaLayer.getID()) != null)
        myMapView.removeLayer(mBusquedaLayer);

    if (mUbicacionLayer != null && myMapView.getLayerByID(mUbicacionLayer.getID()) != null)
        myMapView.removeLayer(mUbicacionLayer);

    if (mSeleccionLayer != null && myMapView.getLayerByID(mSeleccionLayer.getID()) != null)
        myMapView.removeLayer(mSeleccionLayer);

    if (bVerCapas)
        toogleCapas(fabVerCapas);

    if (bIngCliente)
        menuMultipleActions.setVisibility(View.VISIBLE);
    menuMicroActions.setVisibility(View.VISIBLE);
    fabShowForm.setVisibility(View.GONE);
    formCrear.dismiss();

    if (LyRetRegEquipo != null)
        LyRetRegEquipo.setVisible(true);
}

From source file:org.opencms.main.OpenCmsCore.java

/**
 * This method performs the error handling for OpenCms.<p>
 *
 * @param cms the current cms context, might be null !
 * @param req the client request/*from   www  .j av  a2 s . co  m*/
 * @param res the client response
 * @param t the exception that occurred
 */
private void errorHandling(CmsObject cms, HttpServletRequest req, HttpServletResponse res, Throwable t) {

    // remove the controller attribute from the request
    CmsFlexController.removeController(req);

    boolean canWrite = (!res.isCommitted() && !res.containsHeader("Location"));
    int status = -1;
    boolean isGuest = true;

    if (t instanceof ServletException) {
        ServletException s = (ServletException) t;
        if (s.getRootCause() != null) {
            t = s.getRootCause();
        }
    } else if (t instanceof CmsSecurityException) {
        // access error - display login dialog
        if (canWrite) {
            try {
                m_authorizationHandler.requestAuthorization(req, res, getLoginFormURL(req, res));
            } catch (IOException ioe) {
                // there is nothing we can do about this
            }
            return;
        }
    } else if (t instanceof CmsDbEntryNotFoundException) {
        // user or group does not exist
        status = HttpServletResponse.SC_SERVICE_UNAVAILABLE;
        isGuest = false;
    } else if (t instanceof CmsVfsResourceNotFoundException) {
        // file not found - display 404 error.
        status = HttpServletResponse.SC_NOT_FOUND;
    } else if (t instanceof CmsException) {
        if (t.getCause() != null) {
            t = t.getCause();
        }
        LOG.error(t.getLocalizedMessage(), t);
    } else {
        LOG.error(t.getLocalizedMessage(), t);
    }

    if (status < 1) {
        // error code not set - set "internal server error" (500)
        status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    }
    res.setStatus(status);

    try {
        if ((cms != null) && (cms.getRequestContext().getCurrentUser() != null)) {
            isGuest = isGuest && (cms.getRequestContext().getCurrentUser().isGuestUser()
                    || cms.userInGroup(cms.getRequestContext().getCurrentUser().getName(),
                            OpenCms.getDefaultUsers().getGroupGuests()));
        }
    } catch (CmsException e) {
        // result is false
        LOG.error(e.getLocalizedMessage(), e);
    }

    if (canWrite) {
        res.setContentType("text/html");
        CmsRequestUtil.setNoCacheHeaders(res);
        if (!isGuest && (cms != null) && !cms.getRequestContext().getCurrentProject().isOnlineProject()) {
            try {
                res.setStatus(HttpServletResponse.SC_OK);
                res.getWriter().print(createErrorBox(t, req, cms));
            } catch (IOException e) {
                // can be ignored
                LOG.error(e.getLocalizedMessage(), e);
            }
        } else {
            try {
                res.sendError(status, t.toString());
            } catch (IOException e) {
                // can be ignored
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
    }
}

From source file:cl.gisred.android.RegEquipoActivity.java

private void cerrarDialogCrear(boolean bSave, @Nullable View viewDialog) {
    final AtomicReference<String> resp = new AtomicReference<>("");

    if (bSave) {// w  ww  .  j  a v a  2  s. c  o m
        if (!validarVista(viewDialog)) {
            DialogoConfirmacion oDialog = new DialogoConfirmacion();
            oDialog.show(getFragmentManager(), "tagAlert");
            return;
        } else {
            switch (idResLayoutSelect) {
            case R.layout.dialog_poste:
                oLyAddGraphs = LyAddPoste;
                break;
            case R.layout.dialog_direccion:
                oLyAddGraphs = LyAddDireccion;
                break;
            case R.layout.dialog_cliente:
                oLyAddGraphs = LyAddCliente;
                break;
            case R.layout.dialog_cliente_cnr:
                oLyAddGraphs = LyAddClienteCnr;
                break;
            }

            if (oLyAddGraphs != null) {
                View oView = getLayoutValidate(viewDialog);
                Util oUtil = new Util(oUbicacion);

                ArrayList<Map<String, Object>> oAttrToSave = oUtil.getAttrAddByView(oView, idResLayoutSelect,
                        empresa);

                Map<String, Object> attributes = oAttrToSave.get(0);
                Graphic newFeatureGraphic = new Graphic(oUbicacion, null, attributes);
                Graphic[] adds = { newFeatureGraphic };

                if (idResLayoutSelect == R.layout.dialog_cliente_cnr
                        || idResLayoutSelect == R.layout.dialog_cliente) {
                    addsUnion = Util.addAttrUnionPoint(oAttrToSave, oUbicacion);
                }

                oLyAddGraphs.applyEdits(adds, null, null, new CallbackListener<FeatureEditResult[][]>() {

                    @Override
                    public void onCallback(FeatureEditResult[][] featureEditResults) {
                        if (featureEditResults[0] != null) {
                            if (featureEditResults[0][0] != null && featureEditResults[0][0].isSuccess()) {

                                resp.set(
                                        "Guardado Correctamente Id: " + featureEditResults[0][0].getObjectId());

                                if (idResLayoutSelect == R.layout.dialog_cliente_cnr
                                        || idResLayoutSelect == R.layout.dialog_cliente)
                                    LyAddUnion.applyEdits(addsUnion, null, null, callBackUnion());

                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        Util.showConfirmation(RegEquipoActivity.this, resp.get());
                                    }
                                });
                            }
                        }
                    }

                    @Override
                    public void onError(Throwable throwable) {
                        resp.set("Error al grabar: " + throwable.getLocalizedMessage());
                        Log.w("onError", resp.get());

                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(RegEquipoActivity.this, resp.get(), Toast.LENGTH_SHORT).show();
                            }
                        });
                    }

                });
            }
        }
    } else {
        resp.set("Cancelado");
        Toast.makeText(RegEquipoActivity.this, resp.get(), Toast.LENGTH_LONG).show();
    }

    bMapTap = false;

    if (mBusquedaLayer != null && myMapView.getLayerByID(mBusquedaLayer.getID()) != null)
        myMapView.removeLayer(mBusquedaLayer);

    if (mUbicacionLayer != null && myMapView.getLayerByID(mUbicacionLayer.getID()) != null)
        myMapView.removeLayer(mUbicacionLayer);

    if (mSeleccionLayer != null && myMapView.getLayerByID(mSeleccionLayer.getID()) != null)
        myMapView.removeLayer(mSeleccionLayer);

    oUbicacion = null;
    if (bVerCapas)
        toogleCapas(fabVerCapas);
    //setLayerAddToggle(false);
    if (bIngCliente)
        menuMultipleActions.setVisibility(View.VISIBLE);
    menuMicroActions.setVisibility(View.VISIBLE);
    fabShowDialog.setVisibility(View.GONE);
    dialogCrear.dismiss();
    if (oLyAddGraphs != null)
        oLyAddGraphs.setVisible(true);
}

From source file:cl.gisred.android.MicroMedidaActivity.java

private void cerrarFormLimit(boolean bSave, View v) {
    if (bSave) {//from  w w w .ja  va  2  s . com

        final AtomicReference<String> resp = new AtomicReference<>("");

        if (!validarZoneLimit(v)) {
            DialogoConfirmacion oDialog = new DialogoConfirmacion();
            oDialog.show(getFragmentManager(), "tagAlert");
            return;
        } else {
            View vAction = getLayoutValidate(v);
            Map<String, Object> objectMap = new HashMap<>();
            for (View view : vAction.getTouchables()) {

                if (view.getClass().equals(GisEditText.class)) {
                    GisEditText oText = (GisEditText) view;

                    if (oText.getText() != null && !oText.getText().toString().isEmpty()) {
                        if (oText.getId() == R.id.txtPoste) {
                            objectMap.put("id_poste", oText.getIdObjeto());
                            oUbicacion = oText.getPoint();
                        } else if (oText.getId() == R.id.txtTramoBt) {
                            objectMap.put("id_tramo", oText.getText().toString());
                        }
                    }
                }
            }

            objectMap.put("empresa", empresa);
            objectMap.put("modulo", modulo);

            Graphic newFeatureGraphic = new Graphic(oUbicacion, null, objectMap);
            Graphic[] adds = { newFeatureGraphic };
            LyAddZoneLimit.applyEdits(adds, null, null, new CallbackListener<FeatureEditResult[][]>() {
                @Override
                public void onCallback(FeatureEditResult[][] featureEditResults) {
                    if (featureEditResults[0] != null) {
                        if (featureEditResults[0][0] != null && featureEditResults[0][0].isSuccess()) {

                            resp.set("Guardado Correctamente Id: " + featureEditResults[0][0].getObjectId());

                            runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    Util.showConfirmation(MicroMedidaActivity.this, resp.get());
                                }
                            });
                        }
                    }
                }

                @Override
                public void onError(Throwable throwable) {
                    resp.set("Error al ingresar: " + throwable.getLocalizedMessage());
                    Log.w("onError", resp.get());

                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            Toast.makeText(MicroMedidaActivity.this, resp.get(), Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            });
        }
    }

    bMapTap = false;
    oUbicacion = null;

    if (mBusquedaLayer != null && myMapView.getLayerByID(mBusquedaLayer.getID()) != null)
        myMapView.removeLayer(mBusquedaLayer);

    if (mUbicacionLayer != null && myMapView.getLayerByID(mUbicacionLayer.getID()) != null)
        myMapView.removeLayer(mUbicacionLayer);

    if (mSeleccionLayer != null && myMapView.getLayerByID(mSeleccionLayer.getID()) != null)
        myMapView.removeLayer(mSeleccionLayer);

    if (bVerCapas)
        toogleCapas(fabVerCapas);

    if (bIngCliente)
        menuMultipleActions.setVisibility(View.VISIBLE);
    menuMicroActions.setVisibility(View.VISIBLE);
    fabShowForm.setVisibility(View.GONE);
    formCrear.dismiss();

    if (LyAddZoneLimit != null)
        LyAddZoneLimit.setVisible(true);
}