1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
39 public class ResourceRemover
{
44 private Helper m_helper
;
45 private String m_contenturl
= "";
46 private com
.sun
.star
.ucb
.XContent m_content
;
51 *@param args This constructor requires the arguments:
53 * -workdir=... (optional)
54 * See Help (method printCmdLineUsage()).
55 * Without the arguments a new connection to a
56 * running office cannot created.
58 public ResourceRemover( String args
[] ) throws java
.lang
.Exception
{
61 parseArguments( args
);
64 m_helper
= new Helper( getContentURL() );
67 m_content
= m_helper
.createUCBContent();
73 *@return true if resource successfully deleted, false otherwise
75 public boolean deleteResource()
76 throws com
.sun
.star
.ucb
.CommandAbortedException
, com
.sun
.star
.uno
.Exception
{
78 boolean result
= false;
79 if ( m_content
!= null ) {
82 // Destroy a resource physically...
85 Boolean deletePhysically
= Boolean
.TRUE
;
87 // Execute command "delete".
88 m_helper
.executeCommand( m_content
, "delete", deletePhysically
);
97 *@return String That contains the connect URL
99 public String
getContentURL() {
106 public void parseArguments( String
[] args
) throws java
.lang
.Exception
{
110 for ( int i
= 0; i
< args
.length
; i
++ ) {
111 if ( args
[i
].startsWith( "-url=" )) {
112 m_contenturl
= args
[i
].substring( 5 );
113 } else if ( args
[i
].startsWith( "-workdir=" )) {
114 workdir
= args
[i
].substring( 9 );
115 } else if ( args
[i
].startsWith( "-help" ) ||
116 args
[i
].startsWith( "-?" )) {
122 if ( m_contenturl
== null || m_contenturl
.equals( "" )) {
123 m_contenturl
= Helper
.createTargetDataFile( workdir
);
128 * Print the commands options
130 public void printCmdLineUsage() {
132 "Usage : ResourceRemover -url=... -workdir=..." );
134 "Defaults: -url=<workdir>/resource-<uniquepostfix> -workdir=<currentdir>" );
136 "\nExample : -url=file:///temp/MyFile.txt \n" );
140 * Create a new connection with the specific args to a running office and
143 public static void main ( String args
[] ) {
145 System
.out
.println( "\n" );
147 "-----------------------------------------------------------------" );
149 "ResourceRemover - destroys a resource." );
151 "-----------------------------------------------------------------" );
154 ResourceRemover delete
= new ResourceRemover( args
);
155 boolean result
= delete
.deleteResource();
156 String url
= delete
.getContentURL();
159 "Delete of resource " + url
+ " succeeded." );
162 "Delete of resource " + url
+ " failed." );
164 } catch ( com
.sun
.star
.ucb
.CommandAbortedException e
) {
165 System
.out
.println( "Error: " + e
);
166 } catch ( com
.sun
.star
.uno
.Exception e
) {
167 System
.out
.println( "Error: " + e
);
168 } catch ( java
.lang
.Exception e
) {
169 System
.out
.println( "Error: " + e
);
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */