KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > meshcms > util > XStreamPathConverter


1 /*
2  * MeshCMS - A simple CMS based on SiteMesh
3  * Copyright (C) 2004-2007 Luciano Vernaschi
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  * You can contact the author at http://www.cromoteca.com
20  * and at info@cromoteca.com
21  */

22
23 package org.meshcms.util;
24
25 import com.thoughtworks.xstream.converters.basic.*;
26
27 /**
28  * Allows to save instances of {@link Path} using XStream.
29  */

30 public class XStreamPathConverter extends AbstractSingleValueConverter {
31   private boolean prependSlash;
32
33   public Object JavaDoc fromString(String JavaDoc string) {
34     return new Path(string);
35   }
36
37   public boolean canConvert(Class JavaDoc aClass) {
38     return aClass.equals(Path.class);
39   }
40
41   public String JavaDoc toString(Object JavaDoc obj) {
42     return prependSlash ? ((Path) obj).getAsLink() : obj.toString();
43   }
44
45   /**
46    * @return the current type of string (with or without prepended slash).
47    */

48   public boolean isPrependSlash() {
49     return prependSlash;
50   }
51
52   /**
53    * Defines the type of string that will be used to save (with or without
54    * prepended slash).
55    *
56    * @param prependSlash if to prepend or not the slah
57    */

58   public void setPrependSlash(boolean prependSlash) {
59     this.prependSlash = prependSlash;
60   }
61 }
62
Popular Tags