001/* 002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * matic 016 */ 017package org.nuxeo.ecm.platform.tag.ws; 018 019import java.util.List; 020 021import org.nuxeo.ecm.core.api.CoreSession; 022import org.nuxeo.ecm.core.api.DocumentModel; 023import org.nuxeo.ecm.platform.api.ws.DocumentLoader; 024import org.nuxeo.ecm.platform.api.ws.DocumentProperty; 025import org.nuxeo.ecm.platform.api.ws.session.WSRemotingSession; 026import org.nuxeo.ecm.platform.tag.Tag; 027import org.nuxeo.ecm.platform.tag.TagService; 028import org.nuxeo.runtime.api.Framework; 029 030/** 031 * @author matic 032 */ 033public class TagsLoader implements DocumentLoader { 034 035 @Override 036 public void fillProperties(DocumentModel doc, List<DocumentProperty> props, WSRemotingSession rs) 037 { 038 CoreSession session = rs.getDocumentManager(); 039 TagService srv = Framework.getLocalService(TagService.class); 040 if (srv == null) { 041 return; 042 } 043 List<Tag> tags = srv.getDocumentTags(session, doc.getId(), rs.getUsername()); 044 String value = ""; 045 String sep = ""; 046 for (Tag tag : tags) { 047 value = value + sep + tag.getLabel(); 048 sep = ","; 049 } 050 DocumentProperty prop = new DocumentProperty("tags", value); 051 props.add(prop); 052 } 053 054}