com.jfinal.kit.PathKit Java Examples

The following examples show how to use com.jfinal.kit.PathKit. 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: InstallController.java    From zrlog with Apache License 2.0 6 votes vote down vote up
/**
 * 检查数据库是否可以正常连接使用,无法连接时给出相应的提示
 */
public String testDbConn() {
    Map<String, String> dbConn = new HashMap<>();
    dbConn.put("jdbcUrl", "jdbc:mysql://" + getPara("dbhost") + ":" + getPara("port") + "/" + getPara("dbname")
            + "?" + ZrLogConfig.JDBC_URL_BASE_QUERY_PARAM);
    dbConn.put("user", getPara("dbuser"));
    dbConn.put("password", getPara("dbpwd"));
    dbConn.put("driverClass", "com.mysql.cj.jdbc.Driver");
    TestConnectDbResult testConnectDbResult = new InstallService(PathKit.getWebRootPath() + "/WEB-INF", dbConn).testDbConn();
    if (testConnectDbResult.getError() != 0) {
        setAttr("errorMsg", "[Error-" + testConnectDbResult.getError() + "] - " + I18nUtil.getStringFromRes("connectDbError_" + testConnectDbResult.getError()));
        return index();
    } else {
        JFinal.me().getServletContext().setAttribute("dbConn", dbConn);
        return "/install/message";
    }
}
 
Example #2
Source File: WarUpdateVersionThread.java    From zrlog with Apache License 2.0 6 votes vote down vote up
private File generatorUpgradeWarFile(String warName) throws IOException {
    ZipUtil.unZip(file.toString(), tempFilePath + File.separator);
    updateProcessMsg("解压安装包 " + file);
    Map<String, String> copyFileMap = new LinkedHashMap<>();
    copyFileMap.put(PathKit.getWebRootPath() + "/WEB-INF/db.properties", tempFilePath + "/WEB-INF/");
    copyFileMap.put(PathKit.getWebRootPath() + "/WEB-INF/install.lock", tempFilePath + "/WEB-INF/");
    copyFileMap.put(PathKit.getWebRootPath() + Constants.ATTACHED_FOLDER, tempFilePath.toString());
    copyFileMap.put(PathKit.getWebRootPath() + "/favicon.ico", tempFilePath.toString());
    copyFileMap.put(PathKit.getWebRootPath() + "/error", tempFilePath.toString());
    fillTemplateCopyInfo(tempFilePath, copyFileMap);
    doCopy(copyFileMap);
    List<File> fileList = new ArrayList<>();
    fileList.add(tempFilePath);
    File tempWarFile = new File(tempFilePath.getParent() + File.separator + warName);
    JarPackageUtil.inJar(fileList, tempFilePath + File.separator, tempWarFile.toString());
    updateProcessMsg("合成更新包 " + tempWarFile);
    return tempWarFile;
}
 
Example #3
Source File: SqlInXmlKit.java    From jfinal-ext3 with Apache License 2.0 6 votes vote down vote up
static void init() {
    sqlMap = new HashMap<String, String>();
    File file = new File(PathKit.getRootClassPath());
    File[] files = file.listFiles(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            if (pathname.getName().endsWith("sql.xml")) {
                return true;
            }
            return false;
        }
    });
    for (File xmlfile : files) {
        SqlGroup group = JaxbKit.unmarshal(xmlfile, SqlGroup.class);
        String name = group.name;
        if (name == null || name.trim().equals("")) {
            name = xmlfile.getName();
        }
        for (SqlItem sqlItem : group.sqlItems) {
            sqlMap.put(name + "." + sqlItem.id, sqlItem.value);
        }
    }
    LOG.debug("sqlMap" + sqlMap);
}
 
Example #4
Source File: InstallController.java    From zrlog with Apache License 2.0 6 votes vote down vote up
/**
 * 数据库检查通过后,根据填写信息,执行数据表,表数据的初始化
 */
public String install() {
    Map<String, String> dbConn = (Map<String, String>) JFinal.me().getServletContext().getAttribute("dbConn");
    Map<String, String> configMsg = new HashMap<>();
    configMsg.put("title", getPara("title"));
    configMsg.put("second_title", getPara("second_title"));
    configMsg.put("username", getPara("username"));
    configMsg.put("password", getPara("password"));
    configMsg.put("email", getPara("email"));
    if (new InstallService(PathKit.getWebRootPath() + "/WEB-INF", dbConn, configMsg).install()) {
        final ZrLogConfig config = (ZrLogConfig) JFinal.me().getServletContext().getAttribute("config");
        //通知启动插件,配置库连接等操作
        config.installFinish();
        return "/install/success";
    } else {
        setAttr("errorMsg", "[Error-" + TestConnectDbResult.UNKNOWN.getError() + "] - " + I18nUtil.getStringFromRes("connectDbError_" + TestConnectDbResult.UNKNOWN.getError()));
        return "/install/message";
    }
}
 
Example #5
Source File: WarUpdateVersionThread.java    From zrlog with Apache License 2.0 6 votes vote down vote up
private String getWarNameAndBackup() {
    String warName;
    String contextPath = JFinal.me().getServletContext().getContextPath();
    if ("/".equals(contextPath) || "".equals(contextPath)) {
        warName = "/ROOT.war";
    } else {
        warName = contextPath + ".war";
    }
    String backupFolder = new File(PathKit.getWebRootPath()).getParentFile().getParentFile() + File.separator + "backup" + File.separator + new SimpleDateFormat("yyyy-MM-dd_HH_mm").format(new Date()) + File.separator;
    new File(backupFolder).mkdirs();
    FileUtils.moveOrCopyFolder(PathKit.getWebRootPath(), backupFolder, false);
    String warPath = new File(PathKit.getWebRootPath()).getParent() + File.separator + warName;
    if (new File(warPath).exists()) {
        FileUtils.moveOrCopyFolder(warPath, backupFolder, false);
    }
    updateProcessMsg("备份当前版本到 " + backupFolder);
    return warName;
}
 
Example #6
Source File: DataSourceBuilder.java    From jboot with Apache License 2.0 6 votes vote down vote up
public DataSource build() {

        String shardingConfigYaml = config.getShardingConfigYaml();

        // 不启用分库分表的配置
        if (StrUtil.isBlank(shardingConfigYaml)) {
            DataSource ds = createDataSource(config);
            return JbootSeataManager.me().wrapDataSource(ds);
        }


        File yamlFile = shardingConfigYaml.startsWith(File.separator)
                ? new File(shardingConfigYaml)
                : new File(PathKit.getRootClassPath(), shardingConfigYaml);

        try {
            return YamlShardingDataSourceFactory.createDataSource(yamlFile);
        } catch (Exception e) {
            throw new JbootException(e);
        }
    }
 
Example #7
Source File: AdminArticlePageController.java    From zrlog with Apache License 2.0 6 votes vote down vote up
public String preview() {
    Integer logId = getParaToInt("id");
    if (logId != null) {
        Log log = new Log().adminFindLogByLogId(logId);
        if (log != null) {
            log.put("lastLog", new Log().findLastLog(logId, I18nUtil.getStringFromRes("noLastLog")));
            log.put("nextLog", new Log().findNextLog(logId, I18nUtil.getStringFromRes("noNextLog")));
            setAttr("log", log.getAttrs());
            TemplateHelper.fillArticleInfo(log, getRequest(), "");
        }
        return getTemplatePath() + "/detail" + ZrLogUtil.getViewExt(new TemplateService().getTemplateVO(JFinal.me().getContextPath(),
                new File(PathKit.getWebRootPath() + getTemplatePath())).getViewType());
    } else {
        return Constants.NOT_FOUND_PAGE;
    }
}
 
Example #8
Source File: ZrLogConfig.java    From zrlog with Apache License 2.0 6 votes vote down vote up
/**
 * 配置JFinal的常用参数,这里可以看出来JFinal推崇使用代码进行配置的,而不是像Spring这样的通过预定配置方式。代码控制的好处在于高度可控制性,
 * 当然这也导致了很多程序员直接硬编码的问题。
 *
 * @param con
 */
@Override
public void configConstant(Constants con) {
    con.setDevMode(BlogBuildInfoUtil.isDev());
    con.setViewType(ViewType.JSP);
    con.setEncoding("utf-8");
    con.setJsonDatePattern("yyyy-MM-dd");
    con.setI18nDefaultBaseName(com.zrlog.common.Constants.I18N);
    con.setI18nDefaultLocale("zh_CN");
    con.setError404View(com.zrlog.common.Constants.NOT_FOUND_PAGE);
    con.setError500View(com.zrlog.common.Constants.ERROR_PAGE);
    con.setError403View(com.zrlog.common.Constants.FORBIDDEN_PAGE);
    con.setBaseUploadPath(PathKit.getWebRootPath() + com.zrlog.common.Constants.ATTACHED_FOLDER);
    //最大的提交的body的大小
    con.setMaxPostSize(1024 * 1024 * 1024);
}
 
Example #9
Source File: ModelGenerator.java    From NewsRecommendSystem with MIT License 6 votes vote down vote up
/**
 * @param dataSource
 * @param baseModelPackageName
 * @param baseModelOutputDir
 * @param modelPackageName
 * @param modelOutputDir
 */
public static void main(String[] args)
{
	// base model 所使用的包名
	String baseModelPackageName = "top.qianxinyao.model.base";
	// base model 文件保存路径
	String baseModelOutputDir = PathKit.getRootClassPath() + "/../../src/top/qianxinyao/model/base";
	System.out.println("rootclasspath:"+baseModelOutputDir);
	// model 所使用的包名 (MappingKit 默认使用的包名)
	String modelPackageName = "top.qianxinyao.model";
	// model 文件保存路径 (MappingKit 与 DataDictionary 文件默认保存路径)
	String modelOutputDir = baseModelOutputDir+"/..";
	System.out.println(baseModelOutputDir);
	// 创建生成器
	Generator gernerator = new Generator(DBKit.getDataSource(), baseModelPackageName, baseModelOutputDir,
			modelPackageName, modelOutputDir);
	gernerator.setDialect(new MysqlDialect());
	// 设置是否在 Model 中生成 dao 对象
	gernerator.setGenerateDaoInModel(true);
	// 设置是否生成字典文件
	gernerator.setGenerateDataDictionary(false);
	// 生成
	gernerator.generate();
}
 
Example #10
Source File: AddonManager.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 启动的时候,加载所有插件
 * 备注:插件可能是复制到插件目录下,而非通过后台进行 "安装"
 */
private void doInitAddons() {

    File addonDir = new File(PathKit.getWebRootPath(), "WEB-INF/addons");
    if (!addonDir.exists()) {
        return;
    }

    File[] addonJarFiles = addonDir.listFiles((dir, name) -> name.endsWith(".jar"));
    if (addonJarFiles == null || addonJarFiles.length == 0) {
        return;
    }

    initAddonsMap(addonJarFiles);
    doInstallAddonsInApplicationStarted();
    doStartAddonInApplicationStarted();

}
 
Example #11
Source File: _AttachmentController.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void doBatchDelRootFile() {
    String fileNames = getPara("names");
    if (StrUtil.isBlank(fileNames) || fileNames.contains("..") || fileNames.contains("/") || fileNames.contains("\\")) {
        renderFailJson();
        return;
    }

    String[] fileNamaArray = fileNames.split(",");
    for (String fileName : fileNamaArray) {
        if (StrUtil.isNotBlank(fileName)) {
            File file = new File(PathKit.getWebRootPath(), fileName.trim());
            file.delete();
        }
    }
    renderOkJson();
}
 
Example #12
Source File: UploadController.java    From zrlog with Apache License 2.0 6 votes vote down vote up
public UploadFileResponse thumbnail() throws IOException {
    String uploadFieldName = "imgFile";
    String uri = generatorUri(uploadFieldName);
    File imgFile = getFile(uploadFieldName).getFile();
    String finalFilePath = PathKit.getWebRootPath() + uri;
    byte[] bytes = IOUtil.getByteByInputStream(new FileInputStream(imgFile));
    File thumbnailFile = new File(finalFilePath);
    if (!thumbnailFile.getParentFile().exists()) {
        thumbnailFile.getParentFile().mkdirs();
    }
    int height = -1;
    int width = -1;
    if (!".gif".endsWith(uri)) {
        IOUtil.writeBytesToFile(ThumbnailUtil.jpeg(bytes, 1f), thumbnailFile);
        BufferedImage bimg = ImageIO.read(thumbnailFile);
        height = bimg.getHeight();
        width = bimg.getWidth();
    } else {
        IOUtil.writeBytesToFile(bytes, thumbnailFile);
    }
    UploadFileResponse uploadFileResponse = new UploadService().getCloudUrl(getRequest().getContextPath(), uri, finalFilePath, getRequest(), AdminTokenThreadLocal.getUser());
    uploadFileResponse.setUrl(uploadFileResponse.getUrl() + "?h=" + height + "&w=" + width);
    imgFile.delete();
    return uploadFileResponse;
}
 
Example #13
Source File: AdminInterceptor.java    From zrlog with Apache License 2.0 5 votes vote down vote up
/**
 * 为了规范代码,这里做了一点类是Spring的ResponseEntity的东西,及通过方法的返回值来判断是应该返回页面还会对应JSON数据
 * 具体方式看 AdminRouters,这里用到了 ThreadLocal
 *
 * @param ai
 */
private void adminPermission(Invocation ai) {
    Controller controller = ai.getController();
    AdminTokenVO adminTokenVO = adminTokenService.getAdminTokenVO(controller.getRequest());
    if (adminTokenVO != null) {
        try {
            User user = new User().findById(adminTokenVO.getUserId());
            if (StringUtils.isEmpty(user.getStr("header"))) {
                user.set("header", Constants.DEFAULT_HEADER);
            }
            controller.setAttr("user", user);
            controller.setAttr("protocol", adminTokenVO.getProtocol());
            TemplateHelper.fullTemplateInfo(controller, false);
            if (!"/admin/logout".equals(ai.getActionKey())) {
                adminTokenService.setAdminToken(user, adminTokenVO.getSessionId(), adminTokenVO.getProtocol(), controller.getRequest(), controller.getResponse());
            }
            ai.invoke();
            // 存在消息提示
            if (controller.getAttr("message") != null) {
                initIndex(controller.getRequest());
                controller.render(new FreeMarkerRender("/admin/index.ftl"));
            } else {
                if (!tryDoRender(ai, controller)) {
                    controller.renderHtml(IOUtil.getStringInputStream(new FileInputStream(PathKit.getWebRootPath() + Constants.NOT_FOUND_PAGE)));
                }
            }
        } catch (Exception e) {
            LOGGER.error("", e);
            exceptionHandler(ai, e);
        } finally {
            AdminTokenThreadLocal.remove();
        }
    } else if ("/admin/login".equals(ai.getActionKey()) || "/api/admin/login".equals(ai.getActionKey())) {
        ai.invoke();
        tryDoRender(ai, controller);
    } else {
        blockUnLoginRequestHandler(ai);
    }
}
 
Example #14
Source File: ZrLogConfig.java    From zrlog with Apache License 2.0 5 votes vote down vote up
/**
 * 设置系统参数到Servlet的Context用于后台管理的主页面的展示,读取Zrlog的版本信息等。
 */
@Override
public void afterJFinalStart() {
    FreeMarkerRender.getConfiguration().setClassForTemplateLoading(ZrLogConfig.class, com.zrlog.common.Constants.FTL_VIEW_PATH);
    try {
        BlogFrontendFreeMarkerRender.getConfiguration().setDirectoryForTemplateLoading(new File(PathKit.getWebRootPath()));
        BlogFrontendFreeMarkerRender.init(JFinal.me().getServletContext(), Locale.getDefault(), Const.DEFAULT_FREEMARKER_TEMPLATE_UPDATE_DELAY);
    } catch (IOException e) {
        e.printStackTrace();
    }
    super.afterJFinalStart();
    if (isInstalled()) {
        initDatabaseVersion();
    }
    SYSTEM_PROP.setProperty("zrlog.runtime.path", PathKit.getWebRootPath());
    SYSTEM_PROP.setProperty("server.info", JFinal.me().getServletContext().getServerInfo());
    JFinal.me().getServletContext().setAttribute("system", SYSTEM_PROP);
    blogProperties.put("version", BlogBuildInfoUtil.getVersion());
    blogProperties.put("buildId", BlogBuildInfoUtil.getBuildId());
    blogProperties.put("buildTime", new SimpleDateFormat("yyyy-MM-dd").format(BlogBuildInfoUtil.getTime()));
    blogProperties.put("runMode", BlogBuildInfoUtil.getRunMode());
    JFinal.me().getServletContext().setAttribute("zrlog", blogProperties);
    JFinal.me().getServletContext().setAttribute("config", this);
    if (haveSqlUpdated) {
        int updatedVersion = ZrLogUtil.getSqlVersion(getUpgradeSqlBasePath());
        if (updatedVersion > 0) {
            new WebSite().updateByKV(com.zrlog.common.Constants.ZRLOG_SQL_VERSION_KEY, updatedVersion + "");
        }
    }
}
 
Example #15
Source File: ModuleGenerator.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ModuleGenerator(String moduleName, String dbUrl, String dbUser, String dbPassword, String dbTables, String modelPackage, String servicePackage) {
    this.moduleName = moduleName;
    this.dbUrl = dbUrl;
    this.dbUser = dbUser;
    this.dbPassword = dbPassword;
    this.dbTables = dbTables;
    this.modelPackage = modelPackage;
    this.servicePackage = servicePackage;
    this.basePath = PathKit.getWebRootPath() + "/../module-" + moduleName;
}
 
Example #16
Source File: ModuleGenerator.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ModuleGenerator(String moduleName, String dbUrl, String dbUser, String dbPassword, String dbTables, String optionsTables, String modelPackage, String servicePackage) {
    this.moduleName = moduleName;
    this.dbUrl = dbUrl;
    this.dbUser = dbUser;
    this.dbPassword = dbPassword;
    this.optionsTables = optionsTables;
    this.dbTables = dbTables;
    this.modelPackage = modelPackage;
    this.servicePackage = servicePackage;
    this.basePath = PathKit.getWebRootPath() + "/../module-" + moduleName;
}
 
Example #17
Source File: VisitorInterceptor.java    From zrlog with Apache License 2.0 5 votes vote down vote up
/**
 * 查询出来的文章数据存放在request域里面,通过判断Key,选择对应需要渲染的模板文件
 *
 * @param ai
 */
private void visitorPermission(Invocation ai) {
    ai.invoke();
    String templateName = ai.getReturnValue();
    if (templateName == null) {
        return;
    }
    GlobalResourceHandler.printUserTime("Template before");
    String templatePath = TemplateHelper.fullTemplateInfo(ai.getController(), true);
    GlobalResourceHandler.printUserTime("Template after");
    TemplateVO templateVO = new TemplateService().getTemplateVO(JFinal.me().getContextPath(), new File(PathKit.getWebRootPath() + templatePath));
    String ext = ZrLogUtil.getViewExt(templateVO.getViewType());
    if (ai.getController().getAttr("log") != null) {
        ai.getController().setAttr("pageLevel", 1);
    } else if (ai.getController().getAttr("data") != null) {
        if ("/".equals(ai.getActionKey()) && new File(PathKit.getWebRootPath() + templatePath + "/" + templateName + ext).exists()) {
            ai.getController().setAttr("pageLevel", 2);
        } else {
            templateName = "page";
            ai.getController().setAttr("pageLevel", 1);
        }
    } else {
        ai.getController().setAttr("pageLevel", 2);
    }
    fullDevData(ai.getController());
    String viewPath = templatePath + "/" + templateName + ext;
    if (ext.equals(".ftl")) {
        BlogFrontendFreeMarkerRender render = new BlogFrontendFreeMarkerRender(viewPath);
        render.setContext(ai.getController().getRequest(), ai.getController().getResponse());
        ai.getController().render(render);
    } else {
        ai.getController().render(viewPath);
    }

}
 
Example #18
Source File: AddonGenerator.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public AddonGenerator(String addonName, String dbUrl, String dbUser, String dbPassword, String dbTables, String optionsTables, String modelPackage, String servicePackage) {
    this.addonName = addonName;
    this.dbUrl = dbUrl;
    this.dbUser = dbUser;
    this.dbPassword = dbPassword;
    this.dbTables = dbTables;
    this.optionsTables = optionsTables;
    this.modelPackage = modelPackage;
    this.servicePackage = servicePackage;
    this.basePath = PathKit.getWebRootPath() + "/../jpress-addon-" + addonName;
}
 
Example #19
Source File: AddonGenerator.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public AddonGenerator(String addonName, String dbUrl, String dbUser, String dbPassword, String dbTables, String modelPackage, String servicePackage) {
    this.addonName = addonName;
    this.dbUrl = dbUrl;
    this.dbUser = dbUser;
    this.dbPassword = dbPassword;
    this.dbTables = dbTables;
    this.modelPackage = modelPackage;
    this.servicePackage = servicePackage;
    this.basePath = PathKit.getWebRootPath() + "/../jpress-addon-" + addonName;
}
 
Example #20
Source File: ModuleUIGenerator.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ModuleUIGenerator(String moduleName, String modelPackage, List<TableMeta> tableMetaList) {

        this.tableMetaList = tableMetaList;
        this.moduleName = moduleName;
        this.modelPackage = modelPackage;
        modulePackage = modelPackage.substring(0, modelPackage.lastIndexOf("."));

        basePath = PathKit.getWebRootPath() + "/../module-" + moduleName;
        webPath = basePath + "/module-" + moduleName + "-web";

        String upcasedModuleName = StrKit.firstCharToUpperCase(moduleName);

        String moduleListenerPakcage = modelPackage.substring(0, modelPackage.lastIndexOf("."));
        String controllerPackage = modelPackage.substring(0, modelPackage.lastIndexOf(".")) + ".controller";


        moduleListenerOutputDir = webPath + "/src/main/java/" + moduleListenerPakcage.replace(".", "/");
        controllerOutputDir = webPath + "/src/main/java/" + controllerPackage.replace(".", "/");
        htmlOutputDir = webPath + "/src/main/webapp/WEB-INF/views/admin/" + moduleName;

        data = Kv.by("moduleName", moduleName);//product
        data.set("upcasedModuleName", upcasedModuleName);//Product
        data.set("modulePackage", modulePackage);//io.jpress.module.product
        data.set("modelPackage", modelPackage);//io.jpress.module.product.model
        data.set("moduleListenerPakcage", moduleListenerPakcage);//io.jpress.module.product
        data.set("controllerPackage", controllerPackage);//io.jpress.module.product.controller

        engine.setSourceFactory(new ClassPathSourceFactory());
        engine.addSharedMethod(new StrKit());

    }
 
Example #21
Source File: LuceneSearcher.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public LuceneSearcher() {
    File indexDir = new File(PathKit.getRootClassPath(), INDEX_PATH);
    if (!indexDir.exists()) {
        indexDir.mkdirs();
    }
    try {
        directory = NIOFSDirectory.open(indexDir.toPath());
    } catch (Exception e) {
        LOG.error(e.toString(), e);
    }
}
 
Example #22
Source File: InstallUtil.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean createJbootPropertiesFile() {

        File propertieFile = new File(PathKit.getRootClassPath(), "jboot.properties");
        DbExecuter dbExecuter = InstallManager.me().getDbExecuter();

        Properties p = propertieFile.exists()
                ? PropKit.use("jboot.properties").getProperties()
                : new Properties();


        //jboot.app.mode
        putPropertie(p, "jboot.app.mode", "product");

        //cookieEncryptKey
        String cookieEncryptKey = StrUtil.uuid();
        if (putPropertie(p, "jboot.web.cookieEncryptKey", cookieEncryptKey)) {
            Jboot.config(JbootWebConfig.class).setCookieEncryptKey("cookieEncryptKey");
            CookieUtil.initEncryptKey(cookieEncryptKey);
        }

        //jwtSecret
        String jwtSecret = StrUtil.uuid();
        if (putPropertie(p, "jboot.web.jwt.secret", jwtSecret)) {
            Jboot.config(JwtConfig.class).setSecret(jwtSecret);
        }

        p.put("jboot.datasource.type", "mysql");
        p.put("jboot.datasource.url", dbExecuter.getJdbcUrl());
        p.put("jboot.datasource.user", dbExecuter.getDbUser());
        p.put("jboot.datasource.password", StrUtil.obtainDefaultIfBlank(dbExecuter.getDbPassword(), ""));

        return savePropertie(p, propertieFile);
    }
 
Example #23
Source File: MyI18nInterceptor.java    From zrlog with Apache License 2.0 5 votes vote down vote up
@Override
public void intercept(Invocation inv) {
    if (Constants.IN_JAR) {
        I18nUtil.addToRequest(null, inv.getController().getRequest(), JFinal.me().getConstants().getDevMode(), false);
    } else {
        I18nUtil.addToRequest(PathKit.getRootClassPath(), inv.getController().getRequest(), JFinal.me().getConstants().getDevMode(), false);
    }
    inv.invoke();
}
 
Example #24
Source File: _JFinalDemoGenerator.java    From sqlhelper with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) {
	// base model 所使用的包名
	String baseModelPackageName = "com.demo.common.model.base";
	// base model 文件保存路径
	String baseModelOutputDir = PathKit.getWebRootPath() + "/src/main/java/com/demo/common/model/base";
	
	// model 所使用的包名 (MappingKit 默认使用的包名)
	String modelPackageName = "com.demo.common.model";
	// model 文件保存路径 (MappingKit 与 DataDictionary 文件默认保存路径)
	String modelOutputDir = baseModelOutputDir + "/..";
	
	// 创建生成器
	Generator generator = new Generator(getDataSource(), baseModelPackageName, baseModelOutputDir, modelPackageName, modelOutputDir);
	
	// 配置是否生成备注
	generator.setGenerateRemarks(true);
	
	// 设置数据库方言
	generator.setDialect(new MysqlDialect());
	
	// 设置是否生成链式 setter 方法
	generator.setGenerateChainSetter(false);
	
	// 添加不需要生成的表名
	generator.addExcludedTable("adv");
	
	// 设置是否在 Model 中生成 dao 对象
	generator.setGenerateDaoInModel(false);
	
	// 设置是否生成字典文件
	generator.setGenerateDataDictionary(false);
	
	// 设置需要被移除的表名前缀用于生成modelName。例如表名 "osc_user",移除前缀 "osc_"后生成的model名为 "User"而非 OscUser
	generator.setRemovedTableNamePrefixes("t_");
	
	// 生成
	generator.generate();
}
 
Example #25
Source File: _AttachmentController.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void detail() {
    Long id = getIdPara();

    Attachment attachment = service.findById(id);

    setAttr("attachment", attachment);

    File attachmentFile = new File(PathKit.getWebRootPath(), attachment.getPath());
    setAttr("attachmentName", attachmentFile.getName());

    long fileLen = attachmentFile.length();
    String fileLenUnit = "Byte";
    if (fileLen > 1024) {
        fileLen = fileLen / 1024;
        fileLenUnit = "KB";
    }
    if (fileLen > 1024) {
        fileLen = fileLen / 1024;
        fileLenUnit = "MB";
    }
    setAttr("attachmentSize", fileLen + fileLenUnit);
    try {
        if (AttachmentUtils.isImage(attachment.getPath())) {
            String ratio = ImageUtils.ratioAsString(attachmentFile.getAbsolutePath());
            setAttr("attachmentRatio", ratio == null ? "unknow" : ratio);
        }
    } catch (Throwable e) {
        LOG.error("detail() ratioAsString error", e);
    }

    render("attachment/detail.html");
}
 
Example #26
Source File: _AttachmentController.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void doUplaodRootFile() {
    if (!isMultipartRequest()) {
        renderError(404);
        return;
    }

    UploadFile uploadFile = getFile();
    if (uploadFile == null) {
        renderJson(Ret.fail().set("message", "请选择要上传的文件"));
        return;
    }

    File file = uploadFile.getFile();
    if (AttachmentUtils.isUnSafe(file)) {
        file.delete();
        renderJson(Ret.fail().set("message", "不支持此类文件上传"));
        return;
    }

    File rootFile = new File(PathKit.getWebRootPath(), file.getName());
    if (rootFile.exists()) {
        file.delete();
        renderJson(Ret.fail().set("message", "该文件已经存在,请手动删除后再重新上传。"));
        return;
    }

    try {
        FileUtils.moveFile(file, rootFile);
        rootFile.setReadable(true, false);
        renderOkJson();
        return;
    } catch (IOException e) {
        e.printStackTrace();
    }

    renderJson(Ret.fail().set("message", "系统错误。"));
}
 
Example #27
Source File: WarUpdateVersionThread.java    From zrlog with Apache License 2.0 5 votes vote down vote up
private void fillTemplateCopyInfo(File tempFilePath, Map<String, String> copyFileMap) {
    File templatePath = new File(PathKit.getWebRootPath() + Constants.TEMPLATE_BASE_PATH);
    File[] templates = templatePath.listFiles();
    if (templates != null && templates.length > 0) {
        for (File template : templates) {
            if (template.isDirectory() && template.toString().substring(PathKit.getWebRootPath().length()).startsWith(Constants.DEFAULT_TEMPLATE_PATH)) {
                //skip default template folder
                continue;
            }
            copyFileMap.put(template.toString(), tempFilePath + File.separator + Constants.TEMPLATE_BASE_PATH);
        }
    }
}
 
Example #28
Source File: UploadController.java    From zrlog with Apache License 2.0 5 votes vote down vote up
public UploadFileResponse index() {
    String uploadFieldName = "imgFile";
    String uri = generatorUri(uploadFieldName);
    File imgFile = getFile(uploadFieldName).getFile();
    String finalFilePath = PathKit.getWebRootPath() + uri;
    FileUtils.moveOrCopyFile(imgFile.toString(), finalFilePath, true);
    return new UploadService().getCloudUrl(getRequest().getContextPath(), uri, finalFilePath, getRequest(), AdminTokenThreadLocal.getUser());
}
 
Example #29
Source File: _AttachmentController.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@AdminMenu(text = "根目录", groupId = JPressConsts.SYSTEM_MENU_ATTACHMENT, order = 99)
public void root() {
    File rootFile = new File(PathKit.getWebRootPath());
    String name = getPara("name");
    File[] files = StrUtil.isBlank(name)
            ? rootFile.listFiles(pathname -> !pathname.isDirectory())
            : rootFile.listFiles(pathname -> !pathname.isDirectory() && pathname.getName().contains(name));

    setAttr("files", RootFile.toFiles(files));
    render("attachment/root.html");
}
 
Example #30
Source File: TemplateManager.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<Template> getInstalledTemplates() {
    String basePath = PathKit.getWebRootPath() + "/templates";

    List<File> templateFolderList = new ArrayList<File>();
    scanTemplateFloders(new File(basePath), templateFolderList);

    List<Template> templatelist = null;
    if (templateFolderList.size() > 0) {
        templatelist = new ArrayList<>();
        for (File templateFolder : templateFolderList) {
            templatelist.add(new Template(templateFolder));
        }
    }
    return templatelist;
}