Java Code Examples for org.apache.commons.lang.BooleanUtils#toBoolean()

The following examples show how to use org.apache.commons.lang.BooleanUtils#toBoolean() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MySQLPuppetComponentProcess.java    From primecloud-controller with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected Map<String, Object> createComponentMap(Long componentNo, ComponentProcessContext context, boolean start) {
    Map<String, Object> map = super.createComponentMap(componentNo, context, start);

    // masterInstanceNoMap
    Map<Long, Long> masterInstanceNoMap = createMasterInstanceNoMap(componentNo, context, start);
    map.put("masterInstanceNoMap", masterInstanceNoMap);

    // phpMyAdmin
    ComponentConfig componentConfig = componentConfigDao.readByComponentNoAndConfigName(componentNo,
            MySQLConstants.CONFIG_NAME_PHP_MY_ADMIN);
    if (componentConfig != null) {
        boolean phpMyAdmin = BooleanUtils.toBoolean(componentConfig.getConfigValue());
        map.put("phpMyAdmin", phpMyAdmin);
    }

    return map;
}
 
Example 2
Source File: ServletLoggingFilter.java    From oxAuth with MIT License 5 votes vote down vote up
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
	Instant start = now(); 
			
    if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) {
        throw new ServletException("LoggingFilter just supports HTTP requests");
    }
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    if (!BooleanUtils.toBoolean(appConfiguration.getHttpLoggingEnabled())) {
        chain.doFilter(httpRequest, httpResponse);
        return;
    }
    Set<String> excludedPaths = appConfiguration.getHttpLoggingExludePaths();
    if (!CollectionUtils.isEmpty(excludedPaths)) {
        for (String excludedPath : excludedPaths) {
            String requestURI = httpRequest.getRequestURI();
            if (requestURI.startsWith(excludedPath)) {
                chain.doFilter(httpRequest, httpResponse);
                return;
            }
        }
    }

    RequestWrapper requestWrapper = new RequestWrapper(httpRequest);
    ResponseWrapper responseWrapper = new ResponseWrapper(httpResponse);

    chain.doFilter(httpRequest, httpResponse);
    
    Duration duration = duration(start);

    // yuriyz: log request and response only after filter handling.
    // #914 - we don't want to effect server functionality due to logging. Currently content can be messed if it is InputStream.
    if (log.isDebugEnabled()) {
     log.debug(getRequestDescription(requestWrapper, duration));
     log.debug(getResponseDescription(responseWrapper));
    }
}
 
Example 3
Source File: XMLServerLoader.java    From heisenberg with Apache License 2.0 5 votes vote down vote up
private void loadUsers(Element root) {
    NodeList list = root.getElementsByTagName("user");
    for (int i = 0, n = list.getLength(); i < n; i++) {
        Node node = list.item(i);
        if (node instanceof Element) {
            Element e = (Element) node;
            String name = e.getAttribute("name");
            UserConfig user = new UserConfig();
            user.setName(name);
            Map<String, Object> props = ConfigUtil.loadElements(e);
            boolean needEncrypt = props.get("needEncrypt") == null ? false : BooleanUtils
                .toBoolean(props.get("needEncrypt").toString());

            String pwd = (String) props.get("password");
            if (needEncrypt) {
                try {
                    user.setPassword(KeyPairGen.decrypt(HeisenbergContext.getPubKey(), pwd));

                } catch (Exception e1) {
                    logger.error("密钥解密失败", e1);
                }
            } else {
                user.setPassword(pwd);
            }
            //System.out.println("ds password-->" + user.getPassword());

            String schemas = (String) props.get("schemas");
            if (schemas != null) {
                String[] strArray = SplitUtil.split(schemas, ',', true);
                user.setSchemas(new HashSet<String>(Arrays.asList(strArray)));
            }
            if (users.containsKey(name)) {
                throw new ConfigException("user " + name + " duplicated!");
            }
            users.put(name, user);
        }
    }
}
 
Example 4
Source File: FileDownloader.java    From rebuild with GNU General Public License v3.0 5 votes vote down vote up
@RequestMapping(value = { "download/**", "access/**" }, method = RequestMethod.GET)
public void download(HttpServletRequest request, HttpServletResponse response) throws IOException {
	String filePath = request.getRequestURI();

	// 共享查看
	if (request.getRequestURI().contains("/filex/access/")) {
           String e = getParameter(request, "e");
           if (StringUtils.isBlank(e) || Application.getCommonCache().get(e) == null) {
               response.sendError(403, "文件已过期");
               return;
           }

           filePath = filePath.split("/filex/access/")[1];
       } else {
           filePath = filePath.split("/filex/download/")[1];
       }

	boolean temp = BooleanUtils.toBoolean(request.getParameter("temp"));
	String fileName = QiniuCloud.parseFileName(filePath);

	ServletUtils.setNoCacheHeaders(response);

	// Local storage || temp
	if (!QiniuCloud.instance().available() || temp) {
		setDownloadHeaders(request, response, fileName);
		writeLocalFile(filePath, temp, response);
	}
	else {
		String privateUrl = QiniuCloud.instance().url(filePath);
		privateUrl += "&attname=" + fileName;
		response.sendRedirect(privateUrl);
	}
}
 
Example 5
Source File: TableMetaParser.java    From tddl5 with Apache License 2.0 5 votes vote down vote up
private IndexMeta parseIndex(String tableName, Map<String, ColumnMeta> columnMetas, Node node) {
    // Node nameNode = node.getAttributes().getNamedItem("name");
    Node typeNode = node.getAttributes().getNamedItem("type");
    Node relNode = node.getAttributes().getNamedItem("rel");
    Node strongConsistentNode = node.getAttributes().getNamedItem("strongConsistent");

    // String name = null;
    String type = null;
    String rel = null;
    boolean strongConsistent = true;
    // if (nameNode != null) {
    // name = nameNode.getNodeValue();
    // }
    if (typeNode != null) {
        type = typeNode.getNodeValue();
    }
    if (relNode != null) {
        rel = relNode.getNodeValue();
    }
    if (strongConsistentNode != null) {
        strongConsistent = BooleanUtils.toBoolean(strongConsistentNode.getNodeValue());
    }

    String[] keys = new String[0];
    String[] values = new String[0];
    NodeList childs = node.getChildNodes();
    for (int i = 0; i < childs.getLength(); i++) {
        Node cnode = childs.item(i);
        if ("keys".equals(cnode.getNodeName())) {
            keys = StringUtils.split(cnode.getFirstChild().getNodeValue(), ',');
        } else if ("values".equals(cnode.getNodeName())) {
            values = StringUtils.split(cnode.getFirstChild().getNodeValue(), ',');
        }
    }

    return new IndexMeta(tableName, toColumnMeta(keys, columnMetas, tableName), toColumnMeta(values,
        columnMetas,
        tableName), getIndexType(type), getRelationship(rel), strongConsistent, false);
}
 
Example 6
Source File: MergeConcurrentOptimizer.java    From tddl with Apache License 2.0 5 votes vote down vote up
private static boolean isMergeConcurrent(Map<String, Object> extraCmd, IMerge query) {
    String value = ObjectUtils.toString(GeneralUtil.getExtraCmdString(extraCmd, ExtraCmd.MERGE_CONCURRENT));
    if (StringUtils.isEmpty(value)) {
        if (query.getSql() != null) {
            // 如果存在sql,那说明是hint直接路由
            return true;
        }

        if ((query.getLimitFrom() != null || query.getLimitTo() != null)) {
            if (query.getOrderBys() == null || query.getOrderBys().isEmpty()) {
                // 存在limit,但不存在order by时不允许走并行
                return false;
            }
        } else if ((query.getOrderBys() == null || query.getOrderBys().isEmpty())
                   && (query.getGroupBys() == null || query.getGroupBys().isEmpty())
                   && query.getHavingFilter() == null) {
            if (isNoFilter(query)) {
                // 没有其他的order by / group by / having /
                // where等条件时,就是个简单的select *
                // from xxx,暂时也不做并行
                return false;
            }
        }

        return true;
    } else {
        return BooleanUtils.toBoolean(value);
    }
}
 
Example 7
Source File: PagerUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static boolean isSkipPaging( Boolean skipPaging, Boolean paging )
{
    if ( skipPaging != null )
    {
        return BooleanUtils.toBoolean( skipPaging );
    }
    else if ( paging != null )
    {
        return !BooleanUtils.toBoolean( paging );
    }
 
    return false;
}
 
Example 8
Source File: TableRuleConfig.java    From heisenberg with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public TableRuleConfig(String name, String forceHit, String[] columns, List<String> dbRuleArray,
        List<String> tbRuleArray, String tbPrefix) {
    if (name == null) {
        throw new IllegalArgumentException("name is null");
    }
    this.name = name;
    this.forceHit = BooleanUtils.toBoolean(forceHit);
    if (columns == null || columns.length == 0) {
        throw new IllegalArgumentException("no column is found!");
    }
    if (dbRuleArray == null || dbRuleArray.isEmpty()) {
        throw new IllegalArgumentException("dbRuleArray is empty!");
    }
    // if (tbRuleArray == null || tbRuleArray.isEmpty()) {
    // throw new IllegalArgumentException("tbRuleArray is empty!");
    // }

    this.columns = Collections.unmodifiableList(Arrays.asList(columns));
    this.dbRuleArray = dbRuleArray;
    this.tbRuleArray = tbRuleArray;

    this.tbPrefix = tbPrefix;
    try {
        if (StringUtil.isNotEmpty(tbPrefix)) {
            GroovyShell gs = new GroovyShell();
            tbMap = (Map<Integer, List<String>>) gs.evaluate(this.tbPrefix);

            if (tbMap.isEmpty()) {
                throw new IllegalArgumentException("tbPrefix eval result is empty!");
            }
            tbIndexMap = new HashMap<String, Integer>();
            for (Map.Entry<Integer, List<String>> entry : tbMap.entrySet()) {
                Integer dn = entry.getKey();
                for (String tbPre : entry.getValue()) {
                    tbIndexMap.put(tbPre, dn);
                }
            }
            LOGGER.info("加载[" + name + "]tbPrefix-->" + tbMap);
            LOGGER.info("加载[" + name + "]tbIndexMap-->" + tbIndexMap);

        }
    } catch (Exception e) {
        LOGGER.error("init table rule error!", e);
        throw e;
    }
}
 
Example 9
Source File: SimpleAdminConnector.java    From canal with Apache License 2.0 4 votes vote down vote up
@Override
public boolean releaseInstance(String destination) {
    return BooleanUtils.toBoolean(Integer.parseInt(doInstanceAdmin(destination, "release")));
}
 
Example 10
Source File: ValidationResultQuery.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public boolean isPaging()
{
    return BooleanUtils.toBoolean( paging );
}
 
Example 11
Source File: FilterPreProcessor.java    From tddl with Apache License 2.0 4 votes vote down vote up
/**
 * 将0=1/1=1/true的恒等式进行优化
 */
private static IFilter shortestFilter(IFilter root) throws EmptyResultFilterException {
    IFilter filter = FilterUtils.toDNFAndFlat(root);
    List<List<IFilter>> DNFfilter = FilterUtils.toDNFNodesArray(filter);

    List<List<IFilter>> newDNFfilter = new ArrayList<List<IFilter>>();
    for (List<IFilter> andDNFfilter : DNFfilter) {
        boolean isShortest = false;
        List<IFilter> newAndDNFfilter = new ArrayList<IFilter>();
        for (IFilter one : andDNFfilter) {
            if (one.getOperation() == OPERATION.CONSTANT) {
                boolean flag = false;
                if (((IBooleanFilter) one).getColumn() instanceof ISelectable) {// 可能是个not函数
                    newAndDNFfilter.add(one);// 不能丢弃
                } else {
                    String value = ((IBooleanFilter) one).getColumn().toString();
                    if (StringUtils.isNumeric(value)) {
                        flag = BooleanUtils.toBoolean(Integer.valueOf(value));
                    } else {
                        flag = BooleanUtils.toBoolean(((IBooleanFilter) one).getColumn().toString());
                    }
                    if (!flag) {
                        isShortest = true;
                        break;
                    }
                }
            } else {
                newAndDNFfilter.add(one);
            }
        }

        if (!isShortest) {
            if (newAndDNFfilter.isEmpty()) {
                // 代表出现为true or xxx,直接返回true
                IBooleanFilter f = ASTNodeFactory.getInstance().createBooleanFilter();
                f.setOperation(OPERATION.CONSTANT);
                f.setColumn("1");
                f.setColumnName(ObjectUtils.toString("1"));
                return f;
            } else {// 针对非false的情况
                newDNFfilter.add(newAndDNFfilter);
            }
        }
    }

    if (newDNFfilter.isEmpty()) {
        throw new EmptyResultFilterException("空结果");
    }

    return FilterUtils.DNFToOrLogicTree(newDNFfilter);
}
 
Example 12
Source File: SimpleAdminConnector.java    From canal with Apache License 2.0 4 votes vote down vote up
@Override
public boolean stop() {
    return BooleanUtils.toBoolean(Integer.parseInt(doServerAdmin("stop")));
}
 
Example 13
Source File: GroupServiceImpl.java    From gazpachoquest with GNU General Public License v3.0 4 votes vote down vote up
@Transactional(readOnly = true)
@Override
public boolean isUserInGroup(Integer userId, Integer groupId) {
    return BooleanUtils.toBoolean(((GroupRepository) repository).isUserInGroup(userId, groupId));
}
 
Example 14
Source File: SimpleAdminConnector.java    From canal with Apache License 2.0 4 votes vote down vote up
@Override
public boolean startInstance(String destination) {
    return BooleanUtils.toBoolean(Integer.parseInt(doInstanceAdmin(destination, "start")));
}
 
Example 15
Source File: SimpleAdminConnector.java    From canal with Apache License 2.0 4 votes vote down vote up
@Override
public boolean start() {
    return BooleanUtils.toBoolean(Integer.parseInt(doServerAdmin("start")));
}
 
Example 16
Source File: SysConfiguration.java    From rebuild with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param name
 * @return
 */
public static boolean getBool(ConfigurableItem name) {
	String s = get(name);
	return s == null ? (Boolean) name.getDefaultValue() : BooleanUtils.toBoolean(s);
}
 
Example 17
Source File: FileUploader.java    From rebuild with GNU General Public License v3.0 4 votes vote down vote up
@RequestMapping(value = "upload", method = RequestMethod.POST)
public void upload(HttpServletRequest request, HttpServletResponse response) throws IOException {
	String uploadName = null;
	try {
		List<FileItem> fileItems = parseFileItem(request);
		for (FileItem item : fileItems) {
			uploadName = item.getName();
			if (uploadName == null) {
				continue;
			}

			uploadName = QiniuCloud.formatFileKey(uploadName);
			File file;
			// 上传临时文件
			if (BooleanUtils.toBoolean(request.getParameter("temp"))) {
				uploadName = uploadName.split("/")[2];
				file = SysConfiguration.getFileOfTemp(uploadName);
			} else {
				file = SysConfiguration.getFileOfData(uploadName);
				FileUtils.forceMkdir(file.getParentFile());
			}
			
			item.write(file);
			if (!file.exists()) {
				ServletUtils.writeJson(response, AppUtils.formatControllMsg(1000, "上传失败"));
				return;
			}

			break;
		}
		
	} catch (Exception e) {
		LOG.error(null, e);
		uploadName = null;
	}
	
	if (uploadName != null) {
		ServletUtils.writeJson(response, AppUtils.formatControllMsg(0, uploadName));
	} else {
		ServletUtils.writeJson(response, AppUtils.formatControllMsg(1000, "上传失败"));
	}
}
 
Example 18
Source File: FileDownloader.java    From rebuild with GNU General Public License v3.0 4 votes vote down vote up
@RequestMapping(value = "img/**", method = RequestMethod.GET)
public void viewImg(HttpServletRequest request, HttpServletResponse response) throws IOException {
	String filePath = request.getRequestURI();
	filePath = filePath.split("/filex/img/")[1];
	
	ServletUtils.addCacheHead(response, IMG_CACHE_TIME);

	if (filePath.startsWith("http://") || filePath.startsWith("https://")) {
		response.sendRedirect(filePath);
		return;
	}

	final boolean temp = BooleanUtils.toBoolean(request.getParameter("temp"));
	String imageView2 = request.getQueryString();
	if (imageView2 != null && !imageView2.startsWith("imageView2")) {
		imageView2 = null;
	}

	// Local storage || temp
	if (!QiniuCloud.instance().available() || temp) {
		String fileName = QiniuCloud.parseFileName(filePath);
		String mimeType = request.getServletContext().getMimeType(fileName);
		if (mimeType != null) {
			response.setContentType(mimeType);
		}

		final int wh = imageView2 == null ? 0 : parseWidth(imageView2);

		// 原图
		if (wh <= 0 || wh >= 1000) {
			writeLocalFile(filePath, temp, response);
		}
		// 粗略图
		else {
			filePath = CodecUtils.urlDecode(filePath);
			File img = temp ? SysConfiguration.getFileOfTemp(filePath) : SysConfiguration.getFileOfData(filePath);

			BufferedImage bi = ImageIO.read(img);
			Thumbnails.Builder<BufferedImage> builder = Thumbnails.of(bi);

			if (bi.getWidth() > wh) {
				builder.size(wh, wh);
			} else {
				builder.scale(1.0);
			}

			builder
					.outputFormat(mimeType != null && mimeType.contains("png") ? "png" : "jpg")
					.toOutputStream(response.getOutputStream());
		}
	}
	else {
		if (imageView2 != null) {
			filePath += "?" + imageView2;
		}

		String privateUrl = QiniuCloud.instance().url(filePath, IMG_CACHE_TIME * 60);
		response.sendRedirect(privateUrl);
	}
}
 
Example 19
Source File: VmwareVmImplementer.java    From cloudstack with Apache License 2.0 3 votes vote down vote up
/**
 * Decide in which cases nested virtualization should be enabled based on (1){@code globalNestedV}, (2){@code globalNestedVPerVM}, (3){@code localNestedV}<br/>
 * Nested virtualization should be enabled when one of this cases:
 * <ul>
 * <li>(1)=TRUE, (2)=TRUE, (3) is NULL (missing)</li>
 * <li>(1)=TRUE, (2)=TRUE, (3)=TRUE</li>
 * <li>(1)=TRUE, (2)=FALSE</li>
 * <li>(1)=FALSE, (2)=TRUE, (3)=TRUE</li>
 * </ul>
 * In any other case, it shouldn't be enabled
 * @param globalNestedV value of {@code 'vmware.nested.virtualization'} global config
 * @param globalNestedVPerVM value of {@code 'vmware.nested.virtualization.perVM'} global config
 * @param localNestedV value of {@code 'nestedVirtualizationFlag'} key in vm details if present, null if not present
 * @return "true" for cases in which nested virtualization is enabled, "false" if not
 */
Boolean shouldEnableNestedVirtualization(Boolean globalNestedV, Boolean globalNestedVPerVM, String localNestedV) {
    if (globalNestedV == null || globalNestedVPerVM == null) {
        return false;
    }
    boolean globalNV = globalNestedV.booleanValue();
    boolean globalNVPVM = globalNestedVPerVM.booleanValue();

    if (globalNVPVM) {
        return (localNestedV == null && globalNV) || BooleanUtils.toBoolean(localNestedV);
    }
    return globalNV;
}
 
Example 20
Source File: BaseControll.java    From rebuild with GNU General Public License v3.0 2 votes vote down vote up
/**
 * @param req
 * @param name
 * @return
 */
protected boolean getBoolParameter(HttpServletRequest req, String name) {
	String v = req.getParameter(name);
	return v != null && BooleanUtils.toBoolean(v);
}