001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * bstefanescu 011 */ 012package org.nuxeo.ecm.automation.client.model; 013 014/** 015 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 016 */ 017public class PathRef extends DocRef { 018 019 private static final long serialVersionUID = 1L; 020 021 public PathRef(String path) { 022 super(path); 023 } 024 025 public String value() { 026 return ref; 027 } 028 029 public PathRef getParent() { 030 if (ref.length() == 0 || ref.equals("/")) { 031 return null; 032 } 033 String path = ref; 034 if (path.endsWith("/")) { 035 path = path.substring(0, path.length() - 1); 036 } 037 int p = path.lastIndexOf('/'); 038 if (p == -1) { 039 return new PathRef("/"); 040 } else { 041 return new PathRef(path.substring(0, p)); 042 } 043 } 044 045 public PathRef getChild(String childPath) { 046 StringBuilder buf = new StringBuilder(ref); 047 if (ref.endsWith("/")) { 048 buf.append(childPath); 049 } else { 050 buf.append('/').append(childPath); 051 } 052 return new PathRef(buf.toString()); 053 } 054 055}