freemarker.template.SimpleDate#freemarker.ext.dom.NodeModel源码实例Demo

下面列出了freemarker.template.SimpleDate#freemarker.ext.dom.NodeModel 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: boubei-tss   文件: FreemarkerParser.java
/**
 * 将XML数据转换为NodeModel
 */
public static NodeModel translateValue(String xmlValue){
	NodeModel node = null;
    try {
    	node = freemarker.ext.dom.NodeModel.parse(new InputSource(new StringReader(xmlValue)));
    } catch (Exception e) { }
    
    return node;
}
 
源代码2 项目: alfresco-repository   文件: TemplateNode.java
/**
 * @return FreeMarker NodeModel for the XML content of this node, or null if no parsable XML found
 */
public NodeModel getXmlNodeModel()
{
    try
    {
        return NodeModel.parse(new InputSource(new StringReader(getContent())));
    }
    catch (Throwable err)
    {
        if (logger.isDebugEnabled())
            logger.debug(err.getMessage(), err);
        
        return null;
    }
}
 
源代码3 项目: cougar   文件: IDLReader.java
private Node getRootNode(NodeModel model) {
    NodeList list = model.getNode().getChildNodes();
    for (int i=0; i<list.getLength(); i++) {
        Node n = list.item(i);
        if (n instanceof Element) {
            return n;
        }
    }
    throw new IllegalStateException("Can't find root node!");
}
 
源代码4 项目: stategen   文件: GeneratorControl.java
/** load xml data */
public NodeModel loadXml(String file) {
    return loadXml(file,true);
}
 
private String renderPathTemplate(String pathTemplate, NodeRef sourceNode, NodeRef tempRenditionLocation, NodeRef companyHome)
{
    NodeService nodeService = serviceRegistry.getNodeService();
    FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
    
    final Map<String, Object> root = new HashMap<String, Object>();

    List<FileInfo> sourcePathInfo;
    String fullSourceName;
    String cwd;
    try
    {
        //Since the root of the store is typically not a folder, we use company home as the root of this tree
        sourcePathInfo = fileFolderService.getNamePath(companyHome, sourceNode);
        //Remove the last element (the actual source file name)
        FileInfo sourceFileInfo = sourcePathInfo.remove(sourcePathInfo.size() - 1);
        fullSourceName = sourceFileInfo.getName();
        
        StringBuilder cwdBuilder = new StringBuilder("/");
        for (FileInfo file : sourcePathInfo)
        {
            cwdBuilder.append(file.getName());
            cwdBuilder.append('/');
        }
        cwd = cwdBuilder.toString();
    }
    catch (FileNotFoundException e)
    {
        log.warn("Failed to resolve path to source node: " + sourceNode + ". Default to Company Home");
        fullSourceName = nodeService.getPrimaryParent(sourceNode).getQName().getLocalName();
        cwd = "/";
    }

    String trimmedSourceName = fullSourceName;
    String sourceExtension = "";
    int extensionIndex = fullSourceName.lastIndexOf('.');
    if (extensionIndex != -1)
    {
        trimmedSourceName = (extensionIndex == 0) ? "" : fullSourceName.substring(0, extensionIndex);
        sourceExtension = (extensionIndex == fullSourceName.length() - 1) ? "" : fullSourceName
                    .substring(extensionIndex + 1);
    }

    root.put("name", trimmedSourceName);
    root.put("extension", sourceExtension);
    root.put("date", new SimpleDate(new Date(), SimpleDate.DATETIME));
    root.put("cwd", cwd);
    TemplateNode companyHomeNode = new TemplateNode(companyHome, serviceRegistry, null); 
    root.put("companyHome", companyHomeNode); 
    root.put("companyhome", companyHomeNode);   //Added this to be consistent with the script API
    root.put("sourceNode", new TemplateNode(sourceNode, serviceRegistry, null));
    root.put("sourceContentType", nodeService.getType(sourceNode).getLocalName());
    root.put("renditionContentType", nodeService.getType(tempRenditionLocation).getLocalName());
    NodeRef person = serviceRegistry.getPersonService().getPerson(AuthenticationUtil.getFullyAuthenticatedUser());
    root.put("person", new TemplateNode(person, serviceRegistry, null));

    if (sourceNodeIsXml(sourceNode))
    {
        try
        {
            Document xml = XMLUtil.parse(sourceNode, serviceRegistry.getContentService());
            pathTemplate = buildNamespaceDeclaration(xml) + pathTemplate;
            root.put("xml", NodeModel.wrap(xml));
        } catch (Exception ex)
        {
            log.warn("Failed to parse XML content into path template model: Node = " + sourceNode);
        }
    }

    if (log.isDebugEnabled())
    {
        log.debug("Path template model: " + root);
    }

    String result = null;
    try
    {
        if (log.isDebugEnabled())
        {
            log.debug("Processing " + pathTemplate + " using source node " + cwd + fullSourceName);
        }
        result = serviceRegistry.getTemplateService().processTemplateString("freemarker", pathTemplate,
                    new SimpleHash(root));
    } catch (TemplateException te)
    {
        log.error("Error while trying to process rendition path template: " + pathTemplate);
        log.error(te.getMessage(), te);
    }
    if (log.isDebugEnabled())
    {
        log.debug("processed pattern " + pathTemplate + " as " + result);
    }
    return result;
}
 
源代码6 项目: cougar   文件: IDLReader.java
public void init(
        Document iddDoc,
        Document extensionDoc,
        final String service,
        String packageName,
        final String basedir,
        final String genSrcDir,
        final Log log,
        final String outputDir,
        boolean client,
        boolean server)
        throws Exception {

    try {
        output = new File(basedir, genSrcDir);
        if (outputDir != null) {
            iDDOutputDir = new File(basedir+"/"+outputDir);
            if (!iDDOutputDir.exists()) {
                if (!iDDOutputDir.mkdirs()) {
                    throw new IllegalArgumentException("IDD Output Directory "+iDDOutputDir+" could not be created");
                }
            }
            if (!iDDOutputDir.isDirectory() || (!iDDOutputDir.canWrite())) {
                throw new IllegalArgumentException("IDD Output Directory "+iDDOutputDir+" is not a directory or cannot be written to.");
            }
        }
        config = new Configuration();
        config.setClassForTemplateLoading(IDLReader.class, "/templates");

        config.setStrictSyntaxMode(true);
        this.log = log;
        this.packageName = packageName;
        this.service = service;
        this.client = client;
        this.server = server || !client; // server must be true if client if false.

        dataModel = NodeModel.wrap(iddDoc.cloneNode(true));

        if (extensionDoc != null) {
            NodeModel extensionModel = NodeModel.wrap(extensionDoc);
            mergeExtensionsIntoDocument(getRootNode(dataModel),
                    getRootNode(extensionModel));
            removeUndefinedOperations(getRootNode(dataModel),
                    getRootNode(extensionModel));
        }
        if(log.isDebugEnabled()) {
            log.debug(serialize());
        }
    } catch (final Exception e) {
        log.error("Failed to initialise FTL", e);
        throw e;
    }
}