Java tutorial
/******************************************************************************* * Copyright (c) 2009 David Harrison. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl-3.0.html * * Contributors: * David Harrison - initial API and implementation ******************************************************************************/ package com.sfs.whichdoctor.xml.writer.helper; import java.util.Collection; import org.apache.commons.lang.StringUtils; import com.sfs.whichdoctor.beans.SpecialtyBean; import com.sfs.whichdoctor.xml.writer.XmlWriter; /** * The Class SpecialtyXmlHelper. */ public class SpecialtyXmlHelper { /** * Instantiates a new specialty xml helper. */ protected SpecialtyXmlHelper() { throw new UnsupportedOperationException(); } /** * Output the specialty collection as an XML string. * * @param specialties the specialties * * @return the xml string */ public static String getSpecialtiesXml(final Collection<SpecialtyBean> specialties) { final XmlWriter xmlwriter = new XmlWriter(); xmlwriter.writeEntity("specialties"); for (SpecialtyBean specialty : specialties) { xmlwriter.writeEntity("specialty").writeAttribute("GUID", specialty.getGUID()) .writeAttribute("specialtyId", specialty.getId()); if (StringUtils.isNotBlank(specialty.getStatus())) { xmlwriter.writeEntity("status").writeText(specialty.getStatus()).endEntity(); } if (StringUtils.isNotBlank(specialty.getTrainingOrganisation())) { xmlwriter.writeEntity("organisation").writeText(specialty.getTrainingOrganisation()).endEntity(); } if (StringUtils.isNotBlank(specialty.getTrainingProgram())) { xmlwriter.writeEntity("program").writeText(specialty.getTrainingProgram()).endEntity(); } if (specialty.getTrainingProgramYear() > 0) { xmlwriter.writeEntity("curriculumYear").writeText(specialty.getTrainingProgramYear()).endEntity(); } xmlwriter.endEntity(); } xmlwriter.endEntity(); return xmlwriter.getXml(); } }