Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 281046 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/wst/xml/xpath2/processor/function/XSCtrLibrary.java (-1 / +4 lines)
Lines 19-25 Link Here
19
 *     Mukul Gandhi - bug 277639 - implementation of xs:byte data type
19
 *     Mukul Gandhi - bug 277639 - implementation of xs:byte data type
20
 *     Mukul Gandhi - bug 277642 - implementation of xs:unsignedInt data type
20
 *     Mukul Gandhi - bug 277642 - implementation of xs:unsignedInt data type
21
 *     Mukul Gandhi - bug 277645 - implementation of xs:unsighedShort data type
21
 *     Mukul Gandhi - bug 277645 - implementation of xs:unsighedShort data type
22
 *     Mukul Gandhi - bug 277650 - implementation of xs:unsignedByte data type  
22
 *     Mukul Gandhi - bug 277650 - implementation of xs:unsignedByte data type
23
 *     Mukul Gandhi - bug 281046 - implementation of xs:base64Binary data type 
23
 *******************************************************************************/
24
 *******************************************************************************/
24
25
25
package org.eclipse.wst.xml.xpath2.processor.function;
26
package org.eclipse.wst.xml.xpath2.processor.function;
Lines 79-83 Link Here
79
		add_type(new XSAnyURI());
80
		add_type(new XSAnyURI());
80
		add_type(new XSYearMonthDuration());
81
		add_type(new XSYearMonthDuration());
81
		add_type(new XSDayTimeDuration());
82
		add_type(new XSDayTimeDuration());
83
		
84
		add_type(new XSBase64Binary());
82
	}
85
	}
83
}
86
}
(-)src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSBase64Binary.java (+149 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Mukul Gandhi, and others
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Mukul Gandhi - bug 281046 - initial API and implementation 
10
 *******************************************************************************/
11
12
package org.eclipse.wst.xml.xpath2.processor.internal.types;
13
14
import org.apache.xerces.impl.dv.util.Base64;
15
import org.eclipse.wst.xml.xpath2.processor.DynamicError;
16
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
17
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
18
import org.eclipse.wst.xml.xpath2.processor.internal.function.CmpEq;
19
20
/**
21
 * A representation of the base64Binary datatype
22
 */
23
public class XSBase64Binary extends CtrType implements CmpEq {
24
25
	private String _value;
26
27
	/**
28
	 * Initialises using the supplied String
29
	 * 
30
	 * @param x
31
	 *            The String to initialise to
32
	 */
33
	public XSBase64Binary(String x) {
34
		_value = x;
35
	}
36
37
	/**
38
	 * Initialises to null
39
	 */
40
	public XSBase64Binary() {
41
		this(null);
42
	}
43
44
	/**
45
	 * Retrieves the datatype's full pathname
46
	 * 
47
	 * @return "xs:base64Binary" which is the datatype's full pathname
48
	 */
49
	@Override
50
	public String string_type() {
51
		return "xs:base64Binary";
52
	}
53
54
	/**
55
	 * Retrieves the datatype's name
56
	 * 
57
	 * @return "base64Binary" which is the datatype's name
58
	 */
59
	@Override
60
	public String type_name() {
61
		return "base64Binary";
62
	}
63
64
	/**
65
	 * Retrieves a String representation of the base64Binary stored. This method is
66
	 * functionally identical to value()
67
	 * 
68
	 * @return The base64Binary stored
69
	 */
70
	@Override
71
	public String string_value() {
72
		return _value;
73
	}
74
75
	/**
76
	 * Retrieves a String representation of the base64Binary stored. This method is
77
	 * functionally identical to string_value()
78
	 * 
79
	 * @return The base64Binary stored
80
	 */
81
	public String value() {
82
		return _value;
83
	}
84
85
	/**
86
	 * Creates a new ResultSequence consisting of the base64Binary value
87
	 * 
88
	 * @param arg
89
	 *            The ResultSequence from which to construct base64Binary value 
90
	 * @return New ResultSequence representing base64Binary value 
91
	 * @throws DynamicError
92
	 */
93
	@Override
94
	public ResultSequence constructor(ResultSequence arg) throws DynamicError {
95
		ResultSequence rs = ResultSequenceFactory.create_new();
96
97
		if (arg.empty())
98
			return rs;
99
100
		AnyAtomicType aat = (AnyAtomicType) arg.first();
101
		
102
		String str_value = aat.string_value();
103
		byte[] decodedValue = Base64.decode(str_value);
104
		if (decodedValue != null) {
105
		  rs.add(new XSBase64Binary(str_value));
106
		}
107
		else {
108
		  // invalid base64 string
109
		  throw DynamicError.throw_type_error();	
110
		}
111
112
		return rs;
113
	}
114
115
116
	/**
117
	 * Equality comparison between this and the supplied representation which
118
	 * must be of type base64Binary
119
	 * 
120
	 * @param arg
121
	 *            The representation to compare with
122
	 * @return True if the two representation are same. False otherwise.
123
	 *         
124
	 * @throws DynamicError
125
	 */
126
	public boolean eq(AnyType arg) throws DynamicError {
127
      String valToCompare = arg.string_value();
128
      
129
      byte[] value1 = Base64.decode(_value);
130
      byte[] value2 = Base64.decode(valToCompare);
131
      if (value2 == null) {
132
    	return false;  
133
      }
134
      
135
      int len = value1.length;
136
      if (len != value2.length) {
137
        return false;
138
      }
139
      
140
      for (int i = 0; i < len; i++) {
141
        if (value1[i] != value2[i]) {
142
          return false;
143
        }
144
      }
145
      
146
      return true;
147
	}
148
149
}

Return to bug 281046