There are 60 code examples for java.net.URI.
The API names are highlighted below.
You can use
button
to vote the code example(s) you like. The best code example will be ranked first next time. Thanks a lot for your feedback.
Project Name: OpenII Package: org.mitre.openii.dialogs.mappings.importer
Source Code: ImportMappingDialog.java (Click to view .java file)
Method Code:
/**
* Handles the actual import of the specified file(s)
*/
protected void okPressed(){
try {
URI uri=uriField.getURI();
Integer sourceID=sourcePane.getSchema().getId();
Integer targetID=targetPane.getSchema().getId();
for ( Mapping mapping : OpenIIManager.getMappings(project.getId())) {
if (mapping.getSourceId().equals(sourceID) && mapping.getTargetId().equals(targetID)) {
throw new Exception("Mapping already exists in project");
}
}
MappingImporter importer=importerSelector.getImporter();
;
importer.initialize(uri);
Integer mappingID=importer.importMapping(project,sourceID,targetID);
if (mappingID != null) {
Mapping mapping=RepositoryManager.getClient().getMapping(mappingID);
OpenIIManager.fireMappingAdded(mapping);
getShell().dispose();
}
}
catch ( Exception e) {
setErrorMessage("Failed to import mapping. " + e.getMessage());
}
}
Project Name: OpenII Package: org.mitre.openii.dialogs.schemas.importer
Source Code: ImportSchemaDialog.java (Click to view .java file)
Method Code:
/**
* Handles the actual import of the specified file(s)
*/
protected void okPressed(){
String errorMessage=null;
SchemaImporter importer=importerSelector.getImporter();
ArrayList<URI> uris=new ArrayList<URI>();
URIField uriField=schemaInfoPane.getURIField();
if (uriField.getMode().equals(URIField.URI)) try {
uris.add(uriField.getURI());
}
catch ( Exception e) {
errorMessage="Invalid URI";
}
else for ( File file : fileSelectionPane.getSelectedFiles()) uris.add(file.toURI());
for ( URI uri : uris) {
try {
String name=schemaInfoPane.getName().equals("") ? new File(uri).getName() : schemaInfoPane.getName();
Integer schemaID=importer.importSchema(name,schemaInfoPane.getAuthor(),schemaInfoPane.getDescription(),uri);
if (schemaID != null) {
Schema schema=RepositoryManager.getClient().getSchema(schemaID);
OpenIIManager.fireSchemaAdded(schema);
}
}
catch ( Exception e) {
errorMessage=e.getMessage();
}
}
if (errorMessage != null) setErrorMessage("Failed to import schemas. " + errorMessage);
else getShell().dispose();
}
Project Name: OpenII Package: org.mitre.openii.model
Source Code: RepositoryManager.java (Click to view .java file)
Method Code:
/**
* Loads in any saved repositories
*/
private static void loadRepositories(){
ScopedPreferenceStore preferences=(ScopedPreferenceStore)OpenIIActivator.getDefault().getPreferenceStore();
Integer count=preferences.getInt("RepositoryCount");
for (int i=0; i < count; i++) try {
String name=preferences.getString("Repository" + i + "Name");
String typeString=preferences.getString("Repository" + i + "Type");
Integer type=typeString.equals("service") ? Repository.SERVICE : typeString.equals("postgres") ? Repository.POSTGRES : Repository.DERBY;
URI uri=null;
try {
uri=new URI(preferences.getString("Repository" + i + "URI"));
}
catch ( Exception e) {
}
String database=preferences.getString("Repository" + i + "Database");
String user=preferences.getString("Repository" + i + "User");
String password=preferences.getString("Repository" + i + "Password");
addRepository(new Repository(name,type,uri,database,user,password));
}
catch ( Exception e) {
}
Integer loc=preferences.getInt("SelectedRepository");
if (repositories.size() > loc && isValidRepository(repositories.get(loc))) setSelectedRepository(repositories.get(loc));
}
Project Name: OpenII Package: org.mitre.openii.views.repositories
Source Code: EditRepositoryDialog.java (Click to view .java file)
Method Code:
/**
* Handles the creating/updating of the repository
*/
protected void okPressed(){
try {
String name=nameField.getText();
Integer type=optionsPanel.getOption().equals(SERVICE) ? Repository.SERVICE : databaseType.getOption().equals(LOCAL) ? Repository.DERBY : Repository.POSTGRES;
URI uri=type.equals(Repository.SERVICE) ? new URI(webURL.getText()) : databaseURI.getURI();
String database=databaseName.getText();
String username=databaseUser.getText();
String password=databasePassword.getText();
Repository newRepository=new Repository(name,type,uri,database,username,password);
if (repository != null) RepositoryManager.disconnectRepository(repository);
RepositoryManager.addRepository(newRepository);
getShell().dispose();
}
catch ( Exception e) {
setErrorMessage("Failed to create repository");
}
}
Project Name: codecover-model Package: org.codecover.model.extensions
Source Code: PluginUtils.java (Click to view .java file)
Method Code:
/**
* Tries to find the path of the jar or directory containing {@code clss},
* returns {@code null} if it can't find it.
*/
public static File getPathOfClass(Logger logger,Class clss,List<ClassLoaderHandler> classLoaderHandlers){
final List<ClassLoaderHandler> myClassLoaderHandlers=new ArrayList<ClassLoaderHandler>(classLoaderHandlers);
myClassLoaderHandlers.add(urlClassLoaderHandler);
final String myJarPath=clss.getName().replace('.','/') + ".class";
final String myPath=clss.getName().replace('.',File.separatorChar) + ".class";
final ClassLoader myClassLoader=clss.getClassLoader();
if (myClassLoader == null) {
logger.warning("Cannot find plugin directory (classloader is null)");
return null;
}
for ( final ClassLoaderHandler handler : myClassLoaderHandlers) {
final List<File> files=handler.handleClassLoader(logger,myClassLoader);
if (files != null) {
for ( final File file : files) {
if (checkPath(file,myJarPath,myPath)) {
return file;
}
}
logger.warning("Cannot find plugin directory (cannot find jar)");
return null;
}
}
final CodeSource codeSource=clss.getProtectionDomain().getCodeSource();
if (codeSource != null) {
final URI uri;
try {
uri=codeSource.getLocation().toURI();
}
catch ( URISyntaxException e) {
throw new RuntimeException(e);
}
if (!uri.getScheme().equals("file")) {
logger.error("Cannot load plugins because we are loaded from a " + uri.getScheme() + ": URI.");
return null;
}
final File file=new File(uri);
if (checkPath(file,myJarPath,myPath)) {
return file;
}
}
logger.warning("Cannot find plugin directory (classloader is of unkown type '" + myClassLoader.getClass().getName() + "')");
return null;
}
Project Name: icTAKES Package: edu.mayo.bmi.uima.core.resource
Source Code: FileLocator.java (Click to view .java file)
Method Code:
private static File locateOnClasspath(String cpLocation) throws FileNotFoundException, URISyntaxException {
ClassLoader cl=FileLocator.class.getClassLoader();
URL indexUrl=cl.getResource(cpLocation);
if (indexUrl == null) {
throw new FileNotFoundException(cpLocation);
}
URI indexUri=new URI(indexUrl.toExternalForm());
File f=new File(indexUri);
return f;
}
Project Name: icTAKES Package: edu.mayo.bmi.uima.core.resource
Source Code: FileResourceImpl.java (Click to view .java file)
Method Code:
public void load(DataResource dr) throws ResourceInitializationException {
URI uri=dr.getUri();
if (uri != null) {
iv_file=new File(dr.getUri());
}
else {
iv_logger.info("URI for data resource is null - using path from URL");
URL url=dr.getUrl();
if (url != null) {
String path=dr.getUrl().getPath();
iv_file=new File(path);
}
}
}
Project Name: rmoffice Package: net.sf.rmoffice.ui.actions
Source Code: DesktopAction.java (Click to view .java file)
Method Code:
public void doPerform(){
if (!java.awt.Desktop.isDesktopSupported()) {
log.error("Desktop is not supported (fatal)");
}
else {
final java.awt.Desktop desktop=java.awt.Desktop.getDesktop();
Action actionType=Action.BROWSE;
if (file != null) {
actionType=Action.OPEN;
}
if (!desktop.isSupported(actionType)) {
log.error("Desktop doesn't support the " + actionType.name() + " action (fatal)");
}
else {
try {
if (uri != null) {
desktop.browse(uri);
}
else if (file != null) {
desktop.open(file);
}
}
catch ( Exception e1) {
log.error(e1.getMessage());
}
}
}
}
Project Name: rssowl.core Package: org.rssowl.core.connection
Source Code: HttpConnectionInputStream.java (Click to view .java file)
Method Code:
/**
* @return the actual {@link URI} used to open this stream.
*/
public URI getLink(){
try {
return new URI(fMethod.getURI().toString());
}
catch ( URIException e) {
return fLink;
}
catch ( URISyntaxException e) {
return fLink;
}
}
Project Name: rssowl.core Package: org.rssowl.core.connection
Source Code: PlatformCredentialsProvider.java (Click to view .java file)
Method Code:
private String toCacheKey(URI link,String realm){
if (realm == null) realm=REALM;
return link.toString() + realm;
}
Project Name: rssowl.core Package: org.rssowl.core.internal.connection
Source Code: ConnectionServiceImpl.java (Click to view .java file)
Method Code:
private ICredentialsProvider internalGetCredentialsProvider(URI link) throws CredentialsException {
String protocol=link.getScheme();
if (!StringUtils.isSet(protocol)) throw new CredentialsException(Activator.getDefault().createErrorStatus(Messages.ConnectionServiceImpl_ERROR_UNKNOWN_PROTOCOL,null));
ICredentialsProvider credentialsProvider=fCredentialsProvider.get(protocol);
if (credentialsProvider == null) throw new CredentialsException(Activator.getDefault().createErrorStatus(NLS.bind(Messages.ConnectionServiceImpl_ERROR_NO_CREDENTIAL_PROVIDER,protocol),null));
return credentialsProvider;
}
Project Name: rssowl.core Package: org.rssowl.core.internal.connection
Source Code: ReaderProtocolHandler.java (Click to view .java file)
Method Code:
private URI readerToHTTP(URI uri) throws ConnectionException {
try {
String scheme=SyncUtils.READER_HTTPS_SCHEME.equals(uri.getScheme()) ? URIUtils.HTTPS_SCHEME : URIUtils.HTTP_SCHEME;
return new URI(scheme,uri.getUserInfo(),uri.getHost(),uri.getPort(),uri.getPath(),uri.getQuery(),uri.getFragment());
}
catch ( URISyntaxException e) {
throw new ConnectionException(Activator.getDefault().createErrorStatus(e.getMessage(),e));
}
}
Project Name: rssowl.core Package: org.rssowl.core.internal.connection
Source Code: DefaultProtocolHandler.java (Click to view .java file)
Method Code:
public URI getFeed(final URI website,IProgressMonitor monitor) throws ConnectionException {
Map<Object,Object> properties=new HashMap<Object,Object>();
properties.put(IConnectionPropertyConstants.PROGRESS_MONITOR,monitor);
properties.put(IConnectionPropertyConstants.CON_TIMEOUT,FEED_LABEL_CON_TIMEOUT);
InputStream inS=openStream(website,properties);
BufferedInputStream bufIns=new BufferedInputStream(inS);
BufferedReader reader=new BufferedReader(new InputStreamReader(bufIns));
try {
if (inS instanceof HttpConnectionInputStream) {
String contentType=((HttpConnectionInputStream)inS).getContentType();
if (contentType != null) {
for ( String feedContentType : CoreUtils.FEED_MIME_TYPES) {
if (contentType.toLowerCase().contains(feedContentType)) return website;
}
}
return CoreUtils.findFeed(reader,((HttpConnectionInputStream)inS).getLink(),monitor);
}
return CoreUtils.findFeed(reader,website,monitor);
}
finally {
closeStream(inS,true);
}
}
Project Name: rssowl.core Package: org.rssowl.core.internal.interpreter
Source Code: AtomInterpreter.java (Click to view .java file)
Method Code:
private void processAuthor(Element element,IPersistable type){
IPerson person=Owl.getModelFactory().createPerson(null,type);
processNamespaceAttributes(element,person);
List<?> personChilds=element.getChildren();
for (Iterator<?> iter=personChilds.iterator(); iter.hasNext(); ) {
Element child=(Element)iter.next();
String name=child.getName().toLowerCase();
if (processElementExtern(child,person)) continue;
else if ("name".equals(name)) {
person.setName(child.getText());
processNamespaceAttributes(child,person);
}
else if ("email".equals(name)) {
URI uri=URIUtils.createURI(child.getText());
if (uri != null) person.setEmail(uri);
processNamespaceAttributes(child,person);
}
else if ("uri".equals(name)) {
URI uri=URIUtils.createURI(child.getText());
if (uri != null) person.setUri(uri);
processNamespaceAttributes(child,person);
}
}
}
Project Name: rssowl.core Package: org.rssowl.core.internal.interpreter
Source Code: XMLNamespaceHandler.java (Click to view .java file)
Method Code:
public void processAttribute(Attribute attribute,IPersistable type){
if ("lang".equals(attribute.getName()) && type instanceof IFeed) ((IFeed)type).setLanguage(attribute.getValue());
if ("base".equals(attribute.getName())) {
URI baseUri=URIUtils.createURI(attribute.getValue());
if (baseUri != null && type instanceof IFeed) ((IFeed)type).setBase(baseUri);
else if (baseUri != null && type instanceof INews) {
INews news=(INews)type;
if (news.getBase() != null && news.getBase().isAbsolute() && !baseUri.isAbsolute()) {
try {
news.setBase(URIUtils.resolve(news.getBase(),baseUri));
}
catch ( URISyntaxException e) {
news.setBase(baseUri);
}
}
else news.setBase(baseUri);
}
}
}
Project Name: rssowl.core Package: org.rssowl.core.internal.interpreter
Source Code: CDFInterpreter.java (Click to view .java file)
Method Code:
private void processItem(Element element,IFeed feed){
INews news=Owl.getModelFactory().createNews(null,feed,new Date(System.currentTimeMillis() - (fNewsCounter++ * 1)));
news.setBase(feed.getBase());
String baseUrl=feed.getHomepage() != null ? feed.getHomepage().toString() : "";
List<?> itemAttributes=element.getAttributes();
for (Iterator<?> iter=itemAttributes.iterator(); iter.hasNext(); ) {
Attribute attribute=(Attribute)iter.next();
String name=attribute.getName().toLowerCase();
if (processAttributeExtern(attribute,news)) continue;
else if ("lastmod".equals(name)) news.setPublishDate(DateUtils.parseDate(attribute.getValue()));
else if ("href".equals(name)) {
URI uri=URIUtils.createURI(baseUrl + attribute.getValue());
if (uri != null) news.setLink(uri);
}
}
List<?> newsChilds=element.getChildren();
for (Iterator<?> iter=newsChilds.iterator(); iter.hasNext(); ) {
Element child=(Element)iter.next();
String name=child.getName().toLowerCase();
if (processElementExtern(child,news)) continue;
else if ("title".equals(name)) {
news.setTitle(child.getText());
processNamespaceAttributes(child,news);
}
else if ("abstract".equals(name)) {
news.setDescription(child.getText());
processNamespaceAttributes(child,news);
}
}
}
Project Name: rssowl.core Package: org.rssowl.core.internal.interpreter
Source Code: OPMLImporter.java (Click to view .java file)
Method Code:
private void processOutline(Element outline,IPersistable parent,List<IEntity> importedEntities,DateFormat dateFormat){
IEntity type=null;
Long id=null;
String title=null;
String link=null;
String homepage=null;
String description=null;
List<?> attributes=outline.getAttributes();
for (Iterator<?> iter=attributes.iterator(); iter.hasNext(); ) {
Attribute attribute=(Attribute)iter.next();
String name=attribute.getName();
if (name.toLowerCase().equals(Attributes.XML_URL.get().toLowerCase())) link=attribute.getValue();
else if (name.toLowerCase().equals(Attributes.TITLE.get())) title=attribute.getValue();
else if (title == null && name.toLowerCase().equals(Attributes.TEXT.get())) title=attribute.getValue();
else if (name.toLowerCase().equals(Attributes.HTML_URL.get().toLowerCase())) homepage=attribute.getValue();
else if (name.toLowerCase().equals(Attributes.DESCRIPTION.get())) description=attribute.getValue();
}
Attribute idAttribute=outline.getAttribute(Attributes.ID.get(),RSSOWL_NS);
if (idAttribute != null) id=Long.valueOf(idAttribute.getValue());
boolean isSet=Boolean.parseBoolean(outline.getAttributeValue(Attributes.IS_SET.get(),RSSOWL_NS));
if (link == null && title != null) {
type=Owl.getModelFactory().createFolder(null,isSet ? null : (IFolder)parent,title);
if (id != null) type.setProperty(ID_KEY,id);
if (isSet) importedEntities.add(type);
}
else {
URI uri=link != null ? URIUtils.createURI(link) : null;
if (uri != null) {
if (uri.getScheme() == null) uri=URIUtils.createURI(URIUtils.HTTP + link);
FeedLinkReference feedLinkRef=new FeedLinkReference(uri);
type=Owl.getModelFactory().createBookMark(null,(IFolder)parent,feedLinkRef,title != null ? title : link);
if (id != null) type.setProperty(ID_KEY,id);
if (StringUtils.isSet(description)) type.setProperty(ITypeImporter.DESCRIPTION_KEY,description);
if (StringUtils.isSet(homepage)) type.setProperty(ITypeImporter.HOMEPAGE_KEY,homepage);
}
}
if (type == null) return;
List<?> children=outline.getChildren();
for (Iterator<?> iter=children.iterator(); iter.hasNext(); ) {
Element child=(Element)iter.next();
String name=child.getName().toLowerCase();
if (Tag.OUTLINE.get().equals(name)) processOutline(child,type,importedEntities,dateFormat);
else if (Tag.SAVED_SEARCH.get().equals(name)) processSavedSearch(child,(IFolder)type,dateFormat);
else if (Tag.BIN.get().equals(name)) processNewsBin(child,(IFolder)type);
else if (Tag.PREFERENCE.get().equals(name)) processPreference(type,child);
}
}
Project Name: rssowl.core Package: org.rssowl.core.internal.interpreter
Source Code: RDFInterpreter.java (Click to view .java file)
Method Code:
private void processItem(Element element,IFeed feed){
INews news=Owl.getModelFactory().createNews(null,feed,new Date(System.currentTimeMillis() - (fNewsCounter++ * 1)));
news.setBase(feed.getBase());
List<?> itemAttributes=element.getAttributes();
for (Iterator<?> iter=itemAttributes.iterator(); iter.hasNext(); ) {
Attribute attribute=(Attribute)iter.next();
String name=attribute.getName().toLowerCase();
if (processAttributeExtern(attribute,news)) continue;
else if ("about".equals(name)) Owl.getModelFactory().createGuid(news,attribute.getValue(),true);
}
List<?> newsChilds=element.getChildren();
for (Iterator<?> iter=newsChilds.iterator(); iter.hasNext(); ) {
Element child=(Element)iter.next();
String name=child.getName().toLowerCase();
if (processElementExtern(child,news)) continue;
else if ("title".equals(name)) {
news.setTitle(child.getText());
processNamespaceAttributes(child,news);
}
else if ("link".equals(name)) {
URI uri=URIUtils.createURI(child.getText());
if (uri != null) news.setLink(uri);
processNamespaceAttributes(child,news);
}
else if ("description".equals(name)) {
news.setDescription(child.getText());
processNamespaceAttributes(child,news);
}
}
}
Project Name: rssowl.core Package: org.rssowl.core.internal.interpreter
Source Code: MediaNamespaceHandler.java (Click to view .java file)
Method Code:
private void processContent(Element element,INews news){
if (element.getAttributes().isEmpty()) return;
URI attachmentUri=null;
String attachmentType=null;
int attachmentLength=-1;
List<?> attributes=element.getAttributes();
for (Iterator<?> iter=attributes.iterator(); iter.hasNext(); ) {
Attribute attribute=(Attribute)iter.next();
String name=attribute.getName();
if ("url".equals(name)) attachmentUri=URIUtils.createURI(attribute.getValue());
else if ("type".equals(name)) attachmentType=attribute.getValue();
else if ("fileSize".equals(name)) attachmentLength=StringUtils.stringToInt(attribute.getValue());
}
if (attachmentUri != null && !CoreUtils.hasAttachment(news,attachmentUri)) {
IAttachment attachment=Owl.getModelFactory().createAttachment(null,news);
attachment.setLink(attachmentUri);
if (StringUtils.isSet(attachmentType)) attachment.setType(attachmentType);
if (attachmentLength != -1) attachment.setLength(attachmentLength);
}
}
Project Name: rssowl.core Package: org.rssowl.core.internal.interpreter
Source Code: OPMLInterpreter.java (Click to view .java file)
Method Code:
private void processOutline(Element element,IFeed feed){
INews news=Owl.getModelFactory().createNews(null,feed,new Date(System.currentTimeMillis() - (fNewsCounter++ * 1)));
news.setBase(feed.getBase());
List<?> outlineAttributes=element.getAttributes();
for (Iterator<?> iter=outlineAttributes.iterator(); iter.hasNext(); ) {
Attribute attribute=(Attribute)iter.next();
String name=attribute.getName().toLowerCase();
if (processAttributeExtern(attribute,news)) continue;
else if ("title".equals(name)) news.setTitle(attribute.getValue());
else if ("url".equals(name)) {
URI uri=URIUtils.createURI(attribute.getValue());
if (uri != null) news.setLink(uri);
}
else if ("htmlurl".equals(name) && news.getLinkAsText() == null) {
URI uri=URIUtils.createURI(attribute.getValue());
if (uri != null) news.setLink(uri);
}
else if ("xmlurl".equals(name)) {
URI uri=URIUtils.createURI(attribute.getValue());
if (uri != null) {
ISource source=Owl.getModelFactory().createSource(news);
source.setLink(uri);
}
}
else if ("text".equals(name)) news.setDescription(attribute.getValue());
else if ("description".equals(name)) news.setDescription(attribute.getValue());
}
List<?> channelChildren=element.getChildren();
for (Iterator<?> iter=channelChildren.iterator(); iter.hasNext(); ) {
Element child=(Element)iter.next();
String name=child.getName().toLowerCase();
if (processElementExtern(child,feed)) continue;
else if ("outline".equals(name)) processOutline(child,feed);
}
}
Project Name: rssowl.core Package: org.rssowl.core.internal.interpreter
Source Code: BugzillaInterpreter.java (Click to view .java file)
Method Code:
private void processDescription(Element element,IFeed feed){
INews news=Owl.getModelFactory().createNews(null,feed,new Date(System.currentTimeMillis() - (fNewsCounter++ * 1)));
news.setBase(feed.getBase());
processNamespaceAttributes(element,feed);
List<?> channelChildren=element.getChildren();
for (Iterator<?> iter=channelChildren.iterator(); iter.hasNext(); ) {
Element child=(Element)iter.next();
String name=child.getName().toLowerCase();
news.setLink(feed.getHomepage());
if (processElementExtern(child,feed)) continue;
else if ("who".equals(name)) {
URI uri=URIUtils.createURI(child.getText());
if (uri != null) {
IPerson person=Owl.getModelFactory().createPerson(null,news);
person.setEmail(uri);
}
news.setTitle(NLS.bind(Messages.BugzillaInterpreter_COMMENT_FROM,child.getText()));
}
else if ("bug_when".equals(name)) {
news.setModifiedDate(DateUtils.parseDate(child.getText()));
}
else if ("thetext".equals(name)) {
news.setDescription(child.getText());
}
}
}
Project Name: rssowl.core Package: org.rssowl.core.internal.interpreter
Source Code: RSSInterpreter.java (Click to view .java file)
Method Code:
private void processTextInput(Element element,IFeed feed){
ITextInput input=Owl.getModelFactory().createTextInput(feed);
processNamespaceAttributes(element,input);
List<?> inputChilds=element.getChildren();
for (Iterator<?> iter=inputChilds.iterator(); iter.hasNext(); ) {
Element child=(Element)iter.next();
String name=child.getName().toLowerCase();
if (processElementExtern(child,input)) continue;
else if ("title".equals(name)) {
input.setTitle(child.getText());
processNamespaceAttributes(child,input);
}
else if ("description".equals(name)) {
input.setDescription(child.getText());
processNamespaceAttributes(child,input);
}
else if ("name".equals(name)) {
input.setName(child.getText());
processNamespaceAttributes(child,input);
}
else if ("link".equals(name)) {
URI uri=URIUtils.createURI(child.getText());
if (uri != null) input.setLink(uri);
processNamespaceAttributes(child,input);
}
}
}
Project Name: rssowl.core Package: org.rssowl.core.internal.persist
Source Code: Attachment.java (Click to view .java file)
Method Code:
public synchronized URI getLink(){
if (fLinkURI == null && fLink != null) fLinkURI=createURI(fLink);
return fLinkURI;
}
Project Name: rssowl.core Package: org.rssowl.core.internal.persist
Source Code: Source.java (Click to view .java file)
Method Code:
public synchronized void setLink(URI link){
if (link != null) fLink=link.toString();
}
Project Name: rssowl.core Package: org.rssowl.core.internal.persist
Source Code: DefaultModelFactory.java (Click to view .java file)
Method Code:
public IConditionalGet createConditionalGet(String ifModifiedSince,URI link,String ifNoneMatch){
return new ConditionalGet(ifModifiedSince,link,ifNoneMatch);
}
Project Name: rssowl.core Package: org.rssowl.core.internal.persist
Source Code: TextInputAdapter.java (Click to view .java file)
Method Code:
public void setLink(URI link){
}
Project Name: rssowl.core Package: org.rssowl.core.internal.persist
Source Code: Persistable.java (Click to view .java file)
Method Code:
/**
* Returns the text representation of <code>uri</code> if <code>uri</code>
* is not <code>null</code>. Returns <code>null</code> otherwise.
* @param uri
* @return the text representation of <code>uri</code> or <code>null</code>.
*/
protected final String getURIText(URI uri){
return uri == null ? null : uri.toString();
}
Project Name: rssowl.core Package: org.rssowl.core.internal.persist
Source Code: ConditionalGet.java (Click to view .java file)
Method Code:
/**
* Creates an instance of this object.
* @param ifModifiedSince the If-Modified Header to be sent as
* If-Modified-Since Request Header.
* @param link the link that this object refers to.
* @param ifNoneMatch the ETag Header to be sent as If-None-Match Request
* Header.
* @throws IllegalArgumentException if <code>ifModifiedSince</code> and
* <code>ifNoneMatch</code> are both null, or if <code>link</code> is
* null.
*/
public ConditionalGet(String ifModifiedSince,URI link,String ifNoneMatch){
Assert.isNotNull(link,"feedLink cannot be null");
internalSetHeaders(ifModifiedSince,ifNoneMatch);
fLink=link.toString();
}
Project Name: rssowl.core Package: org.rssowl.core.internal.persist
Source Code: Person.java (Click to view .java file)
Method Code:
public synchronized void setEmail(URI email){
fEmail=getURIText(email);
}
Project Name: rssowl.core Package: org.rssowl.core.internal.persist
Source Code: Folder.java (Click to view .java file)
Method Code:
public synchronized void setBlogrollLink(URI blogrollLink){
fBlogrollLink=getURIText(blogrollLink);
}
Project Name: rssowl.core Package: org.rssowl.core.internal.persist
Source Code: Feed.java (Click to view .java file)
Method Code:
public synchronized void setBase(URI baseUri){
fBaseUri=getURIText(baseUri);
}
Project Name: rssowl.core Package: org.rssowl.core.internal.persist
Source Code: Image.java (Click to view .java file)
Method Code:
public synchronized void setHomepage(URI homepage){
fHomepage=getURIText(homepage);
}
Project Name: rssowl.core Package: org.rssowl.core.internal.persist
Source Code: News.java (Click to view .java file)
Method Code:
public void setBase(URI baseUri){
fLock.acquireWriteLock();
try {
fBaseUri=getURIText(baseUri);
}
finally {
fLock.releaseWriteLock();
}
}
Project Name: rssowl.core Package: org.rssowl.core.internal.persist.dao
Source Code: FeedDAOImpl.java (Click to view .java file)
Method Code:
public boolean exists(URI link){
return DBHelper.existsFeed(fDb,link);
}
Project Name: rssowl.core Package: org.rssowl.core.internal.persist.dao
Source Code: ConditionalGetDAOImpl.java (Click to view .java file)
Method Code:
public IConditionalGet load(URI link){
Assert.isNotNull(link,"link cannot be null");
try {
Query query=fDb.query();
query.constrain(fEntityClass);
query.descend("fLink").constrain(link.toString());
for ( IConditionalGet entity : getList(query)) {
fDb.activate(entity,Integer.MAX_VALUE);
return entity;
}
}
catch ( Db4oException e) {
throw new PersistenceException(e);
}
return null;
}
Project Name: rssowl.core Package: org.rssowl.core.internal.persist.search
Source Code: ModelSearchImpl.java (Click to view .java file)
Method Code:
private BooleanQuery createNewsByLinkBooleanQuery(URI link,boolean copy){
BooleanQuery query=new BooleanQuery(true);
query.add(new TermQuery(new Term(String.valueOf(INews.LINK),link.toString().toLowerCase())),Occur.MUST);
query.add(createIsCopyTermQuery(copy));
return query;
}
Project Name: rssowl.core Package: org.rssowl.core.internal.persist.service
Source Code: DBHelper.java (Click to view .java file)
Method Code:
public static final boolean existsFeed(ObjectContainer db,URI link){
try {
List<Feed> feeds=getFeeds(db,link);
return !feeds.isEmpty();
}
catch ( Db4oException e) {
throw new PersistenceException(e);
}
}
Project Name: rssowl.core Package: org.rssowl.core.persist.reference
Source Code: FeedLinkReference.java (Click to view .java file)
Method Code:
/**
* Creates an instance of this object for a Feed with link <code>link</code>.
* @param link The link of the Feed that this object references. This cannot
* be null.
*/
public FeedLinkReference(URI link){
Assert.isNotNull(link,"link");
fLinkText=link.toString();
}
Project Name: rssowl.core Package: org.rssowl.core.util
Source Code: CoreUtils.java (Click to view .java file)
Method Code:
/**
* @param news the {@link INews} to check if it contains an{@link IAttachment} with the given link.
* @param link the {@link URI} of an attachment.
* @return <code>true</code> if the {@link INews} contains an{@link IAttachment} with the provided link and <code>false</code>
* otherwise.
*/
public static boolean hasAttachment(INews news,URI link){
List<IAttachment> attachments=news.getAttachments();
for ( IAttachment attachment : attachments) {
if (link.equals(attachment.getLink())) return true;
}
return false;
}
Project Name: rssowl.core Package: org.rssowl.core.util
Source Code: URIUtils.java (Click to view .java file)
Method Code:
/**
* A helper to convert custom schemes (like feed://) to the HTTP counterpart.
* @param uri the uri to get as HTTP/HTTPS {@link URI}.
* @return the converted {@link URI} if necessary.
*/
public static URI toHTTP(URI uri){
if (uri == null) return uri;
String scheme=uri.getScheme();
if (HTTP_SCHEME.equals(scheme) || HTTPS_SCHEME.equals(scheme)) return uri;
String newScheme=HTTP_SCHEME;
if (SyncUtils.READER_HTTPS_SCHEME.equals(scheme)) newScheme=HTTPS_SCHEME;
try {
return new URI(newScheme,uri.getUserInfo(),uri.getHost(),uri.getPort(),uri.getPath(),uri.getQuery(),uri.getFragment());
}
catch ( URISyntaxException e) {
return uri;
}
}
Project Name: rssowl.core Package: org.rssowl.core.util
Source Code: SyncUtils.java (Click to view .java file)
Method Code:
private static String internalGetGoogleApiToken(String email,String pw,boolean refresh,IProgressMonitor monitor) throws ConnectionException, IOException, URISyntaxException {
URI uri=new URI(GOOGLE_API_TOKEN_URL);
IProtocolHandler handler=Owl.getConnectionService().getHandler(uri);
if (handler != null) {
String token=SyncUtils.getGoogleAuthToken(email,pw,refresh,monitor);
Map<String,String> headers=new HashMap<String,String>();
headers.put("Authorization",SyncUtils.getGoogleAuthorizationHeader(token));
Map<Object,Object> properties=new HashMap<Object,Object>();
properties.put(IConnectionPropertyConstants.HEADERS,headers);
properties.put(IConnectionPropertyConstants.CON_TIMEOUT,getConnectionTimeout());
BufferedReader reader=null;
try {
InputStream inS=handler.openStream(uri,monitor,properties);
reader=new BufferedReader(new InputStreamReader(inS));
String line;
while (!monitor.isCanceled() && (line=reader.readLine()) != null) {
return line;
}
}
finally {
try {
if (reader != null) reader.close();
}
catch ( IOException e) {
}
}
}
return null;
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal
Source Code: Controller.java (Click to view .java file)
Method Code:
StringBuilder createLogEntry(IBookMark bookmark,URI feedLink,String msg){
StringBuilder entry=new StringBuilder();
entry.append(NLS.bind(Messages.Controller_ERROR_LOADING,bookmark.getName()));
if (StringUtils.isSet(msg)) entry.append(fNl).append(NLS.bind(Messages.Controller_PROBLEM,msg));
if (feedLink != null) entry.append(fNl).append(NLS.bind(Messages.Controller_LINK,feedLink));
else if (bookmark.getFeedLinkReference() != null) entry.append(fNl).append(NLS.bind(Messages.Controller_LINK,bookmark.getFeedLinkReference().getLinkAsText()));
return entry;
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal
Source Code: OwlUI.java (Click to view .java file)
Method Code:
/**
* Opens the Login Dialog to authenticate against sync services.
* @param shell the {@link Shell} as parent of the dialog or <code>null</code>
* if none.
* @return one of the {@link IDialogConstants} depending on the users choice
* of closing the dialog with OK or Cancel.
*/
public static int openSyncLogin(Shell shell){
if (shell == null) shell=getActiveShell();
if (shell != null) {
URI googleLoginUri=URI.create(SyncUtils.GOOGLE_LOGIN_URL);
LoginDialog dialog=new LoginDialog(shell,googleLoginUri,null,true);
dialog.setHeader(Messages.OwlUI_SYNC_LOGIN);
dialog.setSubline(Messages.OwlUI_SYNC_LOGIN_TEXT);
dialog.setTitleImageDescriptor(OwlUI.getImageDescriptor("icons/wizban/reader_wiz.png"));
return dialog.open();
}
return IDialogConstants.CANCEL_ID;
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal
Source Code: Application.java (Click to view .java file)
Method Code:
private IBookMark getBookMark(String link){
URI linkAsURI;
try {
linkAsURI=new URI(URIUtils.fastEncode(link));
}
catch ( URISyntaxException e) {
return null;
}
Collection<IBookMark> existingBookmarks=DynamicDAO.getDAO(IBookMarkDAO.class).loadAll(new FeedLinkReference(linkAsURI));
if (existingBookmarks.size() > 0) return existingBookmarks.iterator().next();
if (link.startsWith(URIUtils.FEED) || link.startsWith(URIUtils.HTTP)) {
if (link.startsWith(URIUtils.FEED)) link=URIUtils.HTTP + link.substring(URIUtils.FEED.length());
else if (link.startsWith(URIUtils.HTTP)) link=URIUtils.FEED + link.substring(URIUtils.HTTP.length());
try {
linkAsURI=new URI(URIUtils.fastEncode(link));
}
catch ( URISyntaxException e) {
return null;
}
existingBookmarks=DynamicDAO.getDAO(IBookMarkDAO.class).loadAll(new FeedLinkReference(linkAsURI));
if (existingBookmarks.size() > 0) return existingBookmarks.iterator().next();
}
return null;
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal.actions
Source Code: OpenInBrowserAction.java (Click to view .java file)
Method Code:
private void internalRun() throws URISyntaxException {
String title=Messages.OpenInBrowserAction_LOADING;
List<?> selection=fSelection.toList();
for ( Object object : selection) {
URI link=null;
if (object instanceof INews) {
INews news=(INews)object;
title=CoreUtils.getHeadline(news,true);
String linkStr=CoreUtils.getLink(news);
if (StringUtils.isSet(linkStr)) link=new URI(linkStr);
}
else if (object instanceof URI) link=(URI)object;
else if (object instanceof String) link=new URI(URIUtils.fastEncode((String)object));
if (link != null && link.isAbsolute()) {
IWorkbenchBrowserSupport browserSupport=PlatformUI.getWorkbench().getBrowserSupport();
try {
IWebBrowser browser=browserSupport.createBrowser(WebBrowserView.EDITOR_ID);
if (browser instanceof EmbeddedWebBrowser) {
if (fContext != null) ((EmbeddedWebBrowser)browser).setContext(fContext);
else ((EmbeddedWebBrowser)browser).setContext(WebBrowserContext.createFrom(title));
try {
((EmbeddedWebBrowser)browser).openURL(link.toURL(),fForceOpenInBackground);
}
catch ( MalformedURLException e) {
((EmbeddedWebBrowser)browser).openURL(link,fForceOpenInBackground);
}
}
else browser.openURL(link.toURL());
}
catch ( PartInitException e) {
Activator.getDefault().getLog().log(e.getStatus());
}
catch ( MalformedURLException e) {
Activator.getDefault().getLog().log(Activator.getDefault().createErrorStatus(e.getMessage(),e));
}
}
}
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal.dialogs
Source Code: LoginDialog.java (Click to view .java file)
Method Code:
private void preload(){
ICredentials authCredentials=null;
try {
if (fCredProvider != null) authCredentials=fCredProvider.getAuthCredentials(fLink,fRealm);
if (fCredProvider != null && fRealm != null && authCredentials == null) authCredentials=fCredProvider.getAuthCredentials(URIUtils.normalizeUri(fLink,true),fRealm);
}
catch ( CredentialsException e) {
Activator.getDefault().getLog().log(e.getStatus());
}
if (authCredentials != null) {
String username=authCredentials.getUsername();
String password=authCredentials.getPassword();
if (StringUtils.isSet(username)) {
fUsername.setText(username);
fUsername.selectAll();
}
if (StringUtils.isSet(password)) fPassword.setText(password);
}
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal.dialogs.bookmark
Source Code: CreateBookmarkWizard.java (Click to view .java file)
Method Code:
public void run(IProgressMonitor monitor){
monitor.beginTask(Messages.CreateBookmarkWizard_LOADING_TITLE,IProgressMonitor.UNKNOWN);
try {
if (monitor.isCanceled()) return;
if (!URIUtils.looksLikeFeedLink(uriObj[0].toString())) {
final URI feedLink=Owl.getConnectionService().getFeed(uriObj[0],monitor);
if (feedLink != null) uriObj[0]=feedLink;
}
if (monitor.isCanceled()) return;
title[0]=Owl.getConnectionService().getLabel(uriObj[0],monitor);
}
catch ( final ConnectionException e) {
if (!monitor.isCanceled() && e instanceof AuthenticationRequiredException && handleProtectedFeed(uriObj[0],((AuthenticationRequiredException)e).getRealm())) {
try {
title[0]=Owl.getConnectionService().getLabel(uriObj[0],monitor);
}
catch ( ConnectionException e1) {
Activator.getDefault().logError(e.getMessage(),e);
}
}
}
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal.dialogs.importer
Source Code: ImportElementsPage.java (Click to view .java file)
Method Code:
private InputStream openStream(URI link,IProgressMonitor monitor,int timeout,boolean setAcceptLanguage,boolean isLocalized,String authToken) throws ConnectionException {
IProtocolHandler handler=Owl.getConnectionService().getHandler(link);
Map<Object,Object> properties=new HashMap<Object,Object>();
properties.put(IConnectionPropertyConstants.CON_TIMEOUT,timeout);
if (StringUtils.isSet(authToken)) {
Map<String,String> headers=new HashMap<String,String>();
headers.put("Authorization",SyncUtils.getGoogleAuthorizationHeader(authToken));
properties.put(IConnectionPropertyConstants.HEADERS,headers);
}
if (setAcceptLanguage) {
StringBuilder languageHeader=new StringBuilder();
String clientLanguage=Locale.getDefault().getLanguage();
if (!isLocalized) {
languageHeader.append(DEFAULT_LANGUAGE);
if (StringUtils.isSet(clientLanguage) && !DEFAULT_LANGUAGE.equals(clientLanguage)) languageHeader.append(",").append(clientLanguage);
}
else {
if (StringUtils.isSet(clientLanguage)) languageHeader.append(clientLanguage);
else languageHeader.append(DEFAULT_LANGUAGE);
}
properties.put(IConnectionPropertyConstants.ACCEPT_LANGUAGE,languageHeader.toString());
}
return handler.openStream(link,monitor,properties);
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal.dialogs.preferences
Source Code: CredentialsPreferencesPage.java (Click to view .java file)
Method Code:
private void reSetAllCredentials(){
boolean clearedOnce=false;
Set<CredentialsModelData> credentials=loadCredentials();
CredentialsModelData dummyCredentials=null;
if (credentials.isEmpty()) {
try {
dummyCredentials=new CredentialsModelData("","",new URI(DUMMY_LINK),"");
credentials.add(dummyCredentials);
}
catch ( URISyntaxException e) {
}
}
for ( CredentialsModelData credential : credentials) {
ICredentialsProvider credentialsProvider=Owl.getConnectionService().getCredentialsProvider(credential.fNormalizedLink);
if (credentialsProvider != null) {
if (!clearedOnce && credentialsProvider instanceof PlatformCredentialsProvider) {
((PlatformCredentialsProvider)credentialsProvider).clear();
clearedOnce=true;
}
try {
credentialsProvider.setAuthCredentials(credential.toCredentials(),credential.fNormalizedLink,credential.fRealm);
}
catch ( CredentialsException e) {
Activator.getDefault().logError(e.getMessage(),e);
}
}
}
if (dummyCredentials != null) {
ICredentialsProvider credentialsProvider=Owl.getConnectionService().getCredentialsProvider(dummyCredentials.fNormalizedLink);
if (credentialsProvider != null) {
try {
credentialsProvider.deleteAuthCredentials(dummyCredentials.fNormalizedLink,dummyCredentials.fRealm);
}
catch ( CredentialsException e) {
Activator.getDefault().logError(e.getMessage(),e);
}
}
}
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal.dialogs.properties
Source Code: InformationPropertyPage.java (Click to view .java file)
Method Code:
@Override protected void runInUI(IProgressMonitor monitor){
if (fEntities.get(0) instanceof IBookMark) fDescriptionLabel.setText(StringUtils.isSet(description) ? description : Messages.InformationPropertyPage_NONE);
if (fEntities.get(0) instanceof IBookMark) {
fHomepageLink.setText(homepage != null ? "<a>" + homepage.toString() + "</a>" : Messages.InformationPropertyPage_NONE);
if (homepage != null) {
fHomepageLink.addSelectionListener(new SelectionAdapter(){
@Override public void widgetSelected( SelectionEvent e){
OpenInBrowserAction action=new OpenInBrowserAction();
action.selectionChanged(null,new StructuredSelection(homepage));
action.run();
}
}
);
}
}
if (newCount != 0 && unreadCount != 0 && updatedCount != 0) createLabel(fContainer,NLS.bind(Messages.InformationPropertyPage_N_NEW_UNREAD_UPDATED,new Object[]{totalCount,newCount,unreadCount,updatedCount}),false);
else if (newCount != 0 && unreadCount != 0) createLabel(fContainer,NLS.bind(Messages.InformationPropertyPage_N_NEW_UNREAD,new Object[]{totalCount,newCount,unreadCount}),false);
else if (unreadCount != 0 && updatedCount != 0) createLabel(fContainer,NLS.bind(Messages.InformationPropertyPage_N_UNREAD_UPDATED,new Object[]{totalCount,unreadCount,updatedCount}),false);
else if (newCount != 0 && updatedCount != 0) createLabel(fContainer,NLS.bind(Messages.InformationPropertyPage_N_NEW_UPDATED,new Object[]{totalCount,newCount,updatedCount}),false);
else if (newCount != 0) createLabel(fContainer,NLS.bind(Messages.InformationPropertyPage_N_NEW,new Object[]{totalCount,newCount}),false);
else if (unreadCount != 0) createLabel(fContainer,NLS.bind(Messages.InformationPropertyPage_N_UNREAD,new Object[]{totalCount,unreadCount}),false);
else if (updatedCount != 0) createLabel(fContainer,NLS.bind(Messages.InformationPropertyPage_N_UPDATED,new Object[]{totalCount,updatedCount}),false);
else createLabel(fContainer,String.valueOf(totalCount),false);
fContainer.layout(true,true);
fSite.contentsChanged();
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal.dialogs.properties
Source Code: InformationPropertyPage.java (Click to view .java file)
Method Code:
@Override public void widgetSelected(SelectionEvent e){
OpenInBrowserAction action=new OpenInBrowserAction();
action.selectionChanged(null,new StructuredSelection(homepage));
action.run();
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal.editors.browser
Source Code: EmbeddedWebBrowser.java (Click to view .java file)
Method Code:
private void openExternal(URI uri){
BrowserUtils.openLinkExternal(uri.toString());
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal.editors.feed
Source Code: FeedView.java (Click to view .java file)
Method Code:
private void saveAsHtml(String fileName){
StringBuilder content=new StringBuilder();
NewsBrowserLabelProvider labelProvider=(NewsBrowserLabelProvider)fNewsBrowserControl.getViewer().getLabelProvider();
URI base=null;
if (fInput.getMark() instanceof IBookMark) {
try {
base=URIUtils.toHTTP(new URI(((IBookMark)fInput.getMark()).getFeedLinkReference().getLinkAsText()));
}
catch ( URISyntaxException e) {
}
}
if (isTableViewerVisible()) {
Tree tree=fNewsTableControl.getViewer().getTree();
TreeItem[] items=tree.getItems();
if (items.length > 0) {
List<INews> newsToSave=new ArrayList<INews>();
if (items[0].getItemCount() == 0) {
for ( TreeItem item : items) {
if (item.getData() instanceof INews) newsToSave.add((INews)item.getData());
}
}
else {
for ( TreeItem parentItem : items) {
TreeItem[] childItems=parentItem.getItems();
for ( TreeItem item : childItems) {
if (item.getData() instanceof INews) newsToSave.add((INews)item.getData());
}
}
}
String text=labelProvider.render(newsToSave.toArray(),base,false);
content.append(text);
}
}
else {
NewsBrowserViewer viewer=fNewsBrowserControl.getViewer();
Object[] elements=fContentProvider.getElements(fInput.getMark().toReference());
elements=viewer.getFlattendChildren(elements,false);
String text=labelProvider.render(elements,base,false);
content.append(text);
}
if (content.length() > 0) CoreUtils.write(fileName,content);
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal.editors.feed
Source Code: NewsBrowserLabelProvider.java (Click to view .java file)
Method Code:
private String internalRender(Object[] elements,URI base,boolean withManagedLinks){
StringBuilder html=new StringBuilder();
html.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
if (Application.IS_WINDOWS) {
html.append(IE_MOTW);
html.append("\n");
}
html.append("<html>\n <head>\n");
if (base != null) {
html.append(" <base href=\"");
html.append(base);
html.append("\">");
}
html.append("\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n");
try {
StringWriter writer=new StringWriter();
writeCSS(writer,elements.length == 1,false);
html.append(writer.toString());
}
catch ( IOException e) {
}
html.append(" </head>\n <body id=\"owlbody\">\n");
for (int i=0; i < elements.length; i++) {
if (elements[i] instanceof INews) html.append(getText(elements[i],false,withManagedLinks,i));
}
html.append("\n </body>\n</html>");
return html.toString();
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal.editors.feed
Source Code: NewsBrowserViewer.java (Click to view .java file)
Method Code:
@Override protected void runInBackground(IProgressMonitor monitor){
try {
URI uri=new URI(transformedUrl);
IProtocolHandler handler=Owl.getConnectionService().getHandler(uri);
if (handler != null) {
BufferedReader reader=null;
try {
InputStream inS=handler.openStream(uri,monitor,null);
reader=new BufferedReader(new InputStreamReader(inS,"UTF-8"));
String line;
while (!monitor.isCanceled() && (line=reader.readLine()) != null) {
result.append(line);
}
}
catch ( IOException e) {
Activator.getDefault().logError(e.getMessage(),e);
monitor.setCanceled(true);
}
finally {
if (reader != null) {
try {
reader.close();
}
catch ( IOException e) {
monitor.setCanceled(true);
}
}
}
}
}
catch ( URISyntaxException e) {
Activator.getDefault().logError(e.getMessage(),e);
monitor.setCanceled(true);
}
catch ( ConnectionException e) {
Activator.getDefault().logError(e.getMessage(),e);
monitor.setCanceled(true);
}
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal.filter
Source Code: DownloadAttachmentsNewsAction.java (Click to view .java file)
Method Code:
public List<IEntity> run(List<INews> news,Map<INews,INews> replacements,Object data){
news=CoreUtils.replace(news,replacements);
if (data != null && data instanceof String) {
File folder=new File((String)data);
if (folder.exists()) {
for ( INews newsitem : news) {
List<IAttachment> attachments=newsitem.getAttachments();
for ( IAttachment attachment : attachments) {
URI link=attachment.getLink();
if (link != null) {
if (!link.isAbsolute()) {
try {
link=URIUtils.resolve(URIUtils.toHTTP(newsitem.getFeedReference().getLink()),link);
}
catch ( URISyntaxException e) {
Activator.safeLogError(e.getMessage(),e);
continue;
}
}
}
if (link != null) Controller.getDefault().getDownloadService().download(DownloadRequest.createAttachmentDownloadRequest(attachment,link,folder,false,null));
}
if (attachments.isEmpty()) {
String newslink=CoreUtils.getLink(newsitem);
if (StringUtils.isSet(newslink) && !newslink.endsWith(".html")) {
try {
Controller.getDefault().getDownloadService().download(DownloadRequest.createNewsDownloadRequest(newsitem,new URI(newslink),folder));
}
catch ( URISyntaxException e) {
}
}
}
}
}
}
return Collections.emptyList();
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal.services
Source Code: DownloadService.java (Click to view .java file)
Method Code:
public void run(){
if (monitor.isCanceled() || Controller.getDefault().isShuttingDown()) return;
try {
URI normalizedUri=URIUtils.normalizeUri(request.getLink(),true);
if (Owl.getConnectionService().getAuthCredentials(normalizedUri,authEx.getRealm()) != null) {
fDownloadQueue.schedule(new AttachmentDownloadTask(request));
showError[0]=false;
return;
}
}
catch ( CredentialsException exe) {
Activator.getDefault().getLog().log(exe.getStatus());
}
LoginDialog login=new LoginDialog(shell,request.getLink(),authEx.getRealm());
if (login.open() == Window.OK && !monitor.isCanceled() && !Controller.getDefault().isShuttingDown()) {
fDownloadQueue.schedule(new AttachmentDownloadTask(request));
showError[0]=false;
}
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal.util
Source Code: CBrowser.java (Click to view .java file)
Method Code:
private void hookListeners(){
fBrowser.addOpenWindowListener(getOpenWindowListener());
fBrowser.addLocationListener(new LocationListener(){
public void changed( LocationEvent event){
if (event.top) {
if (StringUtils.isSet(event.location) && event.location.equals(fLastSetUrl)) fAllowExternalNavigation=true;
}
}
public void changing( LocationEvent event){
if (StringUtils.isSet(event.location) && !URIUtils.ABOUT_BLANK.equals(event.location) && !event.location.startsWith(URIUtils.JS_IDENTIFIER)) setScriptDisabled(shouldDisableScript(event.location));
if (event.location != null && event.location.contains(ILinkHandler.HANDLER_PROTOCOL)) {
try {
final URI link=new URI(event.location);
final String host=URIUtils.safeGetHost(link);
if (StringUtils.isSet(host) && fLinkHandler.containsKey(host)) {
try {
fLinkHandler.get(host).handle(host,link);
}
finally {
event.doit=false;
}
return;
}
}
catch ( URISyntaxException e) {
Activator.getDefault().getLog().log(Activator.getDefault().createErrorStatus(e.getMessage(),e));
}
}
if (OwlUI.useExternalBrowser()) {
if (!StringUtils.isSet(event.location) || URIUtils.ABOUT_BLANK.equals(event.location)) return;
if (ApplicationServer.getDefault().isNewsServerUrl(event.location)) return;
boolean isManaged=URIUtils.isManaged(event.location);
if (!fAllowExternalNavigation) {
if (!isManaged) return;
}
long currentTimeMillis=System.currentTimeMillis();
if (!isManaged && currentTimeMillis - fLastRefresh < REFRESH_NAVIGATION_DELAY) return;
if (Application.IS_MAC && !isManaged && currentTimeMillis - fLastUrlChange < URL_CHANGE_NAVIGATION_DELAY) return;
for ( String blacklistItem : EXTERNAL_BLACKLIST) {
if (event.location.contains(blacklistItem)) return;
}
event.doit=false;
BrowserUtils.openLinkExternal(URIUtils.toUnManaged(event.location));
}
}
}
);
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal.util
Source Code: CBrowser.java (Click to view .java file)
Method Code:
public void changing(LocationEvent event){
if (StringUtils.isSet(event.location) && !URIUtils.ABOUT_BLANK.equals(event.location) && !event.location.startsWith(URIUtils.JS_IDENTIFIER)) setScriptDisabled(shouldDisableScript(event.location));
if (event.location != null && event.location.contains(ILinkHandler.HANDLER_PROTOCOL)) {
try {
final URI link=new URI(event.location);
final String host=URIUtils.safeGetHost(link);
if (StringUtils.isSet(host) && fLinkHandler.containsKey(host)) {
try {
fLinkHandler.get(host).handle(host,link);
}
finally {
event.doit=false;
}
return;
}
}
catch ( URISyntaxException e) {
Activator.getDefault().getLog().log(Activator.getDefault().createErrorStatus(e.getMessage(),e));
}
}
if (OwlUI.useExternalBrowser()) {
if (!StringUtils.isSet(event.location) || URIUtils.ABOUT_BLANK.equals(event.location)) return;
if (ApplicationServer.getDefault().isNewsServerUrl(event.location)) return;
boolean isManaged=URIUtils.isManaged(event.location);
if (!fAllowExternalNavigation) {
if (!isManaged) return;
}
long currentTimeMillis=System.currentTimeMillis();
if (!isManaged && currentTimeMillis - fLastRefresh < REFRESH_NAVIGATION_DELAY) return;
if (Application.IS_MAC && !isManaged && currentTimeMillis - fLastUrlChange < URL_CHANGE_NAVIGATION_DELAY) return;
for ( String blacklistItem : EXTERNAL_BLACKLIST) {
if (event.location.contains(blacklistItem)) return;
}
event.doit=false;
BrowserUtils.openLinkExternal(URIUtils.toUnManaged(event.location));
}
}
Project Name: rssowl.ui Package: org.rssowl.ui.internal.util
Source Code: ModelUtils.java (Click to view .java file)
Method Code:
/**
* @param selection a {@link IStructuredSelection} of {@link INews}.
* @return a {@link List} of {@link IAttachment} and {@link URI} from the
* selection of {@link INews} pointing to downloadable attachment links.
*/
public static List<Pair<IAttachment,URI>> getAttachmentLinks(IStructuredSelection selection){
List<Pair<IAttachment,URI>> attachmentLinks=new ArrayList<Pair<IAttachment,URI>>();
Collection<INews> news=normalize(selection.toList());
for ( INews newsitem : news) {
List<IAttachment> attachments=newsitem.getAttachments();
for ( IAttachment attachment : attachments) {
URI link=attachment.getLink();
if (link != null) {
if (!link.isAbsolute()) {
try {
link=URIUtils.resolve(URIUtils.toHTTP(newsitem.getFeedReference().getLink()),link);
}
catch ( URISyntaxException e) {
Activator.getDefault().logError(e.getMessage(),e);
continue;
}
}
attachmentLinks.add(Pair.create(attachment,link));
}
}
}
return attachmentLinks;
}