001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/wizard/api-impl/src/java/org/theospi/portfolio/wizard/taggable/impl/WizardReference.java $
003: * $Id: WizardReference.java 20653 2007-01-25 01:31:44Z jmpease@syr.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2007 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.theospi.portfolio.wizard.taggable.impl;
021:
022: /**
023: * Represents a reference to a wizard activity or item.
024: *
025: * @author The Sakai Foundation.
026: */
027: public class WizardReference {
028:
029: /**
030: * Separates parts of a wizard activity/item reference
031: */
032: static final String REF_SEPARATOR = "/";
033:
034: /**
035: * First part of every wizard activity/item reference
036: */
037: static final String REF_BASE = "wizard";
038:
039: /**
040: * Second part of a reference to identify that the reference is for a wizard
041: * page definition
042: */
043: static final String REF_DEF = "def";
044:
045: /**
046: * Second part of a reference to identify that the reference is for a wizard
047: * page
048: */
049: static final String REF_PAGE = "page";
050:
051: String type, id;
052:
053: public WizardReference(String type, String id) {
054: this .type = type;
055: this .id = id;
056: }
057:
058: /**
059: * Method to get the type part of this wizard reference.
060: *
061: * @return The type part of this wizard reference.
062: */
063: public String getType() {
064: return type;
065: }
066:
067: /**
068: * Method to get the identifier part of this wizard reference.
069: *
070: * @return The identifier part of this wizard reference.
071: */
072: public String getId() {
073: return id;
074: }
075:
076: /**
077: * Method to get a wizard activity/item reference object given a reference
078: * string.
079: *
080: * @param ref
081: * The reference string.
082: * @return A wizard activity/item reference.
083: */
084: public static WizardReference getReference(String ref) {
085: WizardReference reference = null;
086: String[] parts = ref.split(REF_SEPARATOR);
087: if (parts.length == 4
088: && REF_BASE.equals(parts[1])
089: && (REF_DEF.equals(parts[2]) || REF_PAGE
090: .equals(parts[2]))) {
091: reference = new WizardReference(parts[2], parts[3]);
092: }
093: return reference;
094: }
095:
096: /**
097: * {@inheritDoc}
098: */
099: public String toString() {
100: StringBuffer sb = new StringBuffer();
101: sb.append(REF_SEPARATOR);
102: sb.append(REF_BASE);
103: sb.append(REF_SEPARATOR);
104: sb.append(type);
105: sb.append(REF_SEPARATOR);
106: sb.append(id);
107: return sb.toString();
108: }
109: }
|