public abstract class CreateFromTemplateHandler extends Object
FileBuilder.build()
and handle them themselves. The NetBeans IDE provides default
implementation that allows use of Freemarker templating engine.
Read more in the howto document.
An implementation of CreateHandler should honor CreateDescriptor.hasFreeExtension()
and
CreateDescriptor.isPreformatted()
.
Constructor and Description |
---|
CreateFromTemplateHandler() |
Modifier and Type | Method and Description |
---|---|
protected abstract boolean |
accept(CreateDescriptor desc)
Method that allows a handler to reject a file.
|
static void |
copyAttributesFromTemplate(CreateFromTemplateHandler h,
FileObject from,
FileObject to)
Copies template attributes over to the created file.
|
protected abstract List<FileObject> |
createFromTemplate(CreateDescriptor desc)
Handles the creation of new files.
|
protected static List<FileObject> |
defaultCopyContents(CreateDescriptor origDescriptor,
FileObject contentsParent,
FileObject target)
Copies the files or folders contained in the specified folder to the target.
|
protected abstract boolean accept(CreateDescriptor desc)
FileBuilder.createFromTemplate(org.openide.filesystems.FileObject, org.openide.filesystems.FileObject, java.lang.String, java.util.Map, org.netbeans.api.templates.FileBuilder.Mode)
is going to take place.desc
- describes the request that is about to be performed@NonNull protected abstract List<FileObject> createFromTemplate(CreateDescriptor desc) throws IOException
desc
- command objects that describes the file creation requestIOException
- if something goes wrong with I/Opublic static void copyAttributesFromTemplate(CreateFromTemplateHandler h, FileObject from, FileObject to) throws IOException
"template."
are not copied. As the operation is not atomic, the method should be called in a
FileSystem.runAtomicAction(org.openide.filesystems.FileSystem.AtomicAction)
.
The "template"
attribute is never copied.h
- the Handler responsible for file creation, usually the calling handler.from
- the original fileto
- the target fileIOException
- if an I/O error occurs.protected static List<FileObject> defaultCopyContents(CreateDescriptor origDescriptor, FileObject contentsParent, FileObject target) throws IOException
null
, in which case the CreateDescriptor.getTemplate()
folder will be used.origDescriptor
- original descriptor to get parameters / lookup fromcontentsParent
- template folder whose contents should be copiedtarget
- target folderIOException