📄 printtask.java
字号:
package com.esri.solutions.jitk.web.tasks.print.browser;
import com.esri.adf.web.data.TocFunctionality;
import com.esri.adf.web.data.TocNode;
import com.esri.adf.web.data.TocNodeContent;
import com.esri.adf.web.data.WebMap;
import com.esri.adf.web.data.WebToc;
import com.esri.adf.web.data.graphics.GraphicsTocFunctionality;
import com.esri.adf.web.data.tasks.TaskInfo;
import com.esri.adf.web.faces.event.TaskEvent;
import com.esri.adf.web.util.ADFDownloadServlet;
import com.esri.adf.web.util.WebUtil;
import com.esri.solutions.jitk.web.tasks.RenderControlledTask;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.StringWriter;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletRequest;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
@SuppressWarnings({"serial",
"unchecked"
})
public class PrintTask extends RenderControlledTask {
private static Logger logger = LogManager.getLogger(PrintTask.class.getName());
private static final String PRINT_TASK = "Print Task";
private static final String ERROR_MSG = "printtask.ui.msg.error";
private PrintTaskInfo taskInfo = null;
private String taskName = null;
private String title = null;
private String footerNote = null;
private String titleParam = null;
private String resolutionParam = null;
private String mapWidth = "";
private String template = "";
private String resolution = null;
private String scale = "";
private String printMap = "true";
private String templateFolder = "/templates/jitk/print";
private String printPropertiesLabel = null;
private String specifyLayoutLabel = null;
private String loadingMessageLabel = null;
private String resultUrl = "";
private Map<String, String> templateList = null;
protected ResolutionMap _resolutionMap;
protected MapWidthMap _mapWidthMap;
public PrintTask() {
setTaskInfo(new PrintTaskInfo());
this.taskName = PRINT_TASK;
_resolutionMap = new ResolutionMap();
_mapWidthMap = new MapWidthMap();
}
public TaskInfo getTaskInfo() {
if (this._context == null) {
taskInfo.getTaskDescriptor().setDisabled(true);
}
if (this.title == null) {
this.setTitle(this.getTitleParam());
}
if (this.resolution == null) {
this.setResolution(this.getResolutionParam());
}
return this.taskInfo;
}
public void setTaskInfo(TaskInfo taskInfo) {
this.taskInfo = (PrintTaskInfo) taskInfo;
super.setTaskInfo(taskInfo);
}
public String getResultUrl() {
return this.resultUrl;
}
public void setResultUrl(String resultUrl) {
this.resultUrl = resultUrl;
}
public String getTaskName() {
return taskName;
}
public void setTaskName(String taskName) {
this.taskName = taskName;
}
/**
* Get footer note
*/
public String getFooterNote() {
return this.footerNote;
}
/**
* Set footer note
*/
public void setFooterNote(String footerNote) {
this.footerNote = footerNote;
}
public void setPrintPropertiesLabel(String printPropertiesLabel) {
this.printPropertiesLabel = printPropertiesLabel;
}
public String getPrintPropertiesLabel() {
return this.printPropertiesLabel;
}
public void setSpecifyLayoutLabel(String specifyLayoutLabel) {
this.specifyLayoutLabel = specifyLayoutLabel;
}
public String getSpecifyLayoutLabel() {
return this.specifyLayoutLabel;
}
public void setLoadingMessageLabel(String loadingMessageLabel) {
this.loadingMessageLabel = loadingMessageLabel;
}
public String getLoadingMessageLabel() {
return this.loadingMessageLabel;
}
public void setTitle(String title) {
this.title = title;
}
public String getTitle() {
return this.title;
}
public void setTitleParam(String titleParam) {
this.titleParam = titleParam;
}
public String getTitleParam() {
return this.titleParam;
}
public void setResolutionParam(String resolutionParam) {
this.resolutionParam = resolutionParam;
}
public String getResolutionParam() {
return this.resolutionParam;
}
public void setPrintMap(String printMap) {
this.printMap = printMap;
}
public String getPrintMap() {
return this.printMap;
}
public void setMapWidth(String mapWidth) {
this.mapWidth = mapWidth;
}
public String getMapWidth() {
return this.mapWidth;
}
public void setTemplate(String template) {
this.template = template;
}
public String getTemplate() {
return this.template;
}
public void setResolution(String resolution) {
this.resolution = resolution;
}
public String getResolution() {
return this.resolution;
}
public void setScale(String scale) {
this.scale = scale;
}
public String getScale() {
return this.scale;
}
public String getTemplateFolder() {
return this.templateFolder;
}
public void setTemplateFolder(String templatePath) {
this.templateFolder = templatePath;
}
public Map<String, String> getMapWidthList() {
return _mapWidthMap;
}
public Map getResolutionList() {
return _resolutionMap;
}
@SuppressWarnings("deprecation")
public Map<String, String> getTemplateList() {
if (templateList != null) {
return templateList;
}
Map<String, String> templateList = new LinkedHashMap<String, String>();
ServletRequest req = (ServletRequest) WebUtil.getExternalContext()
.getRequest();
String tempDirName = req.getRealPath(getTemplateFolder());
File f1 = new File(tempDirName);
File[] strFilesDirs = f1.listFiles();
for (int i = 0; i < strFilesDirs.length; i++) {
if (strFilesDirs[i].isFile()) {
String fullpath = strFilesDirs[i].toString();
int pos = fullpath.lastIndexOf(System.getProperty(
"file.separator"));
String filename = fullpath.substring(pos + 1);
pos = filename.indexOf(".");
if (pos >= 0) {
filename = filename.substring(0, pos);
}
// Only add it to the list if the extention ends in HTML
if (fullpath.toLowerCase().endsWith(".html") ||
fullpath.toLowerCase().endsWith(".htm")) {
templateList.put(fullpath, filename);
}
}
}
return templateList;
}
private String ElementToString(Element a) {
try {
DOMSource source = new DOMSource(a);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.transform(source, result);
return writer.toString();
} catch (javax.xml.transform.TransformerException e) {
logger.warn("Unable to convert element to string", e);
}
return "";
}
private static void replaceNode(String node2Replace,
String nodeAttr2Replace, Node node2ReplaceWith, Node curNode) {
try {
if (curNode.getNodeType() != Node.ELEMENT_NODE) {
System.err.println("Error: Search node is not of element type.");
return;
}
if (!curNode.hasChildNodes()) {
return;
}
NodeList list = curNode.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node subnode = list.item(i);
if (subnode.getNodeType() == Node.ELEMENT_NODE) {
if (subnode.getNodeName().equals(node2Replace)) {
if (nodeAttr2Replace != null) {
NamedNodeMap namedNodeMap = subnode.getAttributes();
Node nameItem = namedNodeMap.getNamedItem("name");
if ((nameItem != null) &&
nameItem.getNodeValue()
.equalsIgnoreCase(nodeAttr2Replace)) {
subnode.getParentNode()
.appendChild(node2ReplaceWith);
subnode.getParentNode().removeChild(subnode);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -