当前位置: 首页>>代码示例>>Java>>正文


Java Bindings.putAll方法代码示例

本文整理汇总了Java中javax.script.Bindings.putAll方法的典型用法代码示例。如果您正苦于以下问题:Java Bindings.putAll方法的具体用法?Java Bindings.putAll怎么用?Java Bindings.putAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.script.Bindings的用法示例。


在下文中一共展示了Bindings.putAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doEvaluate

import javax.script.Bindings; //导入方法依赖的package包/类
private Object doEvaluate(String js, Object input) {
    Objects.requireNonNull(input);
    Objects.requireNonNull(engine, "No JavaScript engine available!");
    Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
    bindings.put("input", input);
    bindings.putAll(references);
    try {
        return engine.eval(js);
    } catch (ScriptException e) {
        throw new IllegalArgumentException("Could not evaluate JavaScript: " + e.getLocalizedMessage(), e);
    }
}
 
开发者ID:pascalgn,项目名称:jiracli,代码行数:13,代码来源:DefaultJavaScriptEngine.java

示例2: createFromTemplate

import javax.script.Bindings; //导入方法依赖的package包/类
@Override
public List<FileObject> createFromTemplate(CreateDescriptor desc) throws IOException {
    FileObject template = desc.getTemplate();
    String name = desc.getProposedName();
    Map<String, ?> values = desc.getParameters();
    FileObject f = desc.getTarget();
    
    boolean noExt = desc.hasFreeExtension() && name.indexOf('.') != -1;
    
    String extWithDot;
    if (noExt) {
        extWithDot = null;
    } else {
        extWithDot = '.' + template.getExt();
        if (name.endsWith(extWithDot)) { // Test whether the extension happens to be there already
            // And remove it if yes, it will be appended to the unique name.
            name = name.substring(0, name.length() - extWithDot.length());
        }
    }
    
    String nameUniq = FileUtil.findFreeFileName(f, name, noExt ? null : template.getExt());
    FileObject output = FileUtil.createData(f, noExt ? nameUniq : nameUniq + extWithDot);
    Charset targetEnc = FileEncodingQuery.getEncoding(output);
    Charset sourceEnc = FileEncodingQuery.getEncoding(template);
    
    ScriptEngine eng = engine(template);
    Bindings bind = eng.getContext().getBindings(ScriptContext.ENGINE_SCOPE);
    bind.putAll(values);
    
    if(!values.containsKey(ENCODING_PROPERTY_NAME)) {
        bind.put(ENCODING_PROPERTY_NAME, targetEnc.name());
    }
    
    //Document doc = createDocument(template.getMIMEType());
    FileLock lock = output.lock();
    try (Writer w = new OutputStreamWriter(output.getOutputStream(lock), targetEnc);
         Reader is = new InputStreamReader(template.getInputStream(), sourceEnc);
        /*IndentWriter w2 = new IndentWriter(doc, 0, w, false) */) {
        StringWriter sw = new StringWriter();
        ScriptEngine eng2 = desc.isPreformatted() ? null : indentEngine();
        
        eng.getContext().setWriter(new PrintWriter(eng2 != null ? sw : w));
        //eng.getContext().setBindings(bind, ScriptContext.ENGINE_SCOPE);
        eng.getContext().setAttribute(FileObject.class.getName(), template, ScriptContext.ENGINE_SCOPE);
        eng.getContext().setAttribute(ScriptEngine.FILENAME, template.getNameExt(), ScriptContext.ENGINE_SCOPE);
        eng.eval(is);
        
        if (eng2 != null) {
            eng2.getContext().setAttribute("mimeType", template.getMIMEType(), ScriptContext.ENGINE_SCOPE);
            eng2.getContext().setWriter(w);
            eng2.eval(new StringReader(sw.toString()));
        }
    }catch (ScriptException ex) {
        IOException io = new IOException(ex.getMessage(), ex);
        throw io;
    } finally {
        lock.releaseLock();
    }
    return Collections.singletonList(output);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:61,代码来源:ScriptingCreateFromTemplateHandler.java

示例3: save

import javax.script.Bindings; //导入方法依赖的package包/类
@Override
public void save( Bindings bindings )
{
  bindings.putAll( _bindings );
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:6,代码来源:JsonImplBase.java


注:本文中的javax.script.Bindings.putAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。