|
1 | 1 | package lucee.runtime; |
2 | 2 |
|
3 | 3 | import lucee.commons.io.SystemUtil; |
4 | | -import lucee.commons.io.log.LogUtil; |
5 | 4 | import lucee.commons.lang.StringUtil; |
6 | 5 | import lucee.runtime.config.Config; |
7 | 6 | import lucee.runtime.config.ConfigFactoryImpl; |
8 | 7 | import lucee.runtime.config.ConfigPro; |
9 | 8 | import lucee.runtime.config.ConfigUtil; |
10 | 9 | import lucee.runtime.config.Prop; |
11 | 10 | import lucee.runtime.config.PropFactory; |
| 11 | +import lucee.runtime.exp.ApplicationException; |
| 12 | +import lucee.runtime.exp.PageException; |
12 | 13 | import lucee.runtime.listener.ApplicationListener; |
13 | 14 | import lucee.runtime.listener.ModernAppListener; |
14 | 15 | import lucee.runtime.op.Caster; |
@@ -43,105 +44,97 @@ public static MappingFactory getInstance(short type) { |
43 | 44 | } |
44 | 45 |
|
45 | 46 | @Override |
46 | | - public Mapping evaluate(Config config, String name, Object val, Mapping defaultValue) { |
47 | | - try { |
48 | | - Struct el = Caster.toStruct(val); |
49 | | - if (el == null) return null; |
50 | | - |
51 | | - String virtual = null; |
52 | | - if (TYPE_REGULAR != type) { |
53 | | - virtual = ConfigFactoryImpl.getAttr(config, el, "virtual"); |
54 | | - } |
55 | | - if (StringUtil.isEmpty(virtual)) virtual = name; |
56 | | - |
57 | | - String physical = ConfigFactoryImpl.getAttr(config, el, "physical"); |
58 | | - String archive = ConfigFactoryImpl.getAttr(config, el, "archive"); |
59 | | - String strListType = ConfigFactoryImpl.getAttr(config, el, "listenerType"); |
60 | | - if (StringUtil.isEmpty(strListType)) strListType = ConfigFactoryImpl.getAttr(config, el, "listener-type"); |
61 | | - if (StringUtil.isEmpty(strListType)) strListType = ConfigFactoryImpl.getAttr(config, el, "listenertype"); |
62 | | - |
63 | | - String strListMode = ConfigFactoryImpl.getAttr(config, el, "listenerMode"); |
64 | | - if (StringUtil.isEmpty(strListMode)) strListMode = ConfigFactoryImpl.getAttr(config, el, "listener-mode"); |
65 | | - if (StringUtil.isEmpty(strListMode)) strListMode = ConfigFactoryImpl.getAttr(config, el, "listenermode"); |
| 47 | + public Mapping evaluate(Config config, String name, Object val) throws PageException { |
66 | 48 |
|
67 | | - boolean readonly = ConfigFactoryImpl.toBoolean(ConfigFactoryImpl.getAttr(config, el, "readonly"), false); |
68 | | - boolean hidden = ConfigFactoryImpl.toBoolean(ConfigFactoryImpl.getAttr(config, el, "hidden"), false); |
69 | | - boolean toplevel = ConfigFactoryImpl.toBoolean(ConfigFactoryImpl.getAttr(config, el, "toplevel"), true); |
| 49 | + Struct el = Caster.toStruct(val); |
70 | 50 |
|
71 | | - boolean appMapping = false; |
72 | | - boolean ignoreVirtual = false; |
73 | | - |
74 | | - // regular type check |
75 | | - if (TYPE_REGULAR == type) { |
76 | | - // lucee |
77 | | - if ("/lucee/".equalsIgnoreCase(virtual)) { |
78 | | - if (StringUtil.isEmpty(strListType, true)) strListType = "modern"; |
79 | | - if (StringUtil.isEmpty(strListMode, true)) strListMode = "curr2root"; |
80 | | - toplevel = true; |
81 | | - } |
82 | | - } |
83 | | - else if (TYPE_COMPONENT == type) { |
84 | | - if ("{lucee-web}/components/".equals(physical) || "{lucee-server}/components/".equals(physical)) return null; |
85 | | - toplevel = true; |
86 | | - ignoreVirtual = true; |
87 | | - } |
88 | | - else if (TYPE_CUSTOM_TAG == type) { |
89 | | - if ("{lucee-web}/customtags/".equals(physical) || "{lucee-server}/customtags/".equals(physical)) return null; |
| 51 | + String virtual = null; |
| 52 | + if (TYPE_REGULAR != type) { |
| 53 | + virtual = ConfigFactoryImpl.getAttr(config, el, "virtual"); |
| 54 | + } |
| 55 | + if (StringUtil.isEmpty(virtual)) virtual = name; |
| 56 | + |
| 57 | + String physical = ConfigFactoryImpl.getAttr(config, el, "physical"); |
| 58 | + String archive = ConfigFactoryImpl.getAttr(config, el, "archive"); |
| 59 | + String strListType = ConfigFactoryImpl.getAttr(config, el, "listenerType"); |
| 60 | + if (StringUtil.isEmpty(strListType)) strListType = ConfigFactoryImpl.getAttr(config, el, "listener-type"); |
| 61 | + if (StringUtil.isEmpty(strListType)) strListType = ConfigFactoryImpl.getAttr(config, el, "listenertype"); |
| 62 | + |
| 63 | + String strListMode = ConfigFactoryImpl.getAttr(config, el, "listenerMode"); |
| 64 | + if (StringUtil.isEmpty(strListMode)) strListMode = ConfigFactoryImpl.getAttr(config, el, "listener-mode"); |
| 65 | + if (StringUtil.isEmpty(strListMode)) strListMode = ConfigFactoryImpl.getAttr(config, el, "listenermode"); |
| 66 | + |
| 67 | + boolean readonly = ConfigFactoryImpl.toBoolean(ConfigFactoryImpl.getAttr(config, el, "readonly"), false); |
| 68 | + boolean hidden = ConfigFactoryImpl.toBoolean(ConfigFactoryImpl.getAttr(config, el, "hidden"), false); |
| 69 | + boolean toplevel = ConfigFactoryImpl.toBoolean(ConfigFactoryImpl.getAttr(config, el, "toplevel"), true); |
| 70 | + |
| 71 | + boolean appMapping = false; |
| 72 | + boolean ignoreVirtual = false; |
| 73 | + |
| 74 | + // regular type check |
| 75 | + if (TYPE_REGULAR == type) { |
| 76 | + // lucee |
| 77 | + if ("/lucee/".equalsIgnoreCase(virtual)) { |
| 78 | + if (StringUtil.isEmpty(strListType, true)) strListType = "modern"; |
| 79 | + if (StringUtil.isEmpty(strListMode, true)) strListMode = "curr2root"; |
90 | 80 | toplevel = true; |
91 | | - ignoreVirtual = true; |
92 | 81 | } |
| 82 | + } |
| 83 | + else if (TYPE_COMPONENT == type) { |
| 84 | + if ("{lucee-web}/components/".equals(physical) || "{lucee-server}/components/".equals(physical)) return null; |
| 85 | + toplevel = true; |
| 86 | + ignoreVirtual = true; |
| 87 | + } |
| 88 | + else if (TYPE_CUSTOM_TAG == type) { |
| 89 | + if ("{lucee-web}/customtags/".equals(physical) || "{lucee-server}/customtags/".equals(physical)) return null; |
| 90 | + toplevel = true; |
| 91 | + ignoreVirtual = true; |
| 92 | + } |
93 | 93 |
|
94 | | - int listenerMode = ConfigUtil.toListenerMode(strListMode, -1); |
95 | | - int listenerType = ConfigUtil.toListenerType(strListType, -1); |
| 94 | + int listenerMode = ConfigUtil.toListenerMode(strListMode, -1); |
| 95 | + int listenerType = ConfigUtil.toListenerType(strListType, -1); |
96 | 96 |
|
97 | | - ApplicationListener listener = null; |
98 | | - if (TYPE_REGULAR == type) { |
99 | | - listener = ConfigUtil.loadListener(listenerType, null); |
100 | | - if (listener != null || listenerMode != -1) { |
101 | | - // type |
102 | | - if (listener == null) listener = ConfigUtil.loadListener(ConfigUtil.toListenerType(config.getApplicationListener().getType(), -1), null); |
103 | | - if (listener == null) listener = new ModernAppListener(); |
104 | | - |
105 | | - // mode |
106 | | - if (listenerMode == -1) { |
107 | | - listenerMode = config.getApplicationListener().getMode(); |
108 | | - } |
109 | | - listener.setMode(listenerMode); |
| 97 | + ApplicationListener listener = null; |
| 98 | + if (TYPE_REGULAR == type) { |
| 99 | + listener = ConfigUtil.loadListener(listenerType, null); |
| 100 | + if (listener != null || listenerMode != -1) { |
| 101 | + // type |
| 102 | + if (listener == null) listener = ConfigUtil.loadListener(ConfigUtil.toListenerType(config.getApplicationListener().getType(), -1), null); |
| 103 | + if (listener == null) listener = new ModernAppListener(); |
110 | 104 |
|
| 105 | + // mode |
| 106 | + if (listenerMode == -1) { |
| 107 | + listenerMode = config.getApplicationListener().getMode(); |
111 | 108 | } |
112 | | - } |
113 | | - else if (TYPE_CUSTOM_TAG == type) { |
114 | | - listenerMode = -1; |
115 | | - listenerType = -1; |
116 | | - // TODO i guess this applies for component as well? |
117 | | - } |
| 109 | + listener.setMode(listenerMode); |
118 | 110 |
|
119 | | - // physical!=null && |
120 | | - if ((physical != null || archive != null)) { |
| 111 | + } |
| 112 | + } |
| 113 | + else if (TYPE_CUSTOM_TAG == type) { |
| 114 | + listenerMode = -1; |
| 115 | + listenerType = -1; |
| 116 | + // TODO i guess this applies for component as well? |
| 117 | + } |
121 | 118 |
|
122 | | - short insTemp = inspectTemplate(config, el); |
| 119 | + // physical!=null && |
| 120 | + if ((physical != null || archive != null)) { |
123 | 121 |
|
124 | | - int insTempSlow = Caster.toIntValue(ConfigFactoryImpl.getAttr(config, el, "inspectTemplateIntervalSlow"), ConfigPro.INSPECT_INTERVAL_UNDEFINED); |
125 | | - int insTempFast = Caster.toIntValue(ConfigFactoryImpl.getAttr(config, el, "inspectTemplateIntervalFast"), ConfigPro.INSPECT_INTERVAL_UNDEFINED); |
126 | | - if (TYPE_REGULAR == type) { |
127 | | - if ("/lucee/".equalsIgnoreCase(virtual) || "/lucee".equalsIgnoreCase(virtual) || "/lucee-server/".equalsIgnoreCase(virtual) |
128 | | - || "/lucee-server-context".equalsIgnoreCase(virtual)) |
129 | | - insTemp = ConfigPro.INSPECT_AUTO; |
130 | | - } |
131 | | - String primary = ConfigFactoryImpl.getAttr(config, el, "primary"); |
132 | | - boolean physicalFirst = primary == null || !"archive".equalsIgnoreCase(primary); |
| 122 | + short insTemp = inspectTemplate(config, el); |
133 | 123 |
|
134 | | - return new MappingImpl(config, virtual, physical, archive, insTemp, insTempSlow, insTempFast, physicalFirst, hidden, readonly, toplevel, appMapping, ignoreVirtual, |
135 | | - listener, listenerMode, listenerType); |
| 124 | + int insTempSlow = Caster.toIntValue(ConfigFactoryImpl.getAttr(config, el, "inspectTemplateIntervalSlow"), ConfigPro.INSPECT_INTERVAL_UNDEFINED); |
| 125 | + int insTempFast = Caster.toIntValue(ConfigFactoryImpl.getAttr(config, el, "inspectTemplateIntervalFast"), ConfigPro.INSPECT_INTERVAL_UNDEFINED); |
| 126 | + if (TYPE_REGULAR == type) { |
| 127 | + if ("/lucee/".equalsIgnoreCase(virtual) || "/lucee".equalsIgnoreCase(virtual) || "/lucee-server/".equalsIgnoreCase(virtual) |
| 128 | + || "/lucee-server-context".equalsIgnoreCase(virtual)) |
| 129 | + insTemp = ConfigPro.INSPECT_AUTO; |
136 | 130 | } |
| 131 | + String primary = ConfigFactoryImpl.getAttr(config, el, "primary"); |
| 132 | + boolean physicalFirst = primary == null || !"archive".equalsIgnoreCase(primary); |
137 | 133 |
|
| 134 | + return new MappingImpl(config, virtual, physical, archive, insTemp, insTempSlow, insTempFast, physicalFirst, hidden, readonly, toplevel, appMapping, ignoreVirtual, |
| 135 | + listener, listenerMode, listenerType); |
138 | 136 | } |
139 | | - catch (Exception ex) { |
140 | | - LogUtil.log("mapping-factory", ex); |
141 | | - return defaultValue; |
142 | | - } |
143 | | - |
144 | | - return null; |
| 137 | + throw new ApplicationException("you need to define [physical] or [archive]"); |
145 | 138 | } |
146 | 139 |
|
147 | 140 | private static short inspectTemplate(Config config, Struct data) { |
|
0 commit comments