1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package javax.xml.catalog; 26 27 import java.net.URL; 28 29 /** 30 * Represents a uriSuffix entry. 31 * 32 * @since 9 33 */ 34 final class UriSuffix extends BaseEntry { 35 String uriSuffix; 36 URL uri; 37 38 /** 39 * Construct a group entry. 40 * @param uriSuffix The uriSuffix attribute. 41 * @param uri The uri attribute. 42 */ 43 public UriSuffix(String base, String uriSuffix, String uri) { 44 super(CatalogEntryType.URISUFFIX, base); 45 setURISuffix (uriSuffix); 46 setURI(uri); 47 } 48 49 /** 50 * Set the uriSuffix attribute. 51 * @param uriSuffix The uriSuffix attribute value. 52 */ 53 public void setURISuffix(String uriSuffix) { 54 CatalogMessages.reportNPEOnNull("uriSuffix", uriSuffix); 55 this.uriSuffix = Normalizer.normalizeURI(uriSuffix); 56 } 57 58 /** 59 * Set the uri attribute. If the value of the uri attribute is relative, it 60 * must be made absolute with respect to the base URI currently in effect. 61 * The URI reference should not include a fragment identifier. 62 * @param uri The uri attribute value. 63 */ 64 public void setURI(String uri) { 65 this.uri = verifyURI("setURI", baseURI, uri); 66 } 67 68 /** 69 * Get the uriSuffix attribute. 70 * @return The uriSuffix 71 */ 72 public String getURISuffix () { 73 return uriSuffix; 74 } 75 /** 76 * Get the uri attribute. 77 * @return The uri attribute value. 78 */ 79 public String getURI() { 80 return uri.toString(); 81 } 82 83 /** 84 * Try to match the specified systemId with the entry. Return the match if it 85 * is successful and the length of the uriSuffix is longer than the longest 86 * of any previous match. 87 * 88 * @param systemId The systemId to be matched. 89 * @param currentMatch The length of uriSuffix of previous match if any. 90 * @return The replacement URI if the match is successful, null if not. 91 */ 92 @Override 93 public String match(String systemId, int currentMatch) { 94 if (systemId.endsWith(uriSuffix)) { 95 if (currentMatch < uriSuffix.length()) { 96 return uri.toString(); 97 } 98 } 99 return null; 100 } 101 102 @Override 103 public String match(String systemId) { 104 return match(systemId, 0); 105 } 106 107 }