001/* 002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Alexandre Russel 016 * 017 * $Id$ 018 */ 019 020package org.nuxeo.ecm.platform.annotations.gwt.client.annotea; 021 022import com.google.gwt.xml.client.NamedNodeMap; 023import com.google.gwt.xml.client.Node; 024 025/** 026 * @author <a href="mailto:arussel@nuxeo.com">Alexandre Russel</a> 027 */ 028public class Statement { 029 030 private String subject; 031 032 private String predicate; 033 034 private String object; 035 036 private boolean isResource; 037 038 public Statement(Node node) { 039 predicate = getFQName(node); 040 if (node.getAttributes() != null && node.getAttributes().getLength() != 0) { 041 NamedNodeMap map = node.getAttributes(); 042 for (int x = 0; x < map.getLength(); x++) { 043 String attr = getFQName(map.item(x)); 044 if (attr.equals(RDFConstant.R_RESOURCE)) { 045 object = map.item(x).getNodeValue(); 046 isResource = true; 047 } 048 } 049 } 050 if (!isResource) { 051 if (node.getChildNodes() != null && node.getChildNodes().getLength() != 0) { 052 object = node.getChildNodes().item(0).getNodeValue().trim(); 053 } else { 054 object = ""; 055 } 056 } 057 058 } 059 060 public boolean isResource() { 061 return isResource; 062 } 063 064 public void setResource(boolean isResource) { 065 this.isResource = isResource; 066 } 067 068 private String getFQName(Node node) { 069 String ns = node.getNamespaceURI(); 070 String name = node.getNodeName(); 071 name = name.replaceFirst(".*:", ""); 072 return "{" + ns + "}" + name; 073 } 074 075 public String getSubject() { 076 return subject; 077 } 078 079 public void setSubject(String subject) { 080 this.subject = subject; 081 } 082 083 public String getPredicate() { 084 return predicate; 085 } 086 087 public void setPredicate(String predicate) { 088 this.predicate = predicate; 089 } 090 091 public String getObject() { 092 return object; 093 } 094 095 public void setObject(String object) { 096 this.object = object; 097 } 098}