Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trac30220 use conditional on LO bookmarks #382

Open
wants to merge 3 commits into
base: WollMux_18.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private static String[] parseIdentifier(String identifierWithArgs,
* Stelle die neue frag_id enthält und in den folgenden Stellen die Argumente.
*
* @param identifierWithArgs
* Ein String in der Form "<identifier>#arg1#...#argN", wobei der
* Ein String in der Form "&lt;identifier&gt;#arg1#...#argN", wobei der
* Separator "#" über den SEPARATOR-Schlüssel in textbausteine verändert
* werden kann.
* @param textbausteine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,6 @@ public static String dumpOOoConfiguration(String nodePath)
* @param spaces
* Indent for children.
* @return String representation of the node.
* @throws Exception
* Can't access the configuration node.
*/
public static String dumpNode(Object element, String spaces)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ else if (zoomValue != null)
/**
* Liefert den Titel des Dokuments, wie er im Fenster des Dokuments angezeigt wird,
* ohne den Zusatz " - OpenOffice.org Writer" oder "NoTitle", wenn der Titel nicht
* bestimmt werden kann. TextDocumentModel('<title>')
* bestimmt werden kann. TextDocumentModel('&lt;title&gt;')
*/
public synchronized String getTitle()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ public synchronized void flushPersistentData()
}

/**
* Calls {@link #insertMailMergeField(String, XTextRange) with the current cursor position.
* Calls {@link #insertMailMergeField(String, XTextRange)} with the current cursor position.
*
* @param fieldId
* The column name of the data base on which this field depends
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ public synchronized void close()
}

/**
* {@link DocumentCommands#addNewDocumentCommand(XTextRange, String)
* {@link DocumentCommands#addNewDocumentCommand(XTextRange, String)}
*
* @param r
* The text range.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public int hashCode()
* Ein IDChangeListener wird benachrichtigt, wenn sich ein {@link IdModel}
* Objekt ändert.
*
* @see ID.addIDChangeListener(IDChangeListener)
* @see #addIDChangeListener(IDChangeListener)
*/
public interface IDChangeListener
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private Dateinamensanpassungen()
* Pfaden/Dateinamen übergeben werden, wovon der erste Eintrag dieser Liste
* zurückgegeben wird, dessen Pfad-Anteil tatsächlich verfügbar ist.
* Innerhalb eines Pfades/Dateinamens kann vor der Verfügbarkeitsprüfung mit
* ${<name>} der Wert einer Java-Systemproperty in den Dateinamen eingefügt
* ${&lt;name&gt;} der Wert einer Java-Systemproperty in den Dateinamen eingefügt
* werden.
*/
public static String verfuegbarenPfadVerwenden(String fileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ protected MailMergePrintFunction(String functionName, int order)
}

/**
* Replaces all occurrences of <code>{{<tag>}}</code> with the value specified in the data set.
* Replaces all occurrences of <code>&lt;tag&gt;</code> with the value specified in the data set.
*
* @param dataset
* Map of key-value pairs, where the key is <code><tag></code>.
* Map of key-value pairs, where the key is <code>&lt;tag&gt;</code>.
* @param text
* Text, which contains tags to be replaced.
* @return Text where all occurrences are replaced, if there exists a record in data set.
Expand All @@ -100,7 +100,7 @@ public static String replaceMergeFieldInText(Map<String, String> dataset, String
}

/**
* Creates a <code><tag></code>, which can be replaced by
* Creates a <code>&lt;tag&gt;</code>, which can be replaced by
* {@link #replaceMergeFieldInText(Map, String)}.
*
* @param mergeField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -47,11 +48,15 @@

import com.sun.star.beans.NamedValue;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.PropertyVetoException;
import com.sun.star.beans.UnknownPropertyException;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.NoSuchElementException;
import com.sun.star.frame.XModel;
import com.sun.star.frame.XStorable;
import com.sun.star.io.IOException;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XSingleServiceFactory;
import com.sun.star.sdb.CommandType;
Expand Down Expand Up @@ -80,6 +85,10 @@
import de.muenchen.allg.afid.UnoDictionary;
import de.muenchen.allg.afid.UnoHelperException;
import de.muenchen.allg.afid.UnoProps;
import de.muenchen.allg.document.text.Bookmark;
import de.muenchen.allg.itd51.wollmux.config.ConfigThingy;
import de.muenchen.allg.itd51.wollmux.config.NodeNotFoundException;
import de.muenchen.allg.itd51.wollmux.config.SyntaxErrorException;
import de.muenchen.allg.itd51.wollmux.dialog.InfoDialog;
import de.muenchen.allg.itd51.wollmux.document.DocumentManager;
import de.muenchen.allg.itd51.wollmux.document.FormFieldFactory;
Expand Down Expand Up @@ -357,11 +366,11 @@ private void createAndAdjustInputFile() throws PrintException
adjustDatabaseAndInputUserFields(tmpDoc);
/*
* Bookmarks make LO mail merge slow. So we delete all of the.
*
*
* If at some time we need bookmarks at least WollMux document commands have to be removed
* so that they are not processed twice.
*/
removeAllBookmarks(tmpDoc);
updateBookmarks(tmpDoc);
ContentBasedDirectiveModel.createModel(UNO.XTextDocument(tmpDoc)).renameTextStyles();
removeWollMuxMetadata(UNO.XTextDocument(tmpDoc));

Expand Down Expand Up @@ -420,7 +429,7 @@ private void updateTextSections(XTextDocument doc)
}

/**
* Remove all non informational meta data of wollmux from the document.
* Remove all non informational meta data of WollMux from the document.
*
* @param doc
* The document.
Expand All @@ -437,25 +446,35 @@ private void removeWollMuxMetadata(XTextDocument doc)
}

/**
* Remove all bookmarks from the document.
* Remove all bookmarks except setGroups-commands from the document. setGroups
* commands are converted, so that they can be interpreted by LibreOffice mail
* merge.
*
* @param tmpDoc
* The document.
*/
private void removeAllBookmarks(XTextDocument tmpDoc)
private void updateBookmarks(XTextDocument tmpDoc)
{
if (UNO.XBookmarksSupplier(tmpDoc) != null)
{
Predicate<String> setGroups = DocumentCommands.getPatternForCommand("setGroups").asMatchPredicate();
UnoDictionary<XTextContent> bookmarks = UnoDictionary
.create(UNO.XBookmarksSupplier(tmpDoc).getBookmarks(), XTextContent.class);
for (XTextContent bookmark : bookmarks.values())
for (Map.Entry<String, XTextContent> bookmark : bookmarks.entrySet())
{
try
{
if (bookmark != null)
if (setGroups.test(bookmark.getKey()))
{
bookmark.getAnchor().getText().removeTextContent(bookmark);
updateSetGroupsBookmark(tmpDoc, bookmark.getKey());
} else if (bookmark.getValue() != null)
{
bookmark.getValue().getAnchor().getText().removeTextContent(bookmark.getValue());
}
}
catch (NoSuchElementException e)
{
continue;
} catch (Exception e)
{
LOGGER.error("", e);
Expand All @@ -464,6 +483,49 @@ private void removeAllBookmarks(XTextDocument tmpDoc)
}
}

/**
* Sets a condition on the given book mark according to its name. All
* mentioned groups are part of the condition. Renames the book mark.
*
* @param tmpDoc
* The document which has the book mark
* @param name
* The name of the book mark.
* @throws NoSuchElementException
* Couldn't find the book mark.
*/
private void updateSetGroupsBookmark(XTextDocument tmpDoc, String name)
throws NoSuchElementException
{
try
{
Bookmark bookmark = new Bookmark(name, UNO.XBookmarksSupplier(tmpDoc));
ConfigThingy groups = new ConfigThingy("cmd", name).get("GROUPS");
List<String> conditions = new ArrayList<>();
List<String> names = new ArrayList<>();

UnoProperty.setPropertyToDefault(bookmark.getAnchor(), UnoProperty.CHAR_HIDDEN);
for (ConfigThingy groupName : groups)
{
conditions.add(String.format("([%s] != \"true\")",
COLUMN_PREFIX_TEXTSECTION + groupName.toString()));
names.add(groupName.toString());
}
String condition = StringUtils.join(conditions, " or ");

XPropertySet ps = UNO.XPropertySet(
UNO.XBookmarksSupplier(tmpDoc).getBookmarks().getByName(name));
ps.setPropertyValue(UnoProperty.BOOKMARK_HIDDEN, true);
ps.setPropertyValue(UnoProperty.BOOKMARK_CONDITION, condition);
bookmark.rename(StringUtils.join(names, "_"));
} catch (NodeNotFoundException | java.io.IOException | SyntaxErrorException
| WrappedTargetException | UnknownPropertyException
| PropertyVetoException | UnoHelperException ex)
{
LOGGER.debug("", ex);
}
}

/**
* Replace all insertFormValue-Bookmarks with mail merge fields.
*
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<wollmux.test.conf.release>v18.1.0/wollmux-config-18.1.0.tar.gz</wollmux.test.conf.release>
<wollmux.test.conf>${project.build.directory}/config/.wollmux/wollmux.conf</wollmux.test.conf>
<office.user.profile>${project.build.directory}/office</office.user.profile>
<maven.javadoc.failOnWarnings>true</maven.javadoc.failOnWarnings>
<maven.javadoc.failOnWarnings>false</maven.javadoc.failOnWarnings>
</properties>

<modules>
Expand Down