001: // ProfileRef.java
002: // $Id: ProfileRef.java,v 1.2 2000/08/16 21:37:34 ylafon Exp $
003: // (c) COPYRIGHT MIT, INRIA and Keio, 2000.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigsaw.ccpp;
007:
008: /**
009: * A Profile reference
010: * (syntax described at http://www.w3.org/1999/06/NOTE-CCPPexchange-19990624)
011: * @version $Revision: 1.2 $
012: * @author Benoît Mahé (bmahe@w3.org)
013: */
014: public class ProfileRef {
015:
016: int number = -1;
017: boolean isDiff = false;
018: String diffname = null;
019: String ref = null;
020: String uri = null;
021: boolean parsed = false;
022:
023: /**
024: * Get the unparsed profile reference (used for error message)
025: * @return a String;
026: */
027: public String getUnparsedRef() {
028: return ref;
029: }
030:
031: /**
032: * Is this Profile reference an absolute URI?
033: * @return a boolean
034: */
035: public boolean isURI() {
036: return !isDiff;
037: }
038:
039: /**
040: * Get the URI
041: * @return a String (or null if this reference is not an URI)
042: * @exception InvalidProfileException if the profile reference is not valid
043: */
044: public String getURI() throws InvalidProfileException {
045: parse();
046: return uri;
047: }
048:
049: /**
050: * Is this Profile reference a profile diff name?
051: * @return a boolean
052: */
053: public boolean isDiffName() {
054: return isDiff;
055: }
056:
057: /**
058: * Get the diff number
059: * @return a integer (or -1 if this reference is not a profile diff name)
060: * @exception InvalidProfileException if the profile reference is not valid
061: */
062: public int getDiffNumber() throws InvalidProfileException {
063: parse();
064: return number;
065: }
066:
067: /**
068: * Get the profile diff name
069: * @return a String (or null if this reference is not a profile diff name)
070: * @exception InvalidProfileException if the profile reference is not valid
071: */
072: public String getDiffName() throws InvalidProfileException {
073: parse();
074: return diffname;
075: }
076:
077: protected void parse() throws InvalidProfileException {
078: if (!parsed) {
079: if (isDiff) {
080: int idx = ref.indexOf('-');
081: if (idx != -1) {
082: this .diffname = ref.substring(idx + 1);
083: String snum = ref.substring(0, idx);
084: try {
085: number = Integer.parseInt(snum);
086: } catch (NumberFormatException ex) {
087: number = -1;
088: }
089: } else {
090: throw new InvalidProfileException(ref);
091: }
092: } else {
093: uri = ref;
094: }
095: parsed = true;
096: }
097: }
098:
099: /**
100: * Constructor
101: * @param ref the raw profile reference. ie :
102: * <ul>
103: * <li> "http://www.aaa.com/hw"
104: * <li> "1-uKhjE/AEeeMzFSejsYshHg=="
105: * </ul>
106: */
107: public ProfileRef(String ref) {
108: this .ref = ref;
109: this .isDiff = !(ref.indexOf(':') != -1);
110: }
111:
112: }
|