本文整理汇总了Java中org.openide.loaders.DataObject.createFromTemplate方法的典型用法代码示例。如果您正苦于以下问题:Java DataObject.createFromTemplate方法的具体用法?Java DataObject.createFromTemplate怎么用?Java DataObject.createFromTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.loaders.DataObject
的用法示例。
在下文中一共展示了DataObject.createFromTemplate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreateNoHandler
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
/**
* Checks that a file without CreateFromTemplate handler creates OK as copy of the template
* @throws Exception
*/
public void testCreateNoHandler() throws Exception {
FileObject root = FileUtil.createMemoryFileSystem().getRoot();
FileObject templ = FileUtil.createData(root, "simpleTemplate.txt");
String txt = "{a}";
OutputStream os = templ.getOutputStream();
os.write(txt.getBytes());
os.close();
DataObject obj = DataObject.find(templ);
DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target"));
Map m = new HashMap();
m.put("a", "eeee");
DataObject x = obj.createFromTemplate(folder, "nue", m);
assertEquals(txt + "\n", x.getPrimaryFile().asText());
}
示例2: instantiate
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
/**
* This is where, the schema gets instantiated from the template.
*/
public Set instantiate (TemplateWizard wizard) throws IOException {
FileObject dir = Templates.getTargetFolder( wizard );
DataFolder df = DataFolder.findFolder( dir );
FileObject template = Templates.getTemplate( wizard );
DataObject dTemplate = DataObject.find( template );
DataObject dobj = dTemplate.createFromTemplate(df, Templates.getTargetName(wizard));
if (dobj == null)
return Collections.emptySet();
encoding = EncodingUtil.getProjectEncoding(df.getPrimaryFile());
if(!EncodingUtil.isValidEncoding(encoding))
encoding = "UTF-8"; //NOI18N
EditCookie edit = dobj.getCookie(EditCookie.class);
if (edit != null) {
EditorCookie editorCookie = dobj.getCookie(EditorCookie.class);
Document doc = (Document)editorCookie.openDocument();
fixEncoding(doc, encoding);
SaveCookie save = dobj.getCookie(SaveCookie.class);
if (save!=null) save.save();
}
return Collections.singleton(dobj.getPrimaryFile());
}
示例3: testCreateFromTemplateUsingFreemarker
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
public void testCreateFromTemplateUsingFreemarker() throws Exception {
FileObject root = FileUtil.createMemoryFileSystem().getRoot();
FileObject fo = FileUtil.createData(root, "simpleObject.txt");
OutputStream os = fo.getOutputStream();
String txt = "print('<html><h1>', title, '</h1></html>');";
os.write(txt.getBytes());
os.close();
fo.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js");
DataObject obj = DataObject.find(fo);
DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target"));
Map<String,String> parameters = Collections.singletonMap("title", "Nazdar");
DataObject n = obj.createFromTemplate(folder, "complex", parameters);
assertEquals("Created in right place", folder, n.getFolder());
assertEquals("Created with right name", "complex.txt", n.getName());
String exp = "<html><h1> Nazdar </h1></html>\n";
assertEquals(exp, readFile(n.getPrimaryFile()));
}
示例4: instantiate
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
@Override
public Set<?> instantiate() throws IOException {
// TODO: Use RequestProcessor for instantiation, this takes too much time.
String className = Templates.getTargetName(wizard);
FileObject pkg = Templates.getTargetFolder(wizard);
DataFolder targetFolder = DataFolder.findFolder(pkg);
FileObject templateFile = Templates.getTemplate(wizard);
DataObject templateDataObject = DataObject.find(templateFile);
DataObject createdDataObject = templateDataObject.createFromTemplate(targetFolder, className);
OpenCookie open = (OpenCookie) createdDataObject.getCookie(OpenCookie.class);
if (open != null) {
open.open();
}
return Collections.singleton(createdDataObject);
}
示例5: XtestCreateFromTemplateDocumentCreated
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
public void XtestCreateFromTemplateDocumentCreated() throws Exception {
FileObject root = FileUtil.createMemoryFileSystem().getRoot();
FileObject fo = FileUtil.createData(root, "simpleObject.txt");
OutputStream os = fo.getOutputStream();
os.write("test".getBytes());
os.close();
fo.setAttribute ("template", Boolean.TRUE);
fo.setAttribute("javax.script.ScriptEngine", "freemarker");
MockServices.setServices(MockMimeLookup.class);
MockMimeLookup.setInstances(MimePath.parse("content/unknown"), new TestEditorKit());
DataObject obj = DataObject.find(fo);
DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target"));
assertFalse(TestEditorKit.createDefaultDocumentCalled);
DataObject inst = obj.createFromTemplate(folder, "test");
assertTrue(TestEditorKit.createDefaultDocumentCalled);
String exp = "test";
assertEquals(exp, inst.getPrimaryFile().asText());
}
示例6: createEmptyTest
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
/**
* Creates a new test class.
*
* @param targetRoot <!-- //PENDING -->
* @param testClassName <!-- //PENDING -->
* @param testCreator {@literal TestCreator} to be used for filling
* the test class template
* @param templateDataObj {@literal DataObject} representing
* the test file template
* @return the created test, or {@literal null} if no test was created
*/
private DataObject createEmptyTest(FileObject targetRoot,
String testClassName,
TestCreator testCreator,
final Map<String, ? extends Object> templateParams,
DataObject templateDataObj) {
if (testClassName == null) {
throw new IllegalArgumentException("testClassName = null"); //NOI18N
}
DataObject testDataObj = null;
try {
DataFolder targetFolderDataObj = DataFolder.findFolder(targetRoot);
testDataObj = templateDataObj.createFromTemplate(
targetFolderDataObj,
testClassName,
templateParams);
/* fill in setup etc. according to dialog settings */
testCreator.createEmptyTest(testDataObj.getPrimaryFile());
} catch (IOException ex) {
ErrorManager.getDefault().notify(ex);
}
return testDataObj;
}
示例7: instantiate
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
public Set<DataObject> instantiate() throws IOException {
FileObject targetFolder = Templates.getTargetFolder(wiz);
TestNGSupport.findTestNGSupport(FileOwnerQuery.getOwner(targetFolder)).configureProject(targetFolder);
String targetName = Templates.getTargetName(wiz);
DataFolder df = DataFolder.findFolder(targetFolder);
FileObject template = Templates.getTemplate(wiz);
DataObject dTemplate = DataObject.find(template);
String pkgName = getSelectedPackageName(targetFolder);
String suiteName = pkgName + " suite";
String projectName = ProjectUtils.getInformation(FileOwnerQuery.getOwner(targetFolder)).getName();
if (pkgName == null || pkgName.trim().length() < 1) {
pkgName = ".*"; //NOI18N
suiteName = "All tests for " + projectName;
}
Map<String, String> props = new HashMap<String, String>();
props.put("suiteName", projectName);
props.put("testName", suiteName);
props.put("pkg", pkgName);
DataObject dobj = dTemplate.createFromTemplate(df, targetName, props);
return Collections.singleton(dobj);
}
示例8: testCreateFromTemplateUsingFreemarkerAndInclude
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
public void testCreateFromTemplateUsingFreemarkerAndInclude() throws Exception {
FileObject root = FileUtil.createMemoryFileSystem().getRoot();
FileObject fclasses = FileUtil.createFolder(root, "classes");
FileObject fincludes = FileUtil.createFolder(root, "includes");
FileObject fclass = FileUtil.createData(fclasses, "class.txt");
OutputStream os = fclass.getOutputStream();
String classtxt = "<#include \"../includes/include.txt\">";
os.write(classtxt.getBytes());
os.close();
fclass.setAttribute("javax.script.ScriptEngine", "freemarker");
FileObject finclude = FileUtil.createData(fincludes, "include.txt");
os = finclude.getOutputStream();
String includetxt = "<html><h1>${title}</h1></html>";
os.write(includetxt.getBytes());
os.close();
DataObject obj = DataObject.find(fclass);
DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target"));
Map<String,String> parameters = Collections.singletonMap("title", "Nazdar");
DataObject n = obj.createFromTemplate(folder, "complex", parameters);
assertEquals("Created in right place", folder, n.getFolder());
assertEquals("Created with right name", "complex.txt", n.getName());
String exp = "<html><h1>Nazdar</h1></html>";
assertEquals(exp, readFile(n.getPrimaryFile()));
}
示例9: testCreateFromTemplate
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
public void testCreateFromTemplate() throws Exception {
FileObject root = FileUtil.createMemoryFileSystem().getRoot();
FileObject fo = FileUtil.createData(root, "simpleObject.txt");
DataObject obj = DataObject.find(fo);
DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target"));
Map<String,String> parameters = Collections.singletonMap("type", "empty");
DataObject n = obj.createFromTemplate(folder, "complex", parameters);
assertEquals("Created in right place", folder, n.getFolder());
assertEquals("Created with right name", "complex.txt", n.getName());
assertEquals("The right source", fo, Hand.origObject.get(0));
assertEquals("The right source in query", fo, Hand.acceptObject.get(0));
assertEquals("The right destiny folder", folder.getPrimaryFile(), Hand.fileObject.get(0));
assertEquals("The right name", "complex", Hand.name);
if (Hand.parameters.size() < 2) {
fail("As least two: " + Hand.parameters + " but was " + Hand.parameters.size());
}
assertEquals("empty", Hand.parameters.get("type"));
assertEquals("complex", Hand.parameters.get("name"));
try {
Hand.parameters.put("kuk", "buk");
} catch (UnsupportedOperationException ex) {
// ok
return;
}
fail("Modifications shall be unsupported");
}
示例10: instantiate
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
@Override
public Set<DataObject> instantiate () throws IOException/*, IllegalStateException*/ {
// Here is the default plain behavior. Simply takes the selected
// template (you need to have included the standard second panel
// in createPanels(), or at least set the properties targetName and
// targetFolder correctly), instantiates it in the provided
// position, and returns the result.
// More advanced wizards can create multiple objects from template
// (return them all in the result of this method), populate file
// contents on the fly, etc.
org.openide.filesystems.FileObject dir = Templates.getTargetFolder( wiz );
DataFolder df = DataFolder.findFolder( dir );
FileObject template = Templates.getTemplate( wiz );
DataObject dTemplate = DataObject.find( template );
final DataObject dobj = dTemplate.createFromTemplate( df, Templates.getTargetName( wiz ) );
//this part might be turned pluggable once we have also ant based osgi projects. if..
Project project = Templates.getProject( wiz );
ClassPath cp = ClassPath.getClassPath(dobj.getPrimaryFile(), ClassPath.SOURCE);
final String path = cp.getResourceName(dobj.getPrimaryFile(), '.', false);
final NbMavenProject prj = project.getLookup().lookup(NbMavenProject.class);
if (prj != null) {
Utilities.performPOMModelOperations(project.getProjectDirectory().getFileObject("pom.xml"),
Collections.<ModelOperation<POMModel>>singletonList(
new ModelOperation<POMModel>() {
@Override
public void performOperation(POMModel model) {
addActivator(prj, model, path);
}
}
));
}
return Collections.singleton(dobj);
}
示例11: testBasePropertiesAlwaysPresent
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
public void testBasePropertiesAlwaysPresent() throws Exception {
FileObject root = FileUtil.createMemoryFileSystem().getRoot();
FileObject fo = FileUtil.createData(root, "simpleObject.txt");
OutputStream os = fo.getOutputStream();
String txt = "print('<html><h1>'); print(name); print('</h1>');" +
"print('<h2>'); print(date); print('</h2>');" +
"print('<h3>'); print(time); print('</h3>');" +
"print('<h4>'); print(user); print('</h4>');" +
"print('<h4>'); print(dateTime.getTime()); print('</h4>');" +
"print('</html>');";
os.write(txt.getBytes());
os.close();
fo.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js");
DataObject obj = DataObject.find(fo);
DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target"));
Map<String,String> parameters = Collections.singletonMap("title", "Nazdar");
DataObject n = obj.createFromTemplate(folder, "complex", parameters);
assertEquals("Created in right place", folder, n.getFolder());
assertEquals("Created with right name", "complex.txt", n.getName());
String res = readFile(n.getPrimaryFile());
if (res.indexOf("date") >= 0) fail(res);
if (res.indexOf("time") >= 0) fail(res);
if (res.indexOf("user") >= 0) fail(res);
if (res.indexOf("name") >= 0) fail(res);
if (res.indexOf("dateTime") >= 0) fail(res);
}
示例12: instantiate
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
@Override
public Set/*<FileObject>*/ instantiate () throws IOException {
FileObject dir = Templates.getTargetFolder( wiz );
DataFolder df = DataFolder.findFolder( dir );
FileObject template = isFolder ? FileUtil.createMemoryFileSystem().getRoot() : Templates.getTemplate( wiz );
DataObject dTemplate = DataObject.find( template );
DataObject dobj = dTemplate.createFromTemplate( df, Templates.getTargetName( wiz ) );
return Collections.singleton (dobj.getPrimaryFile ());
}
示例13: create
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
@Override
public FileObject create(FileObject template, FileObject folder, String name) throws IOException {
DataObject templateDobj = DataObject.find(template);
if (templateDobj == null || !templateDobj.isTemplate()) {
return FileUtil.createData(folder, name);
}
DataFolder target = DataFolder.findFolder(folder);
String simpleName = FileObjects.stripExtension(name);
DataObject newDobj = templateDobj.createFromTemplate(target, simpleName);
return newDobj.getPrimaryFile();
}
示例14: testBasePropertiesAlwaysPresent
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
public void testBasePropertiesAlwaysPresent() throws Exception {
FileObject root = FileUtil.createMemoryFileSystem().getRoot();
FileObject fo = FileUtil.createData(root, "simpleObject.txt");
OutputStream os = fo.getOutputStream();
String txt = "<html><h1>${name}</h1>" +
"<h2>${date}</h2>" +
"<h3>${time}</h3>" +
"<h4>${user}</h4>" +
"<h4>${dateTime?string(\"yy\")}</h4>" +
"</html>";
os.write(txt.getBytes());
os.close();
fo.setAttribute("javax.script.ScriptEngine", "freemarker");
DataObject obj = DataObject.find(fo);
DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target"));
Map<String,String> parameters = Collections.singletonMap("title", "Nazdar");
DataObject n = obj.createFromTemplate(folder, "complex", parameters);
assertEquals("Created in right place", folder, n.getFolder());
assertEquals("Created with right name", "complex.txt", n.getName());
String res = readFile(n.getPrimaryFile());
if (res.indexOf("date") >= 0) fail(res);
if (res.indexOf("time") >= 0) fail(res);
if (res.indexOf("user") >= 0) fail(res);
if (res.indexOf("name") >= 0) fail(res);
if (res.indexOf("dateTime") >= 0) fail(res);
}
示例15: testCreateWithNameAndExtForForm
import org.openide.loaders.DataObject; //导入方法依赖的package包/类
public void testCreateWithNameAndExtForForm() throws Exception {
LocalFileSystem lfs = new LocalFileSystem();
lfs.setRootDirectory(getWorkDir());
FileObject root = lfs.getRoot();
FileObject fo = FileUtil.createData(root, "j.java");
OutputStream os = fo.getOutputStream();
String txt = "print('<html><h1>', nameAndExt, '</h1></html>')";
os.write(txt.getBytes());
os.close();
fo.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js");
FileObject fo2 = FileUtil.createData(root, "j.form");
OutputStream os2 = fo2.getOutputStream();
String txt2 = "print('<html><h2>', nameAndExt, '</h2></html>')";
os2.write(txt2.getBytes());
os2.close();
fo2.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js");
DataObject obj = DataObject.find(fo);
assertEquals("Both files", 2, obj.files().size());
DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target"));
Map<String,String> parameters = Collections.emptyMap();
DataObject n = obj.createFromTemplate(folder, "complex", parameters);
assertEquals("Two files", 2, n.files().size());
FileObject newForm = FileUtil.findBrother(n.getPrimaryFile(), "form");
assertEquals("Primary file is java", "java", n.getPrimaryFile().getExt());
assertNotNull("Form copied", newForm);
DataObject frm = DataObject.find(newForm);
assertSame("Form belongs to java", n, frm);
assertEquals("Created in right place", folder, n.getFolder());
assertEquals("Created with right name", "complex", n.getName());
String exp = "<html><h1> complex.java </h1></html>\n";
assertEquals("Primary file" + n.getPrimaryFile(), exp, readFile(n.getPrimaryFile()));
String exp2 = "<html><h2> complex.form </h2></html>\n";
assertEquals(exp2, readFile(newForm));
}