Example usage for java.text MessageFormat applyPattern

List of usage examples for java.text MessageFormat applyPattern

Introduction

In this page you can find the example usage for java.text MessageFormat applyPattern.

Prototype

@SuppressWarnings("fallthrough") 
public void applyPattern(String pattern) 

Source Link

Document

Sets the pattern used by this message format.

Usage

From source file:org.web4thejob.print.CsvPrinter.java

@Override
public File print(String title, RenderScheme renderScheme, Query query, List<Entity> entities) {
    Assert.notNull(renderScheme);// w w w.j a  v  a2s. c  o  m
    Assert.isTrue(renderScheme.getSchemeType() == SchemeType.LIST_SCHEME);

    if (entities == null) {
        Assert.notNull(query);
        entities = ContextUtil.getDRS().findByQuery(query);
    }

    File file;
    try {
        String crlf = System.getProperty("line.separator");
        file = createTempFile();
        BufferedWriter writer = createFileStream(file);
        writer.write(title + crlf);
        writer.newLine();

        if (query != null && query.hasMasterCriterion()) {
            writer.write(describeMasterCriteria(query));
            writer.newLine();
        }

        if (query != null) {
            writer.write(describeCriteria(query));
            writer.newLine();
        }

        CSVWriter csv = new CSVWriter(writer);
        List<String> header = new ArrayList<String>();
        for (RenderElement item : renderScheme.getElements()) {
            if (item.getPropertyPath().getLastStep().isBlobType())
                continue;
            header.add(item.getFriendlyName());
        }
        csv.writeNext(header.toArray(new String[header.size()]));

        ConversionService conversionService = ContextUtil.getBean(ConversionService.class);
        for (final Entity entity : entities) {
            writeLine(csv, conversionService, entity, renderScheme);
        }

        writer.newLine();

        //timestamp
        List<String> line = new ArrayList<String>();
        line.add(L10nMessages.L10N_LABEL_TIMESTAMP.toString());
        MessageFormat df = new MessageFormat("");
        df.setLocale(CoreUtil.getUserLocale());
        df.applyPattern("{0,date,yyyy-MM-dd hh:mm:ss}");
        line.add(df.format(new Object[] { new Date() }));
        csv.writeNext(line.toArray(new String[line.size()]));

        writer.newLine();

        writer.write("powered by web4thejob.org");
        writer.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return file;
}

From source file:net.jcreate.e3.table.message.AbstractMessageSource.java

/**
 * Create a MessageFormat for the given message and Locale.
 * <p>This implementation creates an empty MessageFormat first,
 * populating it with Locale and pattern afterwards, to stay
 * compatible with J2SE 1.3./*  w  ww . j  av a  2 s  .  c o m*/
 * @param msg the message to create a MessageFormat for
 * @param locale the Locale to create a MessageFormat for
 * @return the MessageFormat instance
 */
protected MessageFormat createMessageFormat(String msg, Locale locale) {
    if (logger.isDebugEnabled()) {
        logger.debug("Creating MessageFormat for pattern [" + msg + "] and locale '" + locale + "'");
    }
    MessageFormat messageFormat = new MessageFormat("");
    messageFormat.setLocale(locale);
    if (msg != null) {
        messageFormat.applyPattern(msg);
    }
    return messageFormat;
}

From source file:org.eclipse.swt.examples.accessibility.BarChart.java

void addListeners() {
    addPaintListener(e -> {/*  www . j av a  2  s . co  m*/
        GC gc = e.gc;
        Rectangle rect = getClientArea();
        Display display = getDisplay();
        int count = data.size();
        Point valueSize = gc.stringExtent(Integer.valueOf(valueMax).toString());
        int leftX = rect.x + 2 * GAP + valueSize.x;
        int bottomY = rect.y + rect.height - 2 * GAP - valueSize.y;
        int unitWidth = (rect.width - 4 * GAP - valueSize.x - AXIS_WIDTH) / count - GAP;
        int unitHeight = (rect.height - 3 * GAP - AXIS_WIDTH - 2 * valueSize.y)
                / ((valueMax - valueMin) / valueIncrement);
        // draw the title
        int titleWidth = gc.stringExtent(title).x;
        int center = (Math.max(titleWidth, count * (unitWidth + GAP) + GAP) - titleWidth) / 2;
        gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
        gc.drawString(title, leftX + AXIS_WIDTH + center, rect.y + GAP);
        // draw the y axis and value labels
        gc.setLineWidth(AXIS_WIDTH);
        gc.drawLine(leftX, rect.y + GAP + valueSize.y, leftX, bottomY);
        for (int i1 = valueMin; i1 <= valueMax; i1 += valueIncrement) {
            int y = bottomY - i1 * unitHeight;
            gc.drawLine(leftX, y, leftX - GAP, y);
            gc.drawString(Integer.valueOf(i1).toString(), rect.x + GAP, y - valueSize.y);
        }
        // draw the x axis and item labels
        gc.drawLine(leftX, bottomY, rect.x + rect.width - GAP, bottomY);
        for (int i2 = 0; i2 < count; i2++) {
            Object[] dataItem1 = data.get(i2);
            String itemLabel = (String) dataItem1[0];
            int x1 = leftX + AXIS_WIDTH + GAP + i2 * (unitWidth + GAP);
            gc.drawString(itemLabel, x1, bottomY + GAP);
        }
        // draw the bars
        gc.setBackground(display.getSystemColor(color));
        for (int i3 = 0; i3 < count; i3++) {
            Object[] dataItem2 = data.get(i3);
            int itemValue1 = ((Integer) dataItem2[1]).intValue();
            int x2 = leftX + AXIS_WIDTH + GAP + i3 * (unitWidth + GAP);
            gc.fillRectangle(x2, bottomY - AXIS_WIDTH - itemValue1 * unitHeight, unitWidth,
                    itemValue1 * unitHeight);
        }
        if (isFocusControl()) {
            if (selectedItem == -1) {
                // draw the focus rectangle around the whole bar chart
                gc.drawFocus(rect.x, rect.y, rect.width, rect.height);
            } else {
                // draw the focus rectangle around the selected item
                Object[] dataItem3 = data.get(selectedItem);
                int itemValue2 = ((Integer) dataItem3[1]).intValue();
                int x3 = leftX + AXIS_WIDTH + GAP + selectedItem * (unitWidth + GAP);
                gc.drawFocus(x3, bottomY - itemValue2 * unitHeight - AXIS_WIDTH, unitWidth,
                        itemValue2 * unitHeight + AXIS_WIDTH + GAP + valueSize.y);
            }
        }
    });

    addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            redraw();
        }

        @Override
        public void focusLost(FocusEvent e) {
            redraw();
        }
    });

    addMouseListener(MouseListener.mouseDownAdapter(e -> {
        if (getClientArea().contains(e.x, e.y)) {
            setFocus();
            int item = -1;
            int count = data.size();
            for (int i = 0; i < count; i++) {
                if (itemBounds(i).contains(e.x, e.y)) {
                    item = i;
                    break;
                }
            }
            if (item != selectedItem) {
                selectedItem = item;
                redraw();
                getAccessible().setFocus(item);
                getAccessible().selectionChanged();
            }
        }
    }));

    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            boolean change = false;
            switch (e.keyCode) {
            case SWT.ARROW_DOWN:
            case SWT.ARROW_RIGHT:
                selectedItem++;
                if (selectedItem >= data.size())
                    selectedItem = 0;
                change = true;
                break;
            case SWT.ARROW_UP:
            case SWT.ARROW_LEFT:
                selectedItem--;
                if (selectedItem <= -1)
                    selectedItem = data.size() - 1;
                change = true;
                break;
            case SWT.HOME:
                selectedItem = 0;
                change = true;
                break;
            case SWT.END:
                selectedItem = data.size() - 1;
                change = true;
                break;
            }
            if (change) {
                redraw();
                getAccessible().setFocus(selectedItem);
                getAccessible().selectionChanged();
            }
        }
    });

    addTraverseListener(e -> {
        switch (e.detail) {
        case SWT.TRAVERSE_TAB_NEXT:
        case SWT.TRAVERSE_TAB_PREVIOUS:
            e.doit = true;
            break;
        }
    });

    getAccessible().addAccessibleListener(new AccessibleAdapter() {
        @Override
        public void getName(AccessibleEvent e) {
            MessageFormat formatter = new MessageFormat(""); //$NON_NLS$
            formatter.applyPattern(bundle.getString("name")); //$NON_NLS$
            int childID = e.childID;
            if (childID == ACC.CHILDID_SELF) {
                e.result = title;
            } else {
                Object[] item = data.get(childID);
                e.result = formatter.format(item);
            }
        }

        @Override
        public void getDescription(AccessibleEvent e) {
            int childID = e.childID;
            if (childID != ACC.CHILDID_SELF) {
                Object[] item = data.get(childID);
                String value = item[1].toString();
                String colorName = bundle.getString("color" + color); //$NON_NLS$
                MessageFormat formatter = new MessageFormat(""); //$NON_NLS$
                formatter.applyPattern(bundle.getString("color_value")); //$NON_NLS$
                e.result = formatter.format(new String[] { colorName, value });
            }
        }
    });

    getAccessible().addAccessibleControlListener(new AccessibleControlAdapter() {
        @Override
        public void getRole(AccessibleControlEvent e) {
            if (e.childID == ACC.CHILDID_SELF) {
                e.detail = ACC.ROLE_LIST;
            } else {
                e.detail = ACC.ROLE_LISTITEM;
            }
        }

        @Override
        public void getChildCount(AccessibleControlEvent e) {
            e.detail = data.size();
        }

        @Override
        public void getChildren(AccessibleControlEvent e) {
            int count = data.size();
            Object[] children = new Object[count];
            for (int i = 0; i < count; i++) {
                children[i] = Integer.valueOf(i);
            }
            e.children = children;
        }

        @Override
        public void getChildAtPoint(AccessibleControlEvent e) {
            Point testPoint = toControl(e.x, e.y);
            int childID = ACC.CHILDID_NONE;
            if (getClientArea().contains(testPoint)) {
                childID = ACC.CHILDID_SELF;
                int count = data.size();
                for (int i = 0; i < count; i++) {
                    if (itemBounds(i).contains(testPoint)) {
                        childID = i;
                        break;
                    }
                }
            }
            e.childID = childID;
        }

        @Override
        public void getLocation(AccessibleControlEvent e) {
            Rectangle location = null;
            Point pt = null;
            int childID = e.childID;
            if (childID == ACC.CHILDID_SELF) {
                location = getClientArea();
                pt = getParent().toDisplay(location.x, location.y);
            } else {
                location = itemBounds(childID);
                pt = toDisplay(location.x, location.y);
            }
            e.x = pt.x;
            e.y = pt.y;
            e.width = location.width;
            e.height = location.height;
        }

        @Override
        public void getFocus(AccessibleControlEvent e) {
            int childID = ACC.CHILDID_NONE;
            if (isFocusControl()) {
                if (selectedItem == -1) {
                    childID = ACC.CHILDID_SELF;
                } else {
                    childID = selectedItem;
                }
            }
            e.childID = childID;

        }

        @Override
        public void getSelection(AccessibleControlEvent e) {
            e.childID = (selectedItem == -1) ? ACC.CHILDID_NONE : selectedItem;
        }

        @Override
        public void getValue(AccessibleControlEvent e) {
            int childID = e.childID;
            if (childID != ACC.CHILDID_SELF) {
                Object[] dataItem = data.get(childID);
                e.result = ((Integer) dataItem[1]).toString();
            }
        }

        @Override
        public void getState(AccessibleControlEvent e) {
            int childID = e.childID;
            e.detail = ACC.STATE_FOCUSABLE;
            if (isFocusControl())
                e.detail |= ACC.STATE_FOCUSED;
            if (childID != ACC.CHILDID_SELF) {
                e.detail |= ACC.STATE_SELECTABLE;
                if (childID == selectedItem)
                    e.detail |= ACC.STATE_SELECTED;
            }
        }
    });
}

From source file:json_to_xml_1.java

private String getI10nStringFormatted(String i10nStringName, Object... arguments) {
    MessageFormat formatter = new MessageFormat("");
    formatter.setLocale(this.getLocale());

    formatter.applyPattern(getI10nString(i10nStringName));
    return formatter.format(arguments);
}

From source file:org.akaza.openclinica.control.submit.ImportCRFDataServlet.java

@Override
public void processRequest() throws Exception {
    resetPanel();/*  w  w w  .  j  av a 2 s .c  om*/
    panel.setStudyInfoShown(false);
    panel.setOrderedData(true);

    FormProcessor fp = new FormProcessor(request);
    // checks which module the requests are from
    String module = fp.getString(MODULE);
    // keep the module in the session
    session.setAttribute(MODULE, module);

    String action = request.getParameter("action");
    CRFVersionBean version = (CRFVersionBean) session.getAttribute("version");

    File xsdFile = new File(SpringServletAccess.getPropertiesDir(context) + "ODM1-3-0.xsd");
    File xsdFile2 = new File(SpringServletAccess.getPropertiesDir(context) + "ODM1-2-1.xsd");

    if (StringUtil.isBlank(action)) {
        logger.info("action is blank");
        request.setAttribute("version", version);
        forwardPage(Page.IMPORT_CRF_DATA);
    }
    if ("confirm".equalsIgnoreCase(action)) {
        String dir = SQLInitServlet.getField("filePath");
        if (!new File(dir).exists()) {
            logger.info("The filePath in datainfo.properties is invalid " + dir);
            addPageMessage(respage.getString("filepath_you_defined_not_seem_valid"));
            forwardPage(Page.IMPORT_CRF_DATA);
        }
        // All the uploaded files will be saved in filePath/crf/original/
        String theDir = dir + "crf" + File.separator + "original" + File.separator;
        if (!new File(theDir).isDirectory()) {
            new File(theDir).mkdirs();
            logger.info("Made the directory " + theDir);
        }
        // MultipartRequest multi = new MultipartRequest(request, theDir, 50 * 1024 * 1024);
        File f = null;
        try {
            f = uploadFile(theDir, version);

        } catch (Exception e) {
            logger.warn("*** Found exception during file upload***");
            e.printStackTrace();

        }
        if (f == null) {
            forwardPage(Page.IMPORT_CRF_DATA);
        }

        // TODO
        // validation steps
        // 1. valid xml - validated by file uploader below

        // LocalConfiguration config = LocalConfiguration.getInstance();
        // config.getProperties().setProperty(
        // "org.exolab.castor.parser.namespaces",
        // "true");
        // config
        // .getProperties()
        // .setProperty("org.exolab.castor.sax.features",
        // "http://xml.org/sax/features/validation,
        // http://apache.org/xml/features/validation/schema,
        // http://apache.org/xml/features/validation/schema-full-checking");
        // // above sets to validate against namespace

        Mapping myMap = new Mapping();
        // @pgawade 18-April-2011 Fix for issue 8394
        String ODM_MAPPING_DIRPath = CoreResources.ODM_MAPPING_DIR;
        myMap.loadMapping(ODM_MAPPING_DIRPath + File.separator + "cd_odm_mapping.xml");

        Unmarshaller um1 = new Unmarshaller(myMap);
        // um1.addNamespaceToPackageMapping("http://www.openclinica.org/ns/odm_ext_v130/v3.1", "OpenClinica");
        // um1.addNamespaceToPackageMapping("http://www.cdisc.org/ns/odm/v1.3"
        // ,
        // "ODMContainer");
        boolean fail = false;
        ODMContainer odmContainer = new ODMContainer();
        session.removeAttribute("odmContainer");
        try {

            // schemaValidator.validateAgainstSchema(f, xsdFile);
            // utf-8 compliance, tbh 06/2009
            InputStreamReader isr = new InputStreamReader(new FileInputStream(f), "UTF-8");
            odmContainer = (ODMContainer) um1.unmarshal(isr);

            logger.debug("Found crf data container for study oid: "
                    + odmContainer.getCrfDataPostImportContainer().getStudyOID());
            logger.debug("found length of subject list: "
                    + odmContainer.getCrfDataPostImportContainer().getSubjectData().size());
            // 2. validates against ODM 1.3
            // check it all below, throw an exception and route to a
            // different
            // page if not working

            // TODO this block of code needs the xerces serializer in order
            // to
            // work

            // StringWriter myWriter = new StringWriter();
            // Marshaller m1 = new Marshaller(myWriter);
            //
            // m1.setProperty("org.exolab.castor.parser.namespaces",
            // "true");
            // m1
            // .setProperty("org.exolab.castor.sax.features",
            // "http://xml.org/sax/features/validation,
            // http://apache.org/xml/features/validation/schema,
            // http://apache.org/xml/features/validation/schema-full-checking
            // ");
            //
            // m1.setMapping(myMap);
            // m1.setNamespaceMapping("",
            // "http://www.cdisc.org/ns/odm/v1.3");
            // m1.setSchemaLocation("http://www.cdisc.org/ns/odm/v1.3
            // ODM1-3.xsd");
            // m1.marshal(odmContainer);
            // if you havent thrown it, you wont throw it here
            addPageMessage(respage.getString("passed_xml_validation"));
        } catch (Exception me1) {
            me1.printStackTrace();
            // expanding it to all exceptions, but hoping to catch Marshal
            // Exception or SAX Exceptions
            logger.info("found exception with xml transform");
            //
            logger.info("trying 1.2.1");
            try {
                schemaValidator.validateAgainstSchema(f, xsdFile2);
                // for backwards compatibility, we also try to validate vs
                // 1.2.1 ODM 06/2008
                InputStreamReader isr = new InputStreamReader(new FileInputStream(f), "UTF-8");
                odmContainer = (ODMContainer) um1.unmarshal(isr);
            } catch (Exception me2) {
                // not sure if we want to report me2
                MessageFormat mf = new MessageFormat("");
                mf.applyPattern(respage.getString("your_xml_is_not_well_formed"));
                Object[] arguments = { me1.getMessage() };
                addPageMessage(mf.format(arguments));
                //
                // addPageMessage("Your XML is not well-formed, and does not
                // comply with the ODM 1.3 Schema. Please check it, and try
                // again. It returned the message: "
                // + me1.getMessage());
                // me1.printStackTrace();
                forwardPage(Page.IMPORT_CRF_DATA);
                // you can't really wait to forward because then you throw
                // NPEs
                // in the next few parts of the code
            }
        }
        // TODO need to output further here
        // 2.a. is the study the same one that the user is in right now?
        // 3. validates against study metadata
        // 3.a. is that study subject in that study?
        // 3.b. is that study event def in that study?
        // 3.c. is that site in that study?
        // 3.d. is that crf version in that study event def?
        // 3.e. are those item groups in that crf version?
        // 3.f. are those items in that item group?

        List<String> errors = getImportCRFDataService().validateStudyMetadata(odmContainer,
                ub.getActiveStudyId());
        if (errors != null) {
            // add to session
            // forward to another page
            logger.info(errors.toString());
            for (String error : errors) {
                addPageMessage(error);
            }
            if (errors.size() > 0) {
                // fail = true;
                forwardPage(Page.IMPORT_CRF_DATA);
            } else {
                addPageMessage(respage.getString("passed_study_check"));
                addPageMessage(respage.getString("passed_oid_metadata_check"));
            }

        }
        logger.debug("passed error check");
        // TODO ADD many validation steps before we get to the
        // session-setting below
        // 4. is the event in the correct status to accept data import?
        // -- scheduled, data entry started, completed
        // (and the event should already be created)
        // (and the event should be independent, ie not affected by other
        // events)

        Boolean eventCRFStatusesValid = getImportCRFDataService().eventCRFStatusesValid(odmContainer, ub);
        ImportCRFInfoContainer importCrfInfo = new ImportCRFInfoContainer(odmContainer, sm.getDataSource());
        // The eventCRFBeans list omits EventCRFs that don't match UpsertOn rules. If EventCRF did not exist and
        // doesn't match upsert, it won't be created.
        List<EventCRFBean> eventCRFBeans = getImportCRFDataService().fetchEventCRFBeans(odmContainer, ub);
        List<DisplayItemBeanWrapper> displayItemBeanWrappers = new ArrayList<DisplayItemBeanWrapper>();
        HashMap<String, String> totalValidationErrors = new HashMap<String, String>();
        HashMap<String, String> hardValidationErrors = new HashMap<String, String>();
        // The following map is used for setting the EventCRF status post import.
        HashMap<Integer, String> importedCRFStatuses = getImportCRFDataService()
                .fetchEventCRFStatuses(odmContainer);
        // @pgawade 17-May-2011 Fix for issue#9590 - collection of
        // eventCRFBeans is returned as null
        // when status of one the events in xml file is either stopped,
        // signed or locked.
        // Instead of repeating the code to fetch the events in xml file,
        // method in the ImportCRFDataService is modified for this fix.
        if (eventCRFBeans == null) {
            fail = true;
            addPageMessage(respage.getString("no_event_status_matching"));
        } else {
            ArrayList<Integer> permittedEventCRFIds = new ArrayList<Integer>();
            logger.info("found a list of eventCRFBeans: " + eventCRFBeans.toString());

            // List<DisplayItemBeanWrapper> displayItemBeanWrappers = new ArrayList<DisplayItemBeanWrapper>();
            // HashMap<String, String> totalValidationErrors = new
            // HashMap<String, String>();
            // HashMap<String, String> hardValidationErrors = new
            // HashMap<String, String>();
            logger.debug("found event crfs " + eventCRFBeans.size());
            // -- does the event already exist? if not, fail
            if (!eventCRFBeans.isEmpty()) {
                for (EventCRFBean eventCRFBean : eventCRFBeans) {
                    DataEntryStage dataEntryStage = eventCRFBean.getStage();
                    Status eventCRFStatus = eventCRFBean.getStatus();

                    logger.info("Event CRF Bean: id " + eventCRFBean.getId() + ", data entry stage "
                            + dataEntryStage.getName() + ", status " + eventCRFStatus.getName());
                    if (eventCRFStatus.equals(Status.AVAILABLE)
                            || dataEntryStage.equals(DataEntryStage.INITIAL_DATA_ENTRY)
                            || dataEntryStage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE)
                            || dataEntryStage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE)
                            || dataEntryStage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
                        // actually want the negative
                        // was status == available and the stage questions, but
                        // when you are at 'data entry complete' your status is
                        // set to 'unavailable'.
                        // >> tbh 09/2008
                        // HOWEVER, when one event crf is removed and the rest
                        // are good, what happens???
                        // need to create a list and inform that one is blocked
                        // and the rest are not...
                        //
                        permittedEventCRFIds.add(new Integer(eventCRFBean.getId()));
                    } else {
                        // fail = true;
                        // addPageMessage(respage.getString(
                        // "the_event_crf_not_correct_status"));
                        // forwardPage(Page.IMPORT_CRF_DATA);
                    }
                }

                // so that we don't repeat this following message
                // did we exclude all the event CRFs? if not, pass, else fail
                if (eventCRFBeans.size() >= permittedEventCRFIds.size()) {
                    addPageMessage(respage.getString("passed_event_crf_status_check"));
                } else {
                    fail = true;
                    addPageMessage(respage.getString("the_event_crf_not_correct_status"));
                }
                // do they all have to have the right status to move
                // forward? answer from bug tracker = no
                // 5. do the items contain the correct data types?

                // 6. are all the related OIDs present?
                // that is to say, do we chain all the way down?
                // this is covered by the OID Metadata Check

                // 7. do the edit checks pass?
                // only then can we pass on to VERIFY_IMPORT_SERVLET

                // do we overwrite?

                // XmlParser xp = new XmlParser();
                // List<HashMap<String, String>> importedData =
                // xp.getData(f);

                // now we generate hard edit checks, and have to set that to the
                // screen. get that from the service, generate a summary bean to
                // set to either
                // page in the workflow, either verifyImport.jsp or import.jsp

                try {
                    List<DisplayItemBeanWrapper> tempDisplayItemBeanWrappers = new ArrayList<DisplayItemBeanWrapper>();
                    tempDisplayItemBeanWrappers = getImportCRFDataService().lookupValidationErrors(request,
                            odmContainer, ub, totalValidationErrors, hardValidationErrors,
                            permittedEventCRFIds);
                    logger.debug("generated display item bean wrappers " + tempDisplayItemBeanWrappers.size());
                    logger.debug("size of total validation errors: " + totalValidationErrors.size());
                    displayItemBeanWrappers.addAll(tempDisplayItemBeanWrappers);
                } catch (NullPointerException npe1) {
                    // what if you have 2 event crfs but the third is a fake?
                    fail = true;
                    logger.debug("threw a NPE after calling lookup validation errors");
                    System.out.println(ExceptionUtils.getStackTrace(npe1));
                    addPageMessage(respage.getString("an_error_was_thrown_while_validation_errors"));
                    // npe1.printStackTrace();
                } catch (OpenClinicaException oce1) {
                    fail = true;
                    logger.debug("threw an OCE after calling lookup validation errors "
                            + oce1.getOpenClinicaMessage());
                    addPageMessage(oce1.getOpenClinicaMessage());
                }
            } else if (!eventCRFStatusesValid) {
                fail = true;
                addPageMessage(respage.getString("the_event_crf_not_correct_status"));
            } else {
                fail = true;
                addPageMessage(respage.getString("no_event_crfs_matching_the_xml_metadata"));
            }
            // for (HashMap<String, String> crfData : importedData) {
            // DisplayItemBeanWrapper displayItemBeanWrapper =
            // testing(request,
            // crfData);
            // displayItemBeanWrappers.add(displayItemBeanWrapper);
            // errors = displayItemBeanWrapper.getValidationErrors();
            //
            // }
        }
        if (fail) {
            logger.debug("failed here - forwarding...");
            forwardPage(Page.IMPORT_CRF_DATA);
        } else {
            addPageMessage(respage.getString("passing_crf_edit_checks"));
            session.setAttribute("odmContainer", odmContainer);
            session.setAttribute("importedData", displayItemBeanWrappers);
            session.setAttribute("validationErrors", totalValidationErrors);
            session.setAttribute("hardValidationErrors", hardValidationErrors);
            session.setAttribute("importedCRFStatuses", importedCRFStatuses);
            session.setAttribute("importCrfInfo", importCrfInfo);
            // above are updated 'statically' by the method that originally
            // generated the wrappers; soon the only thing we will use
            // wrappers for is the 'overwrite' flag

            logger.debug("+++ content of total validation errors: " + totalValidationErrors.toString());
            SummaryStatsBean ssBean = getImportCRFDataService().generateSummaryStatsBean(odmContainer,
                    displayItemBeanWrappers, importCrfInfo);
            session.setAttribute("summaryStats", ssBean);
            // will have to set hard edit checks here as well
            session.setAttribute("subjectData", odmContainer.getCrfDataPostImportContainer().getSubjectData());
            forwardPage(Page.VERIFY_IMPORT_SERVLET);
        }
        // }
    }
}

From source file:com.opensymphony.xwork2.util.DefaultLocalizedTextProvider.java

private MessageFormat buildMessageFormat(String pattern, Locale locale) {
    MessageFormatKey key = new MessageFormatKey(pattern, locale);
    MessageFormat format = messageFormats.get(key);
    if (format == null) {
        format = new MessageFormat(pattern);
        format.setLocale(locale);//from  www  . j  a v  a2 s  . c  o  m
        format.applyPattern(pattern);
        messageFormats.put(key, format);
    }

    return format;
}