當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。