001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-api/api/src/java/org/sakaiproject/metaobj/shared/mgt/ReferenceParser.java $
003: * $Id: ReferenceParser.java 8052 2006-04-20 18:16:21Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 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.sakaiproject.metaobj.shared.mgt;
021:
022: import org.sakaiproject.entity.api.Entity;
023: import org.sakaiproject.entity.api.EntityProducer;
024:
025: /**
026: * Created by IntelliJ IDEA.
027: * User: John Ellis
028: * Date: Nov 8, 2005
029: * Time: 2:43:22 PM
030: * To change this template use File | Settings | File Templates.
031: */
032: public class ReferenceParser {
033:
034: private String context;
035: private String id;
036: private String siteId;
037: private String ref;
038:
039: public ReferenceParser(String reference, EntityProducer parent,
040: boolean siteInfo) {
041: parse(reference, parent, siteInfo);
042: }
043:
044: public ReferenceParser(String reference, EntityProducer parent) {
045: parse(reference, parent, true);
046: }
047:
048: protected void parse(String reference, EntityProducer parent,
049: boolean siteInfo) {
050: // with /pres/<siteid>/<preseId>/content/etc/etc.xml
051: String baseRef = reference
052: .substring(parent.getLabel().length() + 2); // lenght of 2 sperators
053:
054: if (siteInfo) {
055: int sep = baseRef.indexOf(Entity.SEPARATOR);
056: siteId = baseRef.substring(0, sep);
057: baseRef = baseRef.substring(sep + 1);
058:
059: sep = baseRef.indexOf(Entity.SEPARATOR);
060: id = baseRef.substring(0, sep);
061: ref = baseRef.substring(sep);
062: } else {
063: ref = Entity.SEPARATOR + baseRef;
064: }
065: context = parent.getLabel();
066: }
067:
068: public String getContext() {
069: return context;
070: }
071:
072: public void setContext(String context) {
073: this .context = context;
074: }
075:
076: public String getId() {
077: return id;
078: }
079:
080: public void setId(String id) {
081: this .id = id;
082: }
083:
084: public String getRef() {
085: return ref;
086: }
087:
088: public void setRef(String ref) {
089: this .ref = ref;
090: }
091:
092: public String getSiteId() {
093: return siteId;
094: }
095:
096: public void setSiteId(String siteId) {
097: this.siteId = siteId;
098: }
099:
100: }
|