Example usage for java.lang IndexOutOfBoundsException getLocalizedMessage

List of usage examples for java.lang IndexOutOfBoundsException getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:org.kitodo.production.process.TiffHeaderGenerator.java

/**
 * Reduce to 255 characters./*from w  w w. jav  a  2s  .  c  om*/
 */
private String reduceLengthOfTifHeaderImageDescription(String tifHeaderImageDescription)
        throws ProcessGenerationException {
    int length = tifHeaderImageDescription.length();
    if (length > 255) {
        try {
            int toCut = length - 255;
            String newTiffHeader = this.tiffHeader.substring(0, this.tiffHeader.length() - toCut);
            return tifHeaderImageDescription.replace(this.tiffHeader, newTiffHeader);
        } catch (IndexOutOfBoundsException e) {
            throw new ProcessGenerationException(e.getLocalizedMessage(), e);
        }
    }
    return tifHeaderImageDescription;
}

From source file:org.pentaho.platform.web.http.HttpOutputHandler.java

public void setOutput(final String name, final Object value) throws IOException {
    if (value == null) {
        HttpOutputHandler.logger/* w  w  w  .j av  a2 s  .c  o  m*/
                .warn(Messages.getInstance().getString("HttpOutputHandler.WARN_0001_VALUE_IS_NULL")); //$NON-NLS-1$
        return;
    }

    /*
     * if setOutput is called, it means someone intends to write some data to the response stream, which they may not
     * have gotten a handle to earlier through getOutputContentItem*. So we need to set the flag here.
     */
    responseExpected = true;

    if ("redirect".equalsIgnoreCase(name)) { //$NON-NLS-1$
        try {
            response.sendRedirect(value.toString());
        } catch (IOException ioe) {
            HttpOutputHandler.logger.error(Messages.getInstance()
                    .getString("HttpOutputHandler.ERROR_0001_REDIRECT_FAILED", value.toString()), ioe); //$NON-NLS-1$
        }
    } else if ("header".equalsIgnoreCase(name)) { //$NON-NLS-1$
        try {
            if (value instanceof Map) {
                for (Iterator it = ((Map) value).entrySet().iterator(); it.hasNext();) {
                    Map.Entry entry = (Map.Entry) it.next();
                    response.addHeader(entry.getKey().toString(), entry.getValue().toString());
                }
            } else {
                String strVal = value.toString();
                int i = strVal.indexOf('=');
                String headerName = strVal.substring(0, i);
                String headerValue = strVal.substring(i + 1);
                response.addHeader(headerName, headerValue);
            }
        } catch (IndexOutOfBoundsException e) {
            HttpOutputHandler.logger.error(e.getLocalizedMessage());
        }
    } else if (IOutputHandler.CONTENT.equalsIgnoreCase(name)) {
        if (value instanceof IContentItem) {
            IContentItem content = (IContentItem) value;
            // See if we should process the input stream. If it's from
            // the content repository, then there's an input stream.
            // SimpleContentItem and HttpContentItem both return null from
            // getInputStream().
            InputStream inStr = content.getInputStream();
            if (inStr != null) {
                if ((response.getContentType() == null)
                        || (!response.getContentType().equalsIgnoreCase(content.getMimeType()))) {
                    // response.setContentType( content.getMimeType() );
                    setMimeType(content.getMimeType());
                }
                try {
                    // Bad idea to write to the output stream directly. This prevents us from
                    // auditing writes. Use the managed destinationOutputStream instead.
                    // OutputStream outStr = response.getOutputStream();
                    int inCnt = 0;
                    byte[] buf = new byte[4096];
                    while (-1 != (inCnt = inStr.read(buf))) {
                        destinationOutputStream.write(buf, 0, inCnt);
                    }
                } finally {
                    try {
                        inStr.close();
                    } catch (IOException ignored) {
                        //ignored
                    }
                }
                contentGenerated = true;
            }
        } else {
            if (response.getContentType() == null) {
                setMimeType("text/html"); //$NON-NLS-1$
            }

            destinationOutputStream.write(value.toString().getBytes());
            contentGenerated = true;
        }
    }
}

From source file:org.opencms.workplace.CmsTabDialog.java

/**
 * Returns the localized name of the currently active tab.<p>
 * //www  . jav a  2 s  .co  m
 * @return the localized name of the currently active tab or null if no tab name was found
 */
public String getActiveTabName() {

    if (m_activeTab < 0) {
        getActiveTab();
    }
    List<String> tabNames = getTabs();
    try {
        return tabNames.get(m_activeTab - 1);
    } catch (IndexOutOfBoundsException e) {
        // should usually never happen
        if (LOG.isInfoEnabled()) {
            LOG.info(e.getLocalizedMessage());
        }
        return null;
    }
}

From source file:com.mifos.mifosxdroid.online.ClientDetailsFragment.java

/**
 * Use this method to fetch and inflate client details
 * in the fragment/*from   www. j  a  v a  2  s. c om*/
 */
public void getClientDetails() {
    showProgress(true);
    App.apiManager.getClient(clientId, new Callback<Client>() {
        @Override
        public void success(final Client client, Response response) {
            /* Activity is null - Fragment has been detached; no need to do anything. */
            if (getActivity() == null)
                return;

            if (client != null) {
                setToolbarTitle(getString(R.string.client) + " - " + client.getLastname());
                tv_fullName.setText(client.getDisplayName());
                tv_accountNumber.setText(client.getAccountNo());
                tv_externalId.setText(client.getExternalId());
                if (TextUtils.isEmpty(client.getAccountNo()))
                    rowAccount.setVisibility(GONE);

                if (TextUtils.isEmpty(client.getExternalId()))
                    rowExternal.setVisibility(GONE);

                try {
                    List<Integer> dateObj = client.getActivationDate();
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM yyyy");
                    Date date = simpleDateFormat.parse(DateHelper.getDateAsString(dateObj));
                    Locale currentLocale = getResources().getConfiguration().locale;
                    DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, currentLocale);
                    String dateString = df.format(date);
                    tv_activationDate.setText(dateString);

                    if (TextUtils.isEmpty(dateString))
                        rowActivation.setVisibility(GONE);

                } catch (IndexOutOfBoundsException e) {
                    Toast.makeText(getActivity(), getString(R.string.error_client_inactive), Toast.LENGTH_SHORT)
                            .show();
                    tv_activationDate.setText("");
                } catch (ParseException e) {
                    Log.d(TAG, e.getLocalizedMessage());
                }
                tv_office.setText(client.getOfficeName());

                if (TextUtils.isEmpty(client.getOfficeName()))
                    rowOffice.setVisibility(GONE);

                if (client.isImagePresent()) {
                    imageLoadingAsyncTask = new ImageLoadingAsyncTask();
                    imageLoadingAsyncTask.execute(client.getId());
                } else {
                    iv_clientImage.setImageDrawable(
                            ResourcesCompat.getDrawable(getResources(), R.drawable.ic_launcher, null));

                    pb_imageProgressBar.setVisibility(GONE);
                }

                iv_clientImage.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        PopupMenu menu = new PopupMenu(getActivity(), view);
                        menu.getMenuInflater().inflate(R.menu.client_image_popup, menu.getMenu());
                        menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                            @Override
                            public boolean onMenuItemClick(MenuItem menuItem) {
                                switch (menuItem.getItemId()) {
                                case R.id.client_image_capture:
                                    captureClientImage();
                                    break;
                                case R.id.client_image_remove:
                                    deleteClientImage();
                                    break;
                                default:
                                    Log.e("ClientDetailsFragment",
                                            "Unrecognized " + "client " + "image menu item");
                                }
                                return true;
                            }
                        });
                        menu.show();
                    }
                });
                showProgress(false);
                inflateClientsAccounts();
            }
        }

        @Override
        public void failure(RetrofitError retrofitError) {
            Toaster.show(rootView, "Client not found.");
            showProgress(false);
        }
    });
}

From source file:org.opencms.db.CmsDriverManager.java

/**
 * Reads the required configurations from the opencms.properties file and creates
 * the various drivers to access the cms resources.<p>
 * /*from w w w.  j a v a  2  s .com*/
 * The initialization process of the driver manager and its drivers is split into
 * the following phases:
 * <ul>
 * <li>the database pool configuration is read</li>
 * <li>a plain and empty driver manager instance is created</li>
 * <li>an instance of each driver is created</li>
 * <li>the driver manager is passed to each driver during initialization</li>
 * <li>finally, the driver instances are passed to the driver manager during initialization</li>
 * </ul>
 * 
 * @param configurationManager the configuration manager
 * @param securityManager the security manager
 * @param runtimeInfoFactory the initialized OpenCms runtime info factory
 * @param publishEngine the publish engine
 * 
 * @return CmsDriverManager the instantiated driver manager
 * @throws CmsInitException if the driver manager couldn't be instantiated
 */
public static CmsDriverManager newInstance(CmsConfigurationManager configurationManager,
        CmsSecurityManager securityManager, I_CmsDbContextFactory runtimeInfoFactory,
        CmsPublishEngine publishEngine) throws CmsInitException {

    // read the opencms.properties from the configuration
    CmsParameterConfiguration config = configurationManager.getConfiguration();

    CmsDriverManager driverManager = null;
    try {
        // create a driver manager instance
        driverManager = new CmsDriverManager();
        if (CmsLog.INIT.isInfoEnabled()) {
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_MANAGER_START_PHASE1_0));
        }
        if (runtimeInfoFactory == null) {
            throw new CmsInitException(org.opencms.main.Messages.get()
                    .container(org.opencms.main.Messages.ERR_CRITICAL_NO_DB_CONTEXT_0));
        }
    } catch (Exception exc) {
        CmsMessageContainer message = Messages.get().container(Messages.LOG_ERR_DRIVER_MANAGER_START_0);
        if (LOG.isFatalEnabled()) {
            LOG.fatal(message.key(), exc);
        }
        throw new CmsInitException(message, exc);
    }

    // store the configuration
    driverManager.m_propertyConfiguration = config;

    // set the security manager
    driverManager.m_securityManager = securityManager;

    // set connection pools
    driverManager.m_connectionPools = new ArrayList<PoolingDriver>();

    // set the lock manager
    driverManager.m_lockManager = new CmsLockManager(driverManager);

    // create and set the sql manager
    driverManager.m_sqlManager = new CmsSqlManager(driverManager);

    // set the publish engine
    driverManager.m_publishEngine = publishEngine;

    if (CmsLog.INIT.isInfoEnabled()) {
        CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_MANAGER_START_PHASE2_0));
    }

    // read the pool names to initialize
    List<String> driverPoolNames = config.getList(CmsDriverManager.CONFIGURATION_DB + ".pools");
    if (CmsLog.INIT.isInfoEnabled()) {
        String names = "";
        for (String name : driverPoolNames) {
            names += name + " ";
        }
        CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_MANAGER_START_POOLS_1, names));
    }

    // initialize each pool
    for (String name : driverPoolNames) {
        driverManager.newPoolInstance(config, name);
    }

    // initialize the runtime info factory with the generated driver manager
    runtimeInfoFactory.initialize(driverManager);

    if (CmsLog.INIT.isInfoEnabled()) {
        CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_MANAGER_START_PHASE3_0));
    }

    // store the access objects
    CmsDbContext dbc = runtimeInfoFactory.getDbContext();
    driverManager.m_vfsDriver = (I_CmsVfsDriver) driverManager.createDriver(dbc, configurationManager, config,
            CONFIGURATION_VFS, ".vfs.driver");
    dbc.clear();

    dbc = runtimeInfoFactory.getDbContext();
    driverManager.m_userDriver = (I_CmsUserDriver) driverManager.createDriver(dbc, configurationManager, config,
            CONFIGURATION_USER, ".user.driver");
    dbc.clear();

    dbc = runtimeInfoFactory.getDbContext();
    driverManager.m_projectDriver = (I_CmsProjectDriver) driverManager.createDriver(dbc, configurationManager,
            config, CONFIGURATION_PROJECT, ".project.driver");
    dbc.clear();

    dbc = runtimeInfoFactory.getDbContext();
    driverManager.m_historyDriver = (I_CmsHistoryDriver) driverManager.createDriver(dbc, configurationManager,
            config, CONFIGURATION_HISTORY, ".history.driver");
    dbc.clear();

    dbc = runtimeInfoFactory.getDbContext();
    try {
        // we wrap this in a try-catch because otherwise it would fail during the update 
        // process, since the subscription driver configuration does not exist at that point. 
        driverManager.m_subscriptionDriver = (I_CmsSubscriptionDriver) driverManager.createDriver(dbc,
                configurationManager, config, CONFIGURATION_SUBSCRIPTION, ".subscription.driver");
    } catch (IndexOutOfBoundsException npe) {
        LOG.warn("Could not instantiate subscription driver!");
        LOG.warn(npe.getLocalizedMessage(), npe);
    }
    dbc.clear();

    // register the driver manager for required events
    org.opencms.main.OpenCms.addCmsEventListener(driverManager,
            new int[] { I_CmsEventListener.EVENT_UPDATE_EXPORTS, I_CmsEventListener.EVENT_CLEAR_CACHES,
                    I_CmsEventListener.EVENT_CLEAR_PRINCIPAL_CACHES, I_CmsEventListener.EVENT_USER_MODIFIED,
                    I_CmsEventListener.EVENT_PUBLISH_PROJECT });

    // return the configured driver manager
    return driverManager;
}