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


Java Representation.isAvailable方法代码示例

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


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

示例1: parse

import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
 * Parses a post into a given entries series.
 * 
 * @param entries
 *            The target entries series.
 * @param post
 *            The posted form.
 */
public static void parse(Series<FormData> entries, Representation post) {
    if (post != null) {
        if (post.isAvailable()) {
            FormReader fr = null;

            try {
                fr = new FormReader(post);
            } catch (IOException ioe) {
                Context.getCurrentLogger().warn("Unable to create a form reader. Parsing aborted.", ioe);
            }

            if (fr != null) {
                fr.addEntries(entries);
            }
        } else {
            throw new IllegalStateException(
                    "The Web form cannot be parsed as no fresh content is available. If this entity has been already read once, caching of the entity is required");
        }
    }
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:29,代码来源:FormUtils.java

示例2: isCompatibleRequestEntity

import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
 * Indicates if the given request entity is compatible with the annotated
 * method described.
 * 
 * @param requestEntity
 *            Optional request entity.
 * @param metadataService
 *            The metadata service to use.
 * @param converterService
 *            The converter service to use.
 * @return True if the given request entity is compatible with the annotated
 *         method described.
 * @throws IOException
 */
public boolean isCompatibleRequestEntity(Representation requestEntity,
        MetadataService metadataService,
        org.restlet.service.ConverterService converterService)
        throws IOException {
    boolean result = true;

    if ((requestEntity != null) && requestEntity.isAvailable()) {
        List<Variant> requestVariants = getRequestVariants(metadataService,
                converterService);

        if ((requestVariants != null) && !requestVariants.isEmpty()) {
            // Check that the compatibility
            result = false;

            for (int i = 0; (!result) && (i < requestVariants.size()); i++) {
                result = (requestVariants.get(i)
                        .isCompatible(requestEntity));
            }
        } else {
            result = false;
        }
    }

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

示例3: parse

import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
 * Parses a post into a given form.
 * 
 * @param form
 *            The target form.
 * @param post
 *            The posted form.
 * @param decode
 *            Indicates if the parameters should be decoded.
 */
public static void parse(Form form, Representation post, boolean decode) {
    if (post != null) {
        if (post.isAvailable()) {
            FormReader fr = null;

            try {
                fr = new FormReader(post, decode);
            } catch (IOException ioe) {
                Context.getCurrentLogger().warn("Unable to create a form reader. Parsing aborted.", ioe);
            }

            if (fr != null) {
                fr.addParameters(form);
            }
        } else {
            Context.getCurrentLogger().debug("The form wasn't changed as the given representation isn't available.");
        }
    }
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:30,代码来源:FormUtils.java

示例4: 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;
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:27,代码来源:IoUtils.java

示例5: addEntityHeaders

import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
 * Adds the entity headers based on the {@link Representation} to the {@link Series}.
 * 
 * @param entity
 *            The source entity {@link Representation}.
 * @param headers
 *            The target headers {@link Series}.
 */
public static void addEntityHeaders(Representation entity,
        Series<Header> headers) {
    if (entity == null || !entity.isAvailable()) {
        addHeader(HeaderConstants.HEADER_CONTENT_LENGTH, "0", headers);
    } else if (entity.getAvailableSize() != Representation.UNKNOWN_SIZE) {
        addHeader(HeaderConstants.HEADER_CONTENT_LENGTH,
                Long.toString(entity.getAvailableSize()), headers);
    }

    if (entity != null) {
        addHeader(HeaderConstants.HEADER_CONTENT_ENCODING,
                EncodingWriter.write(entity.getEncodings()), headers);
        addHeader(HeaderConstants.HEADER_CONTENT_LANGUAGE,
                LanguageWriter.write(entity.getLanguages()), headers);

        if (entity.getLocationRef() != null) {
            addHeader(HeaderConstants.HEADER_CONTENT_LOCATION, entity
                    .getLocationRef().getTargetRef().toString(), headers);
        }

        if (entity.getDigest() != null
                && Digest.ALGORITHM_MD5.equals(entity.getDigest()
                        .getAlgorithm())) {
            addHeader(
                    HeaderConstants.HEADER_CONTENT_MD5,
                    new String(org.restlet.engine.util.Base64.encode(entity
                            .getDigest().getValue(), false)),
                    headers);
        }

        if (entity.getRange() != null) {
            Range range = entity.getRange();
            if (isBytesRange(range)) {
                addHeader(HeaderConstants.HEADER_CONTENT_RANGE,
                        RangeWriter.write(range, entity.getSize()),
                        headers);
            } else {
                addHeader(HeaderConstants.HEADER_CONTENT_RANGE,
                        RangeWriter.write(range, range.getInstanceSize()),
                        headers);
            }
        }

        if (entity.getMediaType() != null) {
            addHeader(HeaderConstants.HEADER_CONTENT_TYPE,
                    ContentType.writeHeader(entity), headers);
        }

        if (entity.getExpirationDate() != null) {
            addHeader(HeaderConstants.HEADER_EXPIRES,
                    DateWriter.write(entity.getExpirationDate()), headers);
        }

        if (entity.getModificationDate() != null) {
            addHeader(HeaderConstants.HEADER_LAST_MODIFIED,
                    DateWriter.write(entity.getModificationDate()), headers);
        }

        if (entity.getTag() != null) {
            addHeader(HeaderConstants.HEADER_ETAG,
                    TagWriter.write(entity.getTag()), headers);
        }

        if (entity.getDisposition() != null
                && !Disposition.TYPE_NONE.equals(entity.getDisposition()
                        .getType())) {
            addHeader(HeaderConstants.HEADER_CONTENT_DISPOSITION,
                    DispositionWriter.write(entity.getDisposition()),
                    headers);
        }
    }
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:81,代码来源:HeaderUtils.java

示例6: toObject

import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
 * Converts a Representation into a regular Java object.
 * 
 * @param <T>
 *            The expected class of the Java object.
 * @param source
 *            The source representation to convert.
 * @param target
 *            The target class of the Java object.
 * @param resource
 *            The parent resource.
 * @return The converted Java object.
 * @throws IOException
 */
public <T> T toObject(Representation source, Class<T> target,
        Resource resource) throws IOException {
    T result = null;
    boolean loggable = (resource == null) ? true : resource.isLoggable();

    if ((source != null) && source.isAvailable() && (source.getSize() != 0)) {
        ConverterHelper ch = ConverterUtils.getBestHelper(source, target,
                resource);

        if (ch != null) {
            if (loggable
                    && Context.getCurrentLogger().isDebugEnabled()) {
                Context.getCurrentLogger().debug(
                        "The following converter was selected for the "
                                + source + " representation: " + ch);
            }

            result = ch.toObject(source, target, resource);

            if (result instanceof Representation) {
                Representation resultRepresentation = (Representation) result;

                // Copy the variant metadata
                resultRepresentation.setCharacterSet(source
                        .getCharacterSet());
                resultRepresentation.setMediaType(source.getMediaType());
                resultRepresentation.getEncodings().addAll(
                        source.getEncodings());
                resultRepresentation.getLanguages().addAll(
                        source.getLanguages());
            }
        } else {
            if (loggable) {
                Context.getCurrentLogger().warn(
                        "Unable to find a converter for this representation : "
                                + source);
            }
        }
    }

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

示例7: getEntries

import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
 * Reads the entries whose name is a key in the given map.<br>
 * If a matching entry is found, its value is put in the map.<br>
 * If multiple values are found, a list is created and set in the map.
 * 
 * @param post
 *            The web form representation.
 * @param entries
 *            The entries map controlling the reading.
 * @throws IOException
 *             If the entries could not be read.
 */
public static void getEntries(Representation post,
        Map<String, Object> entries) throws IOException {
    if (!post.isAvailable()) {
        throw new IllegalStateException(
                "The Web form cannot be parsed as no fresh content is available. If this entity has been already read once, caching of the entity is required");
    }

    new FormReader(post).readEntries(entries);
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:22,代码来源:FormUtils.java

示例8: getEntry

import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
 * Reads the entries with the given name.<br>
 * If multiple values are found, a list is returned created.
 * 
 * @param form
 *            The web form representation.
 * @param name
 *            The name to match.
 * @return The form data or list of values.
 * @throws IOException
 *             If the entries could not be read.
 */
public static Object getEntry(Representation form, String name)
        throws IOException {
    if (!form.isAvailable()) {
        throw new IllegalStateException(
                "The HTML form cannot be parsed as no fresh content is available. If this entity has been already read once, caching of the entity is required");
    }

    return new FormReader(form).readEntry(name);
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:22,代码来源:FormUtils.java

示例9: getFirstEntry

import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
 * Reads the first entry with the given name.
 * 
 * @param post
 *            The web form representation.
 * @param name
 *            The name to match.
 * @return The form data entry.
 * @throws IOException
 */
public static FormData getFirstEntry(Representation post, String name)
        throws IOException {
    if (!post.isAvailable()) {
        throw new IllegalStateException(
                "The Web form cannot be parsed as no fresh content is available. If this entity has been already read once, caching of the entity is required");
    }

    return new FormReader(post).readFirstEntry(name);
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:20,代码来源:FormUtils.java

示例10: getFirstParameter

import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
 * Reads the first parameter with the given name.
 * 
 * @param post
 *            The web form representation.
 * @param name
 *            The parameter name to match.
 * @return The parameter.
 * @throws IOException
 */
public static Parameter getFirstParameter(Representation post, String name)
        throws IOException {
    if (!post.isAvailable()) {
        throw new IllegalStateException(
                "The Web form cannot be parsed as no fresh content is available. If this entity has been already read once, caching of the entity is required");
    }

    return new FormReader(post).readFirstParameter(name);
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:20,代码来源:FormUtils.java

示例11: getParameter

import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
 * Reads the parameters with the given name.<br>
 * If multiple values are found, a list is returned created.
 * 
 * @param form
 *            The web form representation.
 * @param name
 *            The parameter name to match.
 * @return The parameter value or list of values.
 * @throws IOException
 *             If the parameters could not be read.
 */
public static Object getParameter(Representation form, String name)
        throws IOException {
    if (!form.isAvailable()) {
        throw new IllegalStateException(
                "The Web form cannot be parsed as no fresh content is available. If this entity has been already read once, caching of the entity is required");
    }

    return new FormReader(form).readParameter(name);
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:22,代码来源:FormUtils.java

示例12: getParameters

import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
 * Reads the parameters whose name is a key in the given map.<br>
 * If a matching parameter is found, its value is put in the map.<br>
 * If multiple values are found, a list is created and set in the map.
 * 
 * @param post
 *            The web form representation.
 * @param parameters
 *            The parameters map controlling the reading.
 * @throws IOException
 *             If the parameters could not be read.
 */
public static void getParameters(Representation post,
        Map<String, Object> parameters) throws IOException {
    if (!post.isAvailable()) {
        throw new IllegalStateException(
                "The Web form cannot be parsed as no fresh content is available. If this entity has been already read once, caching of the entity is required");
    }

    new FormReader(post).readParameters(parameters);
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:22,代码来源:FormUtils.java


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