當前位置: 首頁>>代碼示例>>Java>>正文


Java DataObject.createFromTemplate方法代碼示例

本文整理匯總了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());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:DefaultCreationNoTest.java

示例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());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:XSLWizardIterator.java

示例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()));
    
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:SCFTHandlerTest.java

示例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);
}
 
開發者ID:kefik,項目名稱:Pogamut3,代碼行數:17,代碼來源:NewPrimitiveWizardIterator.java

示例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());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:ScriptingCreateFromTemplateTest.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:36,代碼來源:DefaultPlugin.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:NewTestSuiteWizardIterator.java

示例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()));
    
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:SCFTHandlerTest.java

示例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");
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:32,代碼來源:CreateFromTemplateHandlerTest.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:40,代碼來源:ActivatorIterator.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:34,代碼來源:SCFTHandlerTest.java

示例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 ());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,代碼來源:NewFileIterator.java

示例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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:DefaultFileObjectFromTemplateCreator.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:34,代碼來源:SCFTHandlerTest.java

示例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));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:47,代碼來源:SCFTHandlerTest.java


注:本文中的org.openide.loaders.DataObject.createFromTemplate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。