View Javadoc
1   /***
2    * Copyright (C) 2008 Jeremy Thomerson (jthomerson@users.sourceforge.net)
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package net.sf.vcaperture.web.models;
18  
19  import net.sf.vcaperture.model.RepoFile;
20  
21  import org.apache.wicket.model.IModel;
22  
23  public class SubdirectoryModel implements IModel {
24  
25      private static final long serialVersionUID = 1L;
26  
27      private final IModel/*<RepoAndPathContext>*/ mContextModel;
28  	private final IModel/*<RepoFile>*/ mRepoFile;
29  	
30  	public SubdirectoryModel(IModel/*<RepoAndPathContext>*/ model, IModel/*<RepoFile>*/ repoFileModel) {
31  		mContextModel = model;
32  		mRepoFile = repoFileModel;
33      }
34  
35  	public Object getObject() {
36  		RepoAndPathContext cont = (RepoAndPathContext) mContextModel.getObject();
37  		RepoFile rf = (RepoFile) mRepoFile.getObject();
38  		if (rf.getRelativePath().startsWith(cont.getRepoFile().getRelativePath())) {
39  			return rf.getRelativePath().substring(cont.getRepoFile().getRelativePath().length());
40  		}
41  		return rf.getRelativePath();
42  	}
43  
44  	public void setObject(Object object) {
45  		throw new UnsupportedOperationException("not supported");
46  	}
47  
48  	public void detach() {
49  		mContextModel.detach();
50  		mRepoFile.detach();
51  	}
52  
53  }