xref: /AOO41X/main/ucb/qa/complex/tdoc/_XContent.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package complex.tdoc;
28 
29 import com.sun.star.ucb.XContent;
30 import com.sun.star.ucb.XContentEventListener;
31 import com.sun.star.ucb.XContentIdentifier;
32 import share.LogWriter;
33 
34 /**
35  *
36  * @author  sg128468
37  */
38 public class _XContent {
39     public XContent oObj = null;
40     public LogWriter log = null;
41     private ContentListener listener = null;
42 
43     public boolean _addContentEventListener() {
44         listener = new ContentListener();
45         oObj.addContentEventListener(listener);
46         return true;
47     }
48     public boolean _getContentType() {
49         String type = oObj.getContentType();
50         log.println("Type: " + type);
51         return type != null && type.indexOf("vnd.sun.star.tdoc") != -1;
52     }
53     public boolean _getIdentifier() {
54         XContentIdentifier xIdent = oObj.getIdentifier();
55         String id = xIdent.getContentIdentifier();
56         String scheme = xIdent.getContentProviderScheme();
57         log.println("Id: " + id);
58         log.println("Scheme: " + scheme);
59         return id != null && scheme != null && id.indexOf("vnd.sun.star.tdoc") != -1 && scheme.indexOf("vnd.sun.star.tdoc") != -1;
60     }
61     public boolean _removeContentEventListener() {
62         System.out.println("Event: " + (listener.disposed || listener.firedEvent));
63         oObj.removeContentEventListener(listener);
64         return true;
65     }
66 
67 
68     private class ContentListener implements XContentEventListener {
69         private boolean disposed = false;
70         private boolean firedEvent = false;
71 
72         public void reset() {
73             disposed = false;
74             firedEvent = false;
75         }
76 
77         public void contentEvent(com.sun.star.ucb.ContentEvent contentEvent) {
78             firedEvent = true;
79         }
80 
81         public void disposing(com.sun.star.lang.EventObject eventObject) {
82             disposed = true;
83         }
84 
85     }
86 }
87