• R/O
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

作業部屋の使い方を試しています。


Commit MetaInfo

Revision30 (tree)
Time2014-06-26 17:58:14
Authortuna_p

Log Message

(empty log message)

Change Summary

Incremental Difference

--- HtmlTest2/src/test1/HtmlParser.java (revision 29)
+++ HtmlTest2/src/test1/HtmlParser.java (revision 30)
@@ -22,6 +22,11 @@
2222
2323 ArrayList sData;
2424
25+ // 作業ワーク
26+ String htmltag;
27+ String htmlid;
28+ String htmlclass;
29+
2530 public HtmlParser() {
2631 UrlAdress = null;
2732 }
@@ -39,29 +44,75 @@
3944 public String search(serachData skey) {
4045
4146 String item = skey.getitem();
42- String htmltag = skey.getHtmltag();
43- String htmlid = skey.getHtmlid();
44- String htmlclass = skey.getHtmlclass();
45- String around = skey.getaround();
4647 String regexp = skey.getregexp();
4748
48- // 数値変換
49+ // htmlページ内を検索
50+ if(isHtmlkeyEq(skey) == false) {
51+ serchpageData(skey);
52+ }
53+
54+ // 検索位置を数値変換
55+ String around = skey.getaround();
4956 byte bAround = 0;
5057 if(around.length() > 0) {
5158 bAround = Byte.parseByte(around);
5259 }
5360
54- //getpageData();
55- serchpageData(skey);
56-
5761 if(bAround < sData.size()) {
5862 String rtn = (String)sData.get(bAround);
5963 return rtn;
6064 }
61-
6265 return null;
6366 }
6467
68+ /**
69+ * 直近のHTMLタグ/ID/CLASS値と引数の値を比較する。
70+ * @param skey HTMLタグ/ID/CLASSが格納された検索キー
71+ * @return boolean HTMLタグ/ID/CLASS値が一致する時、true
72+ */
73+ public boolean isHtmlkeyEq(serachData skey) {
74+
75+ String stag = skey.getHtmltag();
76+ String sid = skey.getHtmlid();
77+ String sclass = skey.getHtmlclass();
78+
79+ boolean rtn = true;
80+
81+ // htmltag
82+ if(htmltag == null) {
83+ rtn = false;
84+ } else {
85+ if(htmltag.equals(stag) == false) {
86+ rtn = false;
87+ }
88+ }
89+
90+ // htmlid
91+ if(htmlid == null) {
92+ rtn = false;
93+ } else {
94+ if(htmlid.equals(sid) == false) {
95+ rtn = false;
96+ }
97+ }
98+
99+ // htmlclass
100+ if(htmlclass == null) {
101+ rtn = false;
102+ } else {
103+ if(htmlclass.equals(sclass) == false) {
104+ rtn = false;
105+ }
106+ }
107+
108+ if(!rtn) {
109+ htmltag = stag;
110+ htmlid = sid;
111+ htmlclass = sclass;
112+ }
113+
114+ return rtn;
115+ }
65116
66117 public void getpageData() {
67118 try {
--- HtmlTest2/src/test1/Frame1.java (revision 29)
+++ HtmlTest2/src/test1/Frame1.java (revision 30)
@@ -234,7 +234,6 @@
234234 }//GEN-LAST:event_jBtnRowInsActionPerformed
235235
236236 private void jBtnRowDelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnRowDelActionPerformed
237- //System.out.println(jTable1.getSelectedRow());
238237 int SelectedRow = jTable1.getSelectedRow();
239238 if(!(SelectedRow < 0)) {
240239 this.serachDataList.remove(SelectedRow);
@@ -259,9 +258,6 @@
259258 }//GEN-LAST:event_jMenuSaveActionPerformed
260259
261260 private void jMenu2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu2MouseClicked
262-
263- System.out.println("jMenu2MouseClicked");
264-
265261 HtmlParser par = new HtmlParser(jTxtUrl.getText());
266262 for (Object slist1 : slist) {
267263 String rtn = par.search((serachData)slist1);
--- HtmlTest2/src/test1/HtmlParserCallback.java (revision 29)
+++ HtmlTest2/src/test1/HtmlParserCallback.java (revision 30)
@@ -18,6 +18,9 @@
1818 */
1919 public class HtmlParserCallback extends HTMLEditorKit.ParserCallback {
2020
21+ // デバック情報表示フラグ
22+ final boolean DEBUG = false;
23+
2124 // Tag毎の階層
2225 HashMap<HTML.Tag,Integer> tagMap = new HashMap<>();
2326
@@ -61,23 +64,25 @@
6164 tagMap.put(tag, count);
6265
6366 //--- DEBUG OUT ---- start ---
64- StringBuffer strBuf = new StringBuffer();
65- String ret;
67+ if(DEBUG) {
68+ StringBuffer strBuf = new StringBuffer();
69+ String ret;
6670
67- strBuf.append(count).append(" : F : ").append(tag.toString());
68- ret = (String)attr.getAttribute(HTML.Attribute.ID);
69- if(ret != null) {
70- strBuf.append(" [ID] ").append(ret);
71+ strBuf.append(count).append(" : F : ").append(tag.toString());
72+ ret = (String)attr.getAttribute(HTML.Attribute.ID);
73+ if(ret != null) {
74+ strBuf.append(" [ID] ").append(ret);
75+ }
76+ ret = (String)attr.getAttribute(HTML.Attribute.CLASS);
77+ if(ret != null) {
78+ strBuf.append(" [CLASS] ").append(ret);
79+ }
80+ ret = (String)attr.getAttribute(HTML.Attribute.VALUE);
81+ if(ret != null) {
82+ strBuf.append(" [VALUE] ").append(ret);
83+ }
84+ System.out.println(strBuf);
7185 }
72- ret = (String)attr.getAttribute(HTML.Attribute.CLASS);
73- if(ret != null) {
74- strBuf.append(" [CLASS] ").append(ret);
75- }
76- ret = (String)attr.getAttribute(HTML.Attribute.VALUE);
77- if(ret != null) {
78- strBuf.append(" [VALUE] ").append(ret);
79- }
80- System.out.println(strBuf);
8186 //--- DEBUG OUT ---- end ---
8287
8388 if(bufCount == 0) {
@@ -101,11 +106,11 @@
101106 }
102107
103108 //--- DEBUG OUT ---- start ---
104- System.out.println(count + " : E : " + tag.toString());
109+ if(DEBUG) {
110+ System.out.println(count + " : E : " + tag.toString());
111+ }
105112 //--- DEBUG OUT ---- end ---
106113
107- //if(tag.equals(bufSerchTag) && bufSerchCount >= count) {
108-
109114 if(tag.equals(bufTag) && count <= bufCount) {
110115
111116 // 溜め込んだ一致情報をリストへ格納
@@ -124,14 +129,15 @@
124129
125130 @Override
126131 public void handleText(char[] data, int pos){
127-
128132 //--- DEBUG OUT ---- start ---
129- String dat = new String(data);
130- System.out.println(dat);
133+ if(DEBUG) {
134+ String dat = new String(data);
135+ System.out.println(dat);
136+ }
131137 //--- DEBUG OUT ---- end ---
132-
138+ String splitchar = " | ";
133139 if(bufCount > 0) {
134- bufText.append(new String(data)).append(" | ");
140+ bufText.append(new String(data)).append(splitchar);
135141 }
136142
137143 }
@@ -139,18 +145,24 @@
139145 @Override
140146 public void handleSimpleTag(HTML.Tag tag, MutableAttributeSet attr, int pos){
141147 //--- DEBUG OUT ---- start ---
142- StringBuffer strBuf = new StringBuffer();
143- String ret;
144-
145- strBuf.append("x : S : ").append(tag.toString());
146- ret = (String)attr.getAttribute(HTML.Attribute.VALUE);
147- if(ret != null) {
148- strBuf.append(" [VALUE] ").append(ret);
148+ if(DEBUG) {
149+ StringBuffer strBuf = new StringBuffer();
150+ String ret;
151+ strBuf.append("x : S : ").append(tag.toString());
152+ ret = (String)attr.getAttribute(HTML.Attribute.VALUE);
153+ if(ret != null) {
154+ strBuf.append(" [VALUE] ").append(ret);
155+ }
156+ System.out.println(strBuf);
149157 }
150- System.out.println(strBuf);
151158 //--- DEBUG OUT ---- end ---
152159 }
153160
161+ /**
162+ * ページ内のID/CLASS値と検索キーを比較する。
163+ * @param attr ページのMutableAttributeSet
164+ * @return boolean 検索キーと一致の時、true
165+ */
154166 public boolean serachAttribute(MutableAttributeSet attr) {
155167 String currentID = (String)attr.getAttribute(HTML.Attribute.ID);
156168 String currentClass = (String)attr.getAttribute(HTML.Attribute.CLASS);