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.engines.LanguageConstants;
008: import com.sun.portal.rewriter.util.StringHelper;
009: import com.sun.portal.rewriter.util.i18n.MIMEHelper;
010:
011: import java.net.MalformedURLException;
012:
013: public final class PageSpec {
014: private final String inputString;
015: private final DecoratedURI pageURI;//BugNo:4898369
016: private DecoratedURI baseURI; //BugNo:4780962
017: private String mime;
018: private String encoding;
019: private boolean valid;
020:
021: public PageSpec(final String aBaseURI) {
022: this (aBaseURI, null);
023: }//constuctor
024:
025: public PageSpec(final String aBaseURI, final String aMIMEType) {
026: this (aBaseURI, aMIMEType, null);
027: }//constructor
028:
029: public PageSpec(final String aBaseURI, final String aMIMEType,
030: final String aEncoding) {
031: inputString = aBaseURI;
032: mime = StringHelper.normalize(aMIMEType,
033: LanguageConstants.UNKNOWN_MIME);
034: encoding = StringHelper.normalize(aEncoding,
035: LanguageConstants.UNKNOWN_MIME);
036: setBase(aBaseURI);
037: pageURI = baseURI;
038: }//constructor
039:
040: public void setBase(final String aBase) {
041: valid = true;
042: try {
043: setBase(new DecoratedURI(aBase));
044: } catch (MalformedURLException e) {
045: valid = false;
046: }//try/catch
047: }//setBase()
048:
049: private void setBase(DecoratedURI aDecoratedURI)
050: throws MalformedURLException {
051: //BugNo:4780962
052: baseURI = new DecoratedURI(aDecoratedURI.toNormalForm());
053: if (!baseURI.isValid() && !baseURI.isAbsolute()) {
054: throw new MalformedURLException(
055: "INVALID URI: Page URI Should be Absolute:"
056: + aDecoratedURI.getInputString());
057: }
058:
059: if (mime.equals(LanguageConstants.UNKNOWN_MIME)) {
060: mime = MIMEHelper.guessContentTypeFromFileName(baseURI
061: .getFileName());
062: }
063:
064: String bValue = baseURI
065: .getParameterValue(LanguageConstants.SCRIPT_REFERRER);
066: //if there is script refferer in the uri, take this as base
067: //need for rewritting the pure javascript files
068: if (bValue != null && bValue.length() != 0) {
069: int idx = bValue.indexOf(".END.");
070: if (idx > -1) {
071: bValue = bValue.substring(0, idx);
072: }
073: setBase(bValue);
074: }
075: }//setBase()
076:
077: public String getInputString() {
078: return inputString;
079: }//getInputString()
080:
081: public DecoratedURI getPageURI() {
082: return pageURI;
083: }//getPageURI()
084:
085: public DecoratedURI getBaseURI() {
086: if (isValid()) {
087: return baseURI;
088: }
089:
090: return DecoratedURI.EMPTY_DECORATED_URI;
091: }//getBaseURI()
092:
093: public String getMIME() {
094: return mime;
095: }//getMIME()
096:
097: public String getEncoding() {
098: return encoding;
099: }//getEncoding()
100:
101: public boolean isValid() {
102: return valid;
103: }//isValid()
104:
105: public String toString() {
106: return "Page URI: "
107: + getInputString()
108: + ",\n"
109: + ((getBaseURI().getInputString()
110: .equalsIgnoreCase(getInputString())) ? ""
111: : "Resolve URI: "
112: + getBaseURI().toExternalForm() + ",\n")
113: + "Content MIME: " + getMIME() + ",\n"
114: + "Content Encoding: " + getEncoding() + ",\n";
115: }//toString()
116:
117: }//class PageSpec
|