1 // Copyright 2011 Google Inc. All Rights Reserved.
3 package com
.google
.appengine
.api
.conversion
;
5 import com
.google
.common
.base
.Preconditions
;
6 import com
.google
.common
.base
.StringUtil
;
11 * Utility methods to validate data structures.
14 class ConversionHelper
{
16 private ConversionHelper() {
20 * Validates the size of document is not over limit, returns itself if the
23 * @throws IllegalArgumentException if the size of document is over limit
25 static Document
validateDocumentSize(Document document
) {
26 Preconditions
.checkNotNull(document
);
28 for (Asset asset
: document
.getAssets()) {
29 size
+= asset
.getData().length
;
31 Preconditions
.checkArgument(size
<= ConversionService
.CONVERSION_MAX_SIZE_BYTES
,
32 String
.format("Each conversion should not be over %d bytes.",
33 ConversionService
.CONVERSION_MAX_SIZE_BYTES
));
38 * Validates the document can be used as input for a conversion, returns
39 * itself if the validation passes.
41 * @throws IllegalArgumentException if additional asset name is null, empty
42 * or comprises only whitespace characters
44 static Document
validateInputDoc(Document document
) {
45 Preconditions
.checkNotNull(document
);
46 List
<Asset
> assets
= document
.getAssets();
47 for (Asset asset
: assets
.subList(1, assets
.size())) {
48 Preconditions
.checkArgument(!StringUtil
.isEmptyOrWhitespace(asset
.getName()),
49 "Additional asset name should not be null, empty or comprises only whitespaces");