Statistics
| Revision:

root / branches / v10 / extensions / extPublish / src / org / gvsig / publish / ProjectPublication.java @ 16634

History | View | Annotate | Download (6.12 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004-2006 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *   Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Iba?ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.publish;
42

    
43
import org.gvsig.publish.gui.addResource.AddResourceController;
44
import org.gvsig.publish.gui.publish.PublishController;
45
import org.gvsig.publish.gui.selectServer.SelectServerController;
46
import org.gvsig.publish.infoproject.IProjectInfo;
47
import org.gvsig.publish.infoproject.ProjectInfoFactory;
48
import org.gvsig.publish.serversmodel.Publication;
49

    
50
import com.iver.andami.ui.mdiManager.IWindow;
51
import com.iver.cit.gvsig.fmap.DriverException;
52
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
53
import com.iver.cit.gvsig.fmap.layers.XMLException;
54
import com.iver.cit.gvsig.project.Project;
55
import com.iver.cit.gvsig.project.documents.ProjectDocument;
56
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
57
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
58
import com.iver.cit.gvsig.project.documents.table.ProjectTableFactory;
59
import com.iver.utiles.XMLEntity;
60

    
61
public class ProjectPublication extends ProjectDocument {
62
        /*
63
         * Dependences
64
         */
65
        private Publication publication = null;
66
        private PublishController publishCtrl = null;
67
        private AddResourceController addResourceCtrl = null;
68
        private SelectServerController slcSrvCtrl = null;
69
                        
70
        /**
71
         * Creates all the controllers and sets the relations
72
         * @see ProjectDocument#setProject(Project, int)
73
         */
74
        public void setProject(Project project, int index) {
75
                super.setProject(project, index);
76
                //super.setName("publication");
77
                //creates the publication an sets the project info
78
                publication = new Publication();                 
79
                IProjectInfo projectInfo = ProjectInfoFactory.getProjectInfo(project);
80
                publication.setProjectInfo(projectInfo);
81
                
82
                //Creates the controllers
83
                addResourceCtrl = new AddResourceController();
84
                publishCtrl = new PublishController();
85
                slcSrvCtrl = new SelectServerController();                
86
                
87
                //Add observers
88
                publication.addObserver(publishCtrl);
89
                                
90
                //sets the publication in the controllers
91
                addResourceCtrl.setPublication(publication);
92
                publishCtrl.setPublication(publication);
93
                slcSrvCtrl.setPublication(publication);
94
                                                        
95
        }
96
        /**
97
         * @see ProjectDocument#getXMLEntity()
98
        */
99
        public XMLEntity getXMLEntity() throws SaveException {
100
                XMLEntity xml= super.getXMLEntity();
101
                xml.addChild(publication.getXMLEntity());                
102
                return xml;
103
        }
104
        /**
105
         * @see ProjectDocument#getXMLEntity()
106
         */
107
        public void setXMLEntity(XMLEntity xml) throws XMLException,
108
                        DriverException, DriverIOException, OpenException {
109
                super.setXMLEntity(xml);
110
//                publication=new Publication();
111
                publication.setXMLEntity(xml.getChild(0));
112
                
113
//                if(publication.getServer() == null){
114
//                        addSrvCtrl.showWindow();
115
//                }        
116
        }
117
        
118
        /**
119
         * 
120
         * @return the publication of the document
121
         */
122
        public Publication getPublication(){
123
                return publication;
124
        }
125

    
126
        /**
127
         * The purpose of this method is provide an entry to controller
128
         * through Extension object
129
         * @see PublishExtension#execute(String) 
130
         * 
131
         * @return the "addServeController's publicaction document 
132
         */
133
        public AddResourceController getAddResourceController(){
134
                return addResourceCtrl;
135
        }
136
        /**
137
         * When you add a publication you must select a server
138
         * @see ProjectDocument#afterAdd()
139
         */
140
        public void afterAdd() {                
141
                
142
        }
143
        /**
144
         * @see ProjectDocument#afterRemove()
145
         */
146
        public void afterRemove() {
147
                // TODO Auto-generated method stub
148
                
149
        }
150
        /**
151
         * This method is called when I open the document 
152
         * @return
153
         * @see {@linkProjectDocument#createWindow()}
154
         */
155
        public IWindow createWindow() {
156
                //If the publication is new, I must select the server
157
                if (publication.getServer() == null){
158
                        publishCtrl.showWindow();
159
                        return slcSrvCtrl.getWindow();
160
                }                
161
                return publishCtrl.getWindow();
162
                //return null;
163
        }
164
        /**
165
         * 
166
         * @param root
167
         * @param project
168
         * @throws SaveException
169
         * @see {@link ProjectDocument#exportToXML(XMLEntity, Project)}
170
         */
171
        public void exportToXML(XMLEntity root, Project project)
172
                        throws SaveException {
173
                XMLEntity tableRoot = project.getExportXMLTypeRootNode(root,ProjectTableFactory.registerName);
174
                tableRoot.addChild(this.getXMLEntity());
175
        }
176
        /**
177
         * 
178
         * @return
179
         * @see {@link ProjectDocument#getProperties()}
180
         */
181
        public IWindow getProperties() {
182
                // TODO Auto-generated method stub
183
                return null;
184
        }
185
        /**
186
         * 
187
         * @param root
188
         * @param typeRoot
189
         * @param elementIndex
190
         * @param project
191
         * @param removeDocumentsFromRoot
192
         * @throws XMLException
193
         * @throws DriverException
194
         * @throws OpenException
195
         * @see {@link ProjectDocument#importFromXML(XMLEntity, XMLEntity, int, Project, boolean)}
196
         */  
197
        public void importFromXML(XMLEntity root, XMLEntity typeRoot,
198
                        int elementIndex, Project project, boolean removeDocumentsFromRoot)
199
                        throws XMLException, DriverException, OpenException {
200
                XMLEntity element = typeRoot.getChild(elementIndex);
201
                try {
202
                        this.setXMLEntity(element);
203
                } catch (DriverIOException e) {                        
204
                        PublishLogger.getLog().error("ERROR ProjectPublication: importXML", e);
205
                }
206
                if (removeDocumentsFromRoot) {
207
                        typeRoot.removeChild(elementIndex);
208
                }
209
                project.addDocument(this);
210
                
211
        }
212
}