(empty log message)
@@ -23,12 +23,21 @@ | ||
23 | 23 | package org.alinous.objects.html; |
24 | 24 | |
25 | 25 | import java.io.IOException; |
26 | +import java.io.StringReader; | |
26 | 27 | import java.io.Writer; |
27 | 28 | |
28 | 29 | import org.alinous.exec.pages.PostContext; |
29 | 30 | import org.alinous.expections.AlinousException; |
31 | +import org.alinous.expections.ExecutionException; | |
32 | +import org.alinous.objects.AlinousAttrs; | |
33 | +import org.alinous.objects.Attribute; | |
34 | +import org.alinous.objects.HrefTargetParser; | |
30 | 35 | import org.alinous.objects.IAlinousObject; |
31 | 36 | import org.alinous.objects.XMLTagBase; |
37 | +import org.alinous.parser.script.attr.AlinousAttrScriptParser; | |
38 | +import org.alinous.parser.script.attr.ParseException; | |
39 | +import org.alinous.script.attribute.ParsedAttribute; | |
40 | +import org.alinous.script.runtime.VariableRepository; | |
32 | 41 | |
33 | 42 | |
34 | 43 | public class LinkTagObject extends XMLTagBase implements IHtmlObject |
@@ -44,7 +53,7 @@ | ||
44 | 53 | return newObj; |
45 | 54 | } |
46 | 55 | |
47 | - public void renderContents(PostContext contexr, Writer wr, int n) throws IOException, AlinousException | |
56 | + public void renderContents(PostContext context, Writer wr, int n) throws IOException, AlinousException | |
48 | 57 | { |
49 | 58 | if(!handleIf(context)){ |
50 | 59 | return; |
@@ -52,8 +61,8 @@ | ||
52 | 61 | |
53 | 62 | if(this.innserObj.size() > 0){ |
54 | 63 | wr.append("<LINK"); |
55 | - renderAttributes(wr, 0); | |
56 | - | |
64 | + renderAttributes(wr, 0, false, true); | |
65 | + renderHref(context, wr, n); | |
57 | 66 | wr.append(">\n"); |
58 | 67 | |
59 | 68 | renderInnerContents(context, wr, n + 1); |
@@ -63,11 +72,78 @@ | ||
63 | 72 | } |
64 | 73 | |
65 | 74 | wr.append("<LINK"); |
66 | - renderAttributes(wr, 0); | |
67 | - | |
75 | + renderAttributes(wr, 0, false, true); | |
76 | + renderHref(context, wr, n); | |
68 | 77 | wr.append(">\n"); |
69 | 78 | } |
70 | 79 | |
80 | + private void renderHref(PostContext context, Writer wr, int n) | |
81 | + throws IOException, AlinousException | |
82 | + { | |
83 | + Attribute targetAttr = this.alinousAttributes.get(AlinousAttrs.ALINOUS_TARGET); | |
84 | + Attribute hrefAttr = this.attributes.get("href"); | |
85 | + if(targetAttr == null){ | |
86 | + if(hrefAttr != null){ | |
87 | + wr.append(" "); | |
88 | + hrefAttr.renderContents(wr, n, this.context, this.valRepo, true); | |
89 | + } | |
90 | + | |
91 | + return; | |
92 | + } | |
93 | + | |
94 | + // Target is specified | |
95 | + String value = makeHrefString(hrefAttr.getValue().getValue(), targetAttr.getValue().getValue()); | |
96 | + | |
97 | + wr.append(" "); | |
98 | + wr.append("href=\""); | |
99 | + | |
100 | + wr.append(context.getFilePath(value)); | |
101 | + | |
102 | + wr.append("\""); | |
103 | + } | |
104 | + | |
105 | + private String makeHrefString(String href, String targetTag) throws AlinousException | |
106 | + { | |
107 | + // parse and input valuable | |
108 | + href = getParsedValue(this.context, this.valRepo, href); | |
109 | + | |
110 | + HrefTargetParser targetParser = new HrefTargetParser(href); | |
111 | + | |
112 | + AlinousTopObject thisPage = getTopObject(); | |
113 | + AlinousTopObject toptopObj = thisPage.getTopTopObject(); | |
114 | + | |
115 | + targetParser.setTopTopPage(toptopObj.getPath()); | |
116 | + targetParser.setThisPagePath(thisPage); | |
117 | + targetParser.setTargetTagId(targetTag); | |
118 | + | |
119 | + return targetParser.getString(); | |
120 | + } | |
121 | + | |
122 | + private String getParsedValue(PostContext context, VariableRepository valRepo, String value) | |
123 | + { | |
124 | + StringReader reader = new StringReader("<" + value + ">"); | |
125 | + String str = null; | |
126 | + | |
127 | + AlinousAttrScriptParser parser = new AlinousAttrScriptParser(reader); | |
128 | + try { | |
129 | + ParsedAttribute attr = parser.parse(); | |
130 | + str = attr.expand(context, valRepo); | |
131 | + } catch (ParseException e) { | |
132 | + //e.printStackTrace(); | |
133 | + | |
134 | + reader.close(); | |
135 | + return null; | |
136 | + } catch (ExecutionException e) { | |
137 | + //e.printStackTrace(); | |
138 | + reader.close(); | |
139 | + return null; | |
140 | + } | |
141 | + | |
142 | + reader.close(); | |
143 | + | |
144 | + return str; | |
145 | + } | |
146 | + | |
71 | 147 | public String getTagName() |
72 | 148 | { |
73 | 149 | return "LINK"; |
@@ -24,6 +24,7 @@ | ||
24 | 24 | |
25 | 25 | import java.io.IOException; |
26 | 26 | import java.io.StringReader; |
27 | +import java.io.StringWriter; | |
27 | 28 | import java.io.Writer; |
28 | 29 | import java.util.Enumeration; |
29 | 30 | import java.util.Hashtable; |
@@ -32,7 +33,9 @@ | ||
32 | 33 | import java.util.concurrent.CopyOnWriteArrayList; |
33 | 34 | |
34 | 35 | import org.alinous.AlinousCore; |
36 | +import org.alinous.AlinousDebug; | |
35 | 37 | import org.alinous.AlinousUtils; |
38 | +import org.alinous.PathUtils; | |
36 | 39 | import org.alinous.datasrc.DataSrcConnection; |
37 | 40 | import org.alinous.datasrc.exception.DataSourceException; |
38 | 41 | import org.alinous.exec.AccessExecutionUnit; |
@@ -228,8 +231,8 @@ | ||
228 | 231 | |
229 | 232 | AlinousTopObject topObj = getTopObject(); |
230 | 233 | AlinousCore core = topObj.getAlinousCore(); |
231 | - | |
232 | 234 | |
235 | + | |
233 | 236 | // getNext Url |
234 | 237 | InnerModulePath modPath = getTopObject().getModulePath().deepClone(); |
235 | 238 | modPath.addPath(getTopObject().getPath()); |
@@ -333,6 +336,13 @@ | ||
333 | 336 | String htmlPath = inner.getValue().getValue(); |
334 | 337 | String modName = AlinousUtils.getModuleName(htmlPath); |
335 | 338 | |
339 | + | |
340 | + // TODO: Check abstract Path | |
341 | + //String nextPath = PathUtils.getAbsPath(getTopObject().getPath(), innerStatus.getNextModuleName()); | |
342 | + modName = PathUtils.getAbsPath(getTopObject().getPath(), modName); | |
343 | + AlinousDebug.debugOut("**********modName : " + modName); | |
344 | + | |
345 | + | |
336 | 346 | retContext.setNextModuleName(modName); |
337 | 347 | retContext.setUseVariableCache(false); |
338 | 348 |
@@ -0,0 +1,74 @@ | ||
1 | +package org.alinous; | |
2 | + | |
3 | +import java.util.Iterator; | |
4 | +import java.util.Stack; | |
5 | + | |
6 | +public class PathUtils | |
7 | +{ | |
8 | + | |
9 | + public static void main(String[] args) | |
10 | + { | |
11 | + String path = getAbsPath("/test/", "../css/test.css"); | |
12 | + | |
13 | + System.out.println(path); | |
14 | + } | |
15 | + | |
16 | + | |
17 | + public static String getAbsPath(String base, String path) | |
18 | + { | |
19 | + if(path.startsWith("/")){ | |
20 | + return path; | |
21 | + } | |
22 | + | |
23 | + // list | |
24 | + Stack<String> baseList = toList(base); | |
25 | + Stack<String> ref = toList(path); | |
26 | + | |
27 | + if(!base.endsWith("/")){ | |
28 | + baseList.pop(); | |
29 | + } | |
30 | + | |
31 | + | |
32 | + Iterator<String> it = ref.iterator(); | |
33 | + while(it.hasNext()){ | |
34 | + String pa = it.next(); | |
35 | + if(pa.equals("..")){ | |
36 | + baseList.pop(); | |
37 | + } | |
38 | + else if(pa.equals(".")){ | |
39 | + continue; | |
40 | + } | |
41 | + else{ | |
42 | + baseList.push(pa); | |
43 | + } | |
44 | + | |
45 | + } | |
46 | + | |
47 | + StringBuffer buffer = new StringBuffer(); | |
48 | + | |
49 | + it = baseList.iterator(); | |
50 | + while(it.hasNext()){ | |
51 | + String pa = it.next(); | |
52 | + | |
53 | + buffer.append("/"); | |
54 | + buffer.append(pa); | |
55 | + } | |
56 | + | |
57 | + return buffer.toString(); | |
58 | + } | |
59 | + | |
60 | + private static Stack<String> toList(String path) | |
61 | + { | |
62 | + String elements[] = path.split("/"); | |
63 | + | |
64 | + Stack<String> baseList = new Stack<String>(); | |
65 | + | |
66 | + for(int i = 0; i < elements.length; i++){ | |
67 | + if(!elements[i].equals("")){ | |
68 | + baseList.add(elements[i]); | |
69 | + } | |
70 | + } | |
71 | + | |
72 | + return baseList; | |
73 | + } | |
74 | +} |
@@ -34,6 +34,8 @@ | ||
34 | 34 | { |
35 | 35 | public static final String SEPARATOR = "/"; |
36 | 36 | |
37 | + | |
38 | + | |
37 | 39 | public static String getModuleName(String path) |
38 | 40 | { |
39 | 41 | String pathes[] = path.split("\\."); |