01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * When distributing Covered Code, include this CDDL Header Notice in each file
10: * and include the License file at http://www.netbeans.org/cddl.txt.
11: * If applicable, add the following below the CDDL Header, with the fields
12: * enclosed by brackets [] replaced by your own identifying information:
13: * "Portions Copyrighted [year] [name of copyright owner]"
14: *
15: * The Original Software is NetBeans. The Initial Developer of the Original
16: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19: package org.netbeans.modules.xslt.model.impl;
20:
21: import javax.xml.namespace.QName;
22:
23: /**
24: * @author ads
25: *
26: */
27: class QNameBuilder {
28:
29: public static QName createQName(XslComponentImpl component,
30: XslAttributes attribute) {
31: String str = component.getAttribute(attribute);
32: return createQName(component, str);
33: }
34:
35: public static QName createQName(XslComponentImpl component,
36: String value) {
37: if (value == null) {
38: return null;
39: }
40: String[] splited = new String[2];
41: splitQName(value, splited);
42:
43: String uri = component.lookupNamespaceURI(splited[0], true);
44: if (uri == null && splited[0] == null) {
45: // prefix isn't defined; default namespace isn't found
46: return new QName(splited[1]);
47: }
48: if (uri != null && splited[0] == null) {
49: // prefix isn't defined but the default namspace is found.
50: // default namespace is used
51: return new QName(uri, splited[1]);
52: }
53: return new QName(uri, splited[1], splited[0]);
54: }
55:
56: public static void splitQName(String qName, String[] result) {
57: assert qName != null;
58: assert result != null;
59: String[] parts = qName.split(":"); //NOI18N
60: String prefix;
61: String localName;
62: if (parts.length == 2) {
63: prefix = parts[0];
64: localName = parts[1];
65: } else {
66: prefix = null;
67: localName = parts[0];
68: }
69: if (result.length > 0) {
70: result[0] = prefix;
71: }
72: if (result.length > 1) {
73: result[1] = localName;
74: }
75: }
76: }
|