public Source getChild(String name) throws SourceException { Source child = (Source) this.children.get(name); if (child == null) throw new SourceException("The block named " + name + "doesn't exist"); return child; }
"unable to delete source: " + se.getMessage(), systemID, RESULT_FAILED,
/** * @see org.apache.excalibur.source.TraversableSource#getParent() */ public Source getParent() throws SourceException { String uri = "context:/" + this.path; uri = uri.substring(0, uri.lastIndexOf('/')); try { return this.factory.getSource(uri, null); } catch (IOException ioe) { throw new SourceException("Unable to get source for: " + uri); } }
public InputStream getInputStream() throws IOException, SourceException { if (!exists()) throw new SourceException("POST data does not exists for request. Make sure you are processing service call."); return requestBody; }
/** * Deletes the source. * * @throws SourceException if an error occurs * @see org.apache.excalibur.source.ModifiableSource#delete() */ public void delete() throws SourceException { try { m_fileObject.delete(); } catch (final FileSystemException e) { throw new SourceException("Unable to delete resource: " + m_location, e); } }
/** * Delete the source. */ public void delete() throws SourceException { if (!this.m_file.exists()) { throw new SourceNotFoundException("Cannot delete non-existing file " + this.m_file.toString()); } if (!this.m_file.delete()) { throw new SourceException("Could not delete " + this.m_file.toString() + " (unknown reason)"); } }
private void init(String scheme, File file) throws SourceException { this.m_scheme = scheme; String uri; try { uri = file.toURL().toExternalForm(); // toExternalForm() is buggy, see e.g. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4924415 // therefore we check if file: is followed by just one slash // TODO when we move to JDK 1.4+, we should use file.toURI().toASCIIString() instead. if ( uri.length() > 6 && uri.startsWith("file:/") && uri.charAt(6) != '/' ) { uri = "file:///" + uri.substring(6); } } catch (MalformedURLException mue) { // Can this really happen ? throw new SourceException("Failed to get URL for file " + file, mue); } if (!uri.startsWith(scheme)) { // Scheme is not "file:" uri = scheme + ':' + uri.substring(uri.indexOf(':') + 1); } this.m_uri = uri; this.m_file = file; }
/** * @see org.apache.excalibur.source.TraversableSource#getChild(java.lang.String) */ public Source getChild(String name) throws SourceException { final String postfixOne = '/' + name + '/'; final String postfixTwo = '/' + name; final Iterator i = this.children.iterator(); while ( i.hasNext() ) { String uri = (String)i.next(); if ( uri.endsWith(postfixOne ) ){ uri = "context:/" + uri; uri = uri.substring(0, uri.length()-1); try { return this.factory.getSource(uri, null); } catch (IOException ioe) { throw new SourceException("Unable to get source for: " + uri); } } else if ( uri.endsWith(postfixTwo) ) { uri = "context:/" + uri; try { return this.factory.getSource(uri, null); } catch (IOException ioe) { throw new SourceException("Unable to get source for: " + uri); } } } return null; }
/** * @see org.apache.excalibur.source.TraversableSource#getChild(java.lang.String) */ public Source getChild(String name) throws SourceException { if (!this.m_file.isDirectory()) { throw new SourceException(this.getURI() + " is not a directory"); } return new FileSource(this.getScheme(), new File(this.m_file, name)); }
/** * @see org.apache.excalibur.source.TraversableSource#getChildren() */ public Collection getChildren() throws SourceException { final List l = new ArrayList(); final Iterator i = this.children.iterator(); while ( i.hasNext() ) { String uri = (String)i.next(); uri = "context:/" + uri; try { l.add(this.factory.getSource(uri, null)); } catch (IOException ioe) { final Iterator ci = l.iterator(); while ( ci.hasNext() ) { this.factory.release((Source)ci.next()); } throw new SourceException("Unable to get source for: " + uri); } } return l; }
/** * @see org.apache.excalibur.source.TraversableSource#getChildren() */ public Collection getChildren() throws SourceException { if (!this.m_file.isDirectory()) { throw new SourceException(this.getURI() + " is not a directory"); } // Build a FileSource object for each of the children File[] files = this.m_file.listFiles(); FileSource[] children = new FileSource[files.length]; for (int i = 0; i < files.length; i++) { children[i] = new FileSource(this.getScheme(), files[i]); } // Return it as a list return Arrays.asList(children); }
throw new SourceException("Request object " + location + " is not an uploaded Part");
/** * Cancel the data sent to an <code>OutputStream</code> returned by * {@link #getOutputStream()}. * <p> * After cancel, the stream should not be used. */ public void cancel( final OutputStream stream ) throws IOException { if ( stream instanceof FTPSourceOutputStream ) { FTPSourceOutputStream fsos = (FTPSourceOutputStream) stream; if ( fsos.getSource() == this ) { try { fsos.cancel(); } catch ( Exception e ) { throw new SourceException( "Exception during cancel.", e ); } return; } } throw new IllegalArgumentException( "The stream is not associated to this source" ); }
/** * Cancel the data sent to an <code>OutputStream</code> returned by * {@link #getOutputStream()}. * <p> * After cancel, the stream should no more be used. */ public void cancel(OutputStream stream) throws SourceException { if (stream instanceof FileSourceOutputStream) { FileSourceOutputStream fsos = (FileSourceOutputStream) stream; if (fsos.getSource() == this) { try { fsos.cancel(); } catch (Exception e) { throw new SourceException("Exception during cancel.", e); } return; } } // Not a valid stream for this source throw new IllegalArgumentException("The stream is not associated to this source"); }
public Source getSource(String location, Map parameters) throws IOException { // Checks URL syntax int protocolEnd = location.indexOf(":"); if (protocolEnd == -1) { throw new MalformedURLException("Protocol ':' separator is missing in URL: " + location); } int archiveEnd = location.lastIndexOf("!/"); if (archiveEnd == -1) { throw new MalformedURLException("File path '!/' separator is missing in URL: " + location); } // Get protocol. Protocol is configurable via cocoon.xconf final String protocol = location.substring(0, protocolEnd); // Get archive URL final String archiveURL = location.substring(protocolEnd + 1, archiveEnd); // Get file path final String filePath = location.substring(archiveEnd + 2); // Resolve archive source Source archive; SourceResolver resolver = null; try { resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE); archive = resolver.resolveURI(archiveURL); } catch (ServiceException se) { throw new SourceException("SourceResolver is not available.", se); } finally { this.manager.release(resolver); } return new ZipSource(protocol, archive, filePath); }
/** * @see org.apache.excalibur.source.MoveableSource#moveTo(org.apache.excalibur.source.Source) */ public void moveTo(Source destination) throws SourceException { if (destination instanceof FileSource) { final File dest = ((FileSource) destination).getFile(); final File parent = dest.getParentFile(); if (parent != null) { parent.mkdirs(); // ensure parent directories exist } if (!this.m_file.renameTo(dest)) { throw new SourceException("Couldn't move " + this.getURI() + " to " + destination.getURI()); } } else { SourceUtil.move(this, destination); } }
/** * Move the source to a specified destination. * * @param source Source of the source. * @param destination Destination of the source. * * @throws SourceException If an exception occurs during * the move. */ static public void move(Source source, Source destination) throws SourceException { if (source instanceof MoveableSource && source.getClass().equals(destination.getClass())) { ((MoveableSource)source).moveTo(destination); } else if (source instanceof ModifiableSource) { copy(source, destination); ((ModifiableSource) source).delete(); } else { throw new SourceException("Source '"+source.getURI()+ "' is not writeable"); } }
return resolver.resolveURI(resolvedPath); } catch (ServiceException se) { throw new SourceException("SourceResolver is not available.", se); } finally { this.serviceManager.release(resolver);
message.append( HTTPClientSource.class.getName() ); throw new SourceException( message.toString(), e );
throw new SourceException( message, e );