Example usage for java.lang Boolean valueOf

List of usage examples for java.lang Boolean valueOf

Introduction

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

Prototype

public static Boolean valueOf(String s) 

Source Link

Document

Returns a Boolean with a value represented by the specified string.

Usage

From source file:com.jonbanjo.cups.operations.HttpPoster.java

static OperationResult sendRequest(URL url, ByteBuffer ippBuf, InputStream documentStream, final AuthInfo auth)
        throws IOException {

    final OperationResult opResult = new OperationResult();

    if (ippBuf == null) {
        return null;
    }/*  w  w  w  .ja v a  2s  . c  o m*/

    if (url == null) {
        return null;
    }

    DefaultHttpClient client = new DefaultHttpClient();

    // will not work with older versions of CUPS!
    client.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
    client.getParams().setParameter("http.socket.timeout", SOCKET_TIMEOUT);
    client.getParams().setParameter("http.connection.timeout", CONNECTION_TIMEOUT);
    client.getParams().setParameter("http.protocol.content-charset", "UTF-8");
    client.getParams().setParameter("http.method.response.buffer.warnlimit", new Integer(8092));
    // probabaly not working with older CUPS versions
    client.getParams().setParameter("http.protocol.expect-continue", Boolean.valueOf(true));

    HttpPost httpPost;

    try {
        httpPost = new HttpPost(url.toURI());
    } catch (Exception e) {
        System.out.println(e.toString());
        return null;
    }

    httpPost.getParams().setParameter("http.socket.timeout", SOCKET_TIMEOUT);

    byte[] bytes = new byte[ippBuf.limit()];
    ippBuf.get(bytes);

    ByteArrayInputStream headerStream = new ByteArrayInputStream(bytes);
    // If we need to send a document, concatenate InputStreams
    InputStream inputStream = headerStream;
    if (documentStream != null) {
        inputStream = new SequenceInputStream(headerStream, documentStream);
    }

    // set length to -1 to advice the entity to read until EOF
    InputStreamEntity requestEntity = new InputStreamEntity(inputStream, -1);

    requestEntity.setContentType(IPP_MIME_TYPE);
    httpPost.setEntity(requestEntity);

    if (auth.reason == AuthInfo.AUTH_REQUESTED) {
        AuthHeader.makeAuthHeader(httpPost, auth);
        if (auth.reason == AuthInfo.AUTH_OK) {
            httpPost.addHeader(auth.getAuthHeader());
            //httpPost.addHeader("Authorization", "Basic am9uOmpvbmJveQ==");
        }
    }

    ResponseHandler<byte[]> handler = new ResponseHandler<byte[]>() {
        @Override
        public byte[] handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
            if (response.getStatusLine().getStatusCode() == 401) {
                auth.setHttpHeader(response.getFirstHeader("WWW-Authenticate"));
            } else {
                auth.reason = AuthInfo.AUTH_OK;
            }
            HttpEntity entity = response.getEntity();
            opResult.setHttResult(response.getStatusLine().toString());
            if (entity != null) {
                return EntityUtils.toByteArray(entity);
            } else {
                return null;
            }
        }
    };

    if (url.getProtocol().equals("https")) {

        Scheme scheme = JfSSLScheme.getScheme();
        if (scheme == null)
            return null;
        client.getConnectionManager().getSchemeRegistry().register(scheme);
    }

    byte[] result = client.execute(httpPost, handler);
    //String test = new String(result);
    IppResponse ippResponse = new IppResponse();

    opResult.setIppResult(ippResponse.getResponse(ByteBuffer.wrap(result)));
    opResult.setAuthInfo(auth);
    client.getConnectionManager().shutdown();
    return opResult;
}

From source file:com.bstek.dorado.data.variant.LinkedMetaData.java

public void setBoolean(String key, boolean b) {
    put(key, Boolean.valueOf(b));
}

From source file:com.haulmont.cuba.core.sys.config.EntityFactory.java

@Override
public Object build(String string) {
    if (StringUtils.isBlank(string)) {
        return null;
    }/*from www.ja  v  a  2s  .  c om*/

    EntityLoadInfo info = EntityLoadInfo.parse(string);
    if (info == null) {
        throw new IllegalArgumentException("Invalid entity info: " + string);
    }

    Entity entity;
    String property = AppContext.getProperty("cuba.useCurrentTxForConfigEntityLoad");
    Transaction tx = Boolean.valueOf(property) ? persistence.getTransaction() : persistence.createTransaction();
    try {
        EntityManager em = persistence.getEntityManager();
        View view = null;
        if (info.getViewName() != null) {
            view = metadata.getViewRepository().getView(info.getMetaClass(), info.getViewName());
        }

        Class javaClass = info.getMetaClass().getJavaClass();
        if (view != null) {
            entity = em.find(javaClass, info.getId(), view);
        } else {
            entity = em.find(javaClass, info.getId());
        }

        tx.commit();
    } finally {
        tx.end();
    }
    return entity;
}

From source file:org.simbasecurity.core.service.http.DBViewer.java

@Override
public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse resp) throws Exception {

    if (enabled == null || !Boolean.valueOf(enabled)) {
        resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
        return null;
    }/*from ww  w  . ja v a2 s .  c  o  m*/

    resp.setContentType("text/html");

    String table = req.getParameter("table");
    String query = req.getParameter("query");
    boolean asSQL = req.getParameter("asSQL") != null;
    PrintWriter out = resp.getWriter();
    printHeader(out);
    printForm(out, req.getRequestURI(), table, asSQL, query);

    if (!StringUtil.isEmpty(table)) {
        if (asSQL) {
            printRecordsAsSQL(out, table);
        } else {
            printRecords(out, "SELECT * FROM " + table);
        }
    } else if (!StringUtil.isEmpty(query)) {
        printRecords(out, query);
    }
    printFooter(out);
    out.close();

    return null;
}

From source file:fr.aliasource.webmail.server.proxy.client.http.folder.ListSubscribedMethod.java

public List<Folder> listSubscribed() {
    Map<String, String> params = new HashMap<String, String>();
    params.put("token", token);

    Document doc = execute(params);
    List<Folder> ret = new LinkedList<Folder>();
    if (doc != null) {
        if (logger.isDebugEnabled()) {
            DOMUtils.logDom(doc);/*ww w .java 2s  . co m*/
        }
        String[][] values = DOMUtils.getAttributes(doc.getDocumentElement(), "folder",
                new String[] { "name", "displayName", "shared" });
        for (int i = 0; i < values.length; i++) {
            ret.add(new Folder(values[i][0], values[i][1], true, Boolean.valueOf(values[i][2])));
        }
    }
    return ret;
}

From source file:com.enonic.cms.core.structure.SiteProperties.java

public Boolean getPropertyAsBoolean(final SitePropertyNames key) {
    String svalue = properties.getProperty(key.getKeyName());

    return svalue == null ? Boolean.FALSE : Boolean.valueOf(svalue);
}

From source file:com.acc.storefront.interceptors.beforeview.DebugInfoBeforeViewHandler.java

@Override
public void beforeView(final HttpServletRequest request, final HttpServletResponse response,
        final ModelAndView modelAndView) {
    final boolean showDebug = Config.getBoolean(SHOW_STOREFRONT_DEBUG_INFO_PROPERTY_KEY, false);

    // Store the show debug flag in a request attribute
    request.setAttribute(SHOW_STOREFRONT_DEBUG_INFO, Boolean.valueOf(showDebug));

    if (showDebug) {
        final JaloSession currentSession = JaloSession.getCurrentSession();

        final TreeMap<String, Object> attributeMap = new TreeMap<String, Object>();
        // Build up the session attributes as a request attribute
        attributeMap.putAll(currentSession.getAttributes());
        // Add the session id as an attribute
        attributeMap.put("JaloSession ID", currentSession.getSessionID());

        request.setAttribute(JALO_SESSION_ATTRIBUTES, mapToString(attributeMap));
    }//ww w  .ja v a2 s.c om
}

From source file:com.sworddance.util.CreateTracking.java

public static CreateTracking getInstance(Boolean create, Class<?> clazz) {
    if (create == null) {
        create = CREATE_TRACK_ALL;/* www .  j av  a 2  s.co m*/
    }
    if (!create && clazz != null && classNameMatching != null) {
        create = createTracking.get(clazz);
        if (create == null) {
            // do not yet know for this class
            Matcher matcher = classNameMatching.matcher(clazz.getName());
            create = Boolean.valueOf(matcher.find());
            createTracking.put(clazz, create);
        }
    }
    return create ? new CreateTracking() : null;
}

From source file:com.enprowess.migration.bulkimport.webscripts.BulkFilesystemImportStatusWebScript.java

protected Map<String, Object> executeImpl(WebScriptRequest request, Status status, Cache cache) {
    Map<String, Object> result = new HashMap<>();

    cache.setNeverCache(true);//from w w w. j a  va2s  .  c  o  m

    LicenseDescriptor licenseDescriptor = this.descriptorService.getLicenseDescriptor();
    boolean isEnterprise = licenseDescriptor != null;

    result.put("isEnterprise", Boolean.valueOf(isEnterprise));
    result.put("importStatus", this.bulkImporter.getStatus());

    return result;
}