001/* 002 * (C) Copyright 2007 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id: NodeInfoImpl.java 21693 2007-07-01 08:00:36Z sfermigier $ 020 */ 021 022package org.nuxeo.ecm.platform.relations.web; 023 024import org.nuxeo.ecm.core.api.DocumentModel; 025import org.nuxeo.ecm.platform.relations.api.Literal; 026import org.nuxeo.ecm.platform.relations.api.Node; 027import org.nuxeo.ecm.platform.relations.api.NodeType; 028import org.nuxeo.ecm.platform.relations.api.QNameResource; 029import org.nuxeo.ecm.platform.relations.api.Resource; 030import org.nuxeo.ecm.platform.ui.web.tag.fn.DocumentModelFunctions; 031 032/** 033 * @author <a href="mailto:[email protected]">Anahide Tchertchian</a> 034 */ 035public class NodeInfoImpl implements NodeInfo { 036 037 private static final long serialVersionUID = -5807130430819964154L; 038 039 protected final Node node; 040 041 protected DocumentModel documentModel; 042 043 protected boolean visible = false; 044 045 public NodeInfoImpl(Node node) { 046 this.node = node; 047 } 048 049 public NodeInfoImpl(Node node, DocumentModel documentModel) { 050 this.node = node; 051 this.documentModel = documentModel; 052 } 053 054 public NodeInfoImpl(Node node, DocumentModel documentModel, boolean visible) { 055 this.node = node; 056 this.documentModel = documentModel; 057 this.visible = visible; 058 } 059 060 // Node interface 061 062 public NodeType getNodeType() { 063 return node.getNodeType(); 064 } 065 066 public boolean isBlank() { 067 return node.isBlank(); 068 } 069 070 public boolean isLiteral() { 071 return node.isLiteral(); 072 } 073 074 public boolean isQNameResource() { 075 return node.isQNameResource(); 076 } 077 078 public boolean isResource() { 079 return node.isResource(); 080 } 081 082 // NodeInfo interface 083 084 public int compareTo(Node o) { 085 return node.compareTo(o); 086 } 087 088 // Node Representation interface 089 090 public String getAction() { 091 if (visible && documentModel != null) { 092 String docId = documentModel.getId(); 093 String actionValue = String.format("#{navigationContext.navigateToId('%s')}", docId); 094 return actionValue; 095 } 096 return null; 097 } 098 099 public DocumentModel getDocumentModel() { 100 return documentModel; 101 } 102 103 public String getHref() { 104 if (documentModel == null && isResource()) { 105 return ((Resource) node).getUri(); 106 } 107 return null; 108 } 109 110 public String getIcon() { 111 return DocumentModelFunctions.iconPath(documentModel); 112 } 113 114 public String getTitle() { 115 String title = null; 116 if (node.isLiteral()) { 117 title = ((Literal) node).getValue(); 118 } else if (node.isQNameResource()) { 119 String resourceTitle = null; 120 QNameResource resource = (QNameResource) node; 121 if (documentModel != null) { 122 String documentTitle = (String) documentModel.getProperty("dublincore", "title"); 123 if (documentTitle != null && documentTitle.length() > 0) { 124 resourceTitle = documentTitle; 125 } 126 } 127 if (resourceTitle == null) { 128 title = resource.getUri(); 129 } else { 130 title = resourceTitle; 131 } 132 } else if (node.isResource()) { 133 title = ((Resource) node).getUri(); 134 } 135 return title; 136 } 137 138 public boolean isLink() { 139 return getHref() != null; 140 } 141 142 public boolean isDocument() { 143 return documentModel != null; 144 } 145 146 public boolean isDocumentVisible() { 147 return documentModel != null && visible; 148 } 149 150 public boolean isText() { 151 return !(isDocumentVisible() || isLink()); 152 } 153 154}