Java Code Examples for cn.hutool.core.text.StrBuilder#toString()

The following examples show how to use cn.hutool.core.text.StrBuilder#toString() . 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: ThemeController.java    From stone with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 获取模板文件内容
 *
 * @param tplName 模板文件名
 *
 * @return 模板内容
 */
@GetMapping(value = "/getTpl", produces = "text/text;charset=UTF-8")
@ResponseBody
public String getTplContent(@RequestParam("tplName") String tplName) {
    String tplContent = "";
    try {
        //获取项目根路径
        final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
        //获取主题路径
        final StrBuilder themePath = new StrBuilder("templates/themes/");
        themePath.append(BaseController.THEME);
        themePath.append("/");
        themePath.append(tplName);
        final File themesPath = new File(basePath.getAbsolutePath(), themePath.toString());
        final FileReader fileReader = new FileReader(themesPath);
        tplContent = fileReader.readString();
    } catch (Exception e) {
        log.error("Get template file error: {}", e.getMessage());
    }
    return tplContent;
}
 
Example 2
Source File: ThemeController.java    From stone with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 保存修改模板
 *
 * @param tplName    模板名称
 * @param tplContent 模板内容
 *
 * @return JsonResult
 */
@PostMapping(value = "/editor/save")
@ResponseBody
public JsonResult saveTpl(@RequestParam("tplName") String tplName,
                          @RequestParam("tplContent") String tplContent) {
    if (StrUtil.isBlank(tplContent)) {
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.edit.no-content"));
    }
    try {
        //获取项目根路径
        final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
        //获取主题路径
        final StrBuilder themePath = new StrBuilder("templates/themes/");
        themePath.append(BaseController.THEME);
        themePath.append("/");
        themePath.append(tplName);
        final File tplPath = new File(basePath.getAbsolutePath(), themePath.toString());
        final FileWriter fileWriter = new FileWriter(tplPath);
        fileWriter.write(tplContent);
    } catch (Exception e) {
        log.error("Template save failed: {}", e.getMessage());
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.save-failed"));
    }
    return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.common.save-success"));
}
 
Example 3
Source File: ApiMetaWeBlog.java    From stone with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 根据文章编号构建文章信息
 *
 * @param postId 文章编号
 * @return 文章信息xml格式
 */
private String buildPost(final Long postId) {
    final StrBuilder strBuilder = new StrBuilder();
    final Post post = postService.findByPostId(postId).orElse(new Post());
    strBuilder.append("<struct>");
    strBuilder.append("<member><name>dateCreated</name>");
    strBuilder.append("<value><dateTime.iso8601>");
    strBuilder.append(DateUtil.format(post.getPostDate(), "yyyy-MM-dd'T'HH:mm:ssZZ"));
    strBuilder.append("</dateTime.iso8601></value></member>");
    strBuilder.append("<member><name>description</name>");
    strBuilder.append("<value>");
    strBuilder.append(post.getPostSummary());
    strBuilder.append("</value></member>");
    strBuilder.append("<member><name>title</name>");
    strBuilder.append("<value>");
    strBuilder.append(post.getPostTitle());
    strBuilder.append("</value></member>");
    strBuilder.append("<member><name>categories</name>");
    strBuilder.append("<value><array><data>");
    List<Category> categories = post.getCategories();
    for (Category category : categories) {
        strBuilder.append("<value>").append(category.getCateName()).append("</value>");
    }
    strBuilder.append("</data></array></value></member></struct>");
    return strBuilder.toString();
}
 
Example 4
Source File: ApiMetaWeBlog.java    From blog-sharon with Apache License 2.0 6 votes vote down vote up
/**
 * 构建分类信息
 *
 * @return 分类信息xml节点
 * @throws Exception Exception
 */
private String buildCategories() throws Exception {
    final StrBuilder strBuilder = new StrBuilder();
    final List<Category> categories = categoryService.findAll();
    for (Category category : categories) {
        final String cateName = category.getCateName();
        final Long cateId = category.getCateId();

        strBuilder.append("<value><struct>");
        strBuilder.append("<member><name>description</name>").append("<value>").append(cateName).append("</value></member>");
        strBuilder.append("<member><name>title</name>").append("<value>").append(cateName).append("</value></member>");
        strBuilder.append("<member><name>categoryid</name>").append("<value>").append(cateId).append("</value></member>");
        strBuilder.append("<member><name>htmlUrl</name>").append("<value>").append(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp())).append("/categories/").append(cateName).append("</value></member>");
        strBuilder.append("</struct></value>");
    }
    return strBuilder.toString();
}
 
Example 5
Source File: ApiMetaWeBlog.java    From stone with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 构建分类信息
 *
 * @return 分类信息xml节点
 * @throws Exception Exception
 */
private String buildCategories() throws Exception {
    final StrBuilder strBuilder = new StrBuilder();
    final List<Category> categories = categoryService.findAll();
    for (Category category : categories) {
        final String cateName = category.getCateName();
        final Long cateId = category.getCateId();

        strBuilder.append("<value><struct>");
        strBuilder.append("<member><name>description</name>").append("<value>").append(cateName).append("</value></member>");
        strBuilder.append("<member><name>title</name>").append("<value>").append(cateName).append("</value></member>");
        strBuilder.append("<member><name>categoryid</name>").append("<value>").append(cateId).append("</value></member>");
        strBuilder.append("<member><name>htmlUrl</name>").append("<value>").append(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp())).append("/categories/").append(cateName).append("</value></member>");
        strBuilder.append("</struct></value>");
    }
    return strBuilder.toString();
}
 
Example 6
Source File: ApiMetaWeBlog.java    From blog-sharon with Apache License 2.0 6 votes vote down vote up
/**
 * 根据文章编号构建文章信息
 *
 * @param postId 文章编号
 * @return 文章信息xml格式
 */
private String buildPost(final Long postId) {
    final StrBuilder strBuilder = new StrBuilder();
    final Post post = postService.findByPostId(postId).orElse(new Post());
    strBuilder.append("<struct>");
    strBuilder.append("<member><name>dateCreated</name>");
    strBuilder.append("<value><dateTime.iso8601>");
    strBuilder.append(DateUtil.format(post.getPostDate(), "yyyy-MM-dd'T'HH:mm:ssZZ"));
    strBuilder.append("</dateTime.iso8601></value></member>");
    strBuilder.append("<member><name>description</name>");
    strBuilder.append("<value>");
    strBuilder.append(post.getPostSummary());
    strBuilder.append("</value></member>");
    strBuilder.append("<member><name>title</name>");
    strBuilder.append("<value>");
    strBuilder.append(post.getPostTitle());
    strBuilder.append("</value></member>");
    strBuilder.append("<member><name>categories</name>");
    strBuilder.append("<value><array><data>");
    List<Category> categories = post.getCategories();
    for (Category category : categories) {
        strBuilder.append("<value>").append(category.getCateName()).append("</value>");
    }
    strBuilder.append("</data></array></value></member></struct>");
    return strBuilder.toString();
}
 
Example 7
Source File: HaloUtils.java    From stone with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获取备份文件信息
 *
 * @param dir dir
 *
 * @return List
 */
public static List<BackupDto> getBackUps(String dir) {
    final StrBuilder srcPathStr = new StrBuilder(System.getProperties().getProperty("user.home"));
    srcPathStr.append("/halo/backup/");
    srcPathStr.append(dir);
    final File srcPath = new File(srcPathStr.toString());
    final File[] files = srcPath.listFiles();
    final List<BackupDto> backupDtos = new ArrayList<>();
    BackupDto backupDto = null;
    // 遍历文件
    if (null != files) {
        for (File file : files) {
            if (file.isFile()) {
                if (StrUtil.equals(file.getName(), ".DS_Store")) {
                    continue;
                }
                backupDto = new BackupDto();
                backupDto.setFileName(file.getName());
                backupDto.setCreateAt(getCreateTime(file.getAbsolutePath()));
                backupDto.setFileType(FileUtil.getType(file));
                backupDto.setFileSize(parseSize(file.length()));
                backupDto.setBackupType(dir);
                backupDtos.add(backupDto);
            }
        }
    }
    return backupDtos;
}
 
Example 8
Source File: HaloUtils.java    From blog-sharon with Apache License 2.0 5 votes vote down vote up
/**
 * 获取备份文件信息
 *
 * @param dir dir
 * @return List
 */
public static List<BackupDto> getBackUps(String dir) {
    StrBuilder srcPathStr = new StrBuilder(System.getProperties().getProperty("user.home"));
    srcPathStr.append("/halo/backup/");
    srcPathStr.append(dir);
    File srcPath = new File(srcPathStr.toString());
    File[] files = srcPath.listFiles();
    List<BackupDto> backupDtos = new ArrayList<>();
    BackupDto backupDto = null;
    // 遍历文件
    if (null != files) {
        for (File file : files) {
            if (file.isFile()) {
                if (StrUtil.equals(file.getName(), ".DS_Store")) {
                    continue;
                }
                backupDto = new BackupDto();
                backupDto.setFileName(file.getName());
                backupDto.setCreateAt(getCreateTime(file.getAbsolutePath()));
                backupDto.setFileType(FileUtil.getType(file));
                backupDto.setFileSize(parseSize(file.length()));
                backupDto.setBackupType(dir);
                backupDtos.add(backupDto);
            }
        }
    }
    return backupDtos;
}
 
Example 9
Source File: ApiMetaWeBlog.java    From blog-sharon with Apache License 2.0 5 votes vote down vote up
/**
 * 组装分类信息
 *
 * @return 分类信息xml格式
 * @throws Exception Exception
 */
private String getCategories() throws Exception {
    final StrBuilder strBuilder = new StrBuilder(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodResponse><params><param><value><array><data>");
    final String categories = buildCategories();
    strBuilder.append(categories);
    strBuilder.append("</data></array></value></param></params></methodResponse>");

    return strBuilder.toString();
}
 
Example 10
Source File: ApiMetaWeBlog.java    From blog-sharon with Apache License 2.0 5 votes vote down vote up
/**
 * 构建博客信息
 *
 * @return 博客信息xml节点
 */
private String buildBlogInfo() {
    final String blogId = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp());
    final String blogTitle = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp());
    final StrBuilder strBuilder = new StrBuilder("<member><name>blogid</name><value>");
    strBuilder.append(blogId);
    strBuilder.append("</value></member>");
    strBuilder.append("<member><name>url</name><value>");
    strBuilder.append(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
    strBuilder.append("</value></member>");
    strBuilder.append("<member><name>blogName</name><value>");
    strBuilder.append(blogTitle);
    strBuilder.append("</value></member>");
    return strBuilder.toString();
}
 
Example 11
Source File: ApiMetaWeBlog.java    From blog-sharon with Apache License 2.0 5 votes vote down vote up
/**
 * 获取用户博客信息
 *
 * @return 用户博客信息xml格式
 */
private String getUserBlogs() {
    final StrBuilder strBuilder = new StrBuilder(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodResponse><params><param><value><array><data><value><struct>");
    final String blogInfo = buildBlogInfo();
    strBuilder.append(blogInfo);
    strBuilder.append("</struct></value></data></array></value></param></params></methodResponse>");

    return strBuilder.toString();
}
 
Example 12
Source File: ApiMetaWeBlog.java    From blog-sharon with Apache License 2.0 5 votes vote down vote up
/**
 * 根据文章编号获取文章信息
 *
 * @param postId 文章编号
 * @return 文章信息xml格式
 */
private String getPost(Long postId) {
    final StrBuilder strBuilder = new StrBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodResponse><params><param><value>");
    final String posts = buildPost(postId);
    strBuilder.append(posts);
    strBuilder.append("</value></param></params></methodResponse>");
    return strBuilder.toString();
}
 
Example 13
Source File: Md5Util.java    From SENS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 生成文件hash值
 *
 * @param file file
 * @return String
 * @throws Exception Exception
 */
public static String getMD5Checksum(MultipartFile file) throws Exception {
    final byte[] b = createChecksum(file);
    StrBuilder result = new StrBuilder();

    for (int i = 0; i < b.length; i++) {
        result.append(Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1));
    }
    return result.toString();
}
 
Example 14
Source File: Md5Util.java    From stone with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 生成文件hash值
 *
 * @param file file
 *
 * @return String
 *
 * @throws Exception Exception
 */
public static String getMD5Checksum(MultipartFile file) throws Exception {
    final byte[] b = createChecksum(file);
    StrBuilder result = new StrBuilder();

    for (int i = 0; i < b.length; i++) {
        result.append(Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1));
    }
    return result.toString();
}
 
Example 15
Source File: ApiMetaWeBlog.java    From stone with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 组装分类信息
 *
 * @return 分类信息xml格式
 * @throws Exception Exception
 */
private String getCategories() throws Exception {
    final StrBuilder strBuilder = new StrBuilder(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodResponse><params><param><value><array><data>");
    final String categories = buildCategories();
    strBuilder.append(categories);
    strBuilder.append("</data></array></value></param></params></methodResponse>");

    return strBuilder.toString();
}
 
Example 16
Source File: ApiMetaWeBlog.java    From stone with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 构建博客信息
 *
 * @return 博客信息xml节点
 */
private String buildBlogInfo() {
    final String blogId = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp());
    final String blogTitle = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp());
    final StrBuilder strBuilder = new StrBuilder("<member><name>blogid</name><value>");
    strBuilder.append(blogId);
    strBuilder.append("</value></member>");
    strBuilder.append("<member><name>url</name><value>");
    strBuilder.append(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
    strBuilder.append("</value></member>");
    strBuilder.append("<member><name>blogName</name><value>");
    strBuilder.append(blogTitle);
    strBuilder.append("</value></member>");
    return strBuilder.toString();
}
 
Example 17
Source File: ApiMetaWeBlog.java    From stone with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获取用户博客信息
 *
 * @return 用户博客信息xml格式
 */
private String getUserBlogs() {
    final StrBuilder strBuilder = new StrBuilder(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodResponse><params><param><value><array><data><value><struct>");
    final String blogInfo = buildBlogInfo();
    strBuilder.append(blogInfo);
    strBuilder.append("</struct></value></data></array></value></param></params></methodResponse>");

    return strBuilder.toString();
}
 
Example 18
Source File: ApiMetaWeBlog.java    From stone with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 根据文章编号获取文章信息
 *
 * @param postId 文章编号
 * @return 文章信息xml格式
 */
private String getPost(Long postId) {
    final StrBuilder strBuilder = new StrBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodResponse><params><param><value>");
    final String posts = buildPost(postId);
    strBuilder.append(posts);
    strBuilder.append("</value></param></params></methodResponse>");
    return strBuilder.toString();
}
 
Example 19
Source File: HaloUtils.java    From stone with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 百度主动推送
 *
 * @param blogUrl 博客地址
 * @param token   百度推送token
 * @param urls    文章路径
 *
 * @return String
 */
public static String baiduPost(String blogUrl, String token, String urls) {
    Assert.hasText(blogUrl, "blog url must not be blank");
    Assert.hasText(token, "token must not be blank");
    Assert.hasText(urls, "urls must not be blank");

    final StrBuilder url = new StrBuilder("http://data.zz.baidu.com/urls?site=");
    url.append(blogUrl);
    url.append("&token=");
    url.append(token);

    final StrBuilder result = new StrBuilder();
    PrintWriter out = null;
    BufferedReader in = null;
    try {
        // 建立URL之间的连接
        final URLConnection conn = new URL(url.toString()).openConnection();
        // 设置通用的请求属性
        conn.setRequestProperty("Host", "data.zz.baidu.com");
        conn.setRequestProperty("User-Agent", "curl/7.12.1");
        conn.setRequestProperty("Content-Length", "83");
        conn.setRequestProperty("Content-Type", "text/plain");

        // 发送POST请求必须设置如下两行
        conn.setDoInput(true);
        conn.setDoOutput(true);

        // 获取conn对应的输出流
        out = new PrintWriter(conn.getOutputStream());
        out.print(urls.trim());
        // 进行输出流的缓冲
        out.flush();
        // 通过BufferedReader输入流来读取Url的响应
        in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = in.readLine()) != null) {
            result.append(line);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (null != out) {
                out.close();
            }
            if (null != in) {
                in.close();
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    return result.toString();
}
 
Example 20
Source File: HaloUtils.java    From blog-sharon with Apache License 2.0 4 votes vote down vote up
/**
 * 百度主动推送
 *
 * @param blogUrl 博客地址
 * @param token   百度推送token
 * @param urls    文章路径
 * @return String
 */
public static String baiduPost(String blogUrl, String token, String urls) {
    Assert.hasText(blogUrl, "blog url must not be blank");
    Assert.hasText(token, "token must not be blank");
    Assert.hasText(urls, "urls must not be blank");

    StrBuilder url = new StrBuilder("http://data.zz.baidu.com/urls?site=");
    url.append(blogUrl);
    url.append("&token=");
    url.append(token);

    StrBuilder result = new StrBuilder();
    PrintWriter out = null;
    BufferedReader in = null;
    try {
        // 建立URL之间的连接
        URLConnection conn = new URL(url.toString()).openConnection();
        // 设置通用的请求属性
        conn.setRequestProperty("Host", "data.zz.baidu.com");
        conn.setRequestProperty("User-Agent", "curl/7.12.1");
        conn.setRequestProperty("Content-Length", "83");
        conn.setRequestProperty("Content-Type", "text/plain");

        // 发送POST请求必须设置如下两行
        conn.setDoInput(true);
        conn.setDoOutput(true);

        // 获取conn对应的输出流
        out = new PrintWriter(conn.getOutputStream());
        out.print(urls.trim());
        // 进行输出流的缓冲
        out.flush();
        // 通过BufferedReader输入流来读取Url的响应
        in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = in.readLine()) != null) {
            result.append(line);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (null != out) {
                out.close();
            }
            if (null != in) {
                in.close();
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    return result.toString();
}