String albumName = attributes.getValue(ALBUM_NAME_ATTRIBUTE);
String albumId = attributes.getValue(ALBUM_ID_ATTRIBUTE);
if (albumName != null && albumId != null) {
Locator locator = pipeline.getPipelineContext().getCurrentLocator();
XMLPipelineException e =
new XMLPipelineException(
"not allowed to use both album and album-id attributes",
locator);
getTargetProcess(pipeline).fatalError(e);
return null;
}
if (albumName != null) {
if (userId == null) {
Locator locator = pipeline.getPipelineContext().getCurrentLocator();
XMLPipelineException e =
new XMLPipelineException(
"not allowed to use album attribute without specifying user-id attribute",
locator);
getTargetProcess(pipeline).fatalError(e);
return null;
}
hrefAttr.append(MessageFormat.format(
PICASA_ALBUM_NAME_FRAGMENT, albumName));
} else if (albumId != null) {
if (userId == null) {
Locator locator = pipeline.getPipelineContext().getCurrentLocator();
XMLPipelineException e =
new XMLPipelineException(
"not allowed to use album-id attribute without specifying user-id attribute",
locator);
getTargetProcess(pipeline).fatalError(e);
return null;
}
hrefAttr.append(MessageFormat.format(
PICASA_ALBUM_ID_FRAGMENT, albumId));
}
String photoId = attributes.getValue(PHOTO_ID_ATTRIBUTE);
if (photoId != null) {
if (albumName == null && albumId == null) {
Locator locator = pipeline.getPipelineContext().getCurrentLocator();
XMLPipelineException e =
new XMLPipelineException(
"not allowed to use photo-id attribute without specifying album or album-id attribute",
locator);
getTargetProcess(pipeline).fatalError(e);
return null;
}
hrefAttr.append(MessageFormat.format(
PICASA_PHOTO_ID_FRAGMENT, photoId));
} else {
queryString.append(PICASA_KIND_PHOTO_FRAGMENT);
}
// tags restriction/constraint can be user-, album- or photo-based
String tags = attributes.getValue(TAGS_ATTRIBUTE);
if (tags != null) {
// convert space separated list to comma separated list
String commaSeparatedTags = tags.trim().replaceAll("\\s+", ",");
if (!"".equals(queryString)) {
queryString.append("&");
}
queryString.append(MessageFormat.format(
PICASA_TAG_FRAGMENT, commaSeparatedTags));
} else if (attributes.getValue(QUERY_ATTRIBUTE) != null) {
if (!"".equals(queryString)) {
queryString.append("&");
}
queryString.append(MessageFormat.format(
PICASA_QUERY_FRAGMENT,
attributes.getValue(QUERY_ATTRIBUTE)));
}
// pagination parameters
String pageSize = attributes.getValue(PAGE_SIZE_ATTRIBUTE);
String pageIndex = attributes.getValue(PAGE_INDEX_ATTRIBUTE);
if (pageSize != null) {
Integer pageSizeInt = null;
try {
pageSizeInt = Integer.parseInt(pageSize);
} catch(NumberFormatException nfe) {
Locator locator = pipeline.getPipelineContext().getCurrentLocator();
XMLPipelineException e =
new XMLPipelineException(
"page-size attribute should be of integer value",
locator);
getTargetProcess(pipeline).fatalError(e);
return null;
}
if (pageSizeInt < 1 || pageSizeInt > 500) {
Locator locator = pipeline.getPipelineContext().getCurrentLocator();
XMLPipelineException e =
new XMLPipelineException(
"page-size attribute value should be in the range of [1,500]",
locator);
getTargetProcess(pipeline).fatalError(e);
return null;
}
pageSize = pageSizeInt.toString();
} else {
pageSize = DEFAULT_PAGE_SIZE;
}
if (!"".equals(queryString)) {
queryString.append("&");
}
queryString.append(MessageFormat.format(
PICASA_MAX_RESULTS_FRAGMENT, pageSize));
if (pageIndex != null) {
Integer pageIndexInt = null;
try {
pageIndexInt = Integer.parseInt(pageIndex);
} catch(NumberFormatException nfe) {
Locator locator = pipeline.getPipelineContext().getCurrentLocator();
XMLPipelineException e =
new XMLPipelineException(
"page-index attribute should be of integer value",
locator);
getTargetProcess(pipeline).fatalError(e);
return null;
}
if (pageIndexInt < 1) {
Locator locator = pipeline.getPipelineContext().getCurrentLocator();
XMLPipelineException e =
new XMLPipelineException(
"page-index attribute value should be in the range of [1,...]",
locator);
getTargetProcess(pipeline).fatalError(e);
return null;
}