/** * Generate a relative path based on provided document. * * @param doc the document to export. * @return the corresponding path. */ public String getPathFromDocument(XWikiDocument doc, XWikiContext context) { return getDirectoryForDocument(doc) + getFileNameFromDocument(doc, context); }
public void addToDir(XWikiDocument doc, File dir, boolean withVersions, XWikiContext context) throws XWikiException { try { filter(doc, context); File spacedir = new File(dir, getDirectoryForDocument(doc)); if (!spacedir.exists()) { if (!spacedir.mkdirs()) { Object[] args = new Object[1]; args[0] = dir.toString(); throw new XWikiException(XWikiException.MODULE_XWIKI, XWikiException.ERROR_XWIKI_MKDIR, "Error creating directory {0}", null, args); } } String filename = getFileNameFromDocument(doc, context); File file = new File(spacedir, filename); FileOutputStream fos = new FileOutputStream(file); doc.toXML(fos, true, false, true, withVersions, context); fos.flush(); fos.close(); } catch (ExcludeDocumentException e) { LOG.info("Skip the document " + doc.getDocumentReference()); } catch (Exception e) { Object[] args = new Object[1]; args[0] = doc.getDocumentReference(); throw new XWikiException(XWikiException.MODULE_XWIKI_DOC, XWikiException.ERROR_XWIKI_DOC_EXPORT, "Error creating file {0}", e, args); } }