001/*
002 * (C) Copyright 2007 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 * $Id$
020 */
021
022package org.nuxeo.ecm.platform.api.ws;
023
024import java.io.Serializable;
025
026import org.nuxeo.ecm.core.api.DocumentModel;
027import org.nuxeo.ecm.core.api.PropertyException;
028
029/**
030 * Web service base document descriptor.
031 * <p>
032 * The document descriptor contains minimal information about a document as needed by a client to display it and
033 * navigate through the repository tree.
034 * <p>
035 * The descriptor exposes:
036 * <ul>
037 * <li>the document UUID
038 * <li>the document type
039 * <li>the document title
040 * </ul>
041 * <p>
042 * In the case of version document versions the title is the version label
043 *
044 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
045 */
046public class DocumentDescriptor implements Serializable {
047
048    private static final long serialVersionUID = 1L;
049
050    private String id;
051
052    private String title;
053
054    private String type;
055
056    /**
057     * Emtpy ctor needed by tools like jaxb.
058     */
059    public DocumentDescriptor() {
060    }
061
062    public DocumentDescriptor(DocumentModel doc) {
063        try {
064            title = (String) doc.getProperty("dublincore", "title");
065        } catch (PropertyException e) {
066            title = null;
067        }
068        if (title == null) {
069            title = doc.getName();
070        }
071        id = doc.getId();
072        type = doc.getType();
073    }
074
075    public DocumentDescriptor(DocumentModel doc, String title) {
076        this.title = title;
077        id = doc.getId();
078        type = doc.getType();
079    }
080
081    public String getTitle() {
082        return title;
083    }
084
085    public String getType() {
086        return type;
087    }
088
089    public String getUUID() {
090        return id;
091    }
092
093    /**
094     * @param title the title to set.
095     */
096    public void setTitle(String title) {
097        this.title = title;
098    }
099
100    /**
101     * @param uuid the uuid to set.
102     */
103    public void setUUID(String uuid) {
104        id = uuid;
105    }
106
107    /**
108     * @param type the type to set.
109     */
110    public void setType(String type) {
111        this.type = type;
112    }
113
114    public String getId() {
115        return id;
116    }
117
118    public void setId(String id) {
119        this.id = id;
120    }
121
122}