1 /*************************************************************************
3 * $RCSfile: ResourceRemover.java,v $
7 * last change: $Author: rt $ $Date: 2005-01-31 16:59:29 $
9 * The Contents of this file are made available subject to the terms of
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
44 public class ResourceRemover
{
49 private Helper m_helper
;
50 private String m_contenturl
= "";
51 private com
.sun
.star
.ucb
.XContent m_content
;
56 *@param String[] This construtor requires the arguments:
58 * -workdir=... (optional)
59 * See Help (method printCmdLineUsage()).
60 * Without the arguments a new connection to a
61 * running office cannot created.
62 *@exception java.lang.Exception
64 public ResourceRemover( String args
[] ) throws java
.lang
.Exception
{
67 parseArguments( args
);
70 m_helper
= new Helper( getContentURL() );
73 m_content
= m_helper
.createUCBContent();
79 *@return boolean Returns true if resource successfully deleted, false otherwise
80 *@exception com.sun.star.ucb.CommandAbortedException
81 *@exception com.sun.star.uno.Exception
83 public boolean deleteResource()
84 throws com
.sun
.star
.ucb
.CommandAbortedException
, com
.sun
.star
.uno
.Exception
{
86 boolean result
= false;
87 if ( m_content
!= null ) {
89 /////////////////////////////////////////////////////////////////////
90 // Destroy a resource physically...
91 /////////////////////////////////////////////////////////////////////
93 Boolean deletePhysically
= new Boolean( true );
95 // Execute command "delete".
96 m_helper
.executeCommand( m_content
, "delete", deletePhysically
);
105 *@return String That contains the connect URL
107 public String
getContentURL() {
114 *@param String[] Arguments
115 *@exception java.lang.Exception
117 public void parseArguments( String
[] args
) throws java
.lang
.Exception
{
121 for ( int i
= 0; i
< args
.length
; i
++ ) {
122 if ( args
[i
].startsWith( "-url=" )) {
123 m_contenturl
= args
[i
].substring( 5 );
124 } else if ( args
[i
].startsWith( "-workdir=" )) {
125 workdir
= args
[i
].substring( 9 );
126 } else if ( args
[i
].startsWith( "-help" ) ||
127 args
[i
].startsWith( "-?" )) {
133 if ( m_contenturl
== null || m_contenturl
.equals( "" )) {
134 m_contenturl
= Helper
.createTargetDataFile( workdir
);
139 * Print the commands options
141 public void printCmdLineUsage() {
143 "Usage : ResourceRemover -url=... -workdir=..." );
145 "Defaults: -url=<workdir>/resource-<uniquepostfix> -workdir=<currentdir>" );
147 "\nExample : -url=file:///temp/MyFile.txt \n" );
151 * Create a new connection with the specific args to a running office and
154 *@param String[] Arguments
156 public static void main ( String args
[] ) {
158 System
.out
.println( "\n" );
160 "-----------------------------------------------------------------" );
162 "ResourceRemover - destroys a resource." );
164 "-----------------------------------------------------------------" );
167 ResourceRemover delete
= new ResourceRemover( args
);
168 boolean result
= delete
.deleteResource();
169 String url
= delete
.getContentURL();
172 "Delete of resource " + url
+ " succeeded." );
175 "Delete of resource " + url
+ " failed." );
177 } catch ( com
.sun
.star
.ucb
.CommandAbortedException e
) {
178 System
.out
.println( "Error: " + e
);
179 } catch ( com
.sun
.star
.uno
.Exception e
) {
180 System
.out
.println( "Error: " + e
);
181 } catch ( java
.lang
.Exception e
) {
182 System
.out
.println( "Error: " + e
);