01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-impl/api-impl/src/java/org/sakaiproject/metaobj/utils/xml/impl/UriElementType.java $
03: * $Id: UriElementType.java 18591 2006-12-01 16:24:01Z john.ellis@rsmart.com $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.metaobj.utils.xml.impl;
21:
22: import java.net.URI;
23: import java.net.URISyntaxException;
24:
25: import org.jdom.Element;
26: import org.jdom.Namespace;
27: import org.sakaiproject.metaobj.utils.xml.NormalizationException;
28: import org.sakaiproject.metaobj.utils.xml.SchemaNode;
29:
30: /**
31: * Created by IntelliJ IDEA.
32: * User: John Ellis
33: * Date: Jan 25, 2006
34: * Time: 10:33:36 AM
35: * To change this template use File | Settings | File Templates.
36: */
37: public class UriElementType extends BaseElementType {
38:
39: private static final String SAKAI_REF_SCHEME = "sakairef";
40:
41: public UriElementType(String typeName, Element schemaElement,
42: SchemaNode parentNode, Namespace xsdNamespace) {
43: super (typeName, schemaElement, parentNode, xsdNamespace);
44: }
45:
46: public Class getObjectType() {
47: return URI.class;
48: }
49:
50: public Object getActualNormalizedValue(String value) {
51: try {
52: if (value.startsWith("/")) {
53: return new URI(SAKAI_REF_SCHEME, value, null);
54: } else {
55: return new URI(value);
56: }
57: } catch (URISyntaxException e) {
58: throw new NormalizationException("Invalid URI",
59: NormalizationException.INVALID_URI,
60: new Object[] { value });
61: }
62: }
63:
64: public String getSchemaNormalizedValue(String value)
65: throws NormalizationException {
66: return getSchemaNormalizedValue(getActualNormalizedValue(value));
67: }
68:
69: public String getSchemaNormalizedValue(Object value)
70: throws NormalizationException {
71: if (value != null) {
72:
73: URI uri = (URI) value;
74: if (uri.getScheme().equals(SAKAI_REF_SCHEME)) {
75: return uri.getSchemeSpecificPart();
76: } else {
77: return uri.toString();
78: }
79: } else {
80: return null;
81: }
82: }
83:
84: }
|