@Override public File getFile(String path) { return FileUtils.getResourceFileFromContext(path); } },
public static void copy(File[] src, File dst) throws IOException { for (File file : src) { copy(file, dst); } }
/** * Copies source to destination. If source and destination are the same, does nothing. Both single files and * directories are handled. * * @param src the source file or directory * @param dst the destination file or directory */ public static void copy(File src, File dst) throws IOException { if (src.equals(dst)) { return; } if (src.isFile()) { copyFile(src, dst); } else { copyTree(src, dst); } }
protected void setBlobAttributes(Blob result, TemplateBasedDocument templateBasedDocument) { // try to guess mimetype and extension of the resulting Blob MimetypeRegistry mreg = Framework.getService(MimetypeRegistry.class); String mimetype = "text/html"; String extension = ".html"; if (mreg != null) { String found_mimetype = guessMimeType(result, mreg); if (found_mimetype != null) { mimetype = found_mimetype; List<String> extensions = mreg.getExtensionsFromMimetypeName(mimetype); if (extensions != null && extensions.size() > 0) { extension = "." + extensions.get(0); } } } if ("text/xml".equalsIgnoreCase(mimetype)) { // because MimetypeRegistry return a stupid result for XML extension = ".xml"; } result.setMimeType(mimetype); String targetFileName = FileUtils.getFileNameNoExt(templateBasedDocument.getAdaptedDoc().getTitle()); result.setFilename(targetFileName + extension); }
/** * @deprecated since 10.1 - seems unused */ @Deprecated public static void copyTree(File src, File dst, PathFilter filter) throws IOException { copyTree(src, dst, new Path("/"), filter); }
@Override public String getType() { if (StringUtils.isBlank(type)) { // try to infer it from name for easier declaration return FileUtils.getFileExtension(name); } return type; }
/** * Asserts that two strings are equal even if their EOL are different. If they are not, an {@link AssertionError} is * thrown with the given message. If <code>expected</code> and <code>actual</code> are <code>null</code>, they are * considered equal. * * @param message the identifying message for the {@link AssertionError} ( <code>null</code> okay) * @param expected expected String with Windows or Unix like EOL * @param actual actual String with Windows or Unix like EOL * @see FileUtils#areFilesContentEquals(String, String) */ static public void assertFilesContentEquals(String message, String expected, String actual) { if (FileUtils.areFilesContentEquals(expected, actual)) { return; } else { String cleanMessage = message == null ? "" : message; throw new ComparisonFailure(cleanMessage, expected, actual); } } }
xdoc.putDocument(FileUtils.getFileNameNoExt(file.getName()), loadXML(file)); } else { // presume a blob xdoc.putBlob(file.getName(), Blobs.createBlob(file));
public static void copyTree(File src, File dst, Path prefix, PathFilter filter) throws IOException { if (!prefix.isAbsolute()) { prefix = prefix.makeAbsolute(); } int rootIndex = src.getPath().length() + 1; for (File file : src.listFiles()) { copyTree(rootIndex, file, new File(dst, file.getName()), prefix, filter); } }
public TemplateProcessorDescriptor findProcessorDescriptor(Blob templateBlob) { TemplateProcessorDescriptor processor = null; String mt = templateBlob.getMimeType(); if (mt != null) { processor = findProcessorByMimeType(mt); } if (processor == null) { String fileName = templateBlob.getFilename(); if (fileName != null) { String ext = FileUtils.getFileExtension(fileName); processor = findProcessorByExtension(ext); } } return processor; }
protected Blob getDefaultThumbnail(DocumentModel doc) { if (doc == null) { return null; } TypeInfo docType = doc.getAdapter(TypeInfo.class); String iconPath = docType.getBigIcon(); if (iconPath == null) { iconPath = docType.getIcon(); } if (iconPath == null) { return null; } try { File iconFile = FileUtils.getResourceFileFromContext("nuxeo.war" + File.separator + iconPath); if (iconFile.exists()) { MimetypeRegistry mimetypeRegistry = Framework.getService(MimetypeRegistry.class); String mimeType = mimetypeRegistry.getMimetypeFromFile(iconFile); if (mimeType == null) { mimeType = mimetypeRegistry.getMimetypeFromFilename(iconPath); } return Blobs.createBlob(iconFile, mimeType); } } catch (IOException e) { log.warn(String.format("Could not fetch the thumbnail blob from icon path '%s'", iconPath), e); } return null; }
public void run(Installer installer, File bundleDir, File installDir) throws IOException { File dest = new File(installDir, target); if (path.endsWith("/*")) { dest.mkdirs(); File file = new File(bundleDir, path.substring(0, path.length() - 1)); FileUtils.copy(file.listFiles(), dest); } else { File file = new File(bundleDir, path); FileUtils.copy(file, dest); } }
String targetFileName = FileUtils.getFileNameNoExt(templateBasedDocument.getAdaptedDoc().getTitle());
/** * Copies recursively source to destination. * <p> * The source file is assumed to be a directory. * * @param src the source directory * @param dst the destination directory * @deprecated since 10.1 - waiting ReloadComponent to be cleaned */ @Deprecated public static void copyTree(File src, File dst) throws IOException { if (src.isFile()) { copyFile(src, dst); } else if (src.isDirectory()) { if (dst.exists()) { dst = new File(dst, src.getName()); dst.mkdir(); } else { // allows renaming dest dir dst.mkdirs(); } File[] files = src.listFiles(); for (File file : files) { copyTree(file, dst); } } }
/** * @deprecated since 5.6, use {@link #runDeploymentPreprocessor()} instead. Keep it as compatibility code until * NXP-9642 is done. */ @Override @Deprecated public void installWebResources(File file) throws IOException { log.info("Install web resources"); if (file.isDirectory()) { File war = new File(file, "web"); war = new File(war, "nuxeo.war"); if (war.isDirectory()) { org.nuxeo.common.utils.FileUtils.copyTree(war, getAppDir()); } else { // compatibility mode with studio 1.5 - see NXP-6186 war = new File(file, "nuxeo.war"); if (war.isDirectory()) { org.nuxeo.common.utils.FileUtils.copyTree(war, getAppDir()); } } } else if (file.isFile()) { // a jar File war = getWarDir(); ZipUtils.unzip("web/nuxeo.war", file, war); // compatibility mode with studio 1.5 - see NXP-6186 ZipUtils.unzip("nuxeo.war", file, war); } }
@Override public Blob getThumbnail(DocumentModel doc, CoreSession session) { if (!doc.hasFacet(VIDEO_FACET)) { throw new NuxeoException("Document is not a video"); } // Choose the nuxeo default thumbnail of the picture views (screenshots // of the video taken during creation) PictureResourceAdapter picResAdapter = doc.getAdapter(PictureResourceAdapter.class); Blob thumbnailView = picResAdapter.getPictureFromTitle("Small"); if (thumbnailView == null) { // try Thumbnail view thumbnailView = picResAdapter.getPictureFromTitle("Thumbnail"); if (thumbnailView == null) { TypeInfo docType = doc.getAdapter(TypeInfo.class); try { return Blobs.createBlob(FileUtils.getResourceFileFromContext("nuxeo.war" + File.separator + docType.getBigIcon())); } catch (IOException e) { throw new NuxeoException(e); } } } return thumbnailView; }
protected void copy(File src, File dst) throws PackageException { try { dst.getParentFile().mkdirs(); File tmp = new File(dst.getPath() + ".tmp"); // File tmp = new File(dst.getParentFile(), dst.getName() + // ".tmp"); FileUtils.copy(src, tmp); if (!tmp.renameTo(dst)) { tmp.delete(); FileUtils.copy(src, dst); } } catch (IOException e) { throw new PackageException("Failed to copy file: " + src + " to " + dst, e); } }
protected Blob applyConverter(Blob blob, String converter, String destMimeType, Map<String, Serializable> params) { ConversionService cs = Framework.getService(ConversionService.class); BlobHolder bh = cs.convert(converter, new SimpleBlobHolder(blob), params); if (bh == null || bh.getBlob() == null) { return blob; } else { Blob result = bh.getBlob(); MimetypeRegistry mtr = Framework.getService(MimetypeRegistry.class); String filename = FileUtils.getFileNameNoExt(blob.getFilename()); filename = filename + "." + mtr.getExtensionsFromMimetypeName(destMimeType).get(0); result.setFilename(filename); if (result.getMimeType() == null) { result.setMimeType(destMimeType); } return result; } }
protected static void copyTree(int rootIndex, File src, File dst, Path prefix, PathFilter filter) throws IOException { if (src.isFile()) { String relPath = src.getPath().substring(rootIndex); if (!filter.accept(new Path(relPath))) { return; } if (!prefix.isRoot()) { // remove prefix from path String path = dst.getPath(); String pff = prefix.toString(); int prefixIndex = path.lastIndexOf(pff); if (prefixIndex > 0) { path = path.substring(0, prefixIndex) + path.substring(prefixIndex + pff.length()); dst = new File(path.toString()); } } dst.getParentFile().mkdirs(); copyFile(src, dst); } else if (src.isDirectory()) { File[] files = src.listFiles(); for (File file : files) { copyTree(rootIndex, file, new File(dst, file.getName()), prefix, filter); } } }
@Override public void populate(CoreSession session) { super.populate(session); DocumentModel doc = session.createDocumentModel("/", "testBlob", "File"); doc.setPropertyValue("file:content", (Serializable) Blobs.createBlob("one")); session.createDocument(doc); File docFile = FileUtils.getResourceFileFromContext("hello.doc"); DocumentModel doc2 = session.createDocumentModel("/", "testBlob2", "File"); doc2.setPropertyValue("file:content", new FileBlob(docFile)); session.createDocument(doc2); TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); } }