Skip to content

Commit

Permalink
SEAMREPORTS-10: implemented nested interations
Browse files Browse the repository at this point in the history
  • Loading branch information
agori committed Jun 25, 2011
1 parent 49d23b1 commit 9bcc0fb
Show file tree
Hide file tree
Showing 22 changed files with 437 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ target
.project
.settings
*.sw?
test-output
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

public class OOSeamReportDefinition implements ReportDefinition<OOSeamReportDataSource, OOSeamReport> {

private static final long serialVersionUID = 1L;

private OdfToolkitFacade odfFacade;

public OOSeamReportDefinition(OdfToolkitFacade odfFacade) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,7 @@ static public VariableField resolveIterativeVar(OdfToolkitFacade documentHandler
return varField;
}


public static void changeIds(Element element, int iterationIndex) {
String id = element.getAttribute("xml:id");
if (!isEmpty(id)) {
element.setAttribute("xml:id", id + "_" + iterationIndex);
}
for (Element child : getChildElements(element)) {
changeIds(child, iterationIndex);
}
}



}
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) {

}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/**
* 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;
Expand Down
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);
}

}


}
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);

}
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;
}

}
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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Map;

import org.jboss.seam.reports.openoffice.lib.OdfToolkitFacade;
import org.w3c.dom.Element;

public interface OOContentHandler {

Expand All @@ -27,5 +28,11 @@ public interface OOContentHandler {
OOContentHandler hide();

void render(Map<String, Object> vars);

void setId(String id);

String getId();

Element getRootElement();

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@
abstract public class OOContentHandlerBase implements OOContentHandler {

private OdfToolkitFacade facade;

private String id;

public OOContentHandlerBase(String id) {
this.id = id;
}

@Override
public String getId() {
return id;
}

@Override
public void setId(String id) {
this.id = id;
}

@Override
public void setFacade(OdfToolkitFacade facade) {
Expand Down
Loading

0 comments on commit 9bcc0fb

Please sign in to comment.