KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lowagie > text > xml > xmp > XmpSchema


1 /*
2  * $Id: XmpSchema.java 2749 2007-05-15 12:09:43Z blowagie $
3  * $Name$
4  *
5  * Copyright 2005 by Bruno Lowagie.
6  *
7  * The contents of this file are subject to the Mozilla Public License Version 1.1
8  * (the "License"); you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the License.
14  *
15  * The Original Code is 'iText, a free JAVA-PDF library'.
16  *
17  * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
18  * the Initial Developer are Copyright (C) 1999-2005 by Bruno Lowagie.
19  * All Rights Reserved.
20  * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
21  * are Copyright (C) 2000-2005 by Paulo Soares. All Rights Reserved.
22  *
23  * Contributor(s): all the names of the contributors are added in the source code
24  * where applicable.
25  *
26  * Alternatively, the contents of this file may be used under the terms of the
27  * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
28  * provisions of LGPL are applicable instead of those above. If you wish to
29  * allow use of your version of this file only under the terms of the LGPL
30  * License and not to allow others to use your version of this file under
31  * the MPL, indicate your decision by deleting the provisions above and
32  * replace them with the notice and other provisions required by the LGPL.
33  * If you do not delete the provisions above, a recipient may use your version
34  * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Library General Public License as published by the Free Software Foundation;
39  * either version 2 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
43  * FOR A PARTICULAR PURPOSE. See the GNU LIBRARY GENERAL PUBLIC LICENSE for more
44  * details.
45  *
46  * If you didn't download this code from the following link, you should check if
47  * you aren't using an obsolete version:
48  * http://www.lowagie.com/iText/
49  */

50
51 package com.lowagie.text.xml.xmp;
52
53 import java.util.Enumeration JavaDoc;
54 import java.util.Properties JavaDoc;
55
56 /**
57  * Abstract superclass of the XmpSchemas supported by iText.
58  */

59 public abstract class XmpSchema extends Properties JavaDoc {
60     
61     /** the namesspace */
62     protected String JavaDoc xmlns;
63     
64     /** Constructs an XMP schema.
65      * @param xmlns
66      */

67     public XmpSchema(String JavaDoc xmlns) {
68         super();
69         this.xmlns = xmlns;
70     }
71     /**
72      * The String representation of the contents.
73      * @return a String representation.
74      */

75     public String JavaDoc toString() {
76         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
77         for (Enumeration JavaDoc e = this.propertyNames(); e.hasMoreElements(); ) {
78             process(buf, e.nextElement());
79         }
80         return buf.toString();
81     }
82     /**
83      * Processes a property
84      * @param buf
85      * @param p
86      */

87     protected void process(StringBuffer JavaDoc buf, Object JavaDoc p) {
88         buf.append('<');
89         buf.append(p);
90         buf.append('>');
91         buf.append(this.get(p));
92         buf.append("</");
93         buf.append(p);
94         buf.append('>');
95     }
96     /**
97      * @return Returns the xmlns.
98      */

99     public String JavaDoc getXmlns() {
100         return xmlns;
101     }
102     
103     /**
104      * @param key
105      * @param value
106      * @return the previous property (null if there wasn't one)
107      */

108     public synchronized Object JavaDoc addProperty(String JavaDoc key, String JavaDoc value) {
109         return this.setProperty(key, value);
110     }
111     
112     /**
113      * @see java.util.Properties#setProperty(java.lang.String, java.lang.String)
114      */

115     public synchronized Object JavaDoc setProperty(String JavaDoc key, String JavaDoc value) {
116         return super.setProperty(key, escape(value));
117     }
118     
119     /**
120      * @see java.util.Properties#setProperty(java.lang.String, java.lang.String)
121      *
122      * @param key
123      * @param value
124      * @return the previous property (null if there wasn't one)
125      */

126     public synchronized Object JavaDoc setProperty(String JavaDoc key, XmpArray value) {
127         return super.setProperty(key, value.toString());
128     }
129     
130     /**
131      * @see java.util.Properties#setProperty(java.lang.String, java.lang.String)
132      *
133      * @param key
134      * @param value
135      * @return the previous property (null if there wasn't one)
136      */

137     public synchronized Object JavaDoc setProperty(String JavaDoc key, LangAlt value) {
138         return super.setProperty(key, value.toString());
139      }
140     
141     /**
142      * @param content
143      * @return an escaped string
144      */

145     public static String JavaDoc escape(String JavaDoc content) {
146         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
147         for (int i = 0; i < content.length(); i++) {
148             switch(content.charAt(i)) {
149             case '<':
150                 buf.append("&lt;");
151                 break;
152             case '>':
153                 buf.append("&gt;");
154                 break;
155             case '\'':
156                 buf.append("&apos;");
157                 break;
158             case '\"':
159                 buf.append("&quot;");
160                 break;
161             case '&':
162                 buf.append("&amp;");
163                 break;
164             default:
165                 buf.append(content.charAt(i));
166             }
167         }
168         return buf.toString();
169     }
170 }
171
Popular Tags