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


Java Representation.getReader方法代码示例

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


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

示例1: getTemplate

import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
 * Returns a FreeMarker template from a representation and a configuration.
 * 
 * @param config
 *            The FreeMarker configuration.
 * @param templateRepresentation
 *            The template representation.
 * @return The template or null if not found.
 */
public static Template getTemplate(Configuration config,
        Representation templateRepresentation) {
    try {
        // Instantiate the template with the character set of the template
        // representation if it has been set, otherwise use UTF-8.
        if (templateRepresentation.getCharacterSet() != null) {
            return new Template("template",
                    templateRepresentation.getReader(), config,
                    templateRepresentation.getCharacterSet().getName());
        }

        return new Template("template", templateRepresentation.getReader(),
                config, CharacterSet.UTF_8.getName());
    } catch (IOException e) {
        Context.getCurrentLogger().warn(
                "Unable to get the template from the representation " + templateRepresentation.getLocationRef(), e);
        return null;
    }
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:29,代码来源:TemplateRepresentation.java

示例2: ReferenceList

import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
 * Constructor from a "text/uri-list" representation.
 * 
 * @param uriList
 *            The "text/uri-list" representation to parse.
 * @throws IOException
 */
public ReferenceList(Representation uriList) throws IOException {
    BufferedReader br = null;
    try {
        br = new BufferedReader(uriList.getReader(), IoUtils.BUFFER_SIZE);

        String line = br.readLine();

        // Checks if the list reference is specified as the first comment.
        if ((line != null) && line.startsWith("#")) {
            setIdentifier(new Reference(line.substring(1).trim()));
            line = br.readLine();
        }

        while (line != null) {
            if (!line.startsWith("#")) {
                add(new Reference(line.trim()));
            }

            line = br.readLine();
        }
    } finally {
        if (br != null) {
            br.close();
        }
    }
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:34,代码来源:ReferenceList.java

示例3: toSaxSource

import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
 * Wraps a source representation into a {@link SAXSource}. This method can
 * detect other {@link XmlRepresentation} instances to use their
 * {@link XmlRepresentation#getSaxSource()} method as well as other
 * {@link TransformRepresentation} instances to support transformation
 * chaining.
 * 
 * @param representation
 *            The source representation.
 * @return The SAX source.
 * @throws IOException
 */
public static SAXSource toSaxSource(Representation representation)
        throws IOException {
    SAXSource result = null;

    if (representation instanceof XmlRepresentation) {
        result = ((XmlRepresentation) representation).getSaxSource();
    } else if (representation instanceof TransformRepresentation) {
        final TransformRepresentation source = (TransformRepresentation) representation;
        XMLReader reader = new AbstractXmlReader() {

            /**
             * Parses the input source by sending the result event to the
             * XML reader's content handler.
             * 
             * @param input
             *            The input source.
             */
            public void parse(InputSource input) throws IOException,
                    SAXException {
                try {
                    source.getTransformer().transform(
                            source.getSaxSource(),
                            new SAXResult(getContentHandler()));
                } catch (TransformerException te) {
                    throw new IOException("Transformer exception. "
                            + te.getMessage());
                }
            }

            public void parse(String systemId) throws IOException,
                    SAXException {
                throw new IllegalStateException("Not implemented");
            }
        };

        result = new SAXSource(reader, new InputSource(
                representation.getReader()));
    } else {
        // Prepare the source and result documents
        result = new SAXSource(new InputSource(representation.getReader()));
    }

    // Copy the representation's URI as an XML system ID.
    if (representation.getLocationRef() != null) {
        result.setSystemId(representation.getLocationRef().getTargetRef()
                .toString());
    }

    return result;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:63,代码来源:TransformRepresentation.java


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