" +
+ "";
+ 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 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);
+ }
+
+ private static String readFile(FileObject fo) throws IOException {
+ byte[] arr = new byte[(int)fo.getSize()];
+ int len = fo.getInputStream().read(arr);
+ assertEquals("Fully read", arr.length, len);
+ return new String(arr);
+ }
+
+ public static final class DD extends DialogDisplayer {
+ public Object notify(NotifyDescriptor descriptor) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Dialog createDialog(final DialogDescriptor descriptor) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ /*
+ return new JDialog() {
+ @Deprecated
+ public void show() {
+ for (Object object : descriptor.getOptions()) {
+ if (object instanceof JButton) {
+ JButton b = (JButton)object;
+ if (b.getText().equals("Finish")) {
+ descriptor.setValue(WizardDescriptor.FINISH_OPTION);
+ b.doClick();
+ return;
+ }
+ }
+ }
+ fail("Cannot find Finish button: " + Arrays.asList(descriptor.getOptions()));
+ }
+ };
+ */
+ }
+ }
+
+ public static final class Pool extends DataLoaderPool {
+ protected Enumeration loaders() {
+ return Enumerations.singleton(SimpleLoader.getLoader(SimpleLoader.class));
+ }
+ }
+
+ public static final class SimpleLoader extends MultiFileLoader {
+ public SimpleLoader() {
+ super(SimpleObject.class.getName());
+ }
+ protected String displayName() {
+ return "SimpleLoader";
+ }
+ protected FileObject findPrimaryFile(FileObject fo) {
+ if (fo.hasExt("prima")) {
+ return fo;
+ }
+ return null;
+ }
+ protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException {
+ return new SimpleObject(this, primaryFile);
+ }
+ protected MultiDataObject.Entry createPrimaryEntry(MultiDataObject obj, FileObject primaryFile) {
+ return new FE(obj, primaryFile);
+ }
+ protected MultiDataObject.Entry createSecondaryEntry(MultiDataObject obj, FileObject secondaryFile) {
+ return new FileEntry(obj, secondaryFile);
+ }
+ }
+
+ private static final class FE extends FileEntry {
+ public FE(MultiDataObject mo, FileObject fo) {
+ super(mo, fo);
+ }
+
+ @Override
+ public FileObject createFromTemplate(FileObject f, String name) throws IOException {
+ fail("I do not want to be called");
+ return null;
+ }
+
+
+
+ }
+
+ public static final class SimpleObject extends MultiDataObject {
+ public SimpleObject(SimpleLoader l, FileObject fo) throws DataObjectExistsException {
+ super(fo, l);
+ }
+
+ public String getName() {
+ return getPrimaryFile().getNameExt();
+ }
+ }
+
+}
Index: libs/external/.cvsignore
===================================================================
RCS file: /shared/data/ccvs/repository/libs/external/.cvsignore,v
retrieving revision 1.24
retrieving revision 1.24.38.2
diff -u -r1.24 -r1.24.38.2
--- libs/external/.cvsignore 8 Sep 2005 18:10:45 -0000 1.24
+++ libs/external/.cvsignore 19 Jan 2007 09:45:38 -0000 1.24.38.2
@@ -1 +1,3 @@
+jsr223-api.jar
dtds
+freemarker-2.3.8.jar
Index: libs/external/freemarker-2.3.8-license.txt
===================================================================
RCS file: libs/external/freemarker-2.3.8-license.txt
diff -N libs/external/freemarker-2.3.8-license.txt
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libs/external/freemarker-2.3.8-license.txt 19 Jan 2007 09:45:38 -0000 1.1.2.1
@@ -0,0 +1,46 @@
+FreeMarker 1.x was released under the LGPL license. Later, by community
+consensus, we have switched over to a BSD-style license. As of FreeMarker
+2.2pre1, the original author, Benjamin Geer, has relinquished the copyright in
+behalf of Visigoth Software Society. The current copyright holder is the
+Visigoth Software Society.
+
+------------------------------------------------------------------------------
+Copyright (c) 2003 The Visigoth Software Society. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+2. The end-user documentation included with the redistribution, if any, must
+ include the following acknowlegement:
+ "This product includes software developed by the
+ Visigoth Software Society (http://www.visigoths.org/)."
+ Alternately, this acknowlegement may appear in the software itself, if and
+ wherever such third-party acknowlegements normally appear.
+
+3. Neither the name "FreeMarker", "Visigoth", nor any of the names of the
+ project contributors may be used to endorse or promote products derived
+ from this software without prior written permission. For written
+ permission, please contact visigoths@visigoths.org.
+
+4. Products derived from this software may not be called "FreeMarker" or
+ "Visigoth" nor may "FreeMarker" or "Visigoth" appear in their names
+ without prior written permission of the Visigoth Software Society.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+VISIGOTH SOFTWARE SOCIETY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+------------------------------------------------------------------------------
+
+This software consists of voluntary contributions made by many individuals on
+behalf of the Visigoth Software Society. For more information on the Visigoth
+Software Society, please see http://www.visigoths.org/
Index: libs/external/jsr223-api-license.txt
===================================================================
RCS file: libs/external/jsr223-api-license.txt
diff -N libs/external/jsr223-api-license.txt
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libs/external/jsr223-api-license.txt 19 Jan 2007 07:58:45 -0000 1.1.2.1
@@ -0,0 +1,225 @@
+SUN MICROSYSTEMS, INC. ("SUN") IS WILLING TO LICENSE THIS SPECIFICATION
+TO YOU ONLY UPON THE CONDITION THAT YOU ACCEPT ALL OF THE TERMS
+CONTAINED IN THIS AGREEMENT. PLEASE READ THE TERMS AND CONDITIONS OF
+THIS AGREEMENT CAREFULLY. BY DOWNLOADING THIS SPECIFICATION, YOU ACCEPT
+THE TERMS AND CONDITIONS OF THE AGREEMENT. IF YOU ARE NOT WILLING TO BE
+BOUND BY IT, SELECT THE "DECLINE" BUTTON AT THE BOTTOM OF THIS PAGE.
+
+
+Specification: JSR-000223 Scripting for the Java(tm) Platform ("Specification")
+
+
+Version: 1.0
+
+
+Status: Final Release
+
+
+Release: 7 December 2006
+
+
+Copyright 2006 SUN MICROSYSTEMS, INC.
+
+4150 Network Circle, Santa Clara, California 95054, U.S.A
+
+All rights reserved.
+
+
+LIMITED LICENSE GRANTS
+
+
+1. _License for Evaluation Purposes_. Sun hereby grants you a
+fully-paid, non-exclusive, non-transferable, worldwide, limited license
+(without the right to sublicense), under Sun's applicable intellectual
+property rights to view, download, use and reproduce the Specification
+only for the purpose of internal evaluation. This includes (i)
+developing applications intended to run on an implementation of the
+Specification, provided that such applications do not themselves
+implement any portion(s) of the Specification, and (ii) discussing the
+Specification with any third party; and (iii) excerpting brief portions
+of the Specification in oral or written communications which discuss the
+Specification provided that such excerpts do not in the aggregate
+constitute a significant portion of the Specification.
+
+
+2. _License for the Distribution of Compliant Implementations_. Sun also
+grants you a perpetual, non-exclusive, non-transferable, worldwide,
+fully paid-up, royalty free, limited license (without the right to
+sublicense) under any applicable copyrights or, subject to the
+provisions of subsection 4 below, patent rights it may have covering the
+Specification to create and/or distribute an Independent Implementation
+of the Specification that: (a) fully implements the Specification
+including all its required interfaces and functionality; (b) does not
+modify, subset, superset or otherwise extend the Licensor Name Space, or
+include any public or protected packages, classes, Java interfaces,
+fields or methods within the Licensor Name Space other than those
+required/authorized by the Specification or Specifications being
+implemented; and (c) passes the Technology Compatibility Kit (including
+satisfying the requirements of the applicable TCK Users Guide) for such
+Specification ("Compliant Implementation"). In addition, the foregoing
+license is expressly conditioned on your not acting outside its scope.
+No license is granted hereunder for any other purpose (including, for
+example, modifying the Specification, other than to the extent of your
+fair use rights, or distributing the Specification to third parties).
+Also, no right, title, or interest in or to any trademarks, service
+marks, or trade names of Sun or Sun's licensors is granted hereunder.
+Java, and Java-related logos, marks and names are trademarks or
+registered trademarks of Sun Microsystems, Inc. in the U.S. and other
+countries.
+
+
+3. _Pass-through Conditions_. You need not include limitations (a)-(c)
+from the previous paragraph or any other particular "pass through"
+requirements in any license You grant concerning the use of your
+Independent Implementation or products derived from it. However, except
+with respect to Independent Implementations (and products derived from
+them) that satisfy limitations (a)-(c) from the previous paragraph, You
+may neither: (a) grant or otherwise pass through to your licensees any
+licenses under Sun's applicable intellectual property rights; nor (b)
+authorize your licensees to make any claims concerning their
+implementation's compliance with the Specification in question.
+
+
+4. _Reciprocity Concerning Patent Licenses_.
+
+
+a. With respect to any patent claims covered by the license granted
+under subparagraph 2 above that would be infringed by all technically
+feasible implementations of the Specification, such license is
+conditioned upon your offering on fair, reasonable and
+non-discriminatory terms, to any party seeking it from You, a perpetual,
+non-exclusive, non-transferable, worldwide license under Your patent
+rights which are or would be infringed by all technically feasible
+implementations of the Specification to develop, distribute and use a
+Compliant Implementation.
+
+
+b With respect to any patent claims owned by Sun and covered by the
+license granted under subparagraph 2, whether or not their infringement
+can be avoided in a technically feasible manner when implementing the
+Specification, such license shall terminate with respect to such claims
+if You initiate a claim against Sun that it has, in the course of
+performing its responsibilities as the Specification Lead, induced any
+other entity to infringe Your patent rights.
+
+
+c Also with respect to any patent claims owned by Sun and covered by the
+license granted under subparagraph 2 above, where the infringement of
+such claims can be avoided in a technically feasible manner when
+implementing the Specification such license, with respect to such
+claims, shall terminate if You initiate a claim against Sun that its
+making, having made, using, offering to sell, selling or importing a
+Compliant Implementation infringes Your patent rights.
+
+
+5. _Definitions_. For the purposes of this Agreement: "Independent
+Implementation" shall mean an implementation of the Specification that
+neither derives from any of Sun's source code or binary code materials
+nor, except with an appropriate and separate license from Sun, includes
+any of Sun's source code or binary code materials; "Licensor Name Space"
+shall mean the public class or interface declarations whose names begin
+with "java", "javax", "com.sun" or their equivalents in any subsequent
+naming convention adopted by Sun through the Java Community Process, or
+any recognized successors or replacements thereof; and "Technology
+Compatibility Kit" or "TCK" shall mean the test suite and accompanying
+TCK User's Guide provided by Sun which corresponds to the Specification
+and that was available either (i) from Sun's 120 days before the first
+release of Your Independent Implementation that allows its use for
+commercial purposes, or (ii) more recently than 120 days from such
+release but against which You elect to test Your implementation of the
+Specification.
+
+
+This Agreement will terminate immediately without notice from Sun if you
+breach the Agreement or act outside the scope of the licenses granted above.
+
+
+DISCLAIMER OF WARRANTIES
+
+
+THE SPECIFICATION IS PROVIDED "AS IS". SUN MAKES NO REPRESENTATIONS OR
+WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO,
+WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+NON-INFRINGEMENT (INCLUDING AS A CONSEQUENCE OF ANY PRACTICE OR
+IMPLEMENTATION OF THE SPECIFICATION), OR THAT THE CONTENTS OF THE
+SPECIFICATION ARE SUITABLE FOR ANY PURPOSE. This document does not
+represent any commitment to release or implement any portion of the
+Specification in any product. In addition, the Specification could
+include technical inaccuracies or typographical errors.
+
+
+LIMITATION OF LIABILITY
+
+
+TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL SUN OR ITS
+LICENSORS BE LIABLE FOR ANY DAMAGES, INCLUDING WITHOUT LIMITATION, LOST
+REVENUE, PROFITS OR DATA, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL,
+INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE
+THEORY OF LIABILITY, ARISING OUT OF OR RELATED IN ANY WAY TO YOUR
+HAVING, IMPLEMENTING OR OTHERWISE USING THE SPECIFICATION, EVEN
+IF SUN AND/OR ITS LICENSORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+You will indemnify, hold harmless, and defend Sun and its licensors from
+any claims arising or resulting from: (i) your use of the Specification;
+(ii) the use or distribution of your Java application, applet and/or
+implementation; and/or (iii) any claims that later versions or releases
+of any Specification furnished to you are incompatible with the
+Specification provided to you under this license.
+
+
+RESTRICTED RIGHTS LEGEND
+
+
+U.S. Government: If this Specification is being acquired by or on behalf
+of the U.S. Government or by a U.S. Government prime contractor or
+subcontractor (at any tier), then the Government's rights in the
+Software and accompanying documentation shall be only as set forth in
+this license; this is in accordance with 48 C.F.R. 227.7201 through
+227.7202-4 (for Department of Defense (DoD) acquisitions) and with 48
+C.F.R. 2.101 and 12.212 (for non-DoD acquisitions).
+
+
+REPORT
+
+
+If you provide Sun with any comments or suggestions concerning the
+Specification ("Feedback"), you hereby: (i) agree that such Feedback is
+provided on a non-proprietary and non-confidential basis, and (ii) grant
+Sun a perpetual, non-exclusive, worldwide, fully paid-up, irrevocable
+license, with the right to sublicense through multiple levels of
+sublicensees, to incorporate, disclose, and use without limitation the
+Feedback for any purpose.
+
+
+GENERAL TERMS
+
+
+Any action related to this Agreement will be governed by California law
+and controlling U.S. federal law. The U.N. Convention for the
+International Sale of Goods and the choice of law rules of any
+jurisdiction will not apply.
+
+
+The Specification is subject to U.S. export control laws and may be
+subject to export or import regulations in other countries. Licensee
+agrees to comply strictly with all such laws and regulations and
+acknowledges that it has the responsibility to obtain such licenses to
+export, re-export or import as may be required after delivery to Licensee.
+
+
+This Agreement is the parties' entire agreement relating to its subject
+matter. It supersedes all prior or contemporaneous oral or written
+communications, proposals, conditions, representations and warranties
+and prevails over any conflicting or additional terms of any quote,
+order, acknowledgment, or other communication between the parties
+relating to its subject matter during the term of this Agreement. No
+modification to this Agreement will be binding, unless in writing and
+signed by an authorized representative of each party.
+
+
+
+
+Rev. April, 2006
+
+Sun/Final/Full
Index: libs/freemarker/.cvsignore
===================================================================
RCS file: libs/freemarker/.cvsignore
diff -N libs/freemarker/.cvsignore
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libs/freemarker/.cvsignore 19 Jan 2007 09:45:40 -0000 1.1.2.1
@@ -0,0 +1 @@
+build
Index: libs/freemarker/build.xml
===================================================================
RCS file: libs/freemarker/build.xml
diff -N libs/freemarker/build.xml
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libs/freemarker/build.xml 19 Jan 2007 09:45:40 -0000 1.1.2.1
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Going to download freemarker binaries! Distributed from http://freemarker.sourceforge.net/
+Or you need to provide path to the freemarker JAR using -Dfreemarker.jar=, download from:
+http://mesh.dl.sourceforge.net/sourceforge/freemarker/freemarker-2.3.8.tar.gz
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ For the integration module:
+
+ For the freemarker:
+
+
+
+
+
+
+
Index: libs/freemarker/manifest.mf
===================================================================
RCS file: libs/freemarker/manifest.mf
diff -N libs/freemarker/manifest.mf
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libs/freemarker/manifest.mf 22 Jan 2007 18:29:06 -0000 1.1.2.3
@@ -0,0 +1,7 @@
+Manifest-Version: 1.0
+OpenIDE-Module: org.netbeans.libs.freemarker/1
+OpenIDE-Module-Provides: javax.script.ScriptEngine.freemarker
+OpenIDE-Module-Specification-Version: 2.3.8
+OpenIDE-Module-Implementation-Version: 238
+OpenIDE-Module-Localizing-Bundle: org/netbeans/libs/freemarker/Bundle.properties
+
Index: libs/freemarker/nbproject/.cvsignore
===================================================================
RCS file: libs/freemarker/nbproject/.cvsignore
diff -N libs/freemarker/nbproject/.cvsignore
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libs/freemarker/nbproject/.cvsignore 19 Jan 2007 09:45:36 -0000 1.1.2.1
@@ -0,0 +1 @@
+private
Index: libs/freemarker/nbproject/project.properties
===================================================================
RCS file: libs/freemarker/nbproject/project.properties
diff -N libs/freemarker/nbproject/project.properties
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libs/freemarker/nbproject/project.properties 19 Jan 2007 10:27:08 -0000 1.1.2.2
@@ -0,0 +1,22 @@
+# The contents of this file are subject to the terms of the Common Development
+# and Distribution License (the License). You may not use this file except in
+# compliance with the License.
+#
+# You can obtain a copy of the License at http://www.netbeans.org/cddl.html
+# or http://www.netbeans.org/cddl.txt.
+#
+# When distributing Covered Code, include this CDDL Header Notice in each file
+# and include the License file at http://www.netbeans.org/cddl.txt.
+# If applicable, add the following below the CDDL Header, with the fields
+# enclosed by brackets [] replaced by your own identifying information:
+# "Portions Copyrighted [year] [name of copyright owner]"
+#
+# The Original Software is NetBeans. The Initial Developer of the Original
+# Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
+# Microsystems, Inc. All Rights Reserved.
+
+is.autoload=true
+
+
+javac.compilerargs=-Xlint:unchecked
+javac.source=1.5
Index: libs/freemarker/nbproject/project.xml
===================================================================
RCS file: libs/freemarker/nbproject/project.xml
diff -N libs/freemarker/nbproject/project.xml
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libs/freemarker/nbproject/project.xml 19 Jan 2007 10:27:08 -0000 1.1.2.2
@@ -0,0 +1,61 @@
+
+
+
+ org.netbeans.modules.apisupport.project
+
+
+ org.netbeans.libs.freemarker
+
+
+ org.netbeans.libs.jsr223
+
+
+
+ 1
+ 1.6
+
+
+
+ org.openide.filesystems
+
+
+
+ 7.0
+
+
+
+ org.openide.util
+
+
+
+ 7.7
+
+
+
+
+ org.netbeans.libs.freemarker
+
+
+ ext/freemarker-2.3.8.jar
+ ../external/freemarker-2.3.8.jar
+
+
+
+
Index: libs/freemarker/src/META-INF/services/javax.script.ScriptEngineFactory
===================================================================
RCS file: libs/freemarker/src/META-INF/services/javax.script.ScriptEngineFactory
diff -N libs/freemarker/src/META-INF/services/javax.script.ScriptEngineFactory
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libs/freemarker/src/META-INF/services/javax.script.ScriptEngineFactory 19 Jan 2007 22:25:29 -0000 1.1.2.1
@@ -0,0 +1 @@
+org.netbeans.libs.freemarker.FreemarkerFactory
Index: libs/freemarker/src/org/netbeans/libs/freemarker/Bundle.properties
===================================================================
RCS file: libs/freemarker/src/org/netbeans/libs/freemarker/Bundle.properties
diff -N libs/freemarker/src/org/netbeans/libs/freemarker/Bundle.properties
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libs/freemarker/src/org/netbeans/libs/freemarker/Bundle.properties 19 Jan 2007 09:45:41 -0000 1.1.2.1
@@ -0,0 +1,24 @@
+# The contents of this file are subject to the terms of the Common Development
+# and Distribution License (the License). You may not use this file except in
+# compliance with the License.
+#
+# You can obtain a copy of the License at http://www.netbeans.org/cddl.html
+# or http://www.netbeans.org/cddl.txt.
+#
+# When distributing Covered Code, include this CDDL Header Notice in each file
+# and include the License file at http://www.netbeans.org/cddl.txt.
+# If applicable, add the following below the CDDL Header, with the fields
+# enclosed by brackets [] replaced by your own identifying information:
+# "Portions Copyrighted [year] [name of copyright owner]"
+#
+# The Original Software is NetBeans. The Initial Developer of the Original
+# Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
+# Microsystems, Inc. All Rights Reserved.
+
+OpenIDE-Module-Name=Freemarker Integration
+OpenIDE-Module-Display-Category=Libraries
+OpenIDE-Module-Short-Description=This module bundles Freemarker.
+OpenIDE-Module-Long-Description=\
+ The module bundles FreeMarker http://freemarker.sf.net and integrates\
+ it into NetBeans.
+
Index: libs/freemarker/src/org/netbeans/libs/freemarker/FreemarkerEngine.java
===================================================================
RCS file: libs/freemarker/src/org/netbeans/libs/freemarker/FreemarkerEngine.java
diff -N libs/freemarker/src/org/netbeans/libs/freemarker/FreemarkerEngine.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libs/freemarker/src/org/netbeans/libs/freemarker/FreemarkerEngine.java 20 Jan 2007 09:11:09 -0000 1.1.2.3
@@ -0,0 +1,205 @@
+/*
+ * The contents of this file are subject to the terms of the Common Development
+ * and Distribution License (the License). You may not use this file except in
+ * compliance with the License.
+ *
+ * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
+ * or http://www.netbeans.org/cddl.txt.
+ *
+ * When distributing Covered Code, include this CDDL Header Notice in each file
+ * and include the License file at http://www.netbeans.org/cddl.txt.
+ * If applicable, add the following below the CDDL Header, with the fields
+ * enclosed by brackets [] replaced by your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * The Original Software is scripting.dev.java.net. The Initial Developer of the Original
+ * Software is Sun Microsystems, Inc.
+ *
+ * Portions Copyrighted 2006 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.libs.freemarker;
+
+
+import javax.script.*;
+import java.io.*;
+import java.util.Properties;
+import java.util.Set;
+import freemarker.template.*;
+import org.openide.filesystems.FileObject;
+
+/* Taken from A. Sundararajan and adopted by Jaroslav Tulach
+ * for NetBeans needs.
+ *
+ * @author A. Sundararajan
+ */
+class FreemarkerEngine extends AbstractScriptEngine {
+
+ public static final String STRING_OUTPUT_MODE = "com.sun.script.freemarker.stringOut";
+ public static final String FREEMARKER_CONFIG = "com.sun.script.freemarker.config";
+ public static final String FREEMARKER_PROPERTIES = "com.sun.script.freemarker.properties";
+ public static final String FREEMARKER_TEMPLATE_DIR = "com.sun.script.freemarker.template.dir";
+ public static final String FREEMARKER_TEMPLATE = "org.openide.filesystems.FileObject";
+
+ // my factory, may be null
+ private volatile ScriptEngineFactory factory;
+ private volatile Configuration conf;
+
+ public FreemarkerEngine(ScriptEngineFactory factory) {
+ this.factory = factory;
+ }
+
+ public FreemarkerEngine() {
+ this(null);
+ }
+
+ // ScriptEngine methods
+ public Object eval(String str, ScriptContext ctx)
+ throws ScriptException {
+ return eval(new StringReader(str), ctx);
+ }
+
+ public Object eval(Reader reader, ScriptContext ctx)
+ throws ScriptException {
+ ctx.setAttribute("context", ctx, ScriptContext.ENGINE_SCOPE);
+ initFreeMarkerConfiguration(ctx);
+ String fileName = getFilename(ctx);
+ boolean outputAsString = isStringOutputMode(ctx);
+ Writer out;
+ if (outputAsString) {
+ out = new StringWriter();
+ } else {
+ out = ctx.getWriter();
+ }
+ Bindings engineScope = ctx.getBindings(ScriptContext.ENGINE_SCOPE);
+
+ try {
+ Template template = new Template(fileName, reader, conf);
+ template.process(engineScope, out);
+ out.flush();
+ } catch (Exception exp) {
+ throw new ScriptException(exp);
+ }
+ return outputAsString? out.toString() : null;
+ }
+
+ public ScriptEngineFactory getFactory() {
+ if (factory == null) {
+ synchronized (this) {
+ if (factory == null) {
+ factory = new FreemarkerFactory();
+ }
+ }
+ }
+ return factory;
+ }
+
+ public Bindings createBindings() {
+ return new SimpleBindings();
+ }
+
+ // internals only below this point
+ private static String getFilename(ScriptContext ctx) {
+ Object fileName = ctx.getAttribute(ScriptEngine.FILENAME);
+ return fileName != null? fileName.toString() : "";
+ }
+
+ private static boolean isStringOutputMode(ScriptContext ctx) {
+ Object flag = ctx.getAttribute(STRING_OUTPUT_MODE);
+ if (flag != null) {
+ return flag.equals(Boolean.TRUE);
+ } else {
+ return false;
+ }
+ }
+
+ private void initFreeMarkerConfiguration(ScriptContext ctx) {
+ if (conf == null) {
+ synchronized (this) {
+ if (conf != null) {
+ return;
+ }
+ Object cfg = ctx.getAttribute(FREEMARKER_CONFIG);
+ if (cfg instanceof Configuration) {
+ conf = (Configuration) cfg;
+ return;
+ }
+
+ Object tfo = ctx.getAttribute(FREEMARKER_TEMPLATE);
+ FileObject fo = tfo instanceof FileObject ? (FileObject)tfo : null;
+
+ Configuration tmpConf = new RsrcLoader(fo, ctx);
+ try {
+ initConfProps(tmpConf, ctx);
+ initTemplateDir(tmpConf, fo, ctx);
+ } catch (RuntimeException rexp) {
+ throw rexp;
+ } catch (Exception exp) {
+ throw new RuntimeException(exp);
+ }
+ conf = tmpConf;
+ }
+ }
+ }
+
+ private static void initConfProps(Configuration conf, ScriptContext ctx) {
+ try {
+ Properties props = null;
+ Object tmp = ctx.getAttribute(FREEMARKER_PROPERTIES);
+ if (props instanceof Properties) {
+ props = (Properties) tmp;
+ } else {
+ String propsName = System.getProperty(FREEMARKER_PROPERTIES);
+ if (propsName != null) {
+ File propsFile = new File(propsName);
+ if (propsFile.exists() && propsFile.canRead()) {
+ props = new Properties();
+ props.load(new FileInputStream(propsFile));
+ }
+ }
+ }
+ if (props != null) {
+ Set