xref: /aoo42x/main/ucb/qa/complex/tdoc/_XContent.java (revision c07c6c98)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package complex.tdoc;
24 
25 import com.sun.star.ucb.XContent;
26 import com.sun.star.ucb.XContentEventListener;
27 import com.sun.star.ucb.XContentIdentifier;
28 import share.LogWriter;
29 
30 /**
31  *
32  * @author  sg128468
33  */
34 public class _XContent {
35     public XContent oObj = null;
36     public LogWriter log = null;
37     private ContentListener listener = null;
38 
39     public boolean _addContentEventListener() {
40         listener = new ContentListener();
41         oObj.addContentEventListener(listener);
42         return true;
43     }
44     public boolean _getContentType() {
45         String type = oObj.getContentType();
46         log.println("Type: " + type);
47         return type != null && type.indexOf("vnd.sun.star.tdoc") != -1;
48     }
49     public boolean _getIdentifier() {
50         XContentIdentifier xIdent = oObj.getIdentifier();
51         String id = xIdent.getContentIdentifier();
52         String scheme = xIdent.getContentProviderScheme();
53         log.println("Id: " + id);
54         log.println("Scheme: " + scheme);
55         return id != null && scheme != null && id.indexOf("vnd.sun.star.tdoc") != -1 && scheme.indexOf("vnd.sun.star.tdoc") != -1;
56     }
57     public boolean _removeContentEventListener() {
58         System.out.println("Event: " + (listener.disposed || listener.firedEvent));
59         oObj.removeContentEventListener(listener);
60         return true;
61     }
62 
63 
64     private class ContentListener implements XContentEventListener {
65         private boolean disposed = false;
66         private boolean firedEvent = false;
67 
68         public void reset() {
69             disposed = false;
70             firedEvent = false;
71         }
72 
73         public void contentEvent(com.sun.star.ucb.ContentEvent contentEvent) {
74             firedEvent = true;
75         }
76 
77         public void disposing(com.sun.star.lang.EventObject eventObject) {
78             disposed = true;
79         }
80 
81     }
82 }
83