Example usage for java.lang Boolean Boolean

List of usage examples for java.lang Boolean Boolean

Introduction

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

Prototype

@Deprecated(since = "9")
public Boolean(String s) 

Source Link

Document

Allocates a Boolean object representing the value true if the string argument is not null and is equal, ignoring case, to the string "true" .

Usage

From source file:com.sun.faces.taglib.html_basic.CommandLinkTag.java

protected void setProperties(UIComponent component) {
    super.setProperties(component);
    UICommand command = null;/*from  w  ww  .  jav  a  2  s  . c o  m*/
    try {
        command = (UICommand) component;
    } catch (ClassCastException cce) {
        throw new IllegalStateException("Component " + component.toString()
                + " not expected type.  Expected: UICommand.  Perhaps you're missing a tag?");
    }

    if (action != null) {
        if (isValueReference(action)) {
            MethodBinding vb = FacesContext.getCurrentInstance().getApplication().createMethodBinding(action,
                    null);
            command.setAction(vb);
        } else {
            final String outcome = action;
            MethodBinding vb = Util.createConstantMethodBinding(action);
            command.setAction(vb);
        }
    }
    if (actionListener != null) {
        if (isValueReference(actionListener)) {
            Class args[] = { ActionEvent.class };
            MethodBinding vb = FacesContext.getCurrentInstance().getApplication()
                    .createMethodBinding(actionListener, args);
            command.setActionListener(vb);
        } else {
            Object params[] = { actionListener };
            throw new javax.faces.FacesException(
                    Util.getExceptionMessageString(Util.INVALID_EXPRESSION_ID, params));
        }
    }
    if (immediate != null) {
        if (isValueReference(immediate)) {
            ValueBinding vb = Util.getValueBinding(immediate);
            command.setValueBinding("immediate", vb);
        } else {
            boolean _immediate = new Boolean(immediate).booleanValue();
            command.setImmediate(_immediate);
        }
    }
    if (value != null) {
        if (isValueReference(value)) {
            ValueBinding vb = Util.getValueBinding(value);
            command.setValueBinding("value", vb);
        } else {
            command.setValue(value);
        }
    }
    if (accesskey != null) {
        if (isValueReference(accesskey)) {
            ValueBinding vb = Util.getValueBinding(accesskey);
            command.setValueBinding("accesskey", vb);
        } else {
            command.getAttributes().put("accesskey", accesskey);
        }
    }
    if (charset != null) {
        if (isValueReference(charset)) {
            ValueBinding vb = Util.getValueBinding(charset);
            command.setValueBinding("charset", vb);
        } else {
            command.getAttributes().put("charset", charset);
        }
    }
    if (coords != null) {
        if (isValueReference(coords)) {
            ValueBinding vb = Util.getValueBinding(coords);
            command.setValueBinding("coords", vb);
        } else {
            command.getAttributes().put("coords", coords);
        }
    }
    if (dir != null) {
        if (isValueReference(dir)) {
            ValueBinding vb = Util.getValueBinding(dir);
            command.setValueBinding("dir", vb);
        } else {
            command.getAttributes().put("dir", dir);
        }
    }
    if (hreflang != null) {
        if (isValueReference(hreflang)) {
            ValueBinding vb = Util.getValueBinding(hreflang);
            command.setValueBinding("hreflang", vb);
        } else {
            command.getAttributes().put("hreflang", hreflang);
        }
    }
    if (lang != null) {
        if (isValueReference(lang)) {
            ValueBinding vb = Util.getValueBinding(lang);
            command.setValueBinding("lang", vb);
        } else {
            command.getAttributes().put("lang", lang);
        }
    }
    if (onblur != null) {
        if (isValueReference(onblur)) {
            ValueBinding vb = Util.getValueBinding(onblur);
            command.setValueBinding("onblur", vb);
        } else {
            command.getAttributes().put("onblur", onblur);
        }
    }
    if (onclick != null) {
        if (isValueReference(onclick)) {
            ValueBinding vb = Util.getValueBinding(onclick);
            command.setValueBinding("onclick", vb);
        } else {
            command.getAttributes().put("onclick", onclick);
        }
    }
    if (ondblclick != null) {
        if (isValueReference(ondblclick)) {
            ValueBinding vb = Util.getValueBinding(ondblclick);
            command.setValueBinding("ondblclick", vb);
        } else {
            command.getAttributes().put("ondblclick", ondblclick);
        }
    }
    if (onfocus != null) {
        if (isValueReference(onfocus)) {
            ValueBinding vb = Util.getValueBinding(onfocus);
            command.setValueBinding("onfocus", vb);
        } else {
            command.getAttributes().put("onfocus", onfocus);
        }
    }
    if (onkeydown != null) {
        if (isValueReference(onkeydown)) {
            ValueBinding vb = Util.getValueBinding(onkeydown);
            command.setValueBinding("onkeydown", vb);
        } else {
            command.getAttributes().put("onkeydown", onkeydown);
        }
    }
    if (onkeypress != null) {
        if (isValueReference(onkeypress)) {
            ValueBinding vb = Util.getValueBinding(onkeypress);
            command.setValueBinding("onkeypress", vb);
        } else {
            command.getAttributes().put("onkeypress", onkeypress);
        }
    }
    if (onkeyup != null) {
        if (isValueReference(onkeyup)) {
            ValueBinding vb = Util.getValueBinding(onkeyup);
            command.setValueBinding("onkeyup", vb);
        } else {
            command.getAttributes().put("onkeyup", onkeyup);
        }
    }
    if (onmousedown != null) {
        if (isValueReference(onmousedown)) {
            ValueBinding vb = Util.getValueBinding(onmousedown);
            command.setValueBinding("onmousedown", vb);
        } else {
            command.getAttributes().put("onmousedown", onmousedown);
        }
    }
    if (onmousemove != null) {
        if (isValueReference(onmousemove)) {
            ValueBinding vb = Util.getValueBinding(onmousemove);
            command.setValueBinding("onmousemove", vb);
        } else {
            command.getAttributes().put("onmousemove", onmousemove);
        }
    }
    if (onmouseout != null) {
        if (isValueReference(onmouseout)) {
            ValueBinding vb = Util.getValueBinding(onmouseout);
            command.setValueBinding("onmouseout", vb);
        } else {
            command.getAttributes().put("onmouseout", onmouseout);
        }
    }
    if (onmouseover != null) {
        if (isValueReference(onmouseover)) {
            ValueBinding vb = Util.getValueBinding(onmouseover);
            command.setValueBinding("onmouseover", vb);
        } else {
            command.getAttributes().put("onmouseover", onmouseover);
        }
    }
    if (onmouseup != null) {
        if (isValueReference(onmouseup)) {
            ValueBinding vb = Util.getValueBinding(onmouseup);
            command.setValueBinding("onmouseup", vb);
        } else {
            command.getAttributes().put("onmouseup", onmouseup);
        }
    }
    if (rel != null) {
        if (isValueReference(rel)) {
            ValueBinding vb = Util.getValueBinding(rel);
            command.setValueBinding("rel", vb);
        } else {
            command.getAttributes().put("rel", rel);
        }
    }
    if (rev != null) {
        if (isValueReference(rev)) {
            ValueBinding vb = Util.getValueBinding(rev);
            command.setValueBinding("rev", vb);
        } else {
            command.getAttributes().put("rev", rev);
        }
    }
    if (shape != null) {
        if (isValueReference(shape)) {
            ValueBinding vb = Util.getValueBinding(shape);
            command.setValueBinding("shape", vb);
        } else {
            command.getAttributes().put("shape", shape);
        }
    }
    if (style != null) {
        if (isValueReference(style)) {
            ValueBinding vb = Util.getValueBinding(style);
            command.setValueBinding("style", vb);
        } else {
            command.getAttributes().put("style", style);
        }
    }
    if (styleClass != null) {
        if (isValueReference(styleClass)) {
            ValueBinding vb = Util.getValueBinding(styleClass);
            command.setValueBinding("styleClass", vb);
        } else {
            command.getAttributes().put("styleClass", styleClass);
        }
    }
    if (tabindex != null) {
        if (isValueReference(tabindex)) {
            ValueBinding vb = Util.getValueBinding(tabindex);
            command.setValueBinding("tabindex", vb);
        } else {
            command.getAttributes().put("tabindex", tabindex);
        }
    }
    if (target != null) {
        if (isValueReference(target)) {
            ValueBinding vb = Util.getValueBinding(target);
            command.setValueBinding("target", vb);
        } else {
            command.getAttributes().put("target", target);
        }
    }
    if (title != null) {
        if (isValueReference(title)) {
            ValueBinding vb = Util.getValueBinding(title);
            command.setValueBinding("title", vb);
        } else {
            command.getAttributes().put("title", title);
        }
    }
    if (type != null) {
        if (isValueReference(type)) {
            ValueBinding vb = Util.getValueBinding(type);
            command.setValueBinding("type", vb);
        } else {
            command.getAttributes().put("type", type);
        }
    }
}

From source file:org.openmrs.web.controller.patient.PatientFormController.java

/**
 * @see org.springframework.web.servlet.mvc.AbstractFormController#processFormSubmission(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object,
 *      org.springframework.validation.BindException)
 *//*w w w . j  av a  2  s  .c o  m*/
@Override
protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response,
        Object object, BindException errors) throws Exception {

    Patient patient = (Patient) object;

    if (Context.isAuthenticated()) {

        PatientService ps = Context.getPatientService();
        LocationService ls = Context.getLocationService();
        Object[] objs = null;

        MessageSourceAccessor msa = getMessageSourceAccessor();
        String action = request.getParameter("action");

        if (action.equals(msa.getMessage("Patient.save"))) {

            patientValidator.validate(patient, errors);

            if (errors.hasErrors()) {
                return showForm(request, response, errors);
            }

            updatePersonNames(request, patient);

            updatePersonAddresses(request, patient, errors);

            updatePersonAttributes(request, errors, patient);

            // Patient Identifiers
            objs = patient.getIdentifiers().toArray();
            for (int i = 0; i < objs.length; i++) {
                if (request.getParameter("identifiers[" + i + "].identifier") == null) {
                    patient.removeIdentifier((PatientIdentifier) objs[i]);
                }
            }

            String[] ids = request.getParameterValues("identifier");
            String[] idTypes = request.getParameterValues("identifierType");
            String[] locs = request.getParameterValues("location");
            String[] idPrefStatus = ServletRequestUtils.getStringParameters(request, "preferred");

            if (ids != null) {
                for (int i = 0; i < ids.length; i++) {
                    String id = ids[i].trim();
                    if (!"".equals(id) && !"".equals(idTypes[i])) { //skips invalid and blank identifiers/identifierTypes
                        PatientIdentifier pi = new PatientIdentifier();
                        pi.setIdentifier(id);
                        pi.setIdentifierType(ps.getPatientIdentifierType(Integer.valueOf(idTypes[i])));
                        if (StringUtils.isNotEmpty(locs[i])) {
                            pi.setLocation(ls.getLocation(Integer.valueOf(locs[i])));
                        }
                        if (idPrefStatus != null && idPrefStatus.length > i) {
                            pi.setPreferred(new Boolean(idPrefStatus[i]));
                        }
                        new PatientIdentifierValidator().validate(pi, errors);
                        if (errors.hasErrors()) {
                            return showForm(request, response, errors);
                        }
                        patient.addIdentifier(pi);
                    }
                }
            }

            Iterator<PatientIdentifier> identifiers = patient.getIdentifiers().iterator();
            PatientIdentifier currentId = null;
            PatientIdentifier preferredId = null;
            while (identifiers.hasNext()) {
                currentId = identifiers.next();
                if (currentId.isPreferred()) {
                    if (preferredId != null) { // if there's a preferred identifier already exists, make it preferred=false
                        preferredId.setPreferred(false);
                    }
                    preferredId = currentId;
                }
            }
            if ((preferredId == null) && (currentId != null)) { // No preferred identifiers. Make the last identifier entry as preferred.
                currentId.setPreferred(true);
            }

            // check patient identifier formats
            for (PatientIdentifier pi : patient.getIdentifiers()) {
                // skip voided identifiers
                if (pi.isVoided()) {
                    continue;
                }
                PatientIdentifierType pit = pi.getIdentifierType();
                String identifier = pi.getIdentifier();
                String format = pit.getFormat();
                String formatDescription = pit.getFormatDescription();
                String formatStr = format;
                if (format == null) {
                    formatStr = "";
                }
                if (formatDescription != null && formatDescription.length() > 0) {
                    formatStr = formatDescription;
                }
                String[] args = { identifier, formatStr };
                try {
                    if (format != null && format.length() > 0 && !identifier.matches(format)) {
                        log.error("Identifier format is not valid: (" + format + ") " + identifier);
                        String msg = getMessageSourceAccessor().getMessage("error.identifier.formatInvalid",
                                args);
                        errors.rejectValue("identifiers", msg);
                    }
                } catch (Exception e) {
                    log.error("exception thrown with: " + pit.getName() + " " + identifier);
                    log.error("Error while adding patient identifiers to savedIdentifier list", e);
                    String msg = getMessageSourceAccessor().getMessage("error.identifier.formatInvalid", args);
                    errors.rejectValue("identifiers", msg);
                }

                if (errors.hasErrors()) {
                    return showForm(request, response, errors);
                }
            }

        } // end "if we're saving the patient"
    }

    return super.processFormSubmission(request, response, patient, errors);
}

From source file:ca.sqlpower.sqlobject.BaseSQLObjectTestCase.java

/**
 * XXX This test should use the {@link GenericNewValueMaker} as it has it's own mini
 * version inside it. This test should also be using the annotations to decide which 
 * setters can fire events./*from   w  ww  .ja v  a 2 s. c  om*/
 * 
 * @throws IllegalArgumentException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws NoSuchMethodException
 * @throws SQLObjectException
 */
public void testAllSettersGenerateEvents() throws IllegalArgumentException, IllegalAccessException,
        InvocationTargetException, NoSuchMethodException, SQLObjectException {
    SQLObject so = getSQLObjectUnderTest();
    so.populate();

    propertiesToIgnoreForEventGeneration.addAll(getPropertiesToIgnoreForEvents());

    //Ignored because we expect the object to be populated.
    propertiesToIgnoreForEventGeneration.add("exportedKeysPopulated");
    propertiesToIgnoreForEventGeneration.add("importedKeysPopulated");
    propertiesToIgnoreForEventGeneration.add("columnsPopulated");
    propertiesToIgnoreForEventGeneration.add("indicesPopulated");

    CountingSQLObjectListener listener = new CountingSQLObjectListener();
    SQLPowerUtils.listenToHierarchy(so, listener);

    if (so instanceof SQLDatabase) {
        // should be handled in the Datasource
        propertiesToIgnoreForEventGeneration.add("name");
    }

    List<PropertyDescriptor> settableProperties;

    settableProperties = Arrays.asList(PropertyUtils.getPropertyDescriptors(so.getClass()));

    for (PropertyDescriptor property : settableProperties) {
        Object oldVal;
        if (propertiesToIgnoreForEventGeneration.contains(property.getName()))
            continue;

        try {
            oldVal = PropertyUtils.getSimpleProperty(so, property.getName());
            // check for a setter
            if (property.getWriteMethod() == null) {
                continue;
            }

        } catch (NoSuchMethodException e) {
            System.out.println(
                    "Skipping non-settable property " + property.getName() + " on " + so.getClass().getName());
            continue;
        }
        Object newVal; // don't init here so compiler can warn if the following code doesn't always give it a value
        if (property.getPropertyType() == Integer.TYPE || property.getPropertyType() == Integer.class) {
            if (oldVal != null) {
                newVal = ((Integer) oldVal) + 1;
            } else {
                newVal = 1;
            }
        } else if (property.getPropertyType() == String.class) {
            // make sure it's unique
            newVal = "new " + oldVal;

        } else if (property.getPropertyType() == Boolean.TYPE || property.getPropertyType() == Boolean.class) {
            if (oldVal == null) {
                newVal = Boolean.TRUE;
            } else {
                newVal = new Boolean(!((Boolean) oldVal).booleanValue());
            }
        } else if (property.getPropertyType() == SQLCatalog.class) {
            newVal = new SQLCatalog(new SQLDatabase(), "This is a new catalog");
        } else if (property.getPropertyType() == SPDataSource.class) {
            newVal = new JDBCDataSource(getPLIni());
            ((SPDataSource) newVal).setName("test");
            ((SPDataSource) newVal).setDisplayName("test");
            ((JDBCDataSource) newVal).setUser("a");
            ((JDBCDataSource) newVal).setPass("b");
            ((JDBCDataSource) newVal).getParentType().setJdbcDriver(MockJDBCDriver.class.getName());
            ((JDBCDataSource) newVal).setUrl("jdbc:mock:tables=tab1");
        } else if (property.getPropertyType() == JDBCDataSource.class) {
            newVal = new JDBCDataSource(getPLIni());
            ((SPDataSource) newVal).setName("test");
            ((SPDataSource) newVal).setDisplayName("test");
            ((JDBCDataSource) newVal).setUser("a");
            ((JDBCDataSource) newVal).setPass("b");
            ((JDBCDataSource) newVal).getParentType().setJdbcDriver(MockJDBCDriver.class.getName());
            ((JDBCDataSource) newVal).setUrl("jdbc:mock:tables=tab1");
        } else if (property.getPropertyType() == SQLTable.class) {
            newVal = new SQLTable();
        } else if (property.getPropertyType() == SQLColumn.class) {
            newVal = new SQLColumn();
        } else if (property.getPropertyType() == SQLIndex.class) {
            newVal = new SQLIndex();
        } else if (property.getPropertyType() == SQLRelationship.SQLImportedKey.class) {
            SQLRelationship rel = new SQLRelationship();
            newVal = rel.getForeignKey();
        } else if (property.getPropertyType() == SQLRelationship.Deferrability.class) {
            if (oldVal == SQLRelationship.Deferrability.INITIALLY_DEFERRED) {
                newVal = SQLRelationship.Deferrability.NOT_DEFERRABLE;
            } else {
                newVal = SQLRelationship.Deferrability.INITIALLY_DEFERRED;
            }
        } else if (property.getPropertyType() == SQLRelationship.UpdateDeleteRule.class) {
            if (oldVal == SQLRelationship.UpdateDeleteRule.CASCADE) {
                newVal = SQLRelationship.UpdateDeleteRule.RESTRICT;
            } else {
                newVal = SQLRelationship.UpdateDeleteRule.CASCADE;
            }
        } else if (property.getPropertyType() == SQLIndex.AscendDescend.class) {
            if (oldVal == SQLIndex.AscendDescend.ASCENDING) {
                newVal = SQLIndex.AscendDescend.DESCENDING;
            } else {
                newVal = SQLIndex.AscendDescend.ASCENDING;
            }
        } else if (property.getPropertyType() == Throwable.class) {
            newVal = new Throwable();
        } else if (property.getPropertyType() == BasicSQLType.class) {
            if (oldVal != BasicSQLType.OTHER) {
                newVal = BasicSQLType.OTHER;
            } else {
                newVal = BasicSQLType.TEXT;
            }
        } else if (property.getPropertyType() == UserDefinedSQLType.class) {
            newVal = new UserDefinedSQLType();
        } else if (property.getPropertyType() == SQLTypeConstraint.class) {
            if (oldVal != SQLTypeConstraint.NONE) {
                newVal = SQLTypeConstraint.NONE;
            } else {
                newVal = SQLTypeConstraint.CHECK;
            }
        } else if (property.getPropertyType() == String[].class) {
            newVal = new String[3];
        } else if (property.getPropertyType() == PropertyType.class) {
            if (oldVal != PropertyType.NOT_APPLICABLE) {
                newVal = PropertyType.NOT_APPLICABLE;
            } else {
                newVal = PropertyType.VARIABLE;
            }
        } else if (property.getPropertyType() == List.class) {
            newVal = Arrays.asList("one", "two");
        } else {
            throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type "
                    + property.getPropertyType().getName() + ") from " + so.getClass() + " on property "
                    + property.getDisplayName());
        }

        int oldChangeCount = listener.getChangedCount();

        try {
            System.out.println("Setting property '" + property.getName() + "' to '" + newVal + "' ("
                    + newVal.getClass().getName() + ")");
            BeanUtils.copyProperty(so, property.getName(), newVal);

            // some setters fire multiple events (they change more than one property)
            assertTrue(
                    "Event for set " + property.getName() + " on " + so.getClass().getName() + " didn't fire!",
                    listener.getChangedCount() > oldChangeCount);
            if (listener.getChangedCount() == oldChangeCount + 1) {
                assertEquals("Property name mismatch for " + property.getName() + " in " + so.getClass(),
                        property.getName(), ((PropertyChangeEvent) listener.getLastEvent()).getPropertyName());
                assertEquals("New value for " + property.getName() + " was wrong", newVal,
                        ((PropertyChangeEvent) listener.getLastEvent()).getNewValue());
            }
        } catch (InvocationTargetException e) {
            System.out.println("(non-fatal) Failed to write property '" + property.getName() + " to type "
                    + so.getClass().getName());
        }
    }
}

From source file:com.alfaariss.oa.util.saml2.binding.BindingProperties.java

/**
 * Return a <code>Boolean</code> property of the given binding.
 * //from  w ww  .ja  v a2  s.c o m
 * @param sBindingType  The binding URI.
 * @param sName The property name.
 * @param bDefault The value that must be returned if property is not available.
 * @return The property value converted to a Boolean object if found, otherwise the supplied default.
 * @throws OAException  If requested value is not a true or false
 * @see SAMLConstants
 */
public Boolean getBooleanProperty(String sBindingType, String sName, boolean bDefault) throws OAException {
    Boolean boolValue = getBooleanProperty(sBindingType, sName);
    if (boolValue == null)
        return new Boolean(bDefault);
    return boolValue;
}

From source file:com.aerothai.database.accessory.AccessoryService.java

/**
* Method to construct JSON with Error Msg
* 
* @param tag//from w  w w .jav  a 2 s  . c  o m
* @param status
* @param err_msg
* @return
*/
public static String constructJSON(String tag, boolean status, String msg) {
    JSONObject obj = new JSONObject();

    obj.put("tag", tag);
    obj.put("status", new Boolean(status));
    obj.put("msg", msg);

    return obj.toString();
}

From source file:com._17od.upm.gui.OptionsDialog.java

public OptionsDialog(JFrame frame) {
    super(frame, Translator.translate("options"), true);

    Container container = getContentPane();

    // Create a pane with an empty border for spacing
    Border emptyBorder = BorderFactory.createEmptyBorder(2, 5, 5, 5);
    JPanel emptyBorderPanel = new JPanel();
    emptyBorderPanel.setLayout(new BoxLayout(emptyBorderPanel, BoxLayout.Y_AXIS));
    emptyBorderPanel.setBorder(emptyBorder);
    container.add(emptyBorderPanel);/*from   w  w w .jav a  2  s.c o m*/

    // ******************
    // *** The DB TO Load On Startup Section
    // ******************
    // Create a pane with an title etched border
    Border etchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
    Border etchedTitleBorder = BorderFactory.createTitledBorder(etchedBorder,
            ' ' + Translator.translate("general") + ' ');
    JPanel mainPanel = new JPanel(new GridBagLayout());
    mainPanel.setBorder(etchedTitleBorder);
    emptyBorderPanel.add(mainPanel);

    GridBagConstraints c = new GridBagConstraints();

    // The "Database to Load on Startup" row
    JLabel urlLabel = new JLabel(Translator.translate("dbToLoadOnStartup"));
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 5, 3, 0);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 2;
    c.fill = GridBagConstraints.NONE;
    mainPanel.add(urlLabel, c);

    // The "Database to Load on Startup" input field row
    dbToLoadOnStartup = new JTextField(Preferences.get(Preferences.ApplicationOptions.DB_TO_LOAD_ON_STARTUP),
            25);
    dbToLoadOnStartup.setHorizontalAlignment(JTextField.LEFT);
    c.gridx = 0;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 5, 5, 5);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(dbToLoadOnStartup, c);

    JButton dbToLoadOnStartupButton = new JButton("...");
    dbToLoadOnStartupButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            getDBToLoadOnStartup();
        }
    });
    c.gridx = 1;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LINE_END;
    c.insets = new Insets(0, 0, 5, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    mainPanel.add(dbToLoadOnStartupButton, c);

    // The "Language" label row
    JLabel localeLabel = new JLabel(Translator.translate("language"));
    c.gridx = 0;
    c.gridy = 2;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 5, 3, 0);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 2;
    c.fill = GridBagConstraints.NONE;
    mainPanel.add(localeLabel, c);

    // The "Locale" field row
    localeComboBox = new JComboBox(getSupportedLocaleNames());
    for (int i = 0; i < localeComboBox.getItemCount(); i++) {
        // If the locale language is blank then set it to the English language
        // I'm not sure why this happens. Maybe it's because the default locale
        // is English???
        String currentLanguage = Translator.getCurrentLocale().getLanguage();
        if (currentLanguage.equals("")) {
            currentLanguage = "en";
        }

        if (currentLanguage.equals(Translator.SUPPORTED_LOCALES[i].getLanguage())) {
            localeComboBox.setSelectedIndex(i);
            break;
        }
    }
    c.gridx = 0;
    c.gridy = 3;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 5, 8, 5);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 2;
    c.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(localeComboBox, c);

    // The "Hide account password" row
    Boolean hideAccountPassword = new Boolean(
            Preferences.get(Preferences.ApplicationOptions.ACCOUNT_HIDE_PASSWORD, "true"));
    hideAccountPasswordCheckbox = new JCheckBox(Translator.translate("hideAccountPassword"),
            hideAccountPassword.booleanValue());
    c.gridx = 0;
    c.gridy = 4;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 2, 5, 0);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    mainPanel.add(hideAccountPasswordCheckbox, c);

    // The "Database auto lock" row
    Boolean databaseAutoLock = new Boolean(
            Preferences.get(Preferences.ApplicationOptions.DATABASE_AUTO_LOCK, "false"));
    databaseAutoLockCheckbox = new JCheckBox(Translator.translate("databaseAutoLock"),
            databaseAutoLock.booleanValue());
    c.gridx = 0;
    c.gridy = 5;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 2, 5, 0);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    mainPanel.add(databaseAutoLockCheckbox, c);
    databaseAutoLockCheckbox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            databaseAutoLockTime.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
        }
    });

    // The "Database auto lock" field row
    databaseAutoLockTime = new JTextField(
            Preferences.get(Preferences.ApplicationOptions.DATABASE_AUTO_LOCK_TIME), 5);
    c.gridx = 1;
    c.gridy = 5;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 5, 5, 0);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(databaseAutoLockTime, c);
    databaseAutoLockTime.setEnabled(databaseAutoLockCheckbox.isSelected());

    // The "Generated password length" row
    accountPasswordLengthLabel = new JLabel(Translator.translate("generatedPasswodLength"));
    c.gridx = 0;
    c.gridy = 6;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 2, 5, 0);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    mainPanel.add(accountPasswordLengthLabel, c);

    accountPasswordLength = new JTextField(
            Preferences.get(Preferences.ApplicationOptions.ACCOUNT_PASSWORD_LENGTH, "8"), 5);
    c.gridx = 1;
    c.gridy = 6;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 5, 5, 0);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(accountPasswordLength, c);

    // Some spacing
    emptyBorderPanel.add(Box.createVerticalGlue());

    // ******************
    // *** The HTTPS Section
    // ******************
    // Create a pane with an title etched border
    Border httpsEtchedTitleBorder = BorderFactory.createTitledBorder(etchedBorder, " HTTPS ");
    final JPanel httpsPanel = new JPanel(new GridBagLayout());
    httpsPanel.setBorder(httpsEtchedTitleBorder);
    emptyBorderPanel.add(httpsPanel);

    // The "Accept Self Sigend Certificates" checkbox row
    Boolean acceptSelfSignedCerts = new Boolean(
            Preferences.get(Preferences.ApplicationOptions.HTTPS_ACCEPT_SELFSIGNED_CERTS, "false"));
    acceptSelfSignedCertsCheckbox = new JCheckBox(Translator.translate("acceptSelfSignedCerts"),
            acceptSelfSignedCerts.booleanValue());
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 2, 5, 0);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    httpsPanel.add(acceptSelfSignedCertsCheckbox, c);

    // ******************
    // *** The Proxy Section
    // ******************
    // Create a pane with an title etched border
    Border proxyEtchedTitleBorder = BorderFactory.createTitledBorder(etchedBorder,
            ' ' + Translator.translate("httpProxy") + ' ');
    final JPanel proxyPanel = new JPanel(new GridBagLayout());
    proxyPanel.setBorder(proxyEtchedTitleBorder);
    emptyBorderPanel.add(proxyPanel);

    // The "Enable Proxy" row
    Boolean proxyEnabled = new Boolean(Preferences.get(Preferences.ApplicationOptions.HTTP_PROXY_ENABLED));
    enableProxyCheckbox = new JCheckBox(Translator.translate("enableProxy"), proxyEnabled.booleanValue());
    enableProxyCheckbox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                enableProxyComponents(true);
            } else {
                enableProxyComponents(false);
            }
        }
    });
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 2, 5, 0);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    proxyPanel.add(enableProxyCheckbox, c);

    // The "HTTP Proxy" label row
    proxyLabel = new JLabel(Translator.translate("httpProxy"));
    c.gridx = 0;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 5, 3, 0);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 2;
    c.fill = GridBagConstraints.NONE;
    proxyPanel.add(proxyLabel, c);

    // The "HTTP Proxy Port" label
    proxyPortLabel = new JLabel(Translator.translate("port"));
    c.gridx = 1;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 5, 3, 5);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    proxyPanel.add(proxyPortLabel, c);

    // The "HTTP Proxy" field row
    httpProxyHost = new JTextField(Preferences.get(Preferences.ApplicationOptions.HTTP_PROXY_HOST), 20);
    c.gridx = 0;
    c.gridy = 2;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 5, 5, 0);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    proxyPanel.add(httpProxyHost, c);

    httpProxyPort = new JTextField(Preferences.get(Preferences.ApplicationOptions.HTTP_PROXY_PORT), 6);
    c.gridx = 1;
    c.gridy = 2;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 5, 5, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    proxyPanel.add(httpProxyPort, c);

    // The "HTTP Proxy Username" label row
    proxyUsernameLabel = new JLabel(Translator.translate("httpProxyUsername"));
    c.gridx = 0;
    c.gridy = 3;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 5, 3, 0);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 2;
    c.fill = GridBagConstraints.NONE;
    proxyPanel.add(proxyUsernameLabel, c);

    // The "HTTP Proxy Username" field row
    httpProxyUsername = new JTextField(Preferences.get(Preferences.ApplicationOptions.HTTP_PROXY_USERNAME), 20);
    c.gridx = 0;
    c.gridy = 4;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 5, 5, 5);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 2;
    c.fill = GridBagConstraints.HORIZONTAL;
    proxyPanel.add(httpProxyUsername, c);

    // The "HTTP Proxy Password" label row
    proxyPasswordLabel = new JLabel(Translator.translate("httpProxyPassword"));
    c.gridx = 0;
    c.gridy = 5;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 5, 3, 0);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 2;
    c.fill = GridBagConstraints.NONE;
    proxyPanel.add(proxyPasswordLabel, c);

    // The "HTTP Proxy Password" field row
    String encodedPassword = Preferences.get(Preferences.ApplicationOptions.HTTP_PROXY_PASSWORD);
    String decodedPassword = null;
    if (encodedPassword != null) {
        decodedPassword = new String(Base64.decodeBase64(encodedPassword.getBytes()));
    }
    httpProxyPassword = new JPasswordField(decodedPassword, 20);
    c.gridx = 0;
    c.gridy = 6;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 5, 5, 5);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    proxyPanel.add(httpProxyPassword, c);

    hidePasswordCheckbox = new JCheckBox(Translator.translate("hide"), true);
    defaultEchoChar = httpProxyPassword.getEchoChar();
    hidePasswordCheckbox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                httpProxyPassword.setEchoChar(defaultEchoChar);
            } else {
                httpProxyPassword.setEchoChar((char) 0);
            }
        }
    });
    c.gridx = 1;
    c.gridy = 6;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 5, 5, 0);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    proxyPanel.add(hidePasswordCheckbox, c);

    // Some spacing
    emptyBorderPanel.add(Box.createVerticalGlue());

    // The buttons row
    JPanel buttonPanel = new JPanel(new FlowLayout());
    emptyBorderPanel.add(buttonPanel);
    JButton okButton = new JButton(Translator.translate("ok"));
    okButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            okButtonAction();
        }
    });
    buttonPanel.add(okButton);

    JButton cancelButton = new JButton(Translator.translate("cancel"));
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setVisible(false);
            dispose();
        }
    });
    buttonPanel.add(cancelButton);

    enableProxyComponents(proxyEnabled.booleanValue());
}

From source file:modnlp.capte.AlignerUtils.java

public static Vector<Object[]> StringToData(String conv, boolean isRe, int number) {
    String alpha = "abcdefghikjlmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ23456789";
    int counter = 0;
    Vector<Object[]> va = new Vector<Object[]>();

    String[] lines = conv.split("\n");

    Object[] oa;// w ww. j  a  v  a  2  s . c o m
    String[] sa;
    for (int i = 0; i < lines.length; i++) {
        //System.out.println(lines[i] + "<END>");
        if (lines[i].indexOf("\t") > -1) {
            sa = lines[i].split("\t");

            if (sa.length == 3) {
                sa[0] = removeLongWhiteSpace(sa[0]);
                sa[1] = removeLongWhiteSpace(sa[1]);
                sa[2] = removeLongWhiteSpace(sa[2]);
                oa = new Object[6];
                oa[0] = sa[0];
                oa[1] = sa[1];
                oa[2] = sa[2];
                oa[3] = new Boolean(false);
                oa[4] = Integer.toString(counter);
                if (isRe) {
                    if (number < alpha.length()) {
                        oa[5] = Integer.toString(counter) + " " + "(" + alpha.charAt(number - 1) + ")";
                    } else {
                        oa[5] = Integer.toString(counter) + " " + "("
                                + alpha.charAt((int) Math.round(Math.random())) + ")";
                    }
                } else {
                    oa[5] = Integer.toString(counter);
                }
                va.add(oa);
                counter++;
            } else {
                for (int j = 0; j < sa.length; j++) {
                    System.out.println(sa[j] + " " + j);
                }
            }
        }
    }
    return va;
}

From source file:de.jwi.jfm.servlets.Controller.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String self = null;// ww w  .  ja v  a2  s  .co  m
    String contextPath = null;
    String pathInfo = null;
    Folder folder = null;
    String queryString = null;

    try {
        contextPath = request.getContextPath();
        String servletPath = request.getServletPath();
        String method = request.getMethod();
        boolean formPosted = "POST".equals(method);

        pathInfo = request.getPathInfo();

        if (null == pathInfo) {

            PrintWriter writer = response.getWriter();
            writer.print(contextPath + servletPath + " is alive.");

            return;
        }

        File f = new File(filebase, pathInfo);

        if (!f.exists()) {

            PrintWriter writer = response.getWriter();
            writer.print(contextPath + pathInfo + " does not exist.");

            return;
        }

        if (f.isFile()) {
            doDownload(request, response, f);
            return;
        }

        if (!pathInfo.endsWith("/")) {
            response.sendRedirect(request.getRequestURL() + "/");
            return;
        }

        queryString = request.getQueryString();

        String pathTranslated = request.getPathTranslated();
        String requestURI = request.getRequestURI();
        String requestURL = request.getRequestURL().toString();

        self = contextPath + servletPath;

        String fileURL = requestURI.replaceFirst(contextPath, "");
        fileURL = fileURL.replaceFirst(servletPath, "");

        folder = new Folder(f, pathInfo, fileURL);

        folder.load();

        String actionresult = "";

        if (FileUpload.isMultipartContent(request)) {
            try {
                actionresult = handleUpload(request, folder);
                folder.load();
            } catch (Exception e) {
                throw new ServletException(e.getMessage(), e);
            }
        } else if (formPosted || null != queryString) {
            try {
                actionresult = handleQuery(request, response, folder);
            } catch (OutOfSyncException e) {
                actionresult = e.getMessage();
            }
            if (null == actionresult) {
                return;
            }
        }

        request.setAttribute("actionresult", actionresult);
    } catch (SecurityException e) {
        request.setAttribute("actionresult", e.getClass().getName() + " " + e.getMessage());
        request.setAttribute("fatalerror", new Boolean(true));

    }

    String s = request.getRemoteUser();

    Principal principal = request.getUserPrincipal();

    if (principal != null) {
        request.setAttribute("principal", principal.getName());
    }

    request.setAttribute("self", self);

    s = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss z").format(new Date());

    request.setAttribute("date", s);

    request.setAttribute("version", version);

    request.setAttribute("builddate", builddate);

    request.setAttribute("javaversion", System.getProperty("java.version"));

    request.setAttribute("serverInfo", getServletContext().getServerInfo());

    request.setAttribute("jfmhome", "https://java.net/projects/jfm");

    request.setAttribute("url", contextPath);

    request.setAttribute("path", pathInfo);

    request.setAttribute("folder", folder);

    String forward = "/WEB-INF/fm.jsp";

    if (queryString != null) {
        // hide get query parameters
        //         response.sendRedirect(request.getRequestURL() + "");
        //         return;
    }

    RequestDispatcher requestDispatcher = getServletContext().getRequestDispatcher(forward);

    requestDispatcher.forward(request, response);
}

From source file:org.esupportail.portlet.filemanager.portlet.PortletControllerAjax.java

@ResourceMapping("toggleThumbnailMode")
public ModelAndView toggleThumbnailMode(@RequestParam boolean thumbnailMode, ResourceRequest request) {
    putThumbnailMode(thumbnailMode, request);

    Map<String, String> jsonMsg = new HashMap<String, String>();
    jsonMsg.put("thumbnail_mode", new Boolean(thumbnailMode).toString());
    return getJacksonView(jsonMsg);
}

From source file:SecuritySupport.java

boolean getFileExists(final File f) {
    return ((Boolean) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            return new Boolean(f.exists());
        }/*from  w  w w.  java2 s  . co m*/
    })).booleanValue();
}