no message

main
이범준 1 year ago
parent 9df2f6abe5
commit 2764d8be74

@ -1,119 +0,0 @@
package cokr.xit.fims.framework.biz.cmm.web;
import cokr.xit.foundation.web.AbstractController;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
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;
import java.io.*;
import java.net.URISyntaxException;
import java.net.URLDecoder;
@Controller
@RequestMapping(name = "", value = "/mresources")
public class ResourceController extends AbstractController {
@GetMapping(name = "", value = "/**")
public void modifySvg(HttpServletRequest request, HttpServletResponse response) throws URISyntaxException, IOException, ParserConfigurationException, SAXException {
String requestURI = request.getRequestURI().toString();
String filepath = requestURI.replace("/mresources","/resources");
filepath = URLDecoder.decode(filepath);
filepath = request.getSession().getServletContext().getRealPath(filepath);
filepath = filepath.replace("\\","/");
filepath = "file:///"+filepath;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = factory.newDocumentBuilder();
Document document = documentBuilder.parse(filepath);
Element root = document.getDocumentElement();
NodeList nodeList = root.getChildNodes();
try {
String modify = request.getParameter("modify");
if(modify == null || modify.equals("")){
} else if(modify.equals("active")){
updateTagFillColor(nodeList, "green");
} else if(modify.equals("alert")){
updateTagFillColor(nodeList, "red");
}
String str4 = DocumentToString(document);
byte[] bytes = str4.getBytes();
response.setHeader(HttpHeaders.ACCEPT_RANGES, "bytes");
response.setHeader(HttpHeaders.CONTENT_TYPE, "image/svg+xml");
response.setHeader(HttpHeaders.CONNECTION, "keep-alive");
response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
response.setHeader("Pragma", "no-cache");
response.setHeader(HttpHeaders.CACHE_CONTROL, "no-cache, must-revalidate");
response.setDateHeader(HttpHeaders.EXPIRES, 0);
response.setHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(bytes.length));
response.setContentType("image/svg+xml");
OutputStream os = response.getOutputStream();
os.write(bytes);
os.flush();
os.close();
} catch (Exception e){
}
}
public static String DocumentToString( Document doc )
{
try
{
StringWriter clsOutput = new StringWriter( );
Transformer clsTrans = TransformerFactory.newInstance( ).newTransformer( );
clsTrans.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "no" );
clsTrans.setOutputProperty( OutputKeys.METHOD, "xml" );
clsTrans.setOutputProperty( OutputKeys.INDENT, "yes" );
clsTrans.setOutputProperty( OutputKeys.ENCODING, "UTF-8" );
clsTrans.transform( new DOMSource( doc ), new StreamResult( clsOutput ) );
return clsOutput.toString( );
}
catch( Exception ex )
{
return "";
}
}
private void updateTagFillColor(NodeList nodeList, String newFillColor) {
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
NamedNodeMap namedNodeMap = node.getAttributes();
if(namedNodeMap != null && namedNodeMap.getLength() > 0){
for (int j = 0; j < namedNodeMap.getLength(); j++) {
Node namedNode = namedNodeMap.item(j);
if (namedNode.getNodeName().equalsIgnoreCase("fill")) {
namedNode.setNodeValue(newFillColor); // Change the color of the fill attribute.
}
}
}
}
}
}
Loading…
Cancel
Save