001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS <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 * Jean-Marc Orliaguet, Chalmers 011 * 012 * $Id$ 013 */ 014 015package org.nuxeo.theme.elements; 016 017import java.net.URL; 018import java.util.List; 019 020import org.nuxeo.theme.nodes.AbstractNode; 021import org.nuxeo.theme.nodes.Node; 022import org.nuxeo.theme.nodes.NodeTypeFamily; 023 024public abstract class AbstractElement extends AbstractNode implements Element { 025 026 private ElementType elementType; 027 028 private Integer uid; 029 030 private String name; 031 032 private String description; 033 034 private String cssClassName; 035 036 public Integer getUid() { 037 return uid; 038 } 039 040 public void setUid(final Integer uid) { 041 this.uid = uid; 042 } 043 044 public ElementType getElementType() { 045 return elementType; 046 } 047 048 public void setElementType(final ElementType elementType) { 049 this.elementType = elementType; 050 } 051 052 @Override 053 public NodeTypeFamily getNodeTypeFamily() { 054 return elementType.getNodeTypeFamily(); 055 } 056 057 public String hash() { 058 if (uid == null) { 059 return null; 060 } 061 return uid.toString(); 062 } 063 064 public List<Node> getChildrenInContext(final URL themeURL) { 065 return getChildren(); 066 } 067 068 public String getName() { 069 return name; 070 } 071 072 public void setName(final String name) { 073 this.name = name; 074 } 075 076 public String getDescription() { 077 return description; 078 } 079 080 public void setDescription(final String description) { 081 this.description = description; 082 } 083 084 public boolean isEmpty() { 085 return !hasChildren(); 086 } 087 088 @Override 089 public String getCssClassName() { 090 return cssClassName; 091 } 092 093 @Override 094 public void setCssClassName(String cssClassName) { 095 this.cssClassName = cssClassName; 096 } 097 098 public String computeXPath() { 099 final StringBuilder s = new StringBuilder(); 100 String typeName = null; 101 Element e = this; 102 do { 103 Integer order = e.getOrder(); 104 if (order != null) { 105 order += 1; 106 s.insert(0, "[" + order + ']'); 107 } 108 typeName = e.getElementType().getTypeName(); 109 if (typeName.equals("theme")) { 110 break; 111 } 112 s.insert(0, typeName); 113 if (typeName.equals("page")) { 114 break; 115 } 116 s.insert(0, '/'); 117 e = (Element) e.getParent(); 118 } while (e != null); 119 return s.toString(); 120 } 121 122}