001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.rewriter.html.neko;
018:
019: import org.apache.jetspeed.rewriter.MutableAttributes;
020: import org.apache.xerces.xni.Augmentations;
021: import org.apache.xerces.xni.QName;
022: import org.apache.xerces.xni.XMLAttributes;
023:
024: /**
025: * <p>
026: * XMLAttributesWrapper
027: * </p>
028: * <p>
029: *
030: * </p>
031: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
032: * @version $Id: XMLAttributesWrapper.java 516448 2007-03-09 16:25:47Z ate $
033: *
034: */
035: public class XMLAttributesWrapper implements MutableAttributes {
036: protected XMLAttributes attrs;
037:
038: /**
039: *
040: */
041: public XMLAttributesWrapper(XMLAttributes attrs) {
042: super ();
043: this .attrs = attrs;
044: }
045:
046: /**
047: * <p>
048: * addAttribute
049: * </p>
050: *
051: * @param arg0
052: * @param arg1
053: * @param arg2
054: * @return
055: */
056: public int addAttribute(QName arg0, String arg1, String arg2) {
057: int i = getIndex(arg0.rawname);
058: if (i >= 0)
059: attrs.removeAttributeAt(i);
060:
061: return attrs.addAttribute(arg0, arg1, arg2);
062: }
063:
064: /**
065: * <p>
066: * equals
067: * </p>
068: *
069: * @see java.lang.Object#equals(java.lang.Object)
070: * @param obj
071: * @return
072: */
073: public boolean equals(Object obj) {
074: return attrs.equals(obj);
075: }
076:
077: /**
078: * <p>
079: * getAugmentations
080: * </p>
081: *
082: * @param arg0
083: * @return
084: */
085: public Augmentations getAugmentations(int arg0) {
086: return attrs.getAugmentations(arg0);
087: }
088:
089: /**
090: * <p>
091: * getAugmentations
092: * </p>
093: *
094: * @param arg0
095: * @return
096: */
097: public Augmentations getAugmentations(String qName) {
098: return attrs.getAugmentations(asNekoAttributeName(qName));
099: }
100:
101: /**
102: * <p>
103: * getAugmentations
104: * </p>
105: *
106: * @param arg0
107: * @param arg1
108: * @return
109: */
110: public Augmentations getAugmentations(String uri, String localPart) {
111: return attrs.getAugmentations(uri,
112: asNekoAttributeName(localPart));
113: }
114:
115: /**
116: * <p>
117: * getIndex
118: * </p>
119: *
120: * @param arg0
121: * @return
122: */
123: public int getIndex(String qName) {
124: return attrs.getIndex(asNekoAttributeName(qName));
125: }
126:
127: /**
128: * <p>
129: * getIndex
130: * </p>
131: *
132: * @param arg0
133: * @param arg1
134: * @return
135: */
136: public int getIndex(String uri, String localName) {
137: return attrs.getIndex(uri, asNekoAttributeName(localName));
138: }
139:
140: /**
141: * <p>
142: * getLength
143: * </p>
144: *
145: * @return
146: */
147: public int getLength() {
148: return attrs.getLength();
149: }
150:
151: /**
152: * <p>
153: * getLocalName
154: * </p>
155: *
156: * @param arg0
157: * @return
158: */
159: public String getLocalName(int arg0) {
160: return attrs.getLocalName(arg0);
161: }
162:
163: /**
164: * <p>
165: * getName
166: * </p>
167: *
168: * @param arg0
169: * @param arg1
170: */
171: public void getName(int arg0, QName arg1) {
172: attrs.getName(arg0, arg1);
173: }
174:
175: /**
176: * <p>
177: * getNonNormalizedValue
178: * </p>
179: *
180: * @param arg0
181: * @return
182: */
183: public String getNonNormalizedValue(int arg0) {
184: return attrs.getNonNormalizedValue(arg0);
185: }
186:
187: /**
188: * <p>
189: * getPrefix
190: * </p>
191: *
192: * @param arg0
193: * @return
194: */
195: public String getPrefix(int arg0) {
196: return attrs.getPrefix(arg0);
197: }
198:
199: /**
200: * <p>
201: * getQName
202: * </p>
203: *
204: * @param arg0
205: * @return
206: */
207: public String getQName(int arg0) {
208: return attrs.getQName(arg0);
209: }
210:
211: /**
212: * <p>
213: * getType
214: * </p>
215: *
216: * @param arg0
217: * @return
218: */
219: public String getType(int arg0) {
220: return attrs.getType(arg0);
221: }
222:
223: /**
224: * <p>
225: * getType
226: * </p>
227: *
228: * @param arg0
229: * @return
230: */
231: public String getType(String qName) {
232: return attrs.getType(asNekoAttributeName(qName));
233: }
234:
235: /**
236: * <p>
237: * getType
238: * </p>
239: *
240: * @param arg0
241: * @param arg1
242: * @return
243: */
244: public String getType(String uri, String localName) {
245: return attrs.getType(uri, asNekoAttributeName(localName));
246: }
247:
248: /**
249: * <p>
250: * getURI
251: * </p>
252: *
253: * @param arg0
254: * @return
255: */
256: public String getURI(int arg0) {
257: return attrs.getURI(arg0);
258: }
259:
260: /**
261: * <p>
262: * getValue
263: * </p>
264: *
265: * @param arg0
266: * @return
267: */
268: public String getValue(int arg0) {
269: return attrs.getValue(arg0);
270: }
271:
272: /**
273: * <p>
274: * getValue
275: * </p>
276: *
277: * @param arg0
278: * @return
279: */
280: public String getValue(String qName) {
281: return attrs.getValue(asNekoAttributeName(qName));
282: }
283:
284: /**
285: * <p>
286: * getValue
287: * </p>
288: *
289: * @param arg0
290: * @param arg1
291: * @return
292: */
293: public String getValue(String uri, String localName) {
294: return attrs.getValue(uri, asNekoAttributeName(localName));
295: }
296:
297: /**
298: * <p>
299: * hashCode
300: * </p>
301: *
302: * @see java.lang.Object#hashCode()
303: * @return
304: */
305: public int hashCode() {
306: return attrs.hashCode();
307: }
308:
309: /**
310: * <p>
311: * isSpecified
312: * </p>
313: *
314: * @param arg0
315: * @return
316: */
317: public boolean isSpecified(int arg0) {
318: return attrs.isSpecified(arg0);
319: }
320:
321: /**
322: * <p>
323: * removeAllAttributes
324: * </p>
325: *
326: *
327: */
328: public void removeAllAttributes() {
329: attrs.removeAllAttributes();
330: }
331:
332: /**
333: * <p>
334: * removeAttributeAt
335: * </p>
336: *
337: * @param arg0
338: */
339: public void removeAttributeAt(int arg0) {
340: attrs.removeAttributeAt(arg0);
341: }
342:
343: /**
344: * <p>
345: * setAugmentations
346: * </p>
347: *
348: * @param arg0
349: * @param arg1
350: */
351: public void setAugmentations(int arg0, Augmentations arg1) {
352: attrs.setAugmentations(arg0, arg1);
353: }
354:
355: /**
356: * <p>
357: * setName
358: * </p>
359: *
360: * @param arg0
361: * @param arg1
362: */
363: public void setName(int arg0, QName arg1) {
364: attrs.setName(arg0, arg1);
365: }
366:
367: /**
368: * <p>
369: * setNonNormalizedValue
370: * </p>
371: *
372: * @param arg0
373: * @param arg1
374: */
375: public void setNonNormalizedValue(int arg0, String arg1) {
376: attrs.setNonNormalizedValue(arg0, arg1);
377: }
378:
379: /**
380: * <p>
381: * setSpecified
382: * </p>
383: *
384: * @param arg0
385: * @param arg1
386: */
387: public void setSpecified(int arg0, boolean arg1) {
388: attrs.setSpecified(arg0, arg1);
389: }
390:
391: /**
392: * <p>
393: * setType
394: * </p>
395: *
396: * @param arg0
397: * @param arg1
398: */
399: public void setType(int arg0, String arg1) {
400: attrs.setType(arg0, arg1);
401: }
402:
403: /**
404: * <p>
405: * setValue
406: * </p>
407: *
408: * @param arg0
409: * @param arg1
410: */
411: public void setValue(int arg0, String arg1) {
412: attrs.setValue(arg0, arg1);
413: }
414:
415: /**
416: * <p>
417: * toString
418: * </p>
419: *
420: * @see java.lang.Object#toString()
421: * @return
422: */
423: public String toString() {
424: return attrs.toString();
425: }
426:
427: /**
428: * <p>
429: * addAttribute
430: * </p>
431: *
432: * @see org.apache.jetspeed.rewriter.MutableAttributes#addAttribute(java.lang.String, java.lang.Object)
433: * @param name
434: * @param value
435: */
436: public void addAttribute(String name, Object value) {
437: QName qName = null;
438: int i = name.indexOf(':');
439: if (i < 0) {
440: name = name.toLowerCase();
441: qName = new QName(null, name, name, null);
442: } else {
443: String prefix = name.substring(0, i);
444: String localPart = name.substring(i + 1).toLowerCase();
445: name = name.toLowerCase();
446: qName = new QName(prefix, localPart, name, null);
447: }
448: addAttribute(qName, "CDATA", value.toString());
449: }
450:
451: // Support Methods
452:
453: protected String asNekoAttributeName(String n) {
454: // neko, by default, converts attribute names to lower case
455: return n != null ? n.toLowerCase() : null;
456: }
457: }
|