Package com.alibaba.citrus.util.templatelite

Examples of com.alibaba.citrus.util.templatelite.Template$TextBuffer


        this.componentName = name.toString();

        URL templateResource = assertNotNull(getClass().getResource(name + ".htm"),
                                             "Could not find template for page component class: %s", className);

        template = new Template(templateResource);
    }
View Full Code Here


        String contentType = defaultIfNull(contentTypes.get(ext), DEFAULT_CONTENT_TYPE);

        if (!template) {
            io(resource.openStream(), request.getOutputStream(contentType), true, true);
        } else {
            Template tpl = new Template(resource);
            PrintWriter out = request.getWriter(contentType);

            // 对于模板文件中,${url:relativeUrl}将被转换成完整的URL
            tpl.accept(new TextWriter<PrintWriter>(out) {
                @SuppressWarnings("unused")
                public void visitUrl(String relativeUrl) {
                    out().print(request.getResourceURL(relativeUrl));
                }
            });
View Full Code Here

            super(out);
            this.value = value;
        }

        private void visitStyledValue(Template[] styledTextTemplates) {
            Template template;

            // 纯文本
            if (value instanceof TextValue) {
                template = styledTextTemplates[0];
                context().put("value", value.getText());

                template.accept(this);
            }

            // raw data
            else if (value instanceof RawValue) {
                template = styledTextTemplates[1];
                context().put("packageName", ((RawValue) value).getRawType().getPackage().getName());
                context().put("className", ClassUtil.getSimpleClassName(((RawValue) value).getRawType()));
                context().put("value", ((RawValue) value).getRawToString());

                template.accept(this);
            }

            // class name
            else if (value instanceof ClassValue) {
                template = styledTextTemplates[2];
                context().put("packageName", ((ClassValue) value).getPackageName());
                context().put("className", ((ClassValue) value).getSimpleName());

                template.accept(this);
            }

            // anchor
            else if (value instanceof AnchorValue) {
                template = styledTextTemplates[3];

                int i = 0;
                for (String name : ((AnchorValue) value).getNames()) {
                    context().put("anchorName", toId(name));
                    context().put("anchorNameDisplay", name);
                    this.withSep = i++ > 0;

                    template.accept(this);
                }
            }

            // ref to anchor
            else if (value instanceof RefValue) {
                template = styledTextTemplates[4];

                int i = 0;
                for (String name : ((RefValue) value).getNames()) {
                    context().put("refName", toId(name));
                    context().put("refNameDisplay", name);
                    this.withSep = i++ > 0;

                    template.accept(this);
                }
            }

            // unknown value
            else {
View Full Code Here

            super(out);
            this.value = value;
        }

        private void visitStyledValue(Template[] styledTextTemplates) {
            Template template;

            // ���ı�
            if (value instanceof TextValue) {
                template = styledTextTemplates[0];
                context().put("value", value.getText());

                template.accept(this);
            }

            // raw data
            else if (value instanceof RawValue) {
                template = styledTextTemplates[1];
                context().put("packageName", ((RawValue) value).getRawType().getPackage().getName());
                context().put("className", ClassUtil.getSimpleClassName(((RawValue) value).getRawType()));
                context().put("value", ((RawValue) value).getRawToString());

                template.accept(this);
            }

            // class name
            else if (value instanceof ClassValue) {
                template = styledTextTemplates[2];
                context().put("packageName", ((ClassValue) value).getPackageName());
                context().put("className", ((ClassValue) value).getSimpleName());

                template.accept(this);
            }

            // anchor
            else if (value instanceof AnchorValue) {
                template = styledTextTemplates[3];

                int i = 0;
                for (String name : ((AnchorValue) value).getNames()) {
                    context().put("anchorName", toId(name));
                    context().put("anchorNameDisplay", name);
                    this.withSep = i++ > 0;

                    template.accept(this);
                }
            }

            // ref to anchor
            else if (value instanceof RefValue) {
                template = styledTextTemplates[4];

                int i = 0;
                for (String name : ((RefValue) value).getNames()) {
                    context().put("refName", toId(name));
                    context().put("refNameDisplay", name);
                    this.withSep = i++ > 0;

                    template.accept(this);
                }
            }

            // unknown value
            else {
View Full Code Here

        this.componentName = name.toString();

        URL templateResource = assertNotNull(getClass().getResource(name + ".htm"),
                "Could not find template for page component class: %s", className);

        template = new Template(templateResource);
    }
View Full Code Here

        String contentType = defaultIfNull(contentTypes.get(ext), DEFAULT_CONTENT_TYPE);

        if (!template) {
            io(resource.openStream(), request.getOutputStream(contentType), true, true);
        } else {
            Template tpl = new Template(resource);
            PrintWriter out = request.getWriter(contentType);

            // ����ģ���ļ��У�${url:relativeUrl}����ת����������URL
            tpl.accept(new TextWriter<PrintWriter>(out) {
                @SuppressWarnings("unused")
                public void visitUrl(String relativeUrl) {
                    out().print(request.getResourceURL(relativeUrl));
                }
            });
View Full Code Here

TOP

Related Classes of com.alibaba.citrus.util.templatelite.Template$TextBuffer

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.