private Document createDocument(Page page, LinkRenderingDetails linkDetails, DecorationPolicy decoration) { Document xhtml; ContentTree tree = new ContentTree(); tree.addRootNode(new ContentNode(page)); try { xhtml = intermediateHtmlBuilder.buildHtml(tree, page.getSpace(), linkDetails, decoration); } catch (ImportExportException e) { log.error("error build xml dom", e); throw new RuntimeException(e); } return xhtml; }
private File generatePdfExportFromImportExportManager() throws ImportExportException { final Page thisPage = getPage(); final DefaultExportContext context = new DefaultExportContext(); context.setExportScope(ExportScope.PAGE); context.setType(ImportExportManager.TYPE_PDF); context.addWorkingEntity(thisPage); context.setExportComments(false); context.setExportAttachments(false); context.setExportHierarchy(false); context.setUser(AuthenticatedUserThreadLocal.get()); final ContentTree contentTree = new ContentTree(); contentTree.addRootNode(new ContentNode(thisPage)); context.setContentTree(contentTree); return new File(importExportManager.exportAs(context, new ProgressMeter())); }
private File doCreatePdfForPage(User user, AbstractPage page, String contextPath) throws ImportExportException { exportPermissionChecker.checkAuthorization(user, page); Document xhtml; if (page instanceof Page) { ContentTree tree = newContentTree(); tree.addRootNode(new ContentNode((Page) page)); xhtml = intermediateHtmlBuilder.buildHtml(tree, page.getSpace(), LinkRenderingDetails.anchors(), DecorationPolicy.none()); } else if (page instanceof BlogPost) { xhtml = intermediateHtmlBuilder.buildHtml((BlogPost) page); } else { throw new IllegalArgumentException("Only pages and blog post are supported"); } String spaceKey = getSpaceKeyForExportFileName(page.getSpaceKey()); File pdf; try { String filename = spaceKey + "-" + ((page.getTitle() == null) ? page.getId() : page.getTitle().replaceAll("\\s", "")); if (!GeneralUtil.isSafeTitleForFilesystem(filename)) { filename = spaceKey + "-" + page.getId(); } pdf = flyingPdfDocumentConverter.convertXhtmlToPdf(filename, xhtml, contextPath); } catch (ImportExportException e) { if (e.getCause() instanceof FileNotFoundException) { String filename = spaceKey + "-" + page.getId(); pdf = flyingPdfDocumentConverter.convertXhtmlToPdf(filename, xhtml, contextPath); } else { throw e; } } return pdf; }