Package org.rythmengine.resource

Examples of org.rythmengine.resource.ITemplateResource


        }

        try {
            TemplateClass tc = classes().getByTemplate(template);
            if (null == tc) {
                ITemplateResource rsrc = resourceManager().getResource(template);
                if (rsrc.isValid()) {
                    tc = new TemplateClass(rsrc, this);
                    //classes().add(key, tc);
                } else {
                    nonExistsTemplates.add(template);
                    if (isDevMode() && nonExistsTemplatesChecker == null) {
View Full Code Here


            scheduler.scheduleAtFixedRate(new Runnable() {
                @Override
                public void run() {
                    List<String> toBeRemoved = new ArrayList<String>();
                    for (String template : nonExistsTemplates) {
                        ITemplateResource rsrc = resourceManager().getResource(template);
                        if (rsrc.isValid()) {
                            toBeRemoved.add(template);
                        }
                    }
                    nonExistsTemplates.removeAll(toBeRemoved);
                    toBeRemoved.clear();
View Full Code Here

            String me = templateClass.getKey().toString();
            int pos = me.lastIndexOf("/");
            if (-1 != pos) extended = me.substring(0, pos) + "/" + extended;
            tc = engine.classes().getByTemplate(extended);
            if (null == tc) {
                ITemplateResource resource = engine.resourceManager().getResource(extended);
                if (resource.isValid()) {
                    tc = new TemplateClass(resource, engine);
                }
            }
        }
        if (null == tc && !extended.startsWith("/")) {
            // it's in class name style ?
            //if (!extended.endsWith(TemplateClass.CN_SUFFIX)) extended = extended + TemplateClass.CN_SUFFIX;
            tc = engine.classes().getByClassName(extended);
        }
        if (null == tc) {
            tc = engine.classes().getByTemplate(origin);
            if (null == tc) {
                ITemplateResource resource = engine.resourceManager().getResource(origin);
                if (resource.isValid()) tc = new TemplateClass(resource, engine);
            }
        }
        if (null == tc) {
            throw new ParseException(engine, templateClass, lineNo, "Cannot find extended template by name \"%s\"", origin);
        }
View Full Code Here

    private Boolean _hasGlobalInclude = null;

    public boolean hasGlobalInclude() {
        if (null == _hasGlobalInclude) {
            ITemplateResource rsrc = engine.resourceManager().getResource("__global.rythm");
            _hasGlobalInclude = rsrc.isValid();
        }
        return _hasGlobalInclude;
    }
View Full Code Here

   
    public TemplateClass getByTemplate(Object name, boolean checkResource) {
        TemplateClass tc = tmplIdx.get(name);
        if (checkResource && null == tc) {
            // try to see if resourceLoader has some kind of name transform
            ITemplateResource r = engine.resourceManager().getResource(name.toString());
            if (!r.isValid()) {
                return null;
            }
            tc = tmplIdx.get(r.getKey());
        }
        checkUpdate(tc);
        return tc;
    }
View Full Code Here

     */
    public synchronized boolean refresh(boolean forceRefresh) {
        if (refreshing()) return false;
        if (inner) return false;
        refreshing(true);
        final ITemplateResource templateResource = this.templateResource;
        try {
            RythmEngine engine = engine();
            if (!templateResource.isValid()) {
                // it is removed?
                isValid = false;
                engine.classes().remove(this);
                return false;
            }
            ICodeType type = engine.renderSettings.codeType();
            if (null == type) {
                type = templateResource.codeType(engine());
            }
            if (null == type || ICodeType.DefImpl.RAW == type) {
                type = engine.conf().defaultCodeType();
            }
            codeType = type;
            if (null == name) {
                // this is the root level template class
                root = this;
                name = templateResource.getSuggestedClassName() + CN_SUFFIX;
                if (engine.conf().typeInferenceEnabled()) {
                    name += ParamTypeInferencer.uuid();
                }
                ITemplateResourceLoader loader = engine().resourceManager().whichLoader(templateResource);
                if (null != loader) {
                    Object k = templateResource.getKey();
                    tagName = toCanonicalName(k.toString(), loader.getResourceLoaderRoot());
                }
                //name = templateResource.getSuggestedClassName();
                engine.registerTemplateClass(this);
            }

            if (null == javaSource) {
                engine.classCache().loadTemplateClass(this);
                if (null != javaSource) {
                    // try refresh extended template class if there is
                    Pattern p = Pattern.compile(".*extends\\s+([a-zA-Z0-9_]+)\\s*\\{\\s*\\/\\/<extended_resource_key\\>(.*)\\<\\/extended_resource_key\\>.*", Pattern.DOTALL);
                    Matcher m = p.matcher(javaSource);
                    if (m.matches()) {
                        String extended = m.group(1);
                        TemplateClassManager tcm = engine().classes();
                        extendedTemplateClass = tcm.getByClassName(extended);
                        if (null == extendedTemplateClass) {
                            String extendedResourceKey = m.group(2);
                            extendedTemplateClass = tcm.getByTemplate(extendedResourceKey);
                            if (null == extendedTemplateClass) {
                                extendedTemplateClass = new TemplateClass(extendedResourceKey, engine());
                                extendedTemplateClass.refresh();
                            }
                        }
                        engine.addExtendRelationship(extendedTemplateClass, this);
                    }
                }
            }

            boolean extendedTemplateChanged = false;
            if (extendedTemplateClass != null) extendedTemplateChanged = extendedTemplateClass.refresh(forceRefresh);
            boolean includedTemplateChanged = false;
            if (includedTemplateClasses.size() == 0 && !S.isEmpty(includeTemplateClassNames) && !NO_INCLUDE_CLASS.equals(includeTemplateClassNames)) {
                // just loaded from persistent store
                for (String tcName : includeTemplateClassNames.split(",")) {
                    if (S.isEmpty(tcName)) continue;
                    tcName = tcName.trim();
                    String fullName = engine().testTemplate(tcName, this);
                    if (null == fullName) {
                        logger.warn("Unable to load included template class from name: %s", tcName);
                        continue;
                    }
                    TemplateClass tc = engine().getRegisteredTemplateClass(fullName);
                    if (null == tc) {
                        logger.warn("Unable to load included template class from name: %s", tcName);
                        continue;
                    }
                    includedTemplateClasses.add(tc);
                }
            }
            for (TemplateClass tc : includedTemplateClasses) {
                if (tc.refresh(forceRefresh)) {
                    includedTemplateChanged = true;
                    break;
                }
            }

            if (extendedTemplateChanged && !forceRefresh) {
                reset();
                compiled = false;
                engine().restart(new ClassReloadException("extended class changed"));
                refreshing(false);
                refresh(forceRefresh);
                return true; // pass refresh state to sub template
            }
            // templateResource.refresh() must be put at first so we make sure resource get refreshed

            boolean resourceChanged = templateResource.refresh();
            boolean refresh = resourceChanged || forceRefresh || (null == javaSource) || includedTemplateChanged || extendedTemplateChanged;
            if (!refresh) return false;

            // now start generate source and compile source to byte code
            reset();
View Full Code Here

TOP

Related Classes of org.rythmengine.resource.ITemplateResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.