1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.jempbox.xmp; 18 19 import java.io.IOException; 20 import java.util.Calendar; 21 22 import org.apache.jempbox.impl.DateConverter; 23 import org.apache.jempbox.impl.XMLUtil; 24 import org.w3c.dom.Element; 25 26 /** 27 * This class represents a high level event that occured during the processing 28 * of this resource. 29 * 30 * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a> 31 * @version $Revision: 1.2 $ 32 */ 33 public class ResourceEvent implements Elementable 34 { 35 36 /** 37 * Namespace for a resource event. 38 */ 39 public static final String NAMESPACE = "http://ns.adobe.com/xap/1.0/sType/ResourceEvent#"; 40 41 /** 42 * A predefined action. 43 */ 44 public static final String ACTION_CONVERTED = "converted"; 45 /** 46 * A predefined action. 47 */ 48 public static final String ACTION_COPIED = "copied"; 49 /** 50 * A predefined action. 51 */ 52 public static final String ACTION_CREATED = "created"; 53 /** 54 * A predefined action. 55 */ 56 public static final String ACTION_CROPPED = "cropped"; 57 /** 58 * A predefined action. 59 */ 60 public static final String ACTION_EDITED = "edited"; 61 /** 62 * A predefined action. 63 */ 64 public static final String ACTION_FILTERED = "filtered"; 65 /** 66 * A predefined action. 67 */ 68 public static final String ACTION_FORMATTED = "formatted"; 69 /** 70 * A predefined action. 71 */ 72 public static final String ACTION_VERSION_UPDATED = "version_updated"; 73 /** 74 * A predefined action. 75 */ 76 public static final String ACTION_PRINTED = "printed"; 77 /** 78 * A predefined action. 79 */ 80 public static final String ACTION_PUBLISHED = "published"; 81 /** 82 * A predefined action. 83 */ 84 public static final String ACTION_MANAGED = "managed"; 85 /** 86 * A predefined action. 87 */ 88 public static final String ACTION_PRODUCED = "produced"; 89 /** 90 * A predefined action. 91 */ 92 public static final String ACTION_RESIZED = "resized"; 93 94 /** 95 * The DOM representation of this object. 96 */ 97 protected Element parent = null; 98 99 /** 100 * Create a resource reference based on a existing parent property set. 101 * 102 * @param parentElement The parent element that will store the resource properties. 103 */ 104 public ResourceEvent( Element parentElement ) 105 { 106 parent = parentElement; 107 if( !parent.hasAttribute( "xmlns:stEvt" ) ) 108 { 109 parent.setAttributeNS( 110 XMPSchema.NS_NAMESPACE, 111 "xmlns:stEvt", 112 NAMESPACE ); 113 } 114 } 115 116 /** 117 * Create resource event based on schema. 118 * 119 * @param schema The schema that this event will be part of. 120 */ 121 public ResourceEvent( XMPSchema schema ) 122 { 123 parent = schema.getElement().getOwnerDocument().createElement( "rdf:li" ); 124 parent.setAttributeNS( 125 XMPSchema.NS_NAMESPACE, 126 "xmlns:stEvt", 127 NAMESPACE ); 128 } 129 130 /** 131 * Get the underlying XML element. 132 * 133 * @return The XML element that this object represents. 134 */ 135 public Element getElement() 136 { 137 return parent; 138 } 139 140 /** 141 * Get the action that occured. See the ACTION_XXX constants. 142 * 143 * @return An action key, such as 'created' or 'printed'. 144 */ 145 public String getAction() 146 { 147 return XMLUtil.getStringValue( parent, "stEvt:action" ); 148 } 149 150 /** 151 * Set the action that this event represents. See the ACTION_XXX constants. 152 * 153 * @param action The action that this event represents. 154 */ 155 public void setAction( String action ) 156 { 157 XMLUtil.setStringValue( parent, "stEvt:action", action ); 158 } 159 160 /** 161 * Get the referenced resource's instance id. 162 * 163 * @return The id of the reference document instance. 164 */ 165 public String getInstanceID() 166 { 167 return XMLUtil.getStringValue( parent, "stEvt:instanceID" ); 168 } 169 170 /** 171 * Set the referenced resource's document instance id. 172 * 173 * @param id The id of the reference document instance. 174 */ 175 public void setInstanceID( String id ) 176 { 177 XMLUtil.setStringValue( parent, "stEvt:instanceID", id ); 178 } 179 180 /** 181 * Get an additional description of the event. 182 * 183 * @return Additional description of this event 184 */ 185 public String getParameters() 186 { 187 return XMLUtil.getStringValue( parent, "stEvt:parameters" ); 188 } 189 190 /** 191 * Set some addition description to this event. 192 * 193 * @param param The additional action parameters. 194 */ 195 public void setParameters( String param ) 196 { 197 XMLUtil.setStringValue( parent, "stEvt:parameters", param ); 198 } 199 200 /** 201 * Get the software that performed this action. 202 * 203 * @return The software that performed the action. 204 */ 205 public String getSoftwareAgent() 206 { 207 return XMLUtil.getStringValue( parent, "stEvt:softwareAgent" ); 208 } 209 210 /** 211 * Set the software that performed this operation. 212 * 213 * @param software The name of the software that performed this action. 214 */ 215 public void setSoftwareAgent( String software ) 216 { 217 XMLUtil.setStringValue( parent, "stEvt:softwareAgent", software ); 218 } 219 220 /** 221 * Get the date/time that this event occured. 222 * 223 * @return The date of the event. 224 * 225 * @throws IOException If there is an error creating the date. 226 */ 227 public Calendar getWhen() throws IOException 228 { 229 return DateConverter.toCalendar( XMLUtil.getStringValue( parent, "stEvt:when" ) ); 230 } 231 232 /** 233 * Set when the event occured. 234 * 235 * @param when The date that the event occured. 236 */ 237 public void setWhen( Calendar when ) 238 { 239 XMLUtil.setStringValue( parent, "stEvt:when", DateConverter.toISO8601( when ) ); 240 } 241 242 /** 243 * Get name of the asset management system that manages this resource. 244 * 245 * @return The name of a asset management system. 246 */ 247 public String getManager() 248 { 249 return XMLUtil.getStringValue( parent, "stRef:manager" ); 250 } 251 252 /** 253 * Set the name of the system that manages this resource. 254 * 255 * @param manager The name of the management system. 256 */ 257 public void setMangager( String manager ) 258 { 259 XMLUtil.setStringValue( parent, "stRef:manager", manager ); 260 } 261 262 /** 263 * Get name of the variant of asset management system that manages this resource. 264 * 265 * @return The name of a asset management system. 266 */ 267 public String getManagerVariant() 268 { 269 return XMLUtil.getStringValue( parent, "stRef:managerVariant" ); 270 } 271 272 /** 273 * Set the name of the variant of the system that manages this resource. 274 * 275 * @param managerVariant The name of the management system. 276 */ 277 public void setMangagerVariant( String managerVariant ) 278 { 279 XMLUtil.setStringValue( parent, "stRef:managerVariant", managerVariant ); 280 } 281 282 /** 283 * URI identifying the managed resource. 284 * 285 * @return The URI to resource. 286 */ 287 public String getManagerTo() 288 { 289 return XMLUtil.getStringValue( parent, "stRef:managerTo" ); 290 } 291 292 /** 293 * Set the URI to the managed resource. 294 * 295 * @param managerTo The URI to the managed resource. 296 */ 297 public void setMangagerTo( String managerTo ) 298 { 299 XMLUtil.setStringValue( parent, "stRef:managerTo", managerTo ); 300 } 301 302 /** 303 * URI to info about the managed resource. 304 * 305 * @return The URI to the resource info. 306 */ 307 public String getManagerUI() 308 { 309 return XMLUtil.getStringValue( parent, "stRef:managerUI" ); 310 } 311 312 /** 313 * Set the URI to the info about the managed resource. 314 * 315 * @param managerUI The URI to the managed resource information. 316 */ 317 public void setMangagerUI( String managerUI ) 318 { 319 XMLUtil.setStringValue( parent, "stRef:managerUI", managerUI ); 320 } 321 322 }