1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.efaps.update.schema.program.staticsource;
22
23 import java.io.BufferedReader;
24 import java.io.ByteArrayOutputStream;
25 import java.io.IOException;
26 import java.io.InputStreamReader;
27 import java.io.OutputStreamWriter;
28
29 import org.efaps.ci.CIAdminProgram;
30 import org.efaps.ci.CIType;
31 import org.efaps.db.Checkout;
32 import org.efaps.db.Instance;
33 import org.efaps.update.schema.program.staticsource.CSSCompiler.OneCSS;
34 import org.efaps.util.EFapsException;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 import com.yahoo.platform.yui.compressor.CssCompressor;
39
40
41
42
43
44
45
46 public class CSSCompiler
47 extends AbstractStaticSourceCompiler<OneCSS>
48 {
49
50
51
52
53 private static final Logger LOG = LoggerFactory.getLogger(CSSCompiler.class);
54
55
56
57
58 @Override
59 protected CIType getClassName4Type()
60 {
61 return CIAdminProgram.CSS;
62 }
63
64
65
66
67 @Override
68 protected CIType getClassName4Type2Type()
69 {
70 return CIAdminProgram.CSS2CSS;
71 }
72
73
74
75
76 @Override
77 protected CIType getClassName4TypeCompiled()
78 {
79 return CIAdminProgram.CSSCompiled;
80 }
81
82
83
84
85 @Override
86 protected String getCompiledString(final Instance _instance)
87 {
88 String ret = "";
89 try {
90 final Checkout checkout = new Checkout(_instance);
91 final BufferedReader in = new BufferedReader(new InputStreamReader(checkout.execute(), "UTF-8"));
92
93 final CssCompressor compressor = new CssCompressor(in);
94 in.close();
95 checkout.close();
96 final ByteArrayOutputStream byteout = new ByteArrayOutputStream();
97 final OutputStreamWriter out = new OutputStreamWriter(byteout, "UTF-8");
98 compressor.compress(out, 2000);
99 out.flush();
100 ret = byteout.toString("UTF-8");
101 ret += "\n";
102 } catch (final EFapsException e) {
103 CSSCompiler.LOG.error("error during checkout of Instance:" + _instance, e);
104 e.printStackTrace();
105 } catch (final IOException e) {
106 CSSCompiler.LOG.error("error during reqding of the Inputstram of Instance with oid:" + _instance, e);
107 }
108 return ret;
109 }
110
111
112
113
114 @Override
115 public OneCSS getNewSource(final String _name,
116 final Instance _instance)
117 {
118 return new OneCSS(_name, _instance);
119 }
120
121
122
123
124 public static class OneCSS
125 extends AbstractStaticSourceCompiler.AbstractSource
126 {
127
128
129
130
131 public OneCSS(final String _name,
132 final Instance _instance)
133 {
134 super(_name, _instance);
135 }
136 }
137
138 }