class SoapDocumentService extends AbstractService implements DocumentService {

	@Override
	public WSDocument[] listDocuments(String sid, long folderId, String fileName) throws Exception {
		User user = validateSession(sid);
		checkReadEnable(user, folderId);

		DocumentDAO docDao = (DocumentDAO) Context.get().getBean(DocumentDAO.class);
		List<Document> docs = docDao.findByFolder(folderId, null);
		if (docs.size() > 1)
			Collections.sort(docs, new Comparator<Document>() {
				@Override
				public int compare(Document o1, Document o2) {
					return o1.getFileName().compareTo(o2.getFileName());
				}
			});

		List<WSDocument> wsDocs = new ArrayList<WSDocument>();
		for (Document doc : docs) {
			try {
				checkPublished(user, doc);
				checkNotArchived(doc);
			} catch (Throwable t) {
				continue;
			}

			if (fileName != null && !FileUtil.matches(doc.getFileName(), new String[] { fileName }, null))
				continue;

			docDao.initialize(doc);
			wsDocs.add(WSUtil.toWSDocument(doc));
		}

		return wsDocs.toArray(new WSDocument[0]);
	}

}