• R/O
  • SSH
  • HTTPS

smart-gs: コミット


コミットメタ情報

リビジョン1200 (tree)
日時2016-10-26 09:26:42
作者ohura

ログメッセージ

[editor-simplyhtml-merge] URLのencode, decodeの追加
右クリックメニューから新しいresourceを追加する時は、encodeしたurlを追加。
TooltipTextでurlを表示する時やLinkのsourceやtargetを設定する時は、decodeしたurlを表示。

変更サマリ

差分

--- branches/editor-simplyhtml-merge/src/smart_gs/simplyhtml/SGSHTMLEditorActions.java (revision 1199)
+++ branches/editor-simplyhtml-merge/src/smart_gs/simplyhtml/SGSHTMLEditorActions.java (revision 1200)
@@ -846,6 +846,7 @@
846846 try {
847847 TextSegment segment = new TextSegment(markup, document, 0); // TODO
848848 String url = segment.createURI();
849+ url = URLcode.encode(url);
849850 String sgResource = "<!--sg:resource id=" + "\"" + url + "\"-->";
850851 editorKit.insertHTML(doc, editorPane.getSelectionStart(), sgResource, 0, 0, HTML.Tag.COMMENT);
851852 editorKit.insertHTML(doc, editorPane.getSelectionStart(),
--- branches/editor-simplyhtml-merge/src/smart_gs/simplyhtml/SGSDocument.java (revision 1199)
+++ branches/editor-simplyhtml-merge/src/smart_gs/simplyhtml/SGSDocument.java (revision 1200)
@@ -275,6 +275,7 @@
275275 if(gtList.get(i).getStartOffset()<pos && pos<gtList.get(i).getEndOffset()){
276276 tagid = gtList.get(i).getTagid();
277277 id = gtList.get(i).getId();
278+ id = URLcode.decode(id);
278279 }
279280 }
280281 SmartDocument smartDocument = editorPane.getSmartDocument();
@@ -291,25 +292,28 @@
291292 ArrayList<SGSResourceTag> resourceList2 = sgsDocument.getResourceList();
292293 for(int i=0;i<resourceList2.size();i++){
293294 SGSResourceTag resource = resourceList2.get(i);
294-
295+ String url = new String();
295296 if(resource.getId().equals("")){
296297 TextSegment segment = new TextSegment("", smartDocument, 0); // TODO
297- String url = segment.createURI();
298- String sgResource = "<!--sg:resource id=" + "\"" + url + "\"-->";
299- try {
300- doc.remove(resource.getStartOffset(), 1);
301- editorKit.insertHTML(doc, resource.getStartOffset(), sgResource, 0, 0, HTML.Tag.COMMENT);
302- } catch (BadLocationException e) {
303- // TODO Auto-generated catch block
304- e.printStackTrace();
305- } catch (IOException e) {
306- // TODO Auto-generated catch block
307- e.printStackTrace();
308- }
309- sgsDocument.init();
310- sgsDocument.parse(doc);
298+ url = segment.createURI();
299+ } else {
300+ url = resource.getId();
311301 }
302+ url = URLcode.encode(url);
303+ String sgResource = "<!--sg:resource id=" + "\"" + url + "\"-->";
304+ try {
305+ doc.remove(resource.getStartOffset(), 1);
306+ editorKit.insertHTML(doc, resource.getStartOffset(), sgResource, 0, 0, HTML.Tag.COMMENT);
307+ } catch (BadLocationException e) {
308+ // TODO Auto-generated catch block
309+ e.printStackTrace();
310+ } catch (IOException e) {
311+ // TODO Auto-generated catch block
312+ e.printStackTrace();
313+ }
312314 }
315+ sgsDocument.init();
316+ sgsDocument.parse(doc);
313317 }
314318
315319 public int getMaxLineNumber() {
--- branches/editor-simplyhtml-merge/src/smart_gs/simplyhtml/URLcode.java (revision 0)
+++ branches/editor-simplyhtml-merge/src/smart_gs/simplyhtml/URLcode.java (revision 1200)
@@ -0,0 +1,52 @@
1+package smart_gs.simplyhtml;
2+
3+import java.util.ArrayList;
4+
5+public class URLcode {
6+
7+ public static String encode(String url) {
8+ String list = "[]";
9+ ArrayList<Integer> dhlist = new ArrayList<Integer>();
10+ if(url.endsWith("]")){
11+ return url;
12+ }
13+ for(int i=0;i<url.length();i++){
14+ if(url.charAt(i)=='-' && url.charAt(i+1)=='-' ){
15+ dhlist.add(i);
16+ i++;
17+ }
18+ }
19+
20+ for(int j=0;j<dhlist.size();j++){
21+ url = url.substring(0, dhlist.get(j)) + "@@" + url.substring(dhlist.get(j)+2);
22+ if(list.length()==2){
23+ list = "[" + dhlist.get(j) + "]";
24+ } else {
25+ list = list.substring(0, list.length()-1) + " " + dhlist.get(j) + "]";
26+ }
27+ }
28+ return url+list;
29+ }
30+
31+ public static String decode(String url) {
32+ ArrayList<Integer> dhlist = new ArrayList<Integer>();
33+ if(!url.endsWith("]")){
34+ return url;
35+ }
36+ if(url.endsWith("[]")){
37+ return url.substring(0, url.length()-2);
38+ }
39+
40+ String list = url.substring(url.lastIndexOf('[')+1, url.length()-1);
41+ url = url.substring(0, url.lastIndexOf('[')-1);
42+ String[] list2 = list.split(" ");
43+ for(int i=0;i<list2.length;i++){
44+ dhlist.add(Integer.decode(list2[i]));
45+ }
46+ for(int j=0;j<dhlist.size();j++){
47+ url = url.substring(0, dhlist.get(j)) + "--" + url.substring(dhlist.get(j)+2);
48+ }
49+ return url;
50+ }
51+
52+}
--- branches/editor-simplyhtml-merge/src/smart_gs/simplyhtml/SGSDocumentPane.java (revision 1199)
+++ branches/editor-simplyhtml-merge/src/smart_gs/simplyhtml/SGSDocumentPane.java (revision 1200)
@@ -244,6 +244,7 @@
244244 int endOffset = gtList.get(i).getEndOffset();
245245 String tagId = gtList.get(i).getTagid();
246246 String id = gtList.get(i).getId();
247+ id = URLcode.decode(id);
247248 while(startView.getViewCount()!=0){
248249 int viewIndex = startView.getViewIndex(startOffset, Position.Bias.Backward);
249250 if(viewIndex==-1){
旧リポジトリブラウザで表示