diff --git a/src/main/java/pro/litvinovg/w2phtml/W2PHTMLExtension.java b/src/main/java/pro/litvinovg/w2phtml/W2PHTMLExtension.java
index 43906c5..28e7dbc 100644
--- a/src/main/java/pro/litvinovg/w2phtml/W2PHTMLExtension.java
+++ b/src/main/java/pro/litvinovg/w2phtml/W2PHTMLExtension.java
@@ -4,6 +4,7 @@ import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import pro.litvinovg.w2phtml.gui.ConfigurationWindow;
+import pro.litvinovg.w2phtml.gui.Document;
import com.sun.star.lib.uno.helper.Factory;
diff --git a/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationReader.java b/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationReader.java
index 77fd3d2..ae0f38f 100644
--- a/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationReader.java
+++ b/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationReader.java
@@ -32,7 +32,6 @@ public class ConfigurationReader {
private void readOptions(HashMap configuration) {
Set options = configuration.keySet();
for (String optionName : options) {
- //Debug.printLog(string, context);
String optionValue = null;
Component component = configuration.get(optionName);
if (component.getClass().equals(JTextField.class)) {
@@ -45,20 +44,7 @@ public class ConfigurationReader {
Debug.printLog(optionName + " : " + optionValue, context);
}
- /*for (Component component : components) {
- if (component.getClass().equals(JTextField.class)) {
- textFields.add(component);
- } else if (component.getClass().equals(JCheckBox.class)) {
- checkBoxes.add(component);
- } else if (component.getClass().equals(JLabel.class)) {
- labels.add(component);
- }
- }
- for (Iterator iterator = checkBoxes.iterator(); iterator.hasNext();) {
- JCheckBox checkBox = (JCheckBox) iterator.next();
- checkBox.get
-
- }*/
+
}
diff --git a/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java b/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java
index 8ace8f9..5efdc89 100644
--- a/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java
+++ b/src/main/java/pro/litvinovg/w2phtml/gui/ConfigurationWindow.java
@@ -566,7 +566,7 @@ public class ConfigurationWindow extends JFrame {
}
public static void runGUI(XComponentContext context) {
-
+ Document doc = new Document(context);
if (singleFrame != null) {
singleFrame.dispose();
}
diff --git a/src/main/java/pro/litvinovg/w2phtml/gui/Document.java b/src/main/java/pro/litvinovg/w2phtml/gui/Document.java
new file mode 100644
index 0000000..5214350
--- /dev/null
+++ b/src/main/java/pro/litvinovg/w2phtml/gui/Document.java
@@ -0,0 +1,115 @@
+package pro.litvinovg.w2phtml.gui;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.sun.star.beans.IllegalTypeException;
+import com.sun.star.beans.NotRemoveableException;
+import com.sun.star.beans.Property;
+import com.sun.star.beans.PropertyExistException;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.PropertyVetoException;
+import com.sun.star.beans.UnknownPropertyException;
+import com.sun.star.beans.XPropertyContainer;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.XPropertySetInfo;
+import com.sun.star.document.XDocumentProperties;
+import com.sun.star.document.XDocumentPropertiesSupplier;
+import com.sun.star.frame.XController;
+import com.sun.star.frame.XDesktop;
+import com.sun.star.frame.XDispatch;
+import com.sun.star.frame.XDispatchHelper;
+import com.sun.star.frame.XDispatchProvider;
+import com.sun.star.frame.XFrame;
+import com.sun.star.frame.XModel;
+import com.sun.star.frame.XStorable;
+import com.sun.star.lang.IllegalArgumentException;
+import com.sun.star.lang.WrappedTargetException;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.text.XText;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.util.XModifiable;
+import com.sun.star.view.XViewSettingsSupplier;
+
+import pro.litvinovg.xml.Debug;
+
+public class Document {
+
+ private XComponentContext context;
+ private XDesktop xDesktop;
+ private XMultiComponentFactory multiComponentFactory;
+ private XMultiServiceFactory multiServiceFactory;
+ private XComponent currentDocument;
+ private XDocumentProperties documentProperties;
+ private XDocumentPropertiesSupplier documentPropertiesSupplier;
+ private XText text = null;
+ private XFrame frame;
+ private XDispatchProvider dispatchProvider;
+ XTextDocument textDocument;
+
+ public Document(XComponentContext componentContext) {
+ if (componentContext != null) {
+ context = componentContext;
+ multiComponentFactory = context.getServiceManager();
+ try {
+ Object oDesktop = multiComponentFactory.createInstanceWithContext("com.sun.star.frame.Desktop", context);
+ xDesktop = UnoRuntime.queryInterface(XDesktop.class, oDesktop);
+ currentDocument = xDesktop.getCurrentComponent();
+ //Get document readOnly status. If so, abort.
+ //Get document path. If doc not saved - abort.
+ if (currentDocument == null) {
+ return;
+ }
+ //Get document type. Work only with ODT.
+ XModel model = UnoRuntime.queryInterface(XModel.class, currentDocument);
+ if (!isSupported(currentDocument,"com.sun.star.text.TextDocument")) {
+ return;
+ }
+ XTextDocument textDoc = UnoRuntime.queryInterface(XTextDocument.class, currentDocument);
+ if (textDoc == null) {
+ Debug.printLog("Error. TextDoc is null.", componentContext);
+ return;
+ }
+ XStorable storable = UnoRuntime.queryInterface(XStorable.class, textDoc);
+
+ if (storable == null || storable.isReadonly()) {
+ Debug.printLog("Document is read only", componentContext);
+ } else {
+ Debug.printLog("Document is in rw mode", componentContext);
+ }
+ XModifiable modifieable = UnoRuntime.queryInterface(XModifiable.class, textDoc);
+
+ if (modifieable == null || modifieable.isModified()) {
+ Debug.printLog("Document is modified", componentContext);
+ } else {
+ Debug.printLog("Document isn't modified", componentContext);
+ }
+
+ String url = model.getURL();
+ Debug.printLog("Document url " + url, componentContext);
+
+ } catch (Exception e) {
+ System.out.println("xDesktop inaccessible. Can not proceed.");
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+
+
+ }
+ private boolean isSupported(Object object, String service) {
+ XServiceInfo info = UnoRuntime.queryInterface(XServiceInfo.class, object);
+ if (info == null) {
+ return false;
+ }
+ return info.supportsService(service);
+ }
+}