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
aa1e5d7d
Commit
aa1e5d7d
authored
Oct 07, 2015
by
Jos van den Oever
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass around an object that keeps track of all names styles.
parent
1d25353e
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
95 additions
and
21 deletions
+95
-21
src/odf/NamedStylesLists.java
src/odf/NamedStylesLists.java
+30
-0
src/odf/OdfFixer.java
src/odf/OdfFixer.java
+4
-1
src/odf/OdfHistoryParser.java
src/odf/OdfHistoryParser.java
+2
-2
src/odf/OdfInfo.java
src/odf/OdfInfo.java
+1
-1
src/odf/OdfRngInfo.java
src/odf/OdfRngInfo.java
+1
-1
src/odf/OdfZipNormalizer.java
src/odf/OdfZipNormalizer.java
+33
-12
src/odf/StyleNames.java
src/odf/StyleNames.java
+18
-0
src/odf/Tester.java
src/odf/Tester.java
+3
-1
src/odf/XML.java
src/odf/XML.java
+3
-3
No files found.
src/odf/NamedStylesLists.java
0 → 100644
View file @
aa1e5d7d
package
odf
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.eclipse.jdt.annotation.Nullable
;
public
class
NamedStylesLists
{
final
private
Map
<
String
,
StyleNames
>
lists
=
new
HashMap
<
String
,
StyleNames
>();
@Nullable
StyleNames
get
(
String
entry
)
{
if
(
entry
.
endsWith
(
"content.xml"
)
||
entry
.
endsWith
(
"styles.xml"
))
{
return
null
;
}
StyleNames
names
=
lists
.
get
(
entry
);
if
(
names
==
null
)
{
StyleNames
styles
=
null
;
if
(
entry
.
endsWith
(
"content.xml"
))
{
String
stylesEntry
=
entry
.
substring
(
0
,
entry
.
length
()
-
11
)
+
"styles.xml"
;
styles
=
lists
.
get
(
stylesEntry
);
}
names
=
new
StyleNames
(
styles
);
lists
.
put
(
entry
,
names
);
}
return
names
;
}
}
src/odf/OdfFixer.java
View file @
aa1e5d7d
...
...
@@ -12,12 +12,15 @@ import org.xml.sax.helpers.XMLFilterImpl;
class
OdfFixer
extends
XMLFilterImpl
{
final
String
version
;
@Nullable
final
private
StyleNames
styleNames
;
final
private
Stack
<
String
>
familyStack
=
new
Stack
<
String
>();
private
boolean
mute
=
false
;
// whether or not to write output
OdfFixer
(
String
version
)
{
OdfFixer
(
String
version
,
@Nullable
StyleNames
styleNames
)
{
this
.
version
=
version
;
this
.
styleNames
=
styleNames
;
}
@Override
...
...
src/odf/OdfHistoryParser.java
View file @
aa1e5d7d
...
...
@@ -20,8 +20,8 @@ public class OdfHistoryParser {
TransformerException
{
FileInputStream
in
=
new
FileInputStream
(
historyFile
.
toFile
());
odfNormalizer
.
odfInfo
.
version
=
"1.2"
;
Document
historyDoc
=
odfNormalizer
.
xml
.
parse
(
in
,
odfNormalizer
.
odfInfo
);
Document
historyDoc
=
odfNormalizer
.
xml
.
parse
(
in
,
odfNormalizer
.
odfInfo
,
null
);
LinkedList
<
OdfHistoryEntry
>
files
=
parseHistory
(
historyDoc
);
return
files
;
}
...
...
src/odf/OdfInfo.java
View file @
aa1e5d7d
...
...
@@ -93,7 +93,7 @@ public class OdfInfo {
throws
FileNotFoundException
,
SAXException
,
IOException
,
TransformerException
{
Document
grammar
=
xml
.
parse
(
new
FileInputStream
(
new
File
(
rngPath
)),
null
);
null
,
null
);
grammar
.
setDocumentURI
(
rngPath
);
return
new
OdfRngInfo
(
grammar
,
xml
);
}
...
...
src/odf/OdfRngInfo.java
View file @
aa1e5d7d
...
...
@@ -448,7 +448,7 @@ class OdfRngInfoParser {
}
String
href
=
includeElement
.
getAttribute
(
"href"
);
File
includeFile
=
new
File
(
dir
,
href
);
Document
doc
=
xml
.
parse
(
new
FileInputStream
(
includeFile
),
null
);
Document
doc
=
xml
.
parse
(
new
FileInputStream
(
includeFile
),
null
,
null
);
n
=
doc
.
getDocumentElement
().
getFirstChild
();
while
(
n
!=
null
)
{
Node
c
=
n
.
getNextSibling
();
...
...
src/odf/OdfZipNormalizer.java
View file @
aa1e5d7d
...
...
@@ -12,6 +12,7 @@ import java.nio.file.Path;
import
java.nio.file.Paths
;
import
java.util.HashSet
;
import
java.util.LinkedList
;
import
java.util.Set
;
import
java.util.zip.CRC32
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipException
;
...
...
@@ -21,6 +22,7 @@ import java.util.zip.ZipOutputStream;
import
javax.xml.stream.XMLStreamException
;
import
javax.xml.transform.TransformerException
;
import
org.eclipse.jdt.annotation.Nullable
;
import
org.w3c.dom.Document
;
import
org.w3c.dom.Element
;
import
org.xml.sax.InputSource
;
...
...
@@ -42,7 +44,8 @@ public class OdfZipNormalizer {
if
(
input
.
getAbsolutePath
().
endsWith
(
".rng"
))
{
info
=
odfNormalizer
.
rngInfo
;
}
Document
doc
=
odfNormalizer
.
xml
.
parse
(
in
,
info
);
StyleNames
styleNames
=
new
StyleNames
();
Document
doc
=
odfNormalizer
.
xml
.
parse
(
in
,
info
,
styleNames
);
in
.
close
();
if
(
NC
.
rng
.
equals
(
doc
.
getDocumentElement
().
getNamespaceURI
()))
{
RngNormalizer
.
normalize
(
doc
);
...
...
@@ -85,10 +88,27 @@ public class OdfZipNormalizer {
addUncompressedEntry
(
out
,
mimetype
.
getBytes
(),
"mimetype"
);
writeXML
(
out
,
manifest
,
"META-INF/manifest.xml"
,
odfNormalizer
.
odfInfo
.
getRngInfo
(
odfNormalizer
.
xml
).
getElementsWithNoText
());
NamedStylesLists
styleNames
=
new
NamedStylesLists
();
// handle all entries, make sure to handle styles.xml before the
// corresponding content.xml so that named styles are known when
// handling content.xml
Set
<
String
>
handledFiles
=
new
HashSet
<
String
>();
for
(
String
entry
:
entries
)
{
System
.
out
.
println
(
entry
);
normalizeEntry
(
zip
,
zip
.
getEntry
(
entry
),
out
,
odfNormalizer
);
if
(
entry
.
equals
(
"content.xml"
)
||
entry
.
endsWith
(
"/content.xml"
))
{
String
stylesEntry
=
entry
.
substring
(
0
,
entry
.
length
()
-
11
)
+
"styles.xml"
;
if
(
entries
.
contains
(
stylesEntry
)
&&
!
handledFiles
.
contains
(
stylesEntry
))
{
normalizeEntry
(
zip
,
zip
.
getEntry
(
stylesEntry
),
out
,
odfNormalizer
,
styleNames
.
get
(
entry
));
handledFiles
.
add
(
stylesEntry
);
}
System
.
out
.
println
(
entry
);
normalizeEntry
(
zip
,
zip
.
getEntry
(
entry
),
out
,
odfNormalizer
,
styleNames
.
get
(
entry
));
handledFiles
.
add
(
entry
);
}
}
out
.
close
();
...
...
@@ -109,9 +129,9 @@ public class OdfZipNormalizer {
}
static
private
void
normalizeEntry
(
ZipFile
zip
,
ZipEntry
entry
,
ZipOutputStream
out
,
OdfNormalizer
odfNormalizer
)
throws
IOException
,
SAXException
,
Transformer
Exception
,
NormalizeException
,
XMLStreamException
{
ZipOutputStream
out
,
OdfNormalizer
odfNormalizer
,
@Nullable
StyleNames
styleNames
)
throws
IOException
,
SAX
Exception
,
TransformerException
,
NormalizeException
,
XMLStreamException
{
if
(
entry
.
isDirectory
())
{
return
;
}
...
...
@@ -120,7 +140,7 @@ public class OdfZipNormalizer {
if
(
entry
.
getSize
()
==
0
)
{
copy
(
zip
,
entry
,
out
);
}
else
{
normalizeXml
(
zip
,
entry
,
out
,
odfNormalizer
);
normalizeXml
(
zip
,
entry
,
out
,
odfNormalizer
,
styleNames
);
}
}
else
{
copy
(
zip
,
entry
,
out
);
...
...
@@ -128,12 +148,12 @@ public class OdfZipNormalizer {
}
static
private
void
normalizeXml
(
ZipFile
zip
,
ZipEntry
entry
,
ZipOutputStream
out
,
OdfNormalizer
normalizer
)
throws
IOException
,
SAXException
,
TransformerException
,
Normalize
Exception
,
XMLStreamException
{
ZipOutputStream
out
,
OdfNormalizer
normalizer
,
@Nullable
StyleNames
styleNames
)
throws
IOException
,
SAX
Exception
,
TransformerException
,
NormalizeException
,
XMLStreamException
{
Path
entryPath
=
Paths
.
get
(
entry
.
getName
());
InputStream
in
=
zip
.
getInputStream
(
entry
);
Document
doc
=
normalizer
.
xml
.
parse
(
in
,
normalizer
.
odfInfo
);
Document
doc
=
normalizer
.
xml
.
parse
(
in
,
normalizer
.
odfInfo
,
styleNames
);
in
.
close
();
if
(
entryPath
.
endsWith
(
"content.xml"
)
||
entryPath
.
endsWith
(
"styles.xml"
)
...
...
@@ -189,7 +209,8 @@ public class OdfZipNormalizer {
throws
IOException
,
SAXException
,
TransformerException
{
InputStream
in
=
zip
.
getInputStream
(
zip
.
getEntry
(
"META-INF/manifest.xml"
));
Document
doc
=
normalizer
.
xml
.
parse
(
in
,
normalizer
.
odfManifestInfo
);
Document
doc
=
normalizer
.
xml
.
parse
(
in
,
normalizer
.
odfManifestInfo
,
null
);
in
.
close
();
return
doc
;
}
...
...
src/odf/StyleNames.java
0 → 100644
View file @
aa1e5d7d
package
odf
;
import
org.eclipse.jdt.annotation.Nullable
;
public
class
StyleNames
{
@Nullable
final
private
StyleNames
styles
;
StyleNames
()
{
this
.
styles
=
null
;
}
StyleNames
(
@Nullable
StyleNames
styles
)
{
this
.
styles
=
styles
;
}
}
src/odf/Tester.java
View file @
aa1e5d7d
...
...
@@ -46,9 +46,11 @@ public class Tester {
FileType
type
=
beforePath
.
toString
().
contains
(
"/manifest/"
)
?
OdfInfo
.
FileType
.
ODFMANIFEST
:
OdfInfo
.
FileType
.
ODF
;
OdfInfo
odfInfo
=
new
OdfInfo
(
type
);
StyleNames
styleNames
=
new
StyleNames
();
try
{
doc
=
odfNormalizer
.
xml
.
parse
(
new
FileInputStream
(
beforePath
.
toFile
()),
odfInfo
);
new
FileInputStream
(
beforePath
.
toFile
()),
odfInfo
,
styleNames
);
}
catch
(
IOException
e
)
{
throw
new
TestFailException
(
"Could not read test input."
,
e
);
}
...
...
src/odf/XML.java
View file @
aa1e5d7d
...
...
@@ -65,8 +65,8 @@ public class XML {
return
false
;
}
public
Document
parse
(
InputStream
in
,
@Nullable
OdfInfo
info
)
throws
IOException
{
public
Document
parse
(
InputStream
in
,
@Nullable
OdfInfo
info
,
@Nullable
StyleNames
styleNames
)
throws
IOException
{
Document
doc
;
try
{
XMLReader
reader
=
parser
.
getXMLReader
();
...
...
@@ -81,7 +81,7 @@ public class XML {
unit
.
setParent
(
whitespace
);
PrefixHandler
prefix
=
new
PrefixHandler
();
prefix
.
setParent
(
unit
);
OdfFixer
f
=
new
OdfFixer
(
info
.
version
);
OdfFixer
f
=
new
OdfFixer
(
info
.
version
,
styleNames
);
f
.
setParent
(
prefix
);
reader
=
f
;
}
...
...
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