001/* 002 * (C) Copyright 2006-2008 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 * Alexandre Russel 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.platform.annotations.gwt.client.annotea; 023 024import com.google.gwt.xml.client.NamedNodeMap; 025import com.google.gwt.xml.client.Node; 026 027/** 028 * @author <a href="mailto:[email protected]">Alexandre Russel</a> 029 */ 030public class Statement { 031 032 private String subject; 033 034 private String predicate; 035 036 private String object; 037 038 private boolean isResource; 039 040 public Statement(Node node) { 041 predicate = getFQName(node); 042 if (node.getAttributes() != null && node.getAttributes().getLength() != 0) { 043 NamedNodeMap map = node.getAttributes(); 044 for (int x = 0; x < map.getLength(); x++) { 045 String attr = getFQName(map.item(x)); 046 if (attr.equals(RDFConstant.R_RESOURCE)) { 047 object = map.item(x).getNodeValue(); 048 isResource = true; 049 } 050 } 051 } 052 if (!isResource) { 053 if (node.getChildNodes() != null && node.getChildNodes().getLength() != 0) { 054 object = node.getChildNodes().item(0).getNodeValue().trim(); 055 } else { 056 object = ""; 057 } 058 } 059 060 } 061 062 public boolean isResource() { 063 return isResource; 064 } 065 066 public void setResource(boolean isResource) { 067 this.isResource = isResource; 068 } 069 070 private String getFQName(Node node) { 071 String ns = node.getNamespaceURI(); 072 String name = node.getNodeName(); 073 name = name.replaceFirst(".*:", ""); 074 return "{" + ns + "}" + name; 075 } 076 077 public String getSubject() { 078 return subject; 079 } 080 081 public void setSubject(String subject) { 082 this.subject = subject; 083 } 084 085 public String getPredicate() { 086 return predicate; 087 } 088 089 public void setPredicate(String predicate) { 090 this.predicate = predicate; 091 } 092 093 public String getObject() { 094 return object; 095 } 096 097 public void setObject(String object) { 098 this.object = object; 099 } 100}