return cp;
}
private ContentPackage createContent(Document doc) throws ParseException {
ContentPackage cp = null;
// Select root element (PackageContent).
Element pkgContentElem = doc.getDocumentElement();
// Retrieve article object from the package content
BasicArticle ba = this.getArticleFromPkgContent(pkgContentElem);
if (ba != null) {
// Create content package.
cp = new ContentPackage();
cp.setArticle(ba);
if (this.contentContainsPhotoPkg(pkgContentElem)) {
String fileName = ba.getFileName();
PhotoPackage pp = new PhotoPackage();
pp.setCategoryId(ba.getCategoryId());
pp.setCreateBy("Insert process");
// CMS limits photo package "name" to 50 characters.
pp.setDescription(fileName.substring(0, Math.min(fileName.length(), 41)) +
"_" + ba.getStartTimeAsMMDDYYYYString());
pp.setStartTime(ba.getStartTime());
Date startTime = ba.getStartTime();
Calendar cal = Calendar.getInstance();
cal.setTime(startTime);
// Make end time one month later than start time.
cal.add(Calendar.MONTH, 1);
Date endTime = cal.getTime();
pp.setEndTime(endTime);
pp.setKeywords(fileName.substring(0, Math.min(fileName.length(), 100)));
pp.setNational(false);
pp.setPubId(ba.getPubId());
Element photoPkgElem =
this.xmlParseUtils.getSingletonElement(pkgContentElem, "PhotoPackage");
NodeList photoNodes = photoPkgElem.getElementsByTagName("Photo");
int numPhotos = 0;
Photo currentPhoto = null;
if (photoNodes != null) {
numPhotos = photoNodes.getLength();
}
for (int i = 0; i < numPhotos; i++) {
currentPhoto = this.getPhotoFromPhotoElem((Element)photoNodes.item(i));
pp.addPhoto(currentPhoto);
}
cp.setPhotoPackage(pp);
}
}
return cp;
}