Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
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
27cd29aa
Commit
27cd29aa
authored
Oct 09, 2015
by
Jos van den Oever
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check that a style exists before applying it.
parent
c5bbcc51
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
18 deletions
+25
-18
src/odf/NamedStylesLists.java
src/odf/NamedStylesLists.java
+1
-1
src/odf/OdfFixer.java
src/odf/OdfFixer.java
+1
-1
src/odf/OdfNormalizer.java
src/odf/OdfNormalizer.java
+13
-9
src/odf/OdfZipNormalizer.java
src/odf/OdfZipNormalizer.java
+9
-6
src/odf/Tester.java
src/odf/Tester.java
+1
-1
No files found.
src/odf/NamedStylesLists.java
View file @
27cd29aa
...
...
@@ -10,7 +10,7 @@ public class NamedStylesLists {
@Nullable
StyleNames
get
(
String
entry
)
{
if
(
entry
.
endsWith
(
"content.xml"
)
||
entry
.
endsWith
(
"styles.xml"
))
{
if
(
!
entry
.
endsWith
(
"content.xml"
)
&&
!
entry
.
endsWith
(
"styles.xml"
))
{
return
null
;
}
StyleNames
names
=
lists
.
get
(
entry
);
...
...
src/odf/OdfFixer.java
View file @
27cd29aa
...
...
@@ -47,7 +47,7 @@ class OdfFixer extends XMLFilterImpl {
level
+=
1
;
automaticStyles
=
automaticStyles
||
(
NC
.
styl
e
.
equals
(
uri
)
&&
"automatic-styles"
||
(
NC
.
offic
e
.
equals
(
uri
)
&&
"automatic-styles"
.
equals
(
localName
));
// correct invalid attributes
...
...
src/odf/OdfNormalizer.java
View file @
27cd29aa
...
...
@@ -343,7 +343,8 @@ public class OdfNormalizer {
}
}
public
void
normalize
(
Document
doc
)
throws
NormalizeException
{
public
void
normalize
(
Document
doc
,
StyleNames
styleNames
)
throws
NormalizeException
{
final
Element
documentElement
=
doc
.
getDocumentElement
();
if
(
documentElement
.
getNamespaceURI
().
equals
(
NC
.
manifest
))
{
cleanManifest
(
doc
);
...
...
@@ -385,8 +386,8 @@ public class OdfNormalizer {
removeUnneededFontAttributes
(
doc
);
fixBibliographyStyles
(
doc
);
setLinkStyle
(
doc
);
fixBibliographyStyles
(
doc
,
styleNames
);
addLinkStyle
(
doc
,
styleNames
);
IdAndReferenceNormalizer
n
=
new
IdAndReferenceNormalizer
(
doc
);
// fonts
...
...
@@ -667,15 +668,15 @@ public class OdfNormalizer {
// 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
private
void
fixBibliographyStyles
(
Document
doc
,
StyleNames
styleNames
)
{
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
)
{
if
(
newName
.
length
()
>
0
&&
styleNames
.
hasStyle
(
newName
,
"text"
))
{
att
.
setNodeValue
(
newName
);
}
else
{
att
.
getOwnerElement
().
removeAttributeNode
(
att
);
...
...
@@ -686,13 +687,16 @@ public class OdfNormalizer {
// workaround for LO behaviour where text:a without a style gets a default
// style
private
void
setLinkStyle
(
Document
doc
)
{
private
void
addLinkStyle
(
Document
doc
,
StyleNames
styleNames
)
{
XPathResult
<
Element
>
es
=
XPath
.
elementIterator
(
doc
,
"//text:a"
);
for
(
Element
e
:
es
)
{
if
(!
e
.
hasAttributeNS
(
NC
.
text
,
"style-name"
))
{
if
(!
e
.
hasAttributeNS
(
NC
.
text
,
"style-name"
)
&&
styleNames
.
hasStyle
(
"Visited_20_Internet_20_Link"
,
"text"
))
{
e
.
setAttributeNS
(
NC
.
text
,
"text:style-name"
,
"Internet_20_link"
);
}
if
(!
e
.
hasAttributeNS
(
NC
.
text
,
"visited-style-name"
))
{
if
(!
e
.
hasAttributeNS
(
NC
.
text
,
"visited-style-name"
)
&&
styleNames
.
hasStyle
(
"Internet_20_link"
,
"text"
))
{
e
.
setAttributeNS
(
NC
.
text
,
"text:visited-style-name"
,
"Visited_20_Internet_20_Link"
);
}
...
...
src/odf/OdfZipNormalizer.java
View file @
27cd29aa
...
...
@@ -50,7 +50,7 @@ public class OdfZipNormalizer {
if
(
NC
.
rng
.
equals
(
doc
.
getDocumentElement
().
getNamespaceURI
()))
{
RngNormalizer
.
normalize
(
doc
);
}
else
{
normalizeOdf
(
doc
,
odfNormalizer
);
normalizeOdf
(
doc
,
odfNormalizer
,
styleNames
);
}
OdfHistory
.
pretty
(
doc
,
output
,
info
.
getRngInfo
(
odfNormalizer
.
xml
)
.
getElementsWithNoText
());
...
...
@@ -161,19 +161,22 @@ public class OdfZipNormalizer {
if
(
entryPath
.
endsWith
(
"content.xml"
)
||
entryPath
.
endsWith
(
"styles.xml"
)
||
entryPath
.
endsWith
(
"meta.xml"
))
{
normalizeOdf
(
doc
,
normalizer
);
normalizeOdf
(
doc
,
normalizer
,
styleNames
);
}
writeXML
(
out
,
doc
,
entry
.
getName
(),
normalizer
.
odfInfo
.
getRngInfo
(
normalizer
.
xml
)
.
getElementsWithNoText
());
}
static
private
void
normalizeOdf
(
Document
doc
,
OdfNormalizer
normalizer
)
throws
TransformerException
,
IOException
,
SAXException
,
NormalizeException
,
XMLStreamException
{
static
private
void
normalizeOdf
(
Document
doc
,
OdfNormalizer
normalizer
,
@Nullable
StyleNames
styleNames
)
throws
TransformerException
,
IOException
,
SAXException
,
NormalizeException
,
XMLStreamException
{
if
(
styleNames
==
null
)
{
styleNames
=
new
StyleNames
();
}
if
(
NC
.
office
.
equals
(
doc
.
getDocumentElement
().
getNamespaceURI
()))
{
validate
(
doc
,
normalizer
.
odfInfo
);
normalizer
.
normalize
(
doc
);
normalizer
.
normalize
(
doc
,
styleNames
);
validate
(
doc
,
normalizer
.
odfInfo
);
}
}
...
...
src/odf/Tester.java
View file @
27cd29aa
...
...
@@ -57,7 +57,7 @@ public class Tester {
byte
result
[];
try
{
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
odfNormalizer
.
normalize
(
doc
);
odfNormalizer
.
normalize
(
doc
,
styleNames
);
OdfHistory
.
pretty
(
doc
,
out
,
odfInfo
.
getRngInfo
(
odfNormalizer
.
xml
)
.
getElementsWithNoText
());
out
.
close
();
...
...
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