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
612e5733
Commit
612e5733
authored
Aug 23, 2015
by
Jos van den Oever
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle <define/> elements with the same name with the combine attribute.
parent
e18f9aa0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
3 deletions
+44
-3
src/odf/OdfRngInfo.java
src/odf/OdfRngInfo.java
+44
-3
No files found.
src/odf/OdfRngInfo.java
View file @
612e5733
...
...
@@ -128,16 +128,57 @@ class OdfRngInfoParser {
return
names
;
}
/**
* Move all child nodes in source to target
*/
static
private
void
appendContents
(
Element
source
,
Element
target
)
{
while
(
source
.
getFirstChild
()
!=
null
)
{
target
.
appendChild
(
source
.
getFirstChild
());
}
}
/**
* Return a map with all <define/> elements. The key in the map is the
* 'name' attribute.
* 'name' attribute. If there are <define/> elements with the same name,
* they are combined according to the rule in the 'combine' attribute.
*/
static
private
HashMap
<
String
,
Element
>
getDefinitions
(
Document
grammar
)
{
static
HashMap
<
String
,
Element
>
getDefinitions
(
Document
grammar
)
{
HashMap
<
String
,
Element
>
defs
=
new
HashMap
<
String
,
Element
>();
XPathResult
<
Element
>
elements
=
XPath
.
elementIterator
(
grammar
,
"/rng:grammar/rng:define"
);
for
(
Element
e
:
elements
)
{
defs
.
put
(
e
.
getAttribute
(
"name"
),
e
);
final
String
name
=
e
.
getAttribute
(
"name"
);
final
Element
def
=
defs
.
get
(
name
);
if
(
def
==
null
)
{
defs
.
put
(
name
,
e
);
}
else
{
final
String
combineMethod
=
def
.
hasAttribute
(
"combine"
)
?
def
.
getAttribute
(
"combine"
)
:
e
.
getAttribute
(
"combine"
);
if
(!
"choice"
.
equals
(
combineMethod
)
&&
!
"interleave"
.
equals
(
combineMethod
))
{
throw
new
RuntimeException
(
"combine attribute has wrong value '"
+
combineMethod
+
"' on definition '"
+
name
+
"'."
);
}
Element
combine
=
getFirstElementChild
(
def
);
if
(
combine
!=
null
&&
isRng
(
combineMethod
,
combine
))
{
appendContents
(
e
,
combine
);
}
else
{
combine
=
getFirstElementChild
(
e
);
if
(
combine
!=
null
&&
isRng
(
combineMethod
,
combine
))
{
appendContents
(
def
,
combine
);
}
else
{
combine
=
e
.
getOwnerDocument
().
createElementNS
(
NC
.
rng
,
def
.
getPrefix
()
+
":"
+
combineMethod
);
appendContents
(
def
,
combine
);
appendContents
(
e
,
combine
);
}
def
.
appendChild
(
combine
);
}
def
.
removeAttribute
(
"combine"
);
e
.
getParentNode
().
removeChild
(
e
);
}
}
return
defs
;
}
...
...
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