001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.rewriter.util.uri;
006:
007: import com.sun.portal.rewriter.util.StringHelper;
008:
009: import java.net.MalformedURLException;
010: import java.util.Map;
011:
012: public abstract class AbstractURI implements URIIntf {
013: protected final String uriString;
014:
015: private boolean valid = false;
016: private String fileURI;
017: private String dirURI;
018: private String fileName;
019: private String fileExtension;
020:
021: protected AbstractURI(final String aURIString) {
022: uriString = StringHelper.normalize(aURIString);
023: }//constructor
024:
025: public final int getDefaultPort() {
026: return URIHelper.getDefaultPort(getProtocol());
027: }//getDefaultPort()
028:
029: private Map getQueryMap() {
030: return URIHelper.parseQueryString(getQuery());
031: }//getQueryMap()
032:
033: public final String getParameterValue(final String aParamName) {
034: final Object value = getQueryMap().get(aParamName);
035:
036: if (value == null) {
037: return "";
038: }
039:
040: //As URI Get param can be array, get the last value rather
041: //than the first
042: String[] lValueArray = (String[]) value;
043: return lValueArray[lValueArray.length - 1];
044: }//getParameterValue()
045:
046: public final String getFileURI() {
047: if (fileURI == null) {
048: fileURI = getPath();
049: if (fileURI.length() == 0 && uriString.length() != 0) {
050: fileURI = "/";
051: }
052: }
053:
054: return fileURI;
055: }//getFileURI()
056:
057: public final String getDirURI() {
058: if (dirURI == null) {
059: String temp = getFileURI();
060: if (URIHelper.needsToAppendDirectorySeperator(temp)) {
061: temp = temp + "/";
062: }
063:
064: int i = temp.lastIndexOf("/");
065: if (i != -1) {
066: dirURI = getFileURI().substring(0, i + 1);
067: } else {
068: dirURI = temp;
069: }
070: }
071:
072: return dirURI;
073: }//getDirURI()
074:
075: public final String getFileName() {
076: if (fileName == null) {
077: String lPath = getFileURI();
078: fileName = lPath.substring(getDirURI().length());
079: }
080:
081: return fileName;
082: }//getFileName()
083:
084: public final String getFileExtension() {
085: if (fileExtension == null) {
086: String bFileName = getFileName();
087: int i = bFileName.lastIndexOf('.');
088: if (i != -1) {
089: fileExtension = bFileName.substring(i + 1);
090: } else {
091: fileExtension = "";
092: }
093: }
094:
095: return fileExtension;
096: }//getFileExtension()
097:
098: public final String getInputString() {
099: return uriString;
100: }//getInputString()
101:
102: public final String toExternalForm() {
103: if (!isValid() & !isAbsolute()) {
104: return uriString;
105: }
106:
107: return getProtocol()
108: + ((getProtocol().length() != 0) ? "://" : "")
109: + ((getUserInfo().equals("")) ? "" : getUserInfo()
110: + "@")
111: + getHost()
112: + ((getPort() != -1) ? (":" + getPort()) : "")
113: + getPath()
114: + ((getQuery().equals("")) ? "" : "?" + getQuery())
115: + ((getReference().equals("")) ? "" : "#"
116: + getReference());
117: }//toExternalForm()
118:
119: protected final void setValid(final boolean aBool) {
120: valid = aBool;
121: }//setValid()
122:
123: public final boolean isValid() {
124: return valid;
125: }//isValid()
126:
127: public static final String appendParams(final String aURI,
128: final Map aParams) {
129: return URIHelper.parameterize(aURI, aParams);
130: }//appendParams()
131:
132: public static URIIntf[] getAvailableURIImpl(final String aURIString)
133: throws MalformedURLException {
134: return new URIIntf[] { new StandardURI(aURIString) };
135: }//getAvailableURIImpl()
136: }//AbstactURI
|