Example usage for java.lang NumberFormatException getLocalizedMessage

List of usage examples for java.lang NumberFormatException getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:org.openestate.io.openimmo.converters.OpenImmo_1_2_3.java

/**
 * Remove unsupported children from all <flaechen> elements.
 * <p>//from w w w  . j  a v a2 s.  co  m
 * OpenImmo 1.2.2 does not support the following children for
 * &lt;flaechen&gt; elements: &lt;anzahl_balkone&gt;, &lt;anzahl_terrassen&gt;
 * <p>
 * These elements are removed by this function. If
 * &lt;anzahl_balkon_terrassen&gt; is not already specified, the sum values of
 * &lt;anzahl_balkone&gt; and &lt;anzahl_terrassen&gt; are written into
 * &lt;anzahl_balkon_terrassen&gt;.
 *
 * @param doc OpenImmo document in version 1.2.3
 * @throws JaxenException
 */
protected void downgradeFlaechenChildElements(Document doc) throws JaxenException {
    List nodes = XmlUtils.newXPath("/io:openimmo/io:anbieter/io:immobilie/io:flaechen", doc).selectNodes(doc);
    for (Object item : nodes) {
        Element parentNode = (Element) item;
        boolean passedAnzahlBalkone = false;
        boolean passedAnzahlTerrassen = false;
        double sum = 0;

        List childNodes = XmlUtils.newXPath("io:anzahl_balkone", doc).selectNodes(parentNode);
        for (Object childItem : childNodes) {
            Node node = (Node) childItem;
            if (!passedAnzahlBalkone) {
                passedAnzahlBalkone = true;
                String value = StringUtils.trimToNull(node.getTextContent());
                try {
                    sum += (value != null) ? Double.parseDouble(value) : 0;
                } catch (NumberFormatException ex) {
                    LOGGER.warn(
                            "Can't parse <anzahl_balkone>" + value + "</anzahl_balkone> into a numeric value!");
                    LOGGER.warn("> " + ex.getLocalizedMessage(), ex);
                }
            }
            parentNode.removeChild(node);
        }

        childNodes = XmlUtils.newXPath("io:anzahl_terrassen", doc).selectNodes(parentNode);
        for (Object childItem : childNodes) {
            Node node = (Node) childItem;
            if (!passedAnzahlTerrassen) {
                passedAnzahlTerrassen = true;
                String value = StringUtils.trimToNull(node.getTextContent());
                try {
                    sum += (value != null) ? Double.parseDouble(value) : 0;
                } catch (NumberFormatException ex) {
                    LOGGER.warn("Can't parse <anzahl_terrassen>" + value
                            + "</anzahl_terrassen> into a numeric value!");
                    LOGGER.warn("> " + ex.getLocalizedMessage(), ex);
                }
            }
            parentNode.removeChild(node);
        }

        if (sum > 0) {
            Element node = (Element) XmlUtils.newXPath("io:anzahl_balkon_terrassen", doc)
                    .selectSingleNode(parentNode);
            if (node == null) {
                node = doc.createElementNS(StringUtils.EMPTY, "anzahl_balkon_terrassen");
                node.setTextContent(String.valueOf(sum));
                parentNode.appendChild(node);
            } else if (StringUtils.isBlank(node.getTextContent())) {
                node.setTextContent(String.valueOf(sum));
            }
        }
    }
}

From source file:com.hybris.mobile.app.commerce.adapter.ProductListAdapterBase.java

@Override
public void bindView(View rowView, final Context context, final Cursor cursor) {

    // When clicking outside a EditText, hide keyboard, remove focus and
    // reset to the default value
    // Clicking on the main view
    rowView.setOnTouchListener(new OnTouchListener() {

        @Override/*from   w  w w.  j  a v a  2s.c  o  m*/
        public boolean onTouch(View v, MotionEvent event) {
            UIUtils.hideKeyboard(getContext());
            v.performClick();
            return false;
        }
    });

    final ProductViewHolder productViewHolder = (ProductViewHolder) rowView.getTag();
    final ProductBase product = getData();

    if (mCurrentSelectedPosition == cursor.getPosition()) {
        //TODO when item is in scrapview, index changed and wrong item is opened
        //createExpandedView(mProductViewHolder, cursor.getPosition());
    } else {

        // Populate name and code for a product when row collapsed
        productViewHolder.productName.setText(product.getName());
        productViewHolder.productNo.setText(product.getCode());
        productViewHolder.quantityEditText.setText(getContext().getString(R.string.default_qty));
        String rangeFormattedPrice = product.getPriceRangeFormattedValue();

        if (product.getPriceRange().getMaxPrice() != null) {
            rangeFormattedPrice = StringUtils
                    .isNotBlank(product.getPriceRange().getMaxPrice().getFormattedValue())
                    && StringUtils.isNotBlank(product.getPriceRange().getMinPrice().getFormattedValue())
                            ? product.getPriceRangeFormattedValue()
                            : "";

            if (StringUtils.isBlank(rangeFormattedPrice)) {
                if (product.getPriceRange().getMaxPrice().getValue() != null
                        && product.getPriceRange().getMinPrice().getValue() != null) {

                    rangeFormattedPrice = "$" + product.getPriceRange().getMinPrice().getValue() + ".00 - "
                            + "$" + product.getPriceRange().getMaxPrice().getValue() + ".00";
                }
            }
        }
        productViewHolder.productPrice.setText(rangeFormattedPrice);

        //Rating
        if (product.getAverageRating() != null) {
            productViewHolder.productItemRating.setVisibility(View.VISIBLE);
            productViewHolder.productItemRating.setRating(product.getAverageRating().floatValue());

            productViewHolder.productItemRatingExpanded.setVisibility(View.VISIBLE);
            productViewHolder.productItemRatingExpanded.setRating(product.getAverageRating().floatValue());
        } else {
            productViewHolder.productItemRating.setVisibility(View.GONE);
            productViewHolder.productItemRatingExpanded.setVisibility(View.GONE);
        }

        // Loading the product image
        loadProductImage(product.getImageThumbnailUrl(), productViewHolder.productImage,
                productViewHolder.productImageLoading, product.getCode());
        productViewHolder.collapse();

        if (product.getMultidimensional() != null && product.getMultidimensional()) {
            // Show arrow down with variants
            productViewHolder.productPriceTotal.setVisibility(View.GONE);
            productViewHolder.productImageViewCartIcon.setVisibility(View.GONE);
            productViewHolder.productImageViewExpandIcon.setVisibility(View.VISIBLE);
            productViewHolder.productItemAddQuantityLayout.setVisibility(View.GONE);
            productViewHolder.quantityEditText.setVisibility(View.GONE);
            productViewHolder.productAvailability.setVisibility(View.GONE);
            productViewHolder.productItemInStock.setVisibility(View.GONE);

            productViewHolder.productImageLoadingExpanded.setVisibility(View.VISIBLE);
            productViewHolder.productItemStockLevelLoadingExpanded.setVisibility(View.VISIBLE);
            productViewHolder.productImageExpanded.setVisibility(View.GONE);
            productViewHolder.productAvailabilityExpanded.setVisibility(View.GONE);

            /**
             * Gray out button
             */
            productViewHolder.setAddCartButton(true);
        } else {
            // Show cart icon without variants
            productViewHolder.productItemAddQuantityLayout.setVisibility(View.VISIBLE);
            productViewHolder.productPriceTotal.setVisibility(View.VISIBLE);
            productViewHolder.productPriceTotal.setText(productViewHolder.setTotalPrice(product.getPrice(),
                    productViewHolder.quantityEditText.getText().toString()));
            productViewHolder.productImageViewCartIcon.setVisibility(View.VISIBLE);
            productViewHolder.productImageViewExpandIcon.setVisibility(View.GONE);
            productViewHolder.quantityEditText.setEnabled(true);
            productViewHolder.quantityEditText.setVisibility(View.VISIBLE);
            productViewHolder.productAvailability.setText(product.getStock().getStockLevel() + "");
            productViewHolder.productItemInStock.setVisibility(View.VISIBLE);

            productViewHolder.setAddCartButton(true);

            if (product.isLowStock() || product.isOutOfStock()) {
                productViewHolder.productAvailability
                        .setTextColor(getContext().getResources().getColor(R.color.product_item_low_stock));
                productViewHolder.productItemInStock
                        .setTextColor(getContext().getResources().getColor(R.color.product_item_low_stock));
                productViewHolder.productAvailability
                        .setContentDescription(getContext().getString(R.string.product_item_low_stock));

                if (product.isOutOfStock()) {
                    productViewHolder.quantityEditText.setEnabled(false);
                    productViewHolder.quantityEditText.setText("");

                }

            }

            if (product.isInStock()) {
                productViewHolder.productAvailability.setText("");
                productViewHolder.productItemInStock
                        .setTextColor(getContext().getResources().getColor(R.color.product_item_in_stock));
            }

        }

    }

    /**
     * Product item row is collapsed and user click the arrow down icon to expand
     */
    productViewHolder.productImageViewExpandIcon.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            // Expanded
            getContext().getLoaderManager().restartLoader(0, null, getProductLoaderExpandView(product,
                    getContext(), CommerceApplication.getContentServiceHelper(), new OnRequestListener() {

                        @Override
                        public void beforeRequest() {
                            // Expanded
                            productViewHolder.productImageLoadingExpanded.setVisibility(View.VISIBLE);
                            productViewHolder.productItemStockLevelLoadingExpanded.setVisibility(View.VISIBLE);
                            productViewHolder.productImageExpanded.setVisibility(View.GONE);
                            productViewHolder.productAvailabilityExpanded.setVisibility(View.GONE);
                            UIUtils.showLoadingActionBar(getContext(), true);
                        }

                        @Override
                        public void afterRequestBeforeResponse() {
                            if (mCurrentSelectedViewHolder != null) {
                                mCurrentSelectedViewHolder.collapse();
                            }

                            mCurrentSelectedPosition = cursor.getPosition();
                            mCurrentSelectedViewHolder = productViewHolder;
                        }

                        @Override
                        public void afterRequest(boolean isDataSynced) {
                            productViewHolder.productImageLoadingExpanded.setVisibility(View.GONE);
                            productViewHolder.productItemStockLevelLoadingExpanded.setVisibility(View.GONE);
                            productViewHolder.productImageExpanded.setVisibility(View.VISIBLE);
                            productViewHolder.productAvailabilityExpanded.setVisibility(View.VISIBLE);
                            productViewHolder.productImageLoading.setVisibility(View.GONE);
                            UIUtils.showLoadingActionBar(getContext(), false);

                        }
                    }, new OnProductLoaded() {
                        @Override
                        public void onProductLoaded(ProductBase productBase, String productCodeFirstVariant) {

                            if (productBase != null) {
                                createExpandedView(mCurrentSelectedViewHolder, productBase);

                                if (!mTriggerSpinnerOnChange) {
                                    mNbVariantLevels = populateVariants(mSpinnersVariants, productBase);

                                    if (StringUtils.isNotBlank(productCodeFirstVariant)) {
                                        selectVariant(productCodeFirstVariant);
                                    }
                                }

                            }

                        }
                    }));

        }
    });

    /**
     * Detect when text is changed
     */
    productViewHolder.quantityEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            try {

                if (cursor.getCount() > cursor.getPosition() && product != null) {
                    if (product.getPrice() != null) {
                        productViewHolder.productPriceTotal.setText(productViewHolder.setTotalPrice(
                                product.getPrice(), productViewHolder.quantityEditText.getText().toString()));
                    }
                }
                productViewHolder.setAddCartButton(true);
            } catch (NumberFormatException e) {
                Log.e(TAG, e.getLocalizedMessage());
            }

        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    /**
     * Detect when text is changed
     */
    productViewHolder.quantityEditTextExpanded.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            try {
                if (cursor.getCount() > cursor.getPosition() && product.getPrice() != null) {
                    productViewHolder.productPriceTotalExpanded
                            .setText(productViewHolder.setTotalPrice(product.getPrice(),
                                    productViewHolder.quantityEditTextExpanded.getText().toString()));
                }
                productViewHolder.setAddCartButton(true);
            } catch (NumberFormatException e) {
                Log.e(TAG, e.getLocalizedMessage());
            }

        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    /**
     * Add to cart when user click on cartIcon in Product item collapsed row
     */
    productViewHolder.productImageViewCartIcon.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            addToCart(product.getCode(), productViewHolder.quantityEditText.getText().toString(),
                    productViewHolder);
            productViewHolder.quantityEditText.setText(getContext().getString(R.string.default_qty));
        }
    });

    productViewHolder.quantityEditText.setOnEditorActionListener(new SubmitListener() {

        @Override
        public void onSubmitAction() {
            addToCart(product.getCode(), productViewHolder.quantityEditText.getText().toString(),
                    productViewHolder);
            productViewHolder.quantityEditText.setText(getContext().getString(R.string.default_qty));
        }
    });

    /**
     * Product item row is expanded and user click the arrow up icon to collapse
     */
    productViewHolder.productItemButtonCollpaseLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            // collapsed
            productViewHolder.collapse();
            mCurrentSelectedViewHolder.collapse();

        }
    });

    /**
     * Product item row is collapsed and user click on the main part of the row to navigate to the product detail page
     */
    productViewHolder.productItemClickableLayoutCollapsed.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ProductHelper.redirectToProductDetail(getContext(),
                    StringUtils.isNotBlank(getFirstVariantCode(product)) ? getFirstVariantCode(product)
                            : product.getCode());
        }
    });

    /**
     * Product item row is collapsed and user click on the main part of the row to navigate to the product detail page
     */
    productViewHolder.productItemClickableLayoutExpanded.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ProductHelper.redirectToProductDetail(getContext(),
                    StringUtils.isNotBlank(getFirstVariantCode(product)) ? getFirstVariantCode(product)
                            : product.getCode());
        }
    });

}

From source file:org.signserver.server.cryptotokens.KeystoreCryptoToken.java

@Override
public void init(int workerId, Properties properties) throws CryptoTokenInitializationFailureException {
    this.properties = properties;
    this.workerId = workerId;
    keystorepath = properties.getProperty(KEYSTOREPATH);
    keystorepassword = properties.getProperty(KEYSTOREPASSWORD);
    keystoretype = properties.getProperty(KEYSTORETYPE);

    // check keystore type
    if (keystoretype == null) {
        throw new CryptoTokenInitializationFailureException("Missing KEYSTORETYPE property");
    }/*from   ww w.j  av a  2  s.c  om*/

    if (!TYPE_PKCS12.equals(keystoretype) && !TYPE_JKS.equals(keystoretype)
            && !TYPE_INTERNAL.equals(keystoretype)) {
        throw new CryptoTokenInitializationFailureException(
                "KEYSTORETYPE should be either PKCS12, JKS, or INTERNAL");
    }

    // check keystore file
    if (TYPE_PKCS12.equals(keystoretype) || TYPE_JKS.equals(keystoretype)) {
        if (keystorepath == null) {
            throw new CryptoTokenInitializationFailureException("Missing KEYSTOREPATH property");
        } else {
            final File keystoreFile = new File(keystorepath);

            if (!keystoreFile.isFile()) {
                throw new CryptoTokenInitializationFailureException("File not found: " + keystorepath);
            }
        }
    }

    // Read property KEYGENERATIONLIMIT
    final String keygenLimitValue = properties.getProperty(CryptoTokenHelper.PROPERTY_KEYGENERATIONLIMIT);
    if (keygenLimitValue != null && !keygenLimitValue.trim().isEmpty()) {
        try {
            keygenerationLimit = Integer.parseInt(keygenLimitValue.trim());
        } catch (NumberFormatException ex) {
            throw new CryptoTokenInitializationFailureException("Incorrect value for "
                    + CryptoTokenHelper.PROPERTY_KEYGENERATIONLIMIT + ": " + ex.getLocalizedMessage());
        }
    }
}

From source file:de.blinkt.openvpn.core.ConfigParser.java

private Pair<Connection, Connection[]> parseConnectionOptions(Connection connDefault) throws ConfigParseError {
    Connection conn;/* w  w  w .j a v  a 2  s.  c  o  m*/
    if (connDefault != null)
        try {
            conn = connDefault.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
            return null;
        }
    else
        conn = new Connection();

    Vector<String> port = getOption("port", 1, 1);
    if (port != null) {
        conn.mServerPort = port.get(1);
    }

    Vector<String> rport = getOption("rport", 1, 1);
    if (rport != null) {
        conn.mServerPort = rport.get(1);
    }

    Vector<String> proto = getOption("proto", 1, 1);
    if (proto != null) {
        conn.mUseUdp = isUdpProto(proto.get(1));
    }

    Vector<String> connectTimeout = getOption("connect-timeout", 1, 1);
    if (connectTimeout != null) {
        try {
            conn.mConnectTimeout = Integer.parseInt(connectTimeout.get(1));
        } catch (NumberFormatException nfe) {
            throw new ConfigParseError(
                    String.format("Argument to connect-timeout (%s) must to be an integer: %s",
                            connectTimeout.get(1), nfe.getLocalizedMessage()));

        }
    }

    // Parse remote config
    Vector<Vector<String>> remotes = getAllOption("remote", 1, 3);

    // Assume that we need custom options if connectionDefault are set
    if (connDefault != null) {
        for (Vector<Vector<String>> option : options.values()) {

            conn.mCustomConfiguration += getOptionStrings(option);

        }
        if (!TextUtils.isEmpty(conn.mCustomConfiguration))
            conn.mUseCustomConfig = true;
    }
    // Make remotes empty to simplify code
    if (remotes == null)
        remotes = new Vector<Vector<String>>();

    Connection[] connections = new Connection[remotes.size()];

    int i = 0;
    for (Vector<String> remote : remotes) {
        try {
            connections[i] = conn.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        switch (remote.size()) {
        case 4:
            connections[i].mUseUdp = isUdpProto(remote.get(3));
        case 3:
            connections[i].mServerPort = remote.get(2);
        case 2:
            connections[i].mServerName = remote.get(1);
        }
        i++;
    }
    return Pair.create(conn, connections);

}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.SelectWMFListener.java

public boolean checkFormat(File file) {
    try {//  w w w.  j  a  v  a 2 s .  c  o  m
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line = br.readLine();
        while ((line = br.readLine()) != null) {
            if (line.compareTo("") != 0) {
                String[] fields = line.split("\t", -1);
                //check columns number
                if (fields.length != 4) {
                    this.selectWMFUI.displayMessage("Error:\nLines have not the right number of columns");
                    br.close();
                    return false;
                }
                //check raw file names
                if (!((ClinicalData) this.dataType).getRawFilesNames().contains(fields[0])) {
                    this.selectWMFUI.displayMessage("Error:\ndata file '" + fields[0] + "' does not exist");
                    br.close();
                    return false;
                }
                //check that column number is set
                if (fields[1].compareTo("") == 0) {
                    this.selectWMFUI.displayMessage("Error:\nColumns numbers have to be set");
                    br.close();
                    return false;
                }
                try {
                    Integer.parseInt(fields[1]);
                } catch (NumberFormatException e) {
                    this.selectWMFUI.displayMessage("Error:\nColumns numbers have to be numbers");
                    br.close();
                    return false;
                }
                //check that original data value is set
                if (fields[2].compareTo("") == 0) {
                    this.selectWMFUI.displayMessage("Error:\nOriginal data values have to be set");
                    br.close();
                    return false;
                }
                //check that new data value is set
                if (fields[3].compareTo("") == 0) {
                    this.selectWMFUI.displayMessage("Error:\nNew data values have to be set");
                    br.close();
                    return false;
                }
            }
        }
        br.close();
    } catch (Exception e) {
        this.selectWMFUI.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:com.amazonaws.mturk.cmd.LoadHITs.java

protected void runCommand(CommandLine cmdLine) throws Exception {
    if (!cmdLine.hasOption(ARG_INPUT)) {

        log.error("Missing: -" + ARG_INPUT + " [path to input file -- ie. c:\\mturk\\helloworld.input]");
        System.exit(-1);/*from  w ww .  j  ava 2s  .co m*/

    } else if (!cmdLine.hasOption(ARG_QUESTION)) {

        log.error("Missing: -" + ARG_QUESTION + " [question file name only -- no path]");
        System.exit(-1);

    } else if (!cmdLine.hasOption(ARG_PROPERTIES)) {

        log.error("Missing: -" + ARG_PROPERTIES
                + " [path to config file -- ie. c:\\mturk\\helloworld.properties]");
        System.exit(-1);

    } else {

        int maxHITs = MAX_HITS_UNLIMITED;

        if (cmdLine.hasOption(ARG_MAXHITS)) {

            String maxHITsValue = cmdLine.getOptionValue(ARG_MAXHITS);

            try {

                maxHITs = Integer.parseInt(maxHITsValue);

            } catch (NumberFormatException e) {
                log.error("Invalid value provided for maxhits: " + maxHITsValue);
                System.exit(-1);
            }
        }

        try {
            loadHITs(cmdLine.getOptionValue(ARG_INPUT), cmdLine.getOptionValue(ARG_QUESTION),
                    cmdLine.getOptionValue(ARG_PROPERTIES), cmdLine.getOptionValue(ARG_PREVIEW_FILE), maxHITs,
                    cmdLine.hasOption(ARG_PREVIEW), cmdLine.getOptionValue(ARG_LABEL), false);
        } catch (ObjectDoesNotExistException objEx) {
            log.error(String.format(
                    "The qualification for the HITs does not exist. Please review the qualification settings in '%s' before retrying. ",
                    cmdLine.getOptionValue(ARG_PROPERTIES)));
            System.exit(-1);
        } catch (Exception e) {
            log.error("Error loading HITs: " + e.getLocalizedMessage(), e);
            System.exit(-1);
        }
    }
}

From source file:fr.paris.lutece.portal.service.page.PageService.java

/**
 * Returns the page for a given ID. The page is built using XML data of each
 * portlet or retrieved from the cache if it's enable.
 *
 * @param strIdPage/* w  ww .  ja v  a2  s  . c  o  m*/
 *            The page ID
 * @param nMode
 *            The current mode.
 * @param request
 *            The HttpRequest
 * @return The HTML code of the page as a String.
 * @throws SiteMessageException
 *             occurs when a site message need to be displayed
 */
@Override
public String getPage(String strIdPage, int nMode, HttpServletRequest request) throws SiteMessageException {
    try {
        String strPage = "";

        // The cache is enable !
        if (_cachePages.isCacheEnable()) {
            // Get request paramaters and store them in a HashMap
            Enumeration<?> enumParam = request.getParameterNames();
            HashMap<String, String> htParamRequest = new HashMap<String, String>();
            String paramName = "";

            while (enumParam.hasMoreElements()) {
                paramName = (String) enumParam.nextElement();
                htParamRequest.put(paramName, request.getParameter(paramName));
            }

            if (!htParamRequest.containsKey(Parameters.PAGE_ID)) {
                htParamRequest.put(Parameters.PAGE_ID, strIdPage);
            }

            LuteceUser user = SecurityService.getInstance().getRegisteredUser(request);
            String strUserTheme = ThemesService.getUserTheme(request);

            if (strUserTheme != null) {
                htParamRequest.put(KEY_THEME, strUserTheme);
            }

            // we add the key in the memory key only if cache is enable
            String strKey = getKey(htParamRequest, nMode, user);

            // get page from cache
            strPage = (String) _cachePages.getFromCache(strKey);

            if (strPage == null) {
                // only one thread can evaluate the page
                synchronized (strKey) {
                    // can be useful if an other thread had evaluate the
                    // page
                    strPage = (String) _cachePages.getFromCache(strKey);

                    // ignore checkstyle, this double verification is useful
                    // when page cache has been created when thread is
                    // blocked on synchronized
                    if (strPage == null) {
                        Boolean bCanBeCached = Boolean.TRUE;

                        AppLogService.debug("Page generation " + strKey);

                        RedirectionResponseWrapper response = new RedirectionResponseWrapper(
                                LocalVariables.getResponse());

                        LocalVariables.setLocal(LocalVariables.getConfig(), LocalVariables.getRequest(),
                                response);
                        request.setAttribute(ATTRIBUTE_CORE_CAN_PAGE_BE_CACHED, null);
                        // The key is not in the cache, so we have to build
                        // the page
                        strPage = buildPageContent(strIdPage, nMode, request, bCanBeCached);

                        // We check if the page contains portlets that can not be cached. 
                        if ((request.getAttribute(ATTRIBUTE_CORE_CAN_PAGE_BE_CACHED) != null)
                                && !(Boolean) request.getAttribute(ATTRIBUTE_CORE_CAN_PAGE_BE_CACHED)) {
                            bCanBeCached = Boolean.FALSE;
                        }

                        if (response.getRedirectLocation() != null) {
                            AppLogService.debug("Redirection found " + response.getRedirectLocation());
                            strPage = REDIRECTION_KEY + response.getRedirectLocation();
                        }

                        // Add the page to the cache if the page can be
                        // cached
                        if (bCanBeCached.booleanValue() && (nMode != MODE_ADMIN)) {
                            _cachePages.putInCache(strKey, strPage);
                        }
                    } else {
                        AppLogService.debug("Page read from cache after synchronisation " + strKey);
                    }
                }
            } else {
                AppLogService.debug("Page read from cache " + strKey);
            }

            // redirection handling
            if (strPage.startsWith(REDIRECTION_KEY)) {
                strPage = strPage.replaceFirst(REDIRECTION_KEY, "");

                try {
                    LocalVariables.getResponse().sendRedirect(strPage);
                } catch (IOException e) {
                    AppLogService.error("Error on sendRedirect for " + strPage);
                }
            }
        } else {
            Boolean bCanBeCached = Boolean.FALSE;
            strPage = buildPageContent(strIdPage, nMode, request, bCanBeCached);
        }

        strPage = setPageBaseUrl(request, strPage);

        return strPage;
    } catch (NumberFormatException nfe) {
        AppLogService.error("PageService.getPage() : " + nfe.getLocalizedMessage(), nfe);

        throw new PageNotFoundException();
    }
}

From source file:com.clust4j.data.BufferedMatrixReader.java

/**
 * Read in the data/*from  w  w  w  .  ja va2 s .c om*/
 * @param parallel - whether to parallelize the operation
 * @return the matrix
 * @throws MatrixParseException
 */
public DataSet read(boolean parallel) throws MatrixParseException {
    LogTimer timer = new LogTimer();
    String msg;

    /*
     * Get lines...
     */
    String[] lines = getLines(setup.stream);

    // Potential for truncation here...
    if (lines.length == GlobalState.MAX_ARRAY_SIZE)
        warn("only " + lines.length + " rows read from data, " + "as this is the max clust4j allows");
    else
        info((lines.length - setup.header_offset) + " record" + (lines.length == 1 ? "" : "s") + " ("
                + setup.stream.length + " byte" + (setup.stream.length == 1 ? "" : "s") + ") read from file");

    /*
     * Do double parsing...
     */
    double[][] res = null;
    if (!parallel) {
        // Let any exceptions propagate
        res = parseSerial(lines);
    } else {

        boolean throwing_exception = true;
        try {
            res = ParallelChunkParser.doAll(lines, setup);
        } catch (NumberFormatException n) {
            error(new MatrixParseException("caught NumberFormatException: " + n.getLocalizedMessage()));
        } catch (DimensionMismatchException d) {
            error(new MatrixParseException("caught row of unexpected dimensions: " + d.getMessage()));
        } catch (RejectedExecutionException r) {
            throwing_exception = false;
            warn("unable to schedule parallel job; falling back to serial parse");
            res = parseSerial(lines);
        } catch (Exception e) {
            msg = "encountered Exception in thread" + e.getMessage();
            error(msg);
            throw e;
        } finally {
            if (null == res && !throwing_exception)
                throw new RuntimeException("unable to parse data");
        }
    }

    sayBye(timer);
    return new DataSet(res, setup.headers);
}

From source file:com.microsoft.tfs.client.common.ui.wit.dialogs.WorkItemPickerDialog.java

private Query makeIDsQuery() {

    int[] workItemIds = null;

    try {// w  w w. j a v  a  2 s . c o  m
        workItemIds = WorkItemLinkUtils.buildWorkItemIDListFromText(idsText.getText());
    } catch (final NumberFormatException e) {
        MessageBoxHelpers.errorMessageBox(getShell(),
                Messages.getString("WorkItemPickerDialog.ErrorDialogTitle"), //$NON-NLS-1$
                e.getLocalizedMessage());
        return null;
    } catch (final RuntimeException e) {
    }

    if (workItemIds == null || workItemIds.length == 0) {
        MessageBoxHelpers.errorMessageBox(getShell(),
                Messages.getString("WorkItemPickerDialog.ErrorDialogTitle"), //$NON-NLS-1$
                Messages.getString("WorkItemPickerDialog.IdErrorDialogText")); //$NON-NLS-1$
        return null;
    }

    final StringBuffer sb = new StringBuffer();

    sb.append("SELECT ["); //$NON-NLS-1$
    sb.append(CoreFieldReferenceNames.ID);
    sb.append("] From WorkItem WHERE ["); //$NON-NLS-1$

    sb.append(CoreFieldReferenceNames.ID);
    sb.append("] IN ("); //$NON-NLS-1$

    for (int i = 0; i < workItemIds.length; i++) {
        if (i > 0) {
            sb.append(","); //$NON-NLS-1$
        }
        sb.append(workItemIds[i]);
    }
    sb.append(")"); //$NON-NLS-1$

    final Project project = getSelectedProject();
    if (project != null) {
        sb.append(" AND ["); //$NON-NLS-1$
        sb.append(CoreFieldReferenceNames.AREA_PATH);
        sb.append("] UNDER \""); //$NON-NLS-1$
        sb.append(project.getName());
        sb.append("\""); //$NON-NLS-1$
    }

    if (workItemTypeFilterWhereClause != null) {
        sb.append(" AND "); //$NON-NLS-1$
        sb.append(workItemTypeFilterWhereClause);
    }

    sb.append(" ORDER BY ["); //$NON-NLS-1$
    sb.append(CoreFieldReferenceNames.ID);
    sb.append("]"); //$NON-NLS-1$

    final String wiql = sb.toString();
    if (log.isTraceEnabled()) {
        log.trace("ids query: [" + wiql + "]"); //$NON-NLS-1$ //$NON-NLS-2$
    }

    return workItemClient.createQuery(wiql);
}

From source file:org.openestate.io.is24_csv.Is24CsvRecord.java

public Integer getGruppierungId() {
    try {/*from   w  ww .  j  a va 2  s .c  o  m*/
        return Is24CsvFormat.parseInteger(this.get(FIELD_GRUPPIERUNG_ID));
    } catch (NumberFormatException ex) {
        LOGGER.warn("Can't read 'Gruppierung ID'!");
        LOGGER.warn("> " + ex.getLocalizedMessage(), ex);
        return null;
    }
}