本文整理汇总了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;
}
}
示例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();
}
}
}
示例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;
}