Java Code Examples for com.jfinal.kit.PathKit#getWebRootPath()

The following examples show how to use com.jfinal.kit.PathKit#getWebRootPath() . 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: _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 2
Source File: UpgradeController.java    From zrlog with Apache License 2.0 5 votes vote down vote up
public DownloadUpdatePackageResponse download() throws IOException {
    DownloadProcessHandle handle = downloadProcessHandleMap.get(AdminTokenThreadLocal.getUser().getSessionId());
    if (handle == null) {
        File file = new File(PathKit.getWebRootPath() + "/WEB-INF/update-temp/" + "zrlog." + (Constants.IN_JAR ? "zip" : "war"));
        file.getParentFile().mkdir();
        Version version = lastVersion().getVersion();
        handle = new DownloadProcessHandle(file, Constants.IN_JAR ? version.getZipFileSize() : version.getFileSize(), Constants.IN_JAR ? version.getZipMd5sum() : version.getMd5sum());
        HttpUtil.getInstance().sendGetRequest(Constants.IN_JAR ? version.getZipDownloadUrl() : version.getDownloadUrl(), handle, new HashMap<>());
        versionMap.put(AdminTokenThreadLocal.getUser().getSessionId(), version);
        downloadProcessHandleMap.put(AdminTokenThreadLocal.getUser().getSessionId(), handle);
    }
    DownloadUpdatePackageResponse downloadUpdatePackageResponse = new DownloadUpdatePackageResponse();
    downloadUpdatePackageResponse.setProcess(handle.getProcess());
    return downloadUpdatePackageResponse;
}
 
Example 3
Source File: SpringPlugin.java    From jfinal-ext3 with Apache License 2.0 5 votes vote down vote up
public boolean start() {
	if (ctx != null)
		IocInterceptor.ctx = ctx;
	else if (configurations != null)
		IocInterceptor.ctx = new FileSystemXmlApplicationContext(configurations);
	else
		IocInterceptor.ctx = new FileSystemXmlApplicationContext(PathKit.getWebRootPath() + "/WEB-INF/applicationContext.xml");
	return true;
}
 
Example 4
Source File: _JFinalGenerator.java    From sdb-mall with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        String rootPath = PathKit.getWebRootPath();

		// base model 所使用的包名
		String baseModelPackageName = "io."+PK_NAME+".model.base";
		// base model 文件保存路径
		String baseModelOutputDir = rootPath + "/src/main/java/io/"+PK_NAME+"/model/base";


		// model 所使用的包名 (MappingKit 默认使用的包名)
		String modelPackageName = "io."+PK_NAME+".model";
		// model 文件保存路径 (MappingKit 与 DataDictionary 文件默认保存路径)
		String modelOutputDir = baseModelOutputDir + "/..";

		// 创建生成器
		Generator gernerator = new Generator(getDataSource(), baseModelPackageName, baseModelOutputDir, modelPackageName, modelOutputDir);


		MetaBuilder mataBuilder = new MetaBuilder(getDataSource());

		mataBuilder.addExcludedTable(excludedTable);

		gernerator.setMetaBuilder(mataBuilder);

		// 添加不需要生成的表名
//		gernerator.addExcludedTable("order_coupon");
		// 设置是否在 Model 中生成 dao 对象
		gernerator.setGenerateDaoInModel(true);
		// 设置是否生成字典文件
		gernerator.setGenerateDataDictionary(false);
		// 设置需要被移除的表名前缀用于生成modelName。例如表名 "osc_user",移除前缀 "osc_"后生成的model名为 "User"而非 OscUser
		gernerator.setRemovedTableNamePrefixes("tb_");
		gernerator.generate();

		//代码生成
        _JFCodeGenerator.me.generate();
	}
 
Example 5
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 6
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 7
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 8
Source File: AddonUtil.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String getAddonBasePath(String addonId) {
    StringBuilder basePath = new StringBuilder(PathKit.getWebRootPath());
    basePath.append(File.separator)
            .append("addons")
            .append(File.separator)
            .append(addonId);
    return basePath.toString();
}
 
Example 9
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 10
Source File: AddonInfo.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public File buildJarFile() {

        String webRoot = PathKit.getWebRootPath();

        StringBuilder fileName = new StringBuilder(webRoot);
        fileName.append(File.separator);
        fileName.append("WEB-INF");
        fileName.append(File.separator);
        fileName.append("addons");
        fileName.append(File.separator);
        fileName.append(getId());
        fileName.append(".jar");

        return new File(fileName.toString());
    }
 
Example 11
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 12
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 13
Source File: FileController.java    From my_curd with Apache License 2.0 4 votes vote down vote up
/**
 * 单文件上传
 */
public void upload() throws IOException {
    UploadFile uploadFile = getFile("file");

    if (uploadFile == null) {
        renderFail(PARAM_FILE_EMPTY);
        return;
    }

    String originalFileName = uploadFile.getOriginalFileName();
    String extension = FilenameUtils.getExtension(originalFileName);

    // 文件类型非法
    if (!checkFileType(extension)) {
        FileUtils.deleteFile(uploadFile.getFile());
        renderFail(extension + FILE_TYPE_NOT_LIMIT);
        return;
    }

    // 文件保存
    String relativePath = fileRelativeSavePath(extension);
    File saveFile = new File(PathKit.getWebRootPath() + "/" + relativePath);
    if (saveFile.exists()) {
        FileUtils.deleteFile(uploadFile.getFile());
        renderFail(originalFileName + FILE_EXIST);
        return;
    }


    FileUtils.copyFile(uploadFile.getFile(), saveFile);
    FileUtils.deleteFile(uploadFile.getFile());

    UploadResult uploadResult = new UploadResult();
    uploadResult.setName(originalFileName);
    uploadResult.setPath(relativePath);
    long sizeL = saveFile.length();
    uploadResult.setSizeL(sizeL);
    uploadResult.setSize(FileUtils.byteCountToDisplaySize(sizeL));
    StringBuffer url = getRequest().getRequestURL();
    String uri = url.delete(url.length() - getRequest().getRequestURI().length(), url.length()).append(getRequest().getServletContext().getContextPath()).append("/").toString();
    uploadResult.setUri(uri + relativePath);

    Ret ret = Ret.create().setOk().set("data", uploadResult);
    renderJson(ret);
}
 
Example 14
Source File: TemplateService.java    From zrlog with Apache License 2.0 4 votes vote down vote up
public TemplateVO getTemplateVO(String contextPath, File file) {
    String templatePath = file.toString().substring(PathKit.getWebRootPath().length()).replace("\\", "/");
    TemplateVO templateVO = new TemplateVO();
    File templateInfo = new File(file.toString() + "/template.properties");
    if (templateInfo.exists()) {
        Properties properties = new Properties();
        try (InputStream in = new FileInputStream(templateInfo)) {
            properties.load(in);
            templateVO.setAuthor(properties.getProperty("author"));
            templateVO.setName(properties.getProperty("name"));
            templateVO.setDigest(properties.getProperty("digest"));
            templateVO.setVersion(properties.getProperty("version"));
            templateVO.setUrl(properties.getProperty("url"));
            templateVO.setViewType(properties.getProperty("viewType"));
            if (properties.get("previewImages") != null) {
                String[] images = properties.get("previewImages").toString().split(",");
                for (int i = 0; i < images.length; i++) {
                    String image = images[i];
                    if (!image.startsWith("https://") && !image.startsWith("http://")) {
                        images[i] = contextPath + templatePath + "/" + image;
                    }
                }
                templateVO.setPreviewImages(Arrays.asList(images));
            }
        } catch (IOException e) {
            //LOGGER.error("", e);
        }
    } else {
        templateVO.setAuthor("");
        templateVO.setName(templatePath.substring(Constants.TEMPLATE_BASE_PATH.length()));
        templateVO.setUrl("");
        templateVO.setViewType("jsp");
        templateVO.setVersion("");
    }
    if (templateVO.getPreviewImages() == null || templateVO.getPreviewImages().isEmpty()) {
        templateVO.setPreviewImages(Collections.singletonList("assets/images/template-default-preview.jpg"));
    }
    if (StringUtils.isEmpty(templateVO.getDigest())) {
        templateVO.setDigest(I18nUtil.getStringFromRes("noIntroduction"));
    }
    File settingFile = new File(PathKit.getWebRootPath() + templatePath + "/setting/index" + ZrLogUtil.getViewExt(templateVO.getViewType()));
    templateVO.setConfigAble(settingFile.exists());
    templateVO.setTemplate(templatePath);
    return templateVO;
}
 
Example 15
Source File: InstallManager.java    From jpress with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void doUpgradeDatabase() throws SQLException {
    String sqlFilePath = PathKit.getWebRootPath() + "/WEB-INF/install/sqls/";
    String upgradeSql = FileUtil.readString(new File(sqlFilePath, upgradeSqlFileName));
    dbExecuter.executeSql(upgradeSql);
}
 
Example 16
Source File: GenTester.java    From jboot with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {

        JbootApplication.setBootArg("jboot.datasource.url", "jdbc:mysql://127.0.0.1:3306/jbootdemo");
        JbootApplication.setBootArg("jboot.datasource.user", "root");

        String modelPackage = "io.jboot.codegen.test.model";
        String baseModelPackage = modelPackage + ".base";

        String modelDir = PathKit.getWebRootPath() + "/src/main/java/" + modelPackage.replace(".", "/");
        String baseModelDir = PathKit.getWebRootPath() + "/src/main/java/" + baseModelPackage.replace(".", "/");

        System.out.println("start generate...");
        System.out.println("generate dir:" + modelDir);


        new JbootBaseModelGenerator(baseModelPackage, baseModelDir).setGenerateRemarks(true).generate();
        new JbootModelGenerator(modelPackage, baseModelPackage, modelDir).generate();


        String servicePackage = "io.jboot.codegen.test.service";
        new JbootServiceInterfaceGenerator(servicePackage, modelPackage).generate();
        new JbootServiceImplGenerator(servicePackage , modelPackage).setImplName("provider").generate();

    }
 
Example 17
Source File: SystemGenerator.java    From jpress with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) {

        String dbTables = "user,attachment,menu,option,payment_record,permission,role,utm," +
                "wechat_menu,wechat_reply," +
                "member,member_group,member_dist_amount,member_joined_record,member_price," +
                "user_address,user_amount,user_amount_statement,user_amount_payout," +
                "coupon,coupon_code,coupon_used_record," +
                "user_cart,user_order,user_order_item,user_order_delivery,user_order_invoice," +
                "user_openid,user_favorite,user_tag," +
                "payment_record";

        String optionsTables = "coupon,member,member_group,product,product_category,user_address," +
                "user_amount_statement,user_amount_payout,user_cart,user_order,user_order_item,user_order_delivery,user_order_invoice," +
                "payment_record,user_openid,member_joined_record,user_favorite,user_tag";

        JbootApplication.setBootArg("jboot.datasource.url", "jdbc:mysql://127.0.0.1:3306/jpress3");
        JbootApplication.setBootArg("jboot.datasource.user", "root");
        JbootApplication.setBootArg("jboot.datasource.password", "123456");

        String modelPackage = "io.jpress.model";

        String baseModelPackage = modelPackage + ".base";

        String modelDir = PathKit.getWebRootPath() + "/../jpress-model/src/main/java/" + modelPackage.replace(".", "/");
        String baseModelDir = PathKit.getWebRootPath() + "/../jpress-model/src/main/java/" + baseModelPackage.replace(".", "/");

        System.out.println("start generate...dir:" + modelDir);

        Set<String> genTableNames = StrUtil.splitToSet(dbTables, ",");
        MetaBuilder metaBuilder = CodeGenHelpler.createMetaBuilder();
        metaBuilder.setGenerateRemarks(true);
        List<TableMeta> tableMetas = metaBuilder.build();
        tableMetas.removeIf(tableMeta -> genTableNames != null && !genTableNames.contains(tableMeta.name.toLowerCase()));


        new BaseModelGenerator(baseModelPackage, baseModelDir).generate(tableMetas);
        new ModelGenerator(modelPackage, baseModelPackage, modelDir).generate(tableMetas);

        String servicePackage = "io.jpress.service";
        String apiPath = PathKit.getWebRootPath() + "/../jpress-service-api/src/main/java/" + servicePackage.replace(".", "/");
        String providerPath = PathKit.getWebRootPath() + "/../jpress-service-provider/src/main/java/" + servicePackage.replace(".", "/") + "/provider";


        new ServiceApiGenerator(servicePackage, modelPackage, apiPath).generate(tableMetas);
        new ServiceProviderGenerator(servicePackage, modelPackage, providerPath).generate(tableMetas);

        Set<String> optionsTableNames = StrUtil.splitToSet(optionsTables, ",");
        if (optionsTableNames != null && optionsTableNames.size() > 0) {
            tableMetas.removeIf(tableMeta -> !optionsTableNames.contains(tableMeta.name.toLowerCase()));
            new BaseOptionsModelGenerator(baseModelPackage, baseModelDir).generate(tableMetas);
        }
    }
 
Example 18
Source File: JFinal3BeetlRenderFactory.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void config(){
	String root = PathKit.getWebRootPath();
	WebAppResourceLoader resourceLoader = new WebAppResourceLoader(root);
	config(resourceLoader);
}
 
Example 19
Source File: ZrLogConfig.java    From zrlog with Apache License 2.0 4 votes vote down vote up
private String getUpgradeSqlBasePath() {
    return PathKit.getWebRootPath() + "/WEB-INF/update-sql";
}
 
Example 20
Source File: AppJbootServiceImplGenerator.java    From jboot-admin with Apache License 2.0 3 votes vote down vote up
public AppJbootServiceImplGenerator(String servicePackage, String modelPacket, String serviceImplPackage) {
    super(serviceImplPackage, PathKit.getWebRootPath() + "/src/main/java/" + serviceImplPackage.replace(".", "/"));


    this.modelPacket = modelPacket;
    this.servicePackage = servicePackage;
    this.serviceImplPackage = serviceImplPackage;
    this.template = "io/jboot/codegen/service/service_impl_template.jf";


}