1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *************************************************************************/
38 public class ResourceRemover
{
43 private Helper m_helper
;
44 private String m_contenturl
= "";
45 private com
.sun
.star
.ucb
.XContent m_content
;
50 *@param args This construtor requires the arguments:
52 * -workdir=... (optional)
53 * See Help (method printCmdLineUsage()).
54 * Without the arguments a new connection to a
55 * running office cannot created.
57 public ResourceRemover( String args
[] ) throws java
.lang
.Exception
{
60 parseArguments( args
);
63 m_helper
= new Helper( getContentURL() );
66 m_content
= m_helper
.createUCBContent();
72 *@return true if resource successfully deleted, false otherwise
74 public boolean deleteResource()
75 throws com
.sun
.star
.ucb
.CommandAbortedException
, com
.sun
.star
.uno
.Exception
{
77 boolean result
= false;
78 if ( m_content
!= null ) {
81 // Destroy a resource physically...
84 Boolean deletePhysically
= Boolean
.TRUE
;
86 // Execute command "delete".
87 m_helper
.executeCommand( m_content
, "delete", deletePhysically
);
96 *@return String That contains the connect URL
98 public String
getContentURL() {
105 public void parseArguments( String
[] args
) throws java
.lang
.Exception
{
109 for ( int i
= 0; i
< args
.length
; i
++ ) {
110 if ( args
[i
].startsWith( "-url=" )) {
111 m_contenturl
= args
[i
].substring( 5 );
112 } else if ( args
[i
].startsWith( "-workdir=" )) {
113 workdir
= args
[i
].substring( 9 );
114 } else if ( args
[i
].startsWith( "-help" ) ||
115 args
[i
].startsWith( "-?" )) {
121 if ( m_contenturl
== null || m_contenturl
.equals( "" )) {
122 m_contenturl
= Helper
.createTargetDataFile( workdir
);
127 * Print the commands options
129 public void printCmdLineUsage() {
131 "Usage : ResourceRemover -url=... -workdir=..." );
133 "Defaults: -url=<workdir>/resource-<uniquepostfix> -workdir=<currentdir>" );
135 "\nExample : -url=file:///temp/MyFile.txt \n" );
139 * Create a new connection with the specific args to a running office and
142 public static void main ( String args
[] ) {
144 System
.out
.println( "\n" );
146 "-----------------------------------------------------------------" );
148 "ResourceRemover - destroys a resource." );
150 "-----------------------------------------------------------------" );
153 ResourceRemover delete
= new ResourceRemover( args
);
154 boolean result
= delete
.deleteResource();
155 String url
= delete
.getContentURL();
158 "Delete of resource " + url
+ " succeeded." );
161 "Delete of resource " + url
+ " failed." );
163 } catch ( com
.sun
.star
.ucb
.CommandAbortedException e
) {
164 System
.out
.println( "Error: " + e
);
165 } catch ( com
.sun
.star
.uno
.Exception e
) {
166 System
.out
.println( "Error: " + e
);
167 } catch ( java
.lang
.Exception e
) {
168 System
.out
.println( "Error: " + e
);