From f756f11bd3bcba0e15c96d68b62db7b9c44dcba7 Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Thu, 15 Jun 2023 10:55:32 +0900 Subject: [PATCH] =?UTF-8?q?SVG=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=83=89?= =?UTF-8?q?=EC=83=81=20=EB=B3=80=EA=B2=BD=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?FileController=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cokr/xit/fims/ResourceController.java | 132 ------------------ .../cokr/xit/fims/base/FileController.java | 128 ++++++++++++++++- .../css/fims/framework/common/xit-icon.css | 72 +++++----- 3 files changed, 163 insertions(+), 169 deletions(-) delete mode 100644 src/main/java/cokr/xit/fims/ResourceController.java diff --git a/src/main/java/cokr/xit/fims/ResourceController.java b/src/main/java/cokr/xit/fims/ResourceController.java deleted file mode 100644 index 46cfb6de..00000000 --- a/src/main/java/cokr/xit/fims/ResourceController.java +++ /dev/null @@ -1,132 +0,0 @@ -package cokr.xit.fims; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.StringWriter; -import java.net.URISyntaxException; -import java.net.URLDecoder; - -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 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.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -import cokr.xit.foundation.Log; -import cokr.xit.foundation.web.AbstractController; - - -@Controller -@RequestMapping(name = "리소스 파일 변환 처리 컨트롤러", value = "/mresources") -public class ResourceController extends AbstractController { - - @GetMapping(name = "이미지 파일 색상 변경", value = "/image/**") - 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("\\","/"); - String contextPath = request.getSession().getServletContext().getContextPath(); - filepath = filepath.replace("webapp"+contextPath+"/resources", "webapp/resources"); - 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. - } - } - } - } - } -} diff --git a/src/main/java/cokr/xit/fims/base/FileController.java b/src/main/java/cokr/xit/fims/base/FileController.java index 13aa36b6..6a307731 100644 --- a/src/main/java/cokr/xit/fims/base/FileController.java +++ b/src/main/java/cokr/xit/fims/base/FileController.java @@ -1,6 +1,132 @@ package cokr.xit.fims.base; +import java.io.IOException; +import java.io.OutputStream; +import java.io.StringWriter; +import java.net.URISyntaxException; +import java.net.URLDecoder; + +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 org.springframework.http.HttpHeaders; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +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 org.xml.sax.SAXException; @Controller -public class FileController extends cokr.xit.base.file.web.FileController {} \ No newline at end of file +public class FileController extends cokr.xit.base.file.web.FileController { + + @GetMapping(name = "SVG 이미지 파일 색상 변경", value = "/modifySvg/**") + public void modifySvg(HttpServletRequest request, HttpServletResponse response) throws URISyntaxException, IOException, ParserConfigurationException, SAXException { + String requestURI = request.getRequestURI().toString(); + + String filepath = requestURI.replace("/file/modifySvg","/resources/image"); + System.out.println("log : "+filepath); + filepath = URLDecoder.decode(filepath); + System.out.println("log : "+filepath); + filepath = request.getSession().getServletContext().getRealPath(filepath); + System.out.println("log : "+filepath); + filepath = filepath.replace("\\","/"); + System.out.println("log : "+filepath); + String contextPath = request.getSession().getServletContext().getContextPath(); + filepath = filepath.replace("webapp"+contextPath+"/resources", "webapp/resources"); + System.out.println("log : "+filepath); + 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. + } + } + } + } + } + +} \ No newline at end of file diff --git a/src/main/webapp/resources/css/fims/framework/common/xit-icon.css b/src/main/webapp/resources/css/fims/framework/common/xit-icon.css index fadf3930..2394723f 100644 --- a/src/main/webapp/resources/css/fims/framework/common/xit-icon.css +++ b/src/main/webapp/resources/css/fims/framework/common/xit-icon.css @@ -1,73 +1,73 @@ .svg-cctv-fixed:before { - --bs-origin : url("../../../../../mresources/image/fims/framework/고정형cctv.svg"); - --bs-active : url("../../../../../mresources/image/fims/framework/고정형cctv.svg?modify=active"); - --bs-alert : url("../../../../../mresources/image/fims/framework/고정형cctv.svg?modify=alert"); + --bs-origin : url("../../../../../resources/image/fims/framework/고정형cctv.svg"); + --bs-active : url("../../../../../file/modifySvg/fims/framework/고정형cctv.svg?modify=active"); + --bs-alert : url("../../../../../file/modifySvg/fims/framework/고정형cctv.svg?modify=alert"); } .svg-cctv-drive:before { - --bs-origin : url("../../../../../mresources/image/fims/framework/이동형cctv.svg"); - --bs-active : url("../../../../../mresources/image/fims/framework/이동형cctv.svg?modify=active"); - --bs-alert : url("../../../../../mresources/image/fims/framework/이동형cctv.svg?modify=alert"); + --bs-origin : url("../../../../../resources/image/fims/framework/이동형cctv.svg"); + --bs-active : url("../../../../../file/modifySvg/fims/framework/이동형cctv.svg?modify=active"); + --bs-alert : url("../../../../../file/modifySvg/fims/framework/이동형cctv.svg?modify=alert"); } .svg-crackdown-road:before { - --bs-origin : url("../../../../../mresources/image/fims/framework/도보단속.svg"); - --bs-active : url("../../../../../mresources/image/fims/framework/도보단속.svg?modify=active"); - --bs-alert : url("../../../../../mresources/image/fims/framework/도보단속.svg?modify=alert"); + --bs-origin : url("../../../../../resources/image/fims/framework/도보단속.svg"); + --bs-active : url("../../../../../file/modifySvg/fims/framework/도보단속.svg?modify=active"); + --bs-alert : url("../../../../../file/modifySvg/fims/framework/도보단속.svg?modify=alert"); } .svg-crackdown-minwon:before { - --bs-origin : url("../../../../../mresources/image/fims/framework/민원(즉시단속).svg"); - --bs-active : url("../../../../../mresources/image/fims/framework/민원(즉시단속).svg?modify=active"); - --bs-alert : url("../../../../../mresources/image/fims/framework/민원(즉시단속).svg?modify=alert"); + --bs-origin : url("../../../../../resources/image/fims/framework/민원(즉시단속).svg"); + --bs-active : url("../../../../../file/modifySvg/fims/framework/민원(즉시단속).svg?modify=active"); + --bs-alert : url("../../../../../file/modifySvg/fims/framework/민원(즉시단속).svg?modify=alert"); } .svg-target-lvy:before { - --bs-origin : url("../../../../../mresources/image/fims/framework/등록대상.svg"); - --bs-active : url("../../../../../mresources/image/fims/framework/등록대상.svg?modify=active"); - --bs-alert : url("../../../../../mresources/image/fims/framework/등록대상.svg?modify=alert"); + --bs-origin : url("../../../../../resources/image/fims/framework/등록대상.svg"); + --bs-active : url("../../../../../file/modifySvg/fims/framework/등록대상.svg?modify=active"); + --bs-alert : url("../../../../../file/modifySvg/fims/framework/등록대상.svg?modify=alert"); } .svg-target-transfer:before { - --bs-origin : url("../../../../../mresources/image/fims/framework/이첩대상.svg"); - --bs-active : url("../../../../../mresources/image/fims/framework/이첩대상.svg?modify=active"); - --bs-alert : url("../../../../../mresources/image/fims/framework/이첩대상.svg?modify=alert"); + --bs-origin : url("../../../../../resources/image/fims/framework/이첩대상.svg"); + --bs-active : url("../../../../../file/modifySvg/fims/framework/이첩대상.svg?modify=active"); + --bs-alert : url("../../../../../file/modifySvg/fims/framework/이첩대상.svg?modify=alert"); } .svg-sendstat-guide:before { - --bs-origin : url("../../../../../mresources/image/fims/framework/계도장 발송현황.svg"); - --bs-active : url("../../../../../mresources/image/fims/framework/계도장 발송현황.svg?modify=active"); - --bs-alert : url("../../../../../mresources/image/fims/framework/계도장 발송현황.svg?modify=alert"); + --bs-origin : url("../../../../../resources/image/fims/framework/계도장 발송현황.svg"); + --bs-active : url("../../../../../file/modifySvg/fims/framework/계도장 발송현황.svg?modify=active"); + --bs-alert : url("../../../../../file/modifySvg/fims/framework/계도장 발송현황.svg?modify=alert"); } .svg-sendstat-before:before { - --bs-origin : url("../../../../../mresources/image/fims/framework/사전통보 발송현황.svg"); - --bs-active : url("../../../../../mresources/image/fims/framework/사전통보 발송현황.svg?modify=active"); - --bs-alert : url("../../../../../mresources/image/fims/framework/사전통보 발송현황.svg?modify=alert"); + --bs-origin : url("../../../../../resources/image/fims/framework/사전통보 발송현황.svg"); + --bs-active : url("../../../../../file/modifySvg/fims/framework/사전통보 발송현황.svg?modify=active"); + --bs-alert : url("../../../../../file/modifySvg/fims/framework/사전통보 발송현황.svg?modify=alert"); } .svg-sendstat-nop:before { - --bs-origin : url("../../../../../mresources/image/fims/framework/고지서 발송현황.svg"); - --bs-active : url("../../../../../mresources/image/fims/framework/고지서 발송현황.svg?modify=active"); - --bs-alert : url("../../../../../mresources/image/fims/framework/고지서 발송현황.svg?modify=alert"); + --bs-origin : url("../../../../../resources/image/fims/framework/고지서 발송현황.svg"); + --bs-active : url("../../../../../file/modifySvg/fims/framework/고지서 발송현황.svg?modify=active"); + --bs-alert : url("../../../../../file/modifySvg/fims/framework/고지서 발송현황.svg?modify=alert"); } .svg-opn-rcp:before { - --bs-origin : url("../../../../../mresources/image/fims/framework/접수.svg"); - --bs-active : url("../../../../../mresources/image/fims/framework/접수.svg?modify=active"); - --bs-alert : url("../../../../../mresources/image/fims/framework/접수.svg?modify=alert"); + --bs-origin : url("../../../../../resources/image/fims/framework/접수.svg"); + --bs-active : url("../../../../../file/modifySvg/fims/framework/접수.svg?modify=active"); + --bs-alert : url("../../../../../file/modifySvg/fims/framework/접수.svg?modify=alert"); } .svg-opn-decision:before { - --bs-origin : url("../../../../../mresources/image/fims/framework/수용_미수용.svg"); - --bs-active : url("../../../../../mresources/image/fims/framework/수용_미수용.svg?modify=active"); - --bs-alert : url("../../../../../mresources/image/fims/framework/수용_미수용.svg?modify=alert"); + --bs-origin : url("../../../../../resources/image/fims/framework/수용_미수용.svg"); + --bs-active : url("../../../../../file/modifySvg/fims/framework/수용_미수용.svg?modify=active"); + --bs-alert : url("../../../../../file/modifySvg/fims/framework/수용_미수용.svg?modify=alert"); } .svg-opn-selfdrop:before { - --bs-origin : url("../../../../../mresources/image/fims/framework/자진취하.svg"); - --bs-active : url("../../../../../mresources/image/fims/framework/자진취하.svg?modify=active"); - --bs-alert : url("../../../../../mresources/image/fims/framework/자진취하.svg?modify=alert"); + --bs-origin : url("../../../../../resources/image/fims/framework/자진취하.svg"); + --bs-active : url("../../../../../file/modifySvg/fims/framework/자진취하.svg?modify=active"); + --bs-alert : url("../../../../../file/modifySvg/fims/framework/자진취하.svg?modify=alert"); } [class^=svg-]:before {