Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
See what's new at GitLab
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
O
odfhistory
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
2
Merge Requests
2
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
odfplugfest
odfhistory
Commits
e513075b
Commit
e513075b
authored
Oct 09, 2015
by
Jos van den Oever
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work around for bibliography style bug in LO.
parent
b6d53141
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
0 deletions
+82
-0
src/odf/OdfFixer.java
src/odf/OdfFixer.java
+13
-0
src/odf/OdfNormalizer.java
src/odf/OdfNormalizer.java
+29
-0
src/odf/StyleNames.java
src/odf/StyleNames.java
+40
-0
No files found.
src/odf/OdfFixer.java
View file @
e513075b
...
...
@@ -17,6 +17,8 @@ class OdfFixer extends XMLFilterImpl {
private
int
muteLevel
=
-
1
;
private
boolean
automaticStyles
;
private
int
level
=
0
;
final
private
Stack
<
String
>
familyStack
=
new
Stack
<
String
>();
...
...
@@ -31,6 +33,7 @@ class OdfFixer extends XMLFilterImpl {
super
.
startDocument
();
familyStack
.
clear
();
muteLevel
=
-
1
;
automaticStyles
=
false
;
}
@Override
...
...
@@ -43,11 +46,15 @@ class OdfFixer extends XMLFilterImpl {
}
level
+=
1
;
automaticStyles
=
automaticStyles
||
(
NC
.
style
.
equals
(
uri
)
&&
"automatic-styles"
.
equals
(
localName
));
// correct invalid attributes
AttributesImpl
atts
=
new
AttributesImpl
(
attributes
);
int
l
=
atts
.
getLength
();
String
family
=
null
;
String
styleName
=
null
;
for
(
int
i
=
0
;
i
<
l
;
++
i
)
{
String
u
=
atts
.
getURI
(
i
);
String
ln
=
atts
.
getLocalName
(
i
);
...
...
@@ -66,6 +73,8 @@ class OdfFixer extends XMLFilterImpl {
atts
.
removeAttribute
(
i
--);
}
else
if
(
"family"
.
equals
(
ln
))
{
family
=
v
;
}
else
if
(
"name"
.
equals
(
ln
))
{
styleName
=
v
;
}
}
else
if
(
NC
.
fo
.
equals
(
u
))
{
if
(
"hyphenation-push-char-count"
.
equals
(
ln
))
{
...
...
@@ -99,6 +108,7 @@ class OdfFixer extends XMLFilterImpl {
}
if
(
NC
.
text
.
equals
(
uri
))
{
if
(
"outline-style"
.
equals
(
localName
))
{
// this seems wrong
int
i
=
atts
.
getIndex
(
NC
.
style
,
"name"
);
if
(
"1.2"
.
equals
(
version
))
{
if
(
i
==
-
1
)
{
...
...
@@ -135,6 +145,9 @@ class OdfFixer extends XMLFilterImpl {
&&
"paragraph"
.
equals
(
familyStack
.
lastElement
()))
{
skipElement
();
}
if
(
family
!=
null
&&
styleName
!=
null
&&
styleNames
!=
null
)
{
styleNames
.
addName
(
styleName
,
family
,
automaticStyles
);
}
familyStack
.
push
(
family
);
if
(
muteLevel
==
-
1
)
{
super
.
startElement
(
uri
,
localName
,
qName
,
atts
);
...
...
src/odf/OdfNormalizer.java
View file @
e513075b
...
...
@@ -15,6 +15,8 @@ import java.util.Map;
import
java.util.Set
;
import
java.util.TreeMap
;
import
java.util.TreeSet
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
org.eclipse.jdt.annotation.Nullable
;
import
org.w3c.dom.Attr
;
...
...
@@ -373,6 +375,7 @@ public class OdfNormalizer {
remove
(
doc
,
"//text:alphabetical-index-mark-end"
);
remove
(
doc
,
"//text:toc-mark-start"
);
remove
(
doc
,
"//text:toc-mark-end"
);
remove
(
doc
,
"//@text:formula[starts-with(.,'ooow:')]"
);
// remove continued list for which the first list item explicitly starts
// at position 1
...
...
@@ -382,6 +385,8 @@ public class OdfNormalizer {
removeUnneededFontAttributes
(
doc
);
fixBibliographyStyles
(
doc
);
IdAndReferenceNormalizer
n
=
new
IdAndReferenceNormalizer
(
doc
);
// fonts
n
.
addIdsAndReferences
(
"F"
,
"//style:font-face/@style:name"
,
...
...
@@ -654,6 +659,30 @@ public class OdfNormalizer {
&&
marks
.
contains
(
n
.
getLocalName
());
}
final
Matcher
matcher
=
Pattern
.
compile
(
"^_[0-9a-f][0-9a-f]__20_(.*)$"
)
.
matcher
(
""
);
// workaround for bug in LO 5.1.2 where text:style-name="Strong_20_Emphasis"
// is saved as text:style-name="_30__20_Strong_20_Emphasis" and new
// attributes text:style-name="_30__20_" are introduces. The '_30_' can
// vary.
private
void
fixBibliographyStyles
(
Document
doc
)
{
// TODO check with list of defined styles
XPathResult
<
Attr
>
atts
=
XPath
.
attrIterator
(
doc
,
"//text:index-entry-bibliography/@text:style-name"
);
for
(
Attr
att
:
atts
)
{
matcher
.
reset
(
att
.
getNodeValue
());
if
(
matcher
.
find
())
{
String
newName
=
matcher
.
group
(
1
);
if
(
newName
.
length
()
>
0
)
{
att
.
setNodeValue
(
newName
);
}
else
{
att
.
getOwnerElement
().
removeAttributeNode
(
att
);
}
}
}
}
static
private
void
fixBookmarkStart
(
Document
document
)
{
// replace each text:bookmark that has a corresponding text:bookmark-end
// by text:bookmark-start
...
...
src/odf/StyleNames.java
View file @
e513075b
package
odf
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
import
org.eclipse.jdt.annotation.Nullable
;
public
class
StyleNames
{
...
...
@@ -7,6 +12,9 @@ public class StyleNames {
@Nullable
final
private
StyleNames
styles
;
final
private
Map
<
String
,
Set
<
String
>>
common
=
new
HashMap
<
String
,
Set
<
String
>>();
final
private
Map
<
String
,
Set
<
String
>>
automatic
=
new
HashMap
<
String
,
Set
<
String
>>();
StyleNames
()
{
this
.
styles
=
null
;
}
...
...
@@ -15,4 +23,36 @@ public class StyleNames {
this
.
styles
=
styles
;
}
boolean
addName
(
String
name
,
String
family
,
boolean
automaticStyle
)
{
Map
<
String
,
Set
<
String
>>
m
=
automaticStyle
?
automatic
:
common
;
Set
<
String
>
s
=
m
.
get
(
family
);
if
(
s
==
null
)
{
s
=
new
HashSet
<
String
>();
m
.
put
(
family
,
s
);
}
boolean
has
=
s
.
contains
(
name
);
s
.
add
(
name
);
return
has
;
}
boolean
hasCommonStyle
(
String
name
,
String
family
)
{
Set
<
String
>
s
=
common
.
get
(
family
);
return
s
==
null
?
false
:
s
.
contains
(
name
);
}
boolean
hasStyle
(
String
name
,
String
family
)
{
Set
<
String
>
s
=
common
.
get
(
family
);
if
(
s
!=
null
&&
s
.
contains
(
name
))
{
return
true
;
}
s
=
automatic
.
get
(
family
);
if
(
s
!=
null
&&
s
.
contains
(
name
))
{
return
true
;
}
if
(
styles
!=
null
)
{
return
styles
.
hasCommonStyle
(
name
,
family
);
}
return
false
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment