/** Set the value of a synthesizer property. * @param property the property whose value will be set * @param value the value to set * @throws IllegalArgumentException if an error occurs while setting the property */ public void setProperty(SpeechProperty property, NSObject value) throws IllegalArgumentException { ObjCObjectByReference errorPtr = new ObjCObjectByReference(); if ( !setObject_forProperty_error(value, property.getNativeValue(), errorPtr) ) { NSError error = errorPtr.getValueAs(NSError.class); throw new IllegalArgumentException("Could not set property: " + property + " to value " + value + ", error: " + error.localizedDescription()); } }
@Override public String create(final Local file) throws AccessDeniedException { final ObjCObjectByReference error = new ObjCObjectByReference(); // Create new security scoped bookmark final NSURL url = NSURL.fileURLWithPath(file.getAbsolute()); if(log.isTraceEnabled()) { log.trace(String.format("Resolved file %s to url %s", file, url)); } final NSData data = url.bookmarkDataWithOptions_includingResourceValuesForKeys_relativeToURL_error( create, null, null, error); if(null == data) { log.warn(String.format("Failure getting bookmark data for file %s", file)); final NSError f = error.getValueAs(NSError.class); if(null == f) { throw new LocalAccessDeniedException(file.getAbsolute()); } throw new LocalAccessDeniedException(String.format("%s", f.localizedDescription())); } final String encoded = data.base64Encoding(); if(log.isTraceEnabled()) { log.trace(String.format("Encoded bookmark for %s as %s", file, encoded)); } return encoded; }
@Override public void symlink(final Local file, final String target) throws AccessDeniedException { final ObjCObjectByReference error = new ObjCObjectByReference(); final boolean success = NSFileManager.defaultManager().createSymbolicLinkAtPath_withDestinationPath_error( file.getAbsolute(), target, error); if(!success) { final NSError f = error.getValueAs(NSError.class); if(null == f) { throw new LocalAccessDeniedException(String.format("%s %s", LocaleFactory.localizedString("Cannot create file", "Error"), file.getAbsolute())); } throw new LocalAccessDeniedException(String.format("%s", f.localizedDescription())); } if(log.isDebugEnabled()) { log.debug(String.format("Created symbolic link %s with target %s", file, target)); } } }
@Override public NSURL resolve(final Local file, final boolean interactive) throws AccessDeniedException { final NSData bookmark; if(null == file.getBookmark()) { log.warn(String.format("Missing security scoped bookmark for file %s", file)); if(interactive) { // Prompt user if no bookmark reference is available final String reference = this.choose(file); file.setBookmark(reference); bookmark = NSData.dataWithBase64EncodedString(reference); } else { throw new LocalAccessDeniedException(String.format("No security scoped bookmark for %s", file.getName())); } } else { bookmark = NSData.dataWithBase64EncodedString(file.getBookmark()); } final ObjCObjectByReference error = new ObjCObjectByReference(); final NSURL resolved = NSURL.URLByResolvingBookmarkData(bookmark, resolve, error); if(null == resolved) { log.warn(String.format("Error resolving bookmark for %s to URL", file)); final NSError f = error.getValueAs(NSError.class); if(null == f) { throw new LocalAccessDeniedException(file.getAbsolute()); } throw new LocalAccessDeniedException(String.format("%s", f.localizedDescription())); } return resolved; }
/** Get the value of a synthesizer property. * @param property the property whose value should be retrieved * @return the value asociated with the property * @throws IllegalArgumentException if an error occurs while reading the property */ public NSObject getProperty(SpeechProperty property) throws IllegalArgumentException { ObjCObjectByReference errorPtr = new ObjCObjectByReference(); NSObject result = objectForProperty_error(property.getNativeValue(), errorPtr); NSError error = errorPtr.getValueAs(NSError.class); //objectForProperty:error isn't well documented, so be very conservative if ( result != null && !result.id().isNull() && (error == null || error.id().isNull() || error.code().intValue() == 0) ) { return result; } else { throw new IllegalArgumentException("Could not get property: " + property + ", error: " + error.localizedDescription()); } }
private NSDictionary getNativeAttributes() throws AccessDeniedException, NotfoundException { if((!local.exists())) { throw new LocalNotfoundException(local.getAbsolute()); } final ObjCObjectByReference error = new ObjCObjectByReference(); // If flag is true and path is a symbolic link, the attributes of the linked-to file are returned; // if the link points to a nonexistent file, this method returns null. If flag is false, // the attributes of the symbolic link are returned. final NSDictionary dict = NSFileManager.defaultManager().attributesOfItemAtPath_error( local.getAbsolute(), error); if(null == dict) { final NSError f = error.getValueAs(NSError.class); if(null == f) { throw new LocalAccessDeniedException(local.getAbsolute()); } throw new LocalAccessDeniedException(String.format("%s", f.localizedDescription())); } return dict; }