01: /*
02: * The contents of this file are subject to the terms
03: * of the Common Development and Distribution License
04: * (the License). You may not use this file except in
05: * compliance with the License.
06: *
07: * You can obtain a copy of the license at
08: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
09: * See the License for the specific language governing
10: * permissions and limitations under the License.
11: *
12: * When distributing Covered Code, include this CDDL
13: * Header Notice in each file and include the License file
14: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
15: * If applicable, add the following below the CDDL Header,
16: * with the fields enclosed by brackets [] replaced by
17: * you own identifying information:
18: * "Portions Copyrighted [year] [name of copyright owner]"
19: *
20: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
21: */
22:
23: /*
24: * AttrSorter.java
25: *
26: * Created on August 21, 2005, 4:38 PM
27: *
28: * To change this template, choose Tools | Options and locate the template under
29: * the Source Creation and Management node. Right-click the template and choose
30: * Open. You can then make changes to the template in the Source Editor.
31: */
32:
33: package com.sun.xml.wss.impl.c14n;
34:
35: /**
36: *
37: * @author K.Venugopal@sun.com
38: */
39: public class AttrSorter implements java.util.Comparator {
40:
41: boolean namespaceSort = false;
42:
43: /** Creates a new instance of AttrSorter */
44: public AttrSorter(boolean namespaceSort) {
45: this .namespaceSort = namespaceSort;
46: }
47:
48: public int compare(Object o1, Object o2) {
49: if (namespaceSort) {
50: return sortNamespaces(o1, o2);
51: } else {
52: return sortAttributes(o1, o2);
53: }
54: }
55:
56: //double check;
57: protected int sortAttributes(Object object, Object object0) {
58: Attribute attr = (Attribute) object;
59: Attribute attr0 = (Attribute) object0;
60: String uri = attr.getNamespaceURI();
61: String uri0 = attr0.getNamespaceURI();
62: int result = uri.compareTo(uri0);
63: if (result == 0) {
64: String lN = attr.getLocalName();
65: String lN0 = attr0.getLocalName();
66: result = lN.compareTo(lN0);
67: }
68: return result;
69: }
70:
71: //double check;
72: protected int sortNamespaces(Object object, Object object0) {
73: AttributeNS attr = (AttributeNS) object;
74: AttributeNS attr0 = (AttributeNS) object0;
75: //assume namespace processing is on.
76: String lN = attr.getPrefix();
77: String lN0 = attr0.getPrefix();
78: return lN.compareTo(lN0);
79: }
80:
81: }
|