Java Code Examples for com.zhazhapan.util.Checker#isNotEmpty()

The following examples show how to use com.zhazhapan.util.Checker#isNotEmpty() . 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: QiniuService.java    From qiniu with MIT License 6 votes vote down vote up
/**
 * 日志下载
 */
public void downloadCdnLog(String logDate) {
    if (Checker.isNotEmpty(QiniuApplication.getConfigBean().getBuckets()) && Checker.isDate(logDate)) {
        // 转换域名成数组格式
        String[] domains = new String[QiniuApplication.getConfigBean().getBuckets().size()];
        for (int i = 0; i < QiniuApplication.getConfigBean().getBuckets().size(); i++) {
            domains[i] = QiniuApplication.getConfigBean().getBuckets().get(i).getUrl();
        }
        Map<String, CdnResult.LogData[]> cdnLog = null;
        try {
            cdnLog = sdkManager.listCdnLog(domains, logDate);
        } catch (QiniuException e) {
            DialogUtils.showException(e);
        }
        if (Checker.isNotEmpty(cdnLog)) {
            // 下载日志
            for (Map.Entry<String, CdnResult.LogData[]> logs : cdnLog.entrySet()) {
                for (CdnResult.LogData log : logs.getValue()) {
                    QiniuUtils.download(log.url);
                }
            }
        }
    }
}
 
Example 2
Source File: UserServiceImpl.java    From efo with MIT License 6 votes vote down vote up
@Override
public User login(String loginName, String password, String token, HttpServletResponse response) {
    boolean allowLogin = settings.getBooleanUseEval(ConfigConsts.ALLOW_LOGIN_OF_SETTINGS);
    User user = null;
    if (allowLogin) {
        if (Checker.isNotEmpty(token) && EfoApplication.tokens.containsKey(token)) {
            user = userDAO.getUserById(EfoApplication.tokens.get(token));
            if (Checker.isNotNull(response)) {
                Cookie cookie = new Cookie(ValueConsts.TOKEN_STRING, TokenConfig.generateToken(token, user.getId
                        ()));
                cookie.setMaxAge(30 * 24 * 60 * 60);
                response.addCookie(cookie);
            }
        }
        if (Checker.isNull(user) && Checker.isNotEmpty(loginName) && Checker.isNotEmpty(password)) {
            user = userDAO.login(loginName, password);
            if (Checker.isNotNull(user)) {
                TokenConfig.removeTokenByValue(user.getId());
            }
        }
        updateUserLoginTime(user);
    }
    return user;
}
 
Example 3
Source File: QiniuService.java    From qiniu with MIT License 6 votes vote down vote up
/**
 * 获取空间带宽统计,使用自定义单位
 */
public XYChart.Series<String, Long> getBucketBandwidth(String[] domains, String startDate, String endDate,
                                                       String unit) {
    // 获取带宽数据
    CdnResult.BandwidthResult bandwidthResult = null;
    try {
        bandwidthResult = sdkManager.getBandwidthData(domains, startDate, endDate);
    } catch (QiniuException e) {
        Platform.runLater(() -> DialogUtils.showException(QiniuValueConsts.BUCKET_BAND_ERROR, e));
    }
    // 设置图表
    XYChart.Series<String, Long> series = new XYChart.Series<>();
    series.setName(QiniuValueConsts.BUCKET_BANDWIDTH_COUNT.replaceAll("[A-Z]+", unit));
    // 格式化数据
    if (Checker.isNotNull(bandwidthResult) && Checker.isNotEmpty(bandwidthResult.data)) {
        long unitSize = Formatter.sizeToLong("1 " + unit);
        for (Map.Entry<String, CdnResult.BandwidthData> bandwidth : bandwidthResult.data.entrySet()) {
            CdnResult.BandwidthData bandwidthData = bandwidth.getValue();
            if (Checker.isNotNull(bandwidthData)) {
                setSeries(bandwidthResult.time, bandwidthData.china, bandwidthData.oversea, series, unitSize);
            }
        }
    }
    return series;
}
 
Example 4
Source File: AuthServiceImpl.java    From efo with MIT License 6 votes vote down vote up
@Override
public boolean addAuth(String files, String users, String auths) {
    if (Checker.isNotEmpty(files) && Checker.isNotEmpty(users) && Checker.isNotEmpty(auths)) {
        String[] file = files.split(ValueConsts.COMMA_SIGN);
        String[] user = users.split(ValueConsts.COMMA_SIGN);
        for (String f : file) {
            long fileId = Formatter.stringToLong(f);
            for (String u : user) {
                int userId = Formatter.stringToInt(u);
                if (Checker.isNull(authDAO.exists(userId, fileId))) {
                    Auth auth = new Auth(userId, fileId);
                    auth.setAuth(BeanUtils.getAuth(auths));
                    authDAO.insertAuth(auth);
                }
            }
        }
    }
    return true;
}
 
Example 5
Source File: ControllerUtils.java    From efo with MIT License 6 votes vote down vote up
/**
 * 加载本地资源
 *
 * @param response 返回的Response
 * @param path 资源路径
 * @param download 直接下载
 */
public static void loadResource(HttpServletResponse response, String path, boolean download) throws IOException {
    if (Checker.isNotEmpty(path)) {
        File file = new File(path);
        if (download) {
            setResponseFileName(response, file.getName());
        }
        FileInputStream in = new FileInputStream(file);
        ServletOutputStream os = response.getOutputStream();
        byte[] b;
        while (in.available() > 0) {
            b = in.available() > 1024 ? new byte[1024] : new byte[in.available()];
            in.read(b, 0, b.length);
            os.write(b, 0, b.length);
        }
        in.close();
        os.flush();
        os.close();
    } else {
        response.sendRedirect(DefaultValues.NOT_FOUND_PAGE);
    }
}
 
Example 6
Source File: QiniuService.java    From qiniu with MIT License 6 votes vote down vote up
/**
 * 获取空间的流量统计,使用自定义单位
 */
public XYChart.Series<String, Long> getBucketFlux(String[] domains, String startDate, String endDate, String unit) {
    // 获取流量数据
    CdnResult.FluxResult fluxResult = null;
    try {
        fluxResult = sdkManager.getFluxData(domains, startDate, endDate);
    } catch (QiniuException e) {
        Platform.runLater(() -> DialogUtils.showException(QiniuValueConsts.BUCKET_FLUX_ERROR, e));
    }
    // 设置图表
    XYChart.Series<String, Long> series = new XYChart.Series<>();
    series.setName(QiniuValueConsts.BUCKET_FLUX_COUNT.replaceAll("[A-Z]+", unit));
    // 格式化数据
    if (Checker.isNotNull(fluxResult) && Checker.isNotEmpty(fluxResult.data)) {
        long unitSize = Formatter.sizeToLong("1 " + unit);
        for (Map.Entry<String, CdnResult.FluxData> flux : fluxResult.data.entrySet()) {
            CdnResult.FluxData fluxData = flux.getValue();
            if (Checker.isNotNull(fluxData)) {
                setSeries(fluxResult.time, fluxData.china, fluxData.oversea, series, unitSize);
            }
        }
    }
    return series;
}
 
Example 7
Source File: MainController.java    From qiniu with MIT License 5 votes vote down vote up
/**
 * 设置文件生存时间
 */
public void setLife() {
    ObservableList<FileBean> selectedItems = resTV.getSelectionModel().getSelectedItems();
    if (Checker.isNotEmpty(selectedItems)) {
        // 弹出输入框
        String fileLife = DialogUtils.showInputDialog(null, QiniuValueConsts.FILE_LIFE,
                QiniuValueConsts.DEFAULT_FILE_LIFE);
        if (Checker.isNumber(fileLife)) {
            int life = Formatter.stringToInt(fileLife);
            selectedItems.forEach(bean -> service.setFileLife(bucketCB.getValue(), bean.getName(), life));
        }
    }
}
 
Example 8
Source File: MainController.java    From visual-spider with MIT License 5 votes vote down vote up
/**
 * 保存爬取日志
 */
public void saveLog() {
    String visitingLog = htmlContent.getText();
    if (Checker.isNotEmpty(visitingLog) && visitingLog.contains(SpiderValueConsts.VISITING_TIP)) {
        SpiderUtils.saveFile(SpiderApplication.DOWNLOAD_FOLDER + SpiderValueConsts.SEPARATOR + "visiting.log",
                visitingLog, ValueConsts.TRUE);
    }
    String downloadingLog = logOut.getText();
    if (Checker.isNotEmpty(downloadingLog) && downloadingLog.contains(SpiderValueConsts.DOWNLOADING_TIP)) {
        SpiderUtils.saveFile(SpiderApplication.DOWNLOAD_FOLDER + SpiderValueConsts.SEPARATOR + "downloading.log",
                downloadingLog, ValueConsts.TRUE);
    }
}
 
Example 9
Source File: TokenConfig.java    From efo with MIT License 5 votes vote down vote up
public static void removeTokenByValue(int userId) {
    if (userId > 0) {
        String removeKey = "";
        for (String key : EfoApplication.tokens.keySet()) {
            if (EfoApplication.tokens.get(key) == userId) {
                removeKey = key;
                break;
            }
        }
        if (Checker.isNotEmpty(removeKey)) {
            EfoApplication.tokens.remove(removeKey);
            TokenConfig.saveToken();
        }
    }
}
 
Example 10
Source File: CategoryServiceImpl.java    From efo with MIT License 4 votes vote down vote up
@Override
public boolean update(int id, String name) {
    return Checker.isNotEmpty(name) && isCategorized(id) && categoryDAO.updateNameById(id, name);
}
 
Example 11
Source File: MysqlConfig.java    From visual-spider with MIT License 4 votes vote down vote up
public static void setDbName(String dbName) {
    if (Checker.isNotEmpty(dbName)) {
        MysqlConfig.dbName = dbName;
    }
}
 
Example 12
Source File: AuthServiceImpl.java    From efo with MIT License 4 votes vote down vote up
@Override
public boolean batchDelete(String ids) {
    return Checker.isNotEmpty(ids) && authDAO.batchDelete(ids);
}
 
Example 13
Source File: MysqlConfig.java    From visual-spider with MIT License 4 votes vote down vote up
public static void setDbCondition(String dbCondition) {
    if (Checker.isNotEmpty(dbCondition)) {
        MysqlConfig.dbCondition = dbCondition;
    }
}
 
Example 14
Source File: UserServiceImpl.java    From efo with MIT License 4 votes vote down vote up
@Override
public boolean usernameExists(String username) {
    return Checker.isNotEmpty(username) && userDAO.checkUsername(username) > 0;
}
 
Example 15
Source File: MysqlConfig.java    From visual-spider with MIT License 4 votes vote down vote up
public static void setDbUsername(String dbUsername) {
    if (Checker.isNotEmpty(dbUsername)) {
        MysqlConfig.dbUsername = dbUsername;
    }
}
 
Example 16
Source File: MainController.java    From qiniu with MIT License 4 votes vote down vote up
/**
 * 显示移动或复制文件的弹窗
 */
public void showFileMovableDialog() {
    ObservableList<FileBean> selectedItems = resTV.getSelectionModel().getSelectedItems();
    if (Checker.isEmpty(selectedItems)) {
        // 没有选择文件,结束方法
        return;
    }
    Pair<SdkManager.FileAction, String[]> resultPair;
    String bucket = bucketCB.getValue();
    if (selectedItems.size() > 1) {
        resultPair = dialog.showFileDialog(bucket, "", false);
    } else {
        resultPair = dialog.showFileDialog(bucket, selectedItems.get(0).getName(), true);
    }
    if (Checker.isNotNull(resultPair)) {
        boolean useNewKey = Checker.isNotEmpty(resultPair.getValue()[1]);
        ObservableList<FileBean> fileBeans = resTV.getItems();
        for (FileBean fileBean : selectedItems) {
            String fromBucket = bucketCB.getValue();
            String toBucket = resultPair.getValue()[0];
            String name = useNewKey ? resultPair.getValue()[1] : fileBean.getName();
            boolean isSuccess = service.moveOrCopyFile(fromBucket, fileBean.getName(), toBucket, name,
                    resultPair.getKey());
            if (resultPair.getKey() == SdkManager.FileAction.MOVE && isSuccess) {
                boolean isInSearch = Checker.isNotEmpty(searchTF.getText());
                if (fromBucket.equals(toBucket)) {
                    // 更新文件名
                    fileBean.setName(name);
                    if (isInSearch) {
                        fileBeans.get(fileBeans.indexOf(fileBean)).setName(name);
                    }
                } else {
                    // 删除数据源
                    fileBeans.remove(fileBean);
                    dataLength--;
                    dataSize -= Formatter.sizeToLong(fileBean.getSize());
                    if (isInSearch) {
                        fileBeans.remove(fileBean);
                    }
                }
            }
        }
        countBucket();
    }
}
 
Example 17
Source File: MainController.java    From visual-spider with MIT License 4 votes vote down vote up
/**
 * 爬取URL
 */
public void toCrawl() {
    if (crawling) {
        // 暂停爬虫
        crawling = false;
        toggleCrawling.setText(SpiderValueConsts.CRAWLER_START);
        statusLabel.setText("crawler suspend");
        SpiderApplication.controller.shutdown();
    } else {
        if (MysqlConfig.isEnableCustom() && !MysqlConfig.isConnectionSuccessful()) {
            MysqlConfig.setEnableSql(true);
            Alerts.showWarning(SpiderValueConsts.MAIN_TITLE, "数据库连接失败,将自动为您生成SQL文件");
        }
        // 开始爬虫
        if (!Checker.isHyperLink(crawlUrl.getText())) {
            String html = htmlContent.getText();
            if (Checker.isNotEmpty(html)) {
                // 如果没有输入要爬取的链接,并且链接访问文本域的内容不为空,将直接把该内容作为源代码传送到下载模式
                ThreadPool.executor.submit(() -> new Crawler().downloadURL("", html));
                htmlContent.clear();
            }
            return;
        }
        crawling = true;
        toggleCrawling.setText(SpiderValueConsts.CRAWLER_STOP);
        LOGGER.info("start to crawl urls: " + crawlUrl.getText());
        statusLabel.setText("starting......");
        // 读取爬虫配置
        String[] urls = crawlUrl.getText().split(" ");
        SpiderApplication.domains = new String[urls.length];
        for (int i = 0; i < urls.length; i++) {
            String url = urls[i].replaceAll("https?://", "");
            if (url.contains("/")) {
                SpiderApplication.domains[i] = url.substring(0, url.indexOf("/") + 1);
            } else {
                SpiderApplication.domains[i] = url;
            }
        }
        // 爬虫参数转换为合法的数据
        int numNon = Formatter.stringToInt(CrawlConfig.getNumberOfCrawlers().get());
        int num = numNon < 1 ? DefaultConfigValues.NUMBER_OF_CRAWLERS : numNon;
        int depNon = Formatter.stringToInt(CrawlConfig.getMaxDepthOfCrawling().get());
        int dep = depNon < 1 || depNon > DefaultConfigValues.MAX_DEPTH_OF_CRAWLING ? DefaultConfigValues
                .MAX_DEPTH_OF_CRAWLING : depNon;
        int pagNon = Formatter.stringToInt(CrawlConfig.getMaxPagesToFetch().get());
        int pag = pagNon < 1 ? Integer.MAX_VALUE : pagNon;
        int delNon = Formatter.stringToInt(CrawlConfig.getPolitenessDelay().get());
        int del = delNon < 1 ? DefaultConfigValues.POLITENESS_DELAY : delNon;
        SpiderApplication.crawlingDelay = del;
        ThreadPool.executor.submit(() -> {
            // 开启爬虫
            SpiderApplication.controller.init(num, dep, pag, del, urls);
            boolean res = SpiderApplication.controller.start();
            finished(res);
        });
    }
}
 
Example 18
Source File: MainController.java    From visual-spider with MIT License 4 votes vote down vote up
/**
 * 打开自定义爬取面板
 */
public void customCrawling() {
    Dialog<ButtonType> dialog = new Dialog<>();
    dialog.setTitle(SpiderValueConsts.MAIN_TITLE);
    dialog.setHeaderText(null);
    dialog.initModality(Modality.APPLICATION_MODAL);
    ButtonType ok = new ButtonType("确定", ButtonBar.ButtonData.OK_DONE);
    ButtonType cancel = new ButtonType("取消", ButtonBar.ButtonData.CANCEL_CLOSE);
    try {
        DialogPane dialogPane = FXMLLoader.load(getClass().getResource("/view/CustomCrawling.fxml"));
        dialogPane.getButtonTypes().addAll(ok, cancel);
        dialog.setDialogPane(dialogPane);
        Optional<ButtonType> result = dialog.showAndWait();
        if (ok.equals(result.get())) {
            //设置配置信息
            CustomCrawlingController controller = SpiderApplication.customCrawlingController;
            if (Checker.isNotNull(controller)) {
                String mappings = controller.mappings.getText();
                boolean enableCustom = controller.enableCustomCrawling.isSelected();
                if (enableCustom && Checker.isNotEmpty(mappings)) {
                    MysqlConfig.setDbCondition(controller.dbCondition.getText());
                    MysqlConfig.setDbHost(controller.dbHost.getText());
                    MysqlConfig.setDbName(controller.dbName.getText());
                    MysqlConfig.setDbPassword(controller.dbPassword.getText());
                    MysqlConfig.setDbPort(controller.dbPort.getText());
                    MysqlConfig.setDbUsername(controller.dbUsername.getText());
                    MysqlConfig.setTableName(controller.dbTable.getText());
                    MysqlConfig.setEnableCustom(true);
                    MysqlConfig.setEnableSql(controller.enableSql.isSelected());
                    String[] mapping = mappings.split(ValueConsts.COMMA_SIGN);
                    MysqlConfig.getFields().clear();
                    for (String s : mapping) {
                        String[] keyValue = s.split("->");
                        Pair<String, String> map = new Pair<>(keyValue[0].trim(), keyValue[1].trim());
                        MysqlConfig.getFields().add(map);
                    }
                    connectDatabase();
                } else {
                    MysqlConfig.setEnableCustom(false);
                    if (enableCustom) {
                        Alerts.showWarning(SpiderValueConsts.MAIN_TITLE, "映射关系为空,无法开启自定义爬取");
                    }
                }
            }
        }
    } catch (IOException e) {
        Alerts.showError(SpiderValueConsts.MAIN_TITLE, e.getMessage());
    }
    customCK.setSelected(MysqlConfig.isEnableCustom());
}
 
Example 19
Source File: MysqlConfig.java    From visual-spider with MIT License 4 votes vote down vote up
public static void setDbHost(String dbHost) {
    if (Checker.isNotEmpty(dbHost)) {
        MysqlConfig.dbHost = dbHost;
    }
}
 
Example 20
Source File: MainController.java    From qiniu with MIT License 3 votes vote down vote up
/**
 * 复制链接
 */
public void copyLink() {
    ObservableList<FileBean> fileBeans = resTV.getSelectionModel().getSelectedItems();
    if (Checker.isNotEmpty(fileBeans)) {
        // 只复制选中的第一个文件的链接
        Utils.copyToClipboard(QiniuUtils.buildUrl(fileBeans.get(0).getName(), domainTF.getText()));
    }
}