-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SEAMREPORTS-10: implemented nested interations
- Loading branch information
Showing
22 changed files
with
437 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ target | |
.project | ||
.settings | ||
*.sw? | ||
test-output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...in/java/org/jboss/seam/reports/openoffice/lib/contenthandler/DefaultIterationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual | ||
* contributors by the @authors tag. See the copyright.txt in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.seam.reports.openoffice.lib.contenthandler; | ||
|
||
public class DefaultIterationHandler<T> implements IterationHandler<T> { | ||
|
||
@Override | ||
public void afterIteration(IterationContext context, T item) { | ||
|
||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
.../src/main/java/org/jboss/seam/reports/openoffice/lib/contenthandler/ExpressionHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
.../src/main/java/org/jboss/seam/reports/openoffice/lib/contenthandler/IdentifierHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual | ||
* contributors by the @authors tag. See the copyright.txt in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.seam.reports.openoffice.lib.contenthandler; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.w3c.dom.Element; | ||
|
||
public class IdentifierHelper { | ||
|
||
public static class AttributeMatch { | ||
|
||
String nodeName; | ||
String attributeName; | ||
|
||
public AttributeMatch(String nodeName, String attributeName) { | ||
this.nodeName = nodeName; | ||
this.attributeName = attributeName; | ||
} | ||
|
||
public AttributeMatch(String attributeName) { | ||
this.attributeName = attributeName; | ||
} | ||
|
||
private String nullifyEmptyString(String s) { | ||
return "".equals(s) ? null : s; | ||
} | ||
|
||
String getMatchingValue(Element element) { | ||
if (nodeName == null) { | ||
return nullifyEmptyString(element.getAttribute(attributeName)); | ||
} else if (element.getNodeName().equals(nodeName)) { | ||
return nullifyEmptyString(element.getAttribute(attributeName)); | ||
} | ||
return null; | ||
} | ||
|
||
} | ||
|
||
private int index; | ||
|
||
private List<AttributeMatch> attributeNames; | ||
|
||
public IdentifierHelper(int index, AttributeMatch... attributeNames) { | ||
this.index = index; | ||
if (attributeNames.length == 0) { | ||
setAttributeNames(new AttributeMatch("xml:id"), new AttributeMatch("table:name")); | ||
} else { | ||
this.setAttributeNames(attributeNames); | ||
} | ||
} | ||
|
||
public void setAttributeNames(AttributeMatch... attributeNames) { | ||
this.attributeNames = Arrays.asList(attributeNames); | ||
} | ||
|
||
public String transformId(String id) { | ||
return id + "_" + index; | ||
} | ||
|
||
public String originalId(String id) { | ||
return id.substring(0, id.lastIndexOf('_')); | ||
} | ||
|
||
public void updateIdentifiers(Element element) { | ||
for (AttributeMatch match : attributeNames) { | ||
String id = match.getMatchingValue(element); | ||
if (id != null) { | ||
element.setAttribute(match.attributeName, transformId(id)); | ||
} | ||
} | ||
|
||
for (Element child : ComponentUtil.getChildElements(element)) { | ||
updateIdentifiers(child); | ||
} | ||
|
||
} | ||
|
||
|
||
} |
35 changes: 35 additions & 0 deletions
35
.../src/main/java/org/jboss/seam/reports/openoffice/lib/contenthandler/IterationContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual | ||
* contributors by the @authors tag. See the copyright.txt in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.seam.reports.openoffice.lib.contenthandler; | ||
|
||
import org.jboss.seam.reports.openoffice.lib.OdfToolkitFacade; | ||
import org.odftoolkit.simple.table.Table; | ||
import org.w3c.dom.Element; | ||
|
||
public interface IterationContext { | ||
|
||
int getIndex(); | ||
|
||
OdfToolkitFacade getFacade(); | ||
|
||
Element getElementById(String id); | ||
|
||
Table getTable(String name); | ||
|
||
void add(OOContentHandler contentHandler); | ||
|
||
} |
76 changes: 76 additions & 0 deletions
76
.../main/java/org/jboss/seam/reports/openoffice/lib/contenthandler/IterationContextImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual | ||
* contributors by the @authors tag. See the copyright.txt in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.seam.reports.openoffice.lib.contenthandler; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.jboss.seam.reports.openoffice.lib.OdfToolkitFacade; | ||
import org.jboss.seam.reports.openoffice.lib.contenthandler.IdentifierHelper.AttributeMatch; | ||
import org.odftoolkit.simple.table.Table; | ||
import org.w3c.dom.Element; | ||
|
||
public class IterationContextImpl implements IterationContext { | ||
|
||
private int index; | ||
private OdfToolkitFacade facade; | ||
private List<OOContentHandler> handlers = new ArrayList<OOContentHandler>(); | ||
|
||
public IterationContextImpl(int index, OdfToolkitFacade facade) { | ||
super(); | ||
this.index = index; | ||
this.facade = facade; | ||
} | ||
|
||
@Override | ||
public int getIndex() { | ||
return index; | ||
} | ||
|
||
@Override | ||
public OdfToolkitFacade getFacade() { | ||
return facade; | ||
} | ||
|
||
protected IdentifierHelper getIdHelper() { | ||
return new IdentifierHelper(getIndex()); | ||
} | ||
|
||
@Override | ||
public Element getElementById(String id) { | ||
return facade.getContentElement().getOwnerDocument().getElementById(getIdHelper().transformId(id)); | ||
} | ||
|
||
@Override | ||
public Table getTable(String name) { | ||
return getFacade().getDocument().getTableByName(getIdHelper().transformId(name)); | ||
} | ||
|
||
@Override | ||
public void add(OOContentHandler contentHandler) { | ||
contentHandler.setFacade(getFacade()); | ||
IdentifierHelper helper = new IdentifierHelper(getIndex(), new AttributeMatch("text:user-field-get", "text:name")); | ||
helper.updateIdentifiers(contentHandler.getRootElement()); | ||
|
||
handlers.add(contentHandler); | ||
} | ||
|
||
public List<OOContentHandler> getHandlers() { | ||
return handlers; | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
.../src/main/java/org/jboss/seam/reports/openoffice/lib/contenthandler/IterationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual | ||
* contributors by the @authors tag. See the copyright.txt in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.seam.reports.openoffice.lib.contenthandler; | ||
|
||
public interface IterationHandler<T> { | ||
|
||
void afterIteration(IterationContext context, T item); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.