class PrintServiceImpl implements PrintService {

	public List<PrintTemplate> getAllTemplates() throws PrintingException {
		List<PrintTemplate> allTemplates = new ArrayList<PrintTemplate>();
		if (printTemplateDao != null) {
			try {
				allTemplates = printTemplateDao.findAll();
			} catch (IOException e) {
				log.warn("could not access templates in dao", e);
			}
		}
		allTemplates.addAll(getDefaults());
		List<PrintTemplate> badTemplates = new ArrayList<PrintTemplate>();
		for (PrintTemplate printTemplate : allTemplates) {
			if (printTemplate.getPage() == null) {
				try {
					Object o = unMarshaller.unmarshal(new StreamSource(new StringReader(printTemplate.getPageXml())));
					printTemplate.setPage((PageComponentImpl) o);
				} catch (Exception e) { // NOSONAR
					badTemplates.add(printTemplate);
				}
			}
		}
		allTemplates.removeAll(badTemplates);
		Collections.sort(allTemplates, new Comparator<PrintTemplate>() {

			public int compare(PrintTemplate p1, PrintTemplate p2) {
				return p1.getName().compareTo(p2.getName());
			}
		});
		return allTemplates;
	}

}