1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.geronimo.schema; 18 19 import javax.xml.namespace.QName; 20 21 import org.apache.xmlbeans.XmlCursor; 22 23 /** 24 * @version $Rev: 545781 $ $Date: 2007-06-09 10:44:02 -0700 (Sat, 09 Jun 2007) $ 25 */ 26 public class SecurityElementConverter implements ElementConverter { 27 28 public static final String GERONIMO_SECURITY_NAMESPACE = "http://geronimo.apache.org/xml/ns/security-2.0"; 29 private static final QName PRINCIPAL_QNAME = new QName(GERONIMO_SECURITY_NAMESPACE, "principal"); 30 private static final QName REALM_NAME_QNAME = new QName("realm-name"); 31 private static final QName DESIGNATED_RUN_AS = new QName("designated-run-as"); 32 33 public void convertElement(XmlCursor cursor, XmlCursor end) { 34 cursor.push(); 35 end.toCursor(cursor); 36 end.toEndToken(); 37 while (cursor.hasNextToken() && cursor.isLeftOf(end)) { 38 if (cursor.isStart()) { 39 if (GERONIMO_SECURITY_NAMESPACE.equals(cursor.getName().getNamespaceURI())) { 40 break; 41 } 42 cursor.setName(new QName(GERONIMO_SECURITY_NAMESPACE, cursor.getName().getLocalPart())); 43 44 } 45 cursor.toNextToken(); 46 } 47 cursor.pop(); 48 XmlCursor source = null; 49 try { 50 while (cursor.hasNextToken() && cursor.isLeftOf(end)) { 51 if (cursor.isStart()) { 52 String localPart = cursor.getName().getLocalPart(); 53 if (localPart.equals("realm")) { 54 if (source == null) { 55 source = cursor.newCursor(); 56 } else { 57 source.toCursor(cursor); 58 } 59 cursor.push(); 60 cursor.toEndToken(); 61 cursor.toNextToken(); 62 if (source.toChild(PRINCIPAL_QNAME)) { 63 do { 64 source.removeAttribute(DESIGNATED_RUN_AS); 65 source.copyXml(cursor); 66 } while (source.toNextSibling(PRINCIPAL_QNAME)); 67 } 68 69 cursor.pop(); 70 cursor.removeXml(); 71 } else if (localPart.equals("default-subject")) { 72 // cursor.removeAttribute(REALM_NAME_QNAME); 73 cursor.toEndToken(); 74 } else if (localPart.equals("default-principal")) { 75 cursor.removeXml(); 76 } else if (localPart.equals("principal")) { 77 cursor.removeAttribute(DESIGNATED_RUN_AS); 78 } else if (localPart.equals("run-as-subject")) { 79 cursor.toEndToken(); 80 } 81 } 82 cursor.toNextToken(); 83 } 84 } finally { 85 if (source != null) { 86 source.dispose(); 87 } 88 } 89 } 90 }