本文整理汇总了Java中org.restlet.representation.Representation类的典型用法代码示例。如果您正苦于以下问题:Java Representation类的具体用法?Java Representation怎么用?Java Representation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Representation类属于org.restlet.representation包,在下文中一共展示了Representation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: handleHeadAndGet
import org.restlet.representation.Representation; //导入依赖的package包/类
@Get() // @Get is required for both GET and HEAD requests
public Representation handleHeadAndGet() {
String path = getReference().getPath();
String dbname = getDatabaseName(path);
if (!dbNameExists(dbname)) {
return databaseNotFound();
}
else if (path.contains("/_local/")) {
return handleLocalGet(path, dbname);
}
else if (path.contains("/_changes/")) {
return handleChangesGet(path);
} else {
if (Method.HEAD.equals(getMethod())) {
return httpSuccess();
} else {
return lastSequence(dbname);
}
}
}
示例3: put
import org.restlet.representation.Representation; //导入依赖的package包/类
@Override
@Put("json")
public Representation put(Representation entity) {
try {
String jsonRequest = entity.getText();
TopicPartition topicPartitionInfo = TopicPartition.init(jsonRequest);
if (_autoTopicWhitelistingManager != null) {
_autoTopicWhitelistingManager.removeFromBlacklist(topicPartitionInfo.getTopic());
}
if (_helixMirrorMakerManager.isTopicExisted(topicPartitionInfo.getTopic())) {
_helixMirrorMakerManager.expandTopicInMirrorMaker(topicPartitionInfo);
return new StringRepresentation(
String.format("Successfully expand topic: %s", topicPartitionInfo));
} else {
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
return new StringRepresentation(String.format(
"Failed to expand topic, topic: %s is not existed!", topicPartitionInfo.getTopic()));
}
} catch (IOException e) {
LOGGER.error("Got error during processing Put request", e);
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
return new StringRepresentation(
String.format("Failed to expand topic, with exception: %s", e));
}
}
示例4: getRepresentationsComparator
import org.restlet.representation.Representation; //导入依赖的package包/类
/**
* Allows to sort the list of representations set by the resource.
*
* @return A Comparator instance imposing a sort order of representations or
* null if no special order is wanted.
*/
private Comparator<Representation> getRepresentationsComparator() {
// Sort the list of representations by their identifier.
Comparator<Representation> identifiersComparator = new Comparator<Representation>() {
public int compare(Representation rep0, Representation rep1) {
boolean bRep0Null = (rep0.getLocationRef() == null);
boolean bRep1Null = (rep1.getLocationRef() == null);
if (bRep0Null && bRep1Null) {
return 0;
}
if (bRep0Null) {
return -1;
}
if (bRep1Null) {
return 1;
}
return rep0.getLocationRef().getLastSegment()
.compareTo(rep1.getLocationRef().getLastSegment());
}
};
return identifiersComparator;
}
示例5: options
import org.restlet.representation.Representation; //导入依赖的package包/类
/**
* Indicates the communication options available for this resource. This
* method is only invoked if content negotiation has been disabled as
* indicated by the {@link #isNegotiated()}, otherwise the
* {@link #options(Variant)} method is invoked.<br>
* <br>
* The default behavior is to set the response status to
* {@link Status#CLIENT_ERROR_METHOD_NOT_ALLOWED}.
*
* @return The optional response entity.
*/
protected Representation options() throws ResourceException {
Representation result = null;
MethodAnnotationInfo annotationInfo;
try {
annotationInfo = getAnnotation(Method.OPTIONS);
// Updates the list of allowed methods
updateAllowedMethods();
if (annotationInfo != null) {
result = doHandle(annotationInfo, null);
} else {
doError(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
}
} catch (IOException e) {
throw new ResourceException(e);
}
return result;
}
示例6: Request
import org.restlet.representation.Representation; //导入依赖的package包/类
/**
* Constructor.
*
* @param method
* The call's method.
* @param resourceRef
* The resource reference.
* @param entity
* The entity.
*/
public Request(Method method, Reference resourceRef, Representation entity) {
super(entity);
this.accessControlRequestHeaders = null;
this.accessControlRequestMethod = null;
this.challengeResponse = null;
this.clientInfo = null;
this.conditions = null;
this.cookies = null;
this.hostRef = null;
this.loggable = true;
this.maxForwards = -1;
this.method = method;
this.originalRef = null;
this.onResponse = null;
this.proxyChallengeResponse = null;
this.protocol = null;
this.ranges = null;
this.referrerRef = null;
this.resourceRef = resourceRef;
this.rootRef = null;
}
示例7: delete
import org.restlet.representation.Representation; //导入依赖的package包/类
@Override
@Delete
public Representation delete() {
final String topicName = (String) getRequest().getAttributes().get("topicName");
if (_autoTopicWhitelistingManager != null) {
_autoTopicWhitelistingManager.addIntoBlacklist(topicName);
}
if (!_helixMirrorMakerManager.isTopicExisted(topicName)) {
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
return new StringRepresentation(
String.format("Failed to delete not existed topic: %s", topicName));
}
try {
_helixMirrorMakerManager.deleteTopicInMirrorMaker(topicName);
return new StringRepresentation(
String.format("Successfully finished delete topic: %s", topicName));
} catch (Exception e) {
getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
LOGGER.error("Failed to delete topic: {}, with exception: {}", topicName, e);
return new StringRepresentation(
String.format("Failed to delete topic: %s, with exception: %s", topicName, e));
}
}
示例8: getText
import org.restlet.representation.Representation; //导入依赖的package包/类
/**
* Converts the representation to a string value. Be careful when using this
* method as the conversion of large content to a string fully stored in
* memory can result in OutOfMemoryErrors being thrown.
*
* @param representation
* The representation to convert.
* @return The representation as a string value.
*/
public static String getText(Representation representation)
throws IOException {
String result = null;
if (representation.isAvailable()) {
if (representation.getSize() == 0) {
result = "";
} else {
java.io.StringWriter sw = new java.io.StringWriter();
representation.write(sw);
sw.flush();
result = sw.toString();
}
}
return result;
}
示例9: get
import org.restlet.representation.Representation; //导入依赖的package包/类
@Override
@Get
public Representation get() {
final String option = (String) getRequest().getAttributes().get("option");
if ("srcKafka".equals(option)) {
if (_srcKafkaValidationManager == null) {
LOGGER.warn("SourceKafkaClusterValidationManager is null!");
return new StringRepresentation("SrcKafkaValidationManager is not been initialized!");
}
LOGGER.info("Trying to call validation on source kafka cluster!");
return new StringRepresentation(_srcKafkaValidationManager.validateSourceKafkaCluster());
} else {
LOGGER.info("Trying to call validation on current cluster!");
return new StringRepresentation(_validationManager.validateExternalView());
}
}
示例10: transform
import org.restlet.representation.Representation; //导入依赖的package包/类
/**
* Transforms a source XML representation by applying an XSLT transform
* sheet to it.
*
* @param source
* The source XML representation.
* @return The generated result representation.
*/
public Representation transform(Representation source) {
final Representation result = new TransformRepresentation(getContext(),
source, getTransformSheet());
if (this.resultLanguages != null) {
result.getLanguages().addAll(getResultLanguages());
}
result.setCharacterSet(getResultCharacterSet());
if (this.resultEncodings != null) {
result.getEncodings().addAll(getResultEncodings());
}
result.setMediaType(getResultMediaType());
return result;
}
示例11: getSchemaLanguageUri
import org.restlet.representation.Representation; //导入依赖的package包/类
/**
* Returns the schema URI for the current schema media type.
*
* @return The schema URI.
*/
private static String getSchemaLanguageUri(
Representation schemaRepresentation) {
String result = null;
if (schemaRepresentation != null) {
if (MediaType.APPLICATION_W3C_SCHEMA.equals(schemaRepresentation
.getMediaType())) {
result = XMLConstants.W3C_XML_SCHEMA_NS_URI;
} else if (MediaType.APPLICATION_RELAXNG_COMPACT
.equals(schemaRepresentation.getMediaType())) {
result = XMLConstants.RELAXNG_NS_URI;
} else if (MediaType.APPLICATION_RELAXNG_XML
.equals(schemaRepresentation.getMediaType())) {
result = XMLConstants.RELAXNG_NS_URI;
}
}
return result;
}
示例12: getBestHelper
import org.restlet.representation.Representation; //导入依赖的package包/类
/**
* Returns the best converter helper matching the given parameters.
*
* @param <T>
* The target class.
* @param source
* The source representation variant.
* @param target
* The target class.
* @param resource
* The parent resource.
* @return The matched converter helper or null.
*/
public static <T> ConverterHelper getBestHelper(Representation source,
Class<T> target, Resource resource) {
ConverterHelper result = null;
float bestScore = -1.0F;
float currentScore;
for (ConverterHelper ch : Engine.getInstance()
.getRegisteredConverters()) {
if (ch != null) {
currentScore = ch.score(source, target, resource);
if (currentScore > bestScore) {
bestScore = currentScore;
result = ch;
}
}
}
return result;
}
示例13: handleInbound
import org.restlet.representation.Representation; //导入依赖的package包/类
/**
* Handles the inbound call. Note that only synchronous calls are processed.
*
* @param response
* @return The response's entity, if any.
*/
public Representation handleInbound(Response response) {
if (response == null) {
return null;
}
// Verify that the request was synchronous
if (response.getRequest().isSynchronous()) {
if (response.getStatus().isError()) {
doError(response.getStatus());
return null;
}
return response.getEntity();
}
return null;
}
示例14: toObject
import org.restlet.representation.Representation; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T toObject(Representation source, Class<T> target,
Resource resource) throws IOException {
JaxbRepresentation<?> jaxbSource = null;
if (source instanceof JaxbRepresentation) {
jaxbSource = (JaxbRepresentation<?>) source;
} else {
jaxbSource = new JaxbRepresentation<T>(source, target);
}
T result = null;
if (target == null) {
result = (T) jaxbSource.getObject();
} else if (JaxbRepresentation.class.isAssignableFrom(target)) {
result = target.cast(jaxbSource);
} else if (isJaxbRootElementClass(target)) {
result = target.cast(jaxbSource.getObject());
}
return result;
}
示例15: toRepresentation
import org.restlet.representation.Representation; //导入依赖的package包/类
@Override
public Representation toRepresentation(Object source, Variant target,
Resource resource) throws IOException {
if (source instanceof TemplateResolution) {
Locale locale = getLocale(resource);
TemplateRepresentation tr = new TemplateRepresentation(
((TemplateResolution) source).getTemplateResource().getBaseName(), locale,
target.getMediaType());
tr.setDataModel(resource.getRequest(), resource.getResponse());
return tr;
}
return null;
}