Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*-
* ========================LICENSE_START=================================
* TeamApps Reporting
* ---
* Copyright (C) 2020 TeamApps.org
* ---
* 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.
* =========================LICENSE_END==================================
*/
package org.teamapps.reporting.builder;
import org.docx4j.XmlUtils;
import org.docx4j.model.structure.HeaderFooterPolicy;
import org.docx4j.model.structure.SectionWrapper;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.wml.*;
import org.jvnet.jaxb2_commons.ppp.Child;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.*;
public class DocumentBuilder {
public Map createReplaceRowMap(String ... values) {
Map map = new HashMap<>();
for (int i = 0; i < values.length; i += 2) {
map.put(values[i], values[i+1]);
}
return map;
}
public WordprocessingMLPackage getTemplate(String path) throws Docx4JException, FileNotFoundException {
return WordprocessingMLPackage.load(new FileInputStream(new File(path)));
}
public T copyElement(T t) {
return XmlUtils.deepCopy(t);
}
public List getAllElements(Object element, T toSearch) {
List result = new ArrayList<>();
if (element instanceof JAXBElement) element = ((JAXBElement>) element).getValue();
if (element.getClass().equals(toSearch.getClass()))
result.add((T) element);
else if (element instanceof ContentAccessor) {
List> children = ((ContentAccessor) element).getContent();
for (Object child : children) {
result.addAll(getAllElements(child, toSearch));
}
}
return result;
}
public void save(WordprocessingMLPackage template, String target) throws Docx4JException {
File f = new File(target);
template.save(f);
}
public void fillTable(List