001/** 002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 003 * 004 * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved 005 * 006 * The contents of this file are subject to the terms 007 * of the Common Development and Distribution License 008 * (the License). You may not use this file except in 009 * compliance with the License. 010 * 011 * You can obtain a copy of the License at 012 * https://opensso.dev.java.net/public/CDDLv1.0.html or 013 * opensso/legal/CDDLv1.0.txt 014 * See the License for the specific language governing 015 * permission and limitations under the License. 016 * 017 * When distributing Covered Code, include this CDDL 018 * Header Notice in each file and include the License file 019 * at opensso/legal/CDDLv1.0.txt. 020 * If applicable, add the following below the CDDL Header, 021 * with the fields enclosed by brackets [] replaced by 022 * your own identifying information: 023 * "Portions Copyrighted [year] [name of copyright owner]" 024 * 025 * $Id: GetComplete.java,v 1.2 2008/06/25 05:46:47 qcheng Exp $ 026 * Portions Copyrighted 2014 ForgeRock AS 027 */ 028 029package com.sun.identity.federation.message.common; 030 031import com.sun.identity.federation.common.FSUtils; 032import com.sun.identity.federation.common.IFSConstants; 033import com.sun.identity.shared.xml.XMLUtils; 034import java.util.List; 035import org.w3c.dom.Document; 036import org.w3c.dom.Element; 037import org.w3c.dom.Node; 038import org.w3c.dom.NodeList; 039 040/** 041 * This class contains methods for the <code>GetComplete</code> 042 * Element. This element specifies a URI which resolves to 043 * the complete IDPList. 044 * 045 * @supported.all.api 046 * @deprecated since 12.0.0 047 */ 048@Deprecated 049 050public class GetComplete extends EntityName { 051 052 /** 053 * Default Constructor. 054 */ 055 public GetComplete() { 056 } 057 058 /** 059 * Constructor create <code>GetComplete</code> object. 060 * 061 * @param uri the value of the <code>URI</code>. 062 */ 063 public GetComplete(String uri) { 064 super(uri); 065 } 066 067 /** 068 * Constructor create <code>GetComplete</code> object. 069 * 070 * @param uri the value of the <code>URI</code>. 071 * @param otherElements list of other elements. 072 */ 073 public GetComplete(String uri, List otherElements) { 074 super(uri, otherElements); 075 } 076 077 /** 078 * Constructor creates <code>GetComplete</code> object from 079 * the Document Element. 080 * 081 * @param root the Document Element object. 082 * @throws FSMsgException if error creating this object. 083 */ 084 public GetComplete(Element root) throws FSMsgException { 085 String tag = null; 086 if (root == null) { 087 FSUtils.debug.message("GetComplete(Element): null input."); 088 throw new FSMsgException("nullInput",null); 089 } 090 if (((tag = root.getLocalName()) == null) || 091 (!tag.equals("GetComplete"))) { 092 FSUtils.debug.message("GetComplete(Element): wrong input"); 093 throw new FSMsgException("wrongInput",null); 094 } 095 096 int length = 0; 097 // get the contents of the request 098 NodeList contentnl = root.getChildNodes(); 099 Node child; 100 String nodeName; 101 length = contentnl.getLength(); 102 for (int i = 0; i < length; i++) { 103 child = contentnl.item(i); 104 nodeName = child.getLocalName(); 105 if ((nodeName != null) && nodeName.equals("URI")) { 106 // make sure the providerId is not assigned already 107 if (uri != null) { 108 if (FSUtils.debug.messageEnabled()) { 109 FSUtils.debug.message("GetComplete(Element): should" 110 + "contain only one URI."); 111 } 112 throw new FSMsgException("wrongInput",null); 113 } 114 uri = XMLUtils.getElementValue((Element) child); 115 } else { 116 if (FSUtils.debug.messageEnabled()) { 117 FSUtils.debug.message("GetComplete(Element): invalid" 118 + " node" + nodeName); 119 } 120 throw new FSMsgException("wrongInput",null); 121 } 122 } 123 } 124 125/** 126 * Returns <code>GetComplete</code> object. This 127 * object is created by parsing the <code>XML</code> string. 128 * 129 * @param xml <code>XML</code> String 130 * @return the <code>GetComplete</code> object. 131 * @throws FSMsgException if there is an error creating this object. 132 */ 133public static GetComplete parseXML(String xml) throws FSMsgException { 134 Document doc = XMLUtils.toDOMDocument(xml, FSUtils.debug); 135 if (doc == null) { 136 if (FSUtils.debug.messageEnabled()) { 137 FSUtils.debug.message("GetComplete.parseXML:Error " 138 + "while parsing input xml string"); 139 } 140 throw new FSMsgException("parseError",null); 141 } 142 Element root = doc.getDocumentElement(); 143 return new GetComplete(root); 144} 145 146/** 147 * Returns the string representation of this object. 148 * 149 * @return An XML String representing this object. 150 * 151 */ 152public String toXMLString() throws FSMsgException { 153 return toXMLString(true, true); 154} 155 156 /** 157 * Returns a String representation of the <samlp:Response> element. 158 * 159 * @param includeNS : Determines whether or not the namespace qualifier 160 * is prepended to the Element when converted 161 * @param declareNS : Determines whether or not the namespace is declared 162 * within the Element. 163 * @return a string containing the valid XML for this element 164 * @throws FSMsgException if there is an error converting 165 * this object ot a string. 166 */ 167 public String toXMLString(boolean includeNS, boolean declareNS) 168 throws FSMsgException { 169 return toXMLString(includeNS, declareNS, false); 170 } 171 172 /** 173 * Returns a String representation of the <samlp:Response> element. 174 * 175 * @param includeNS Determines whether or not the namespace qualifier 176 * is prepended to the Element when converted 177 * @param declareNS Determines whether or not the namespace is declared 178 * within the Element. 179 * @param includeHeader Determines whether the output include the xml 180 * declaration header. 181 * @return a string containing the valid XML for this element 182 * @throws FSMsgException if there is an error converting 183 * this object ot a string. 184 */ 185 186 public String toXMLString(boolean includeNS,boolean declareNS, 187 boolean includeHeader) throws FSMsgException { 188 StringBuffer xml = new StringBuffer(300); 189 if (includeHeader) { 190 xml.append("<?xml version=\"1.0\" encoding=\""). 191 append(IFSConstants.DEFAULT_ENCODING).append("\" ?>"); 192 } 193 String prefix = ""; 194 String uri = ""; 195 if (includeNS) { 196 prefix = IFSConstants.LIB_PREFIX; 197 } 198 if (declareNS) { 199 uri = IFSConstants.LIB_NAMESPACE_STRING; 200 } 201 202 xml.append("<").append(prefix).append("GetComplete").append(uri). 203 append(">\n"); 204 205 xml.append("<").append(prefix).append("URI").append(uri).append(">"). 206 append(this.uri). 207 append("</").append(prefix).append("URI").append(">"); 208 209 xml.append("</").append(prefix).append("GetComplete>"); 210 211 return xml.toString(); 212 } 213}