作業部屋の使い方を試しています。
(empty log message)
| @@ -22,6 +22,11 @@ | ||
| 22 | 22 | |
| 23 | 23 | ArrayList sData; |
| 24 | 24 | |
| 25 | + // 作業ワーク | |
| 26 | + String htmltag; | |
| 27 | + String htmlid; | |
| 28 | + String htmlclass; | |
| 29 | + | |
| 25 | 30 | public HtmlParser() { |
| 26 | 31 | UrlAdress = null; |
| 27 | 32 | } |
| @@ -39,29 +44,75 @@ | ||
| 39 | 44 | public String search(serachData skey) { |
| 40 | 45 | |
| 41 | 46 | String item = skey.getitem(); |
| 42 | - String htmltag = skey.getHtmltag(); | |
| 43 | - String htmlid = skey.getHtmlid(); | |
| 44 | - String htmlclass = skey.getHtmlclass(); | |
| 45 | - String around = skey.getaround(); | |
| 46 | 47 | String regexp = skey.getregexp(); |
| 47 | 48 | |
| 48 | - // 数値変換 | |
| 49 | + // htmlページ内を検索 | |
| 50 | + if(isHtmlkeyEq(skey) == false) { | |
| 51 | + serchpageData(skey); | |
| 52 | + } | |
| 53 | + | |
| 54 | + // 検索位置を数値変換 | |
| 55 | + String around = skey.getaround(); | |
| 49 | 56 | byte bAround = 0; |
| 50 | 57 | if(around.length() > 0) { |
| 51 | 58 | bAround = Byte.parseByte(around); |
| 52 | 59 | } |
| 53 | 60 | |
| 54 | - //getpageData(); | |
| 55 | - serchpageData(skey); | |
| 56 | - | |
| 57 | 61 | if(bAround < sData.size()) { |
| 58 | 62 | String rtn = (String)sData.get(bAround); |
| 59 | 63 | return rtn; |
| 60 | 64 | } |
| 61 | - | |
| 62 | 65 | return null; |
| 63 | 66 | } |
| 64 | 67 | |
| 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 | + } | |
| 65 | 116 | |
| 66 | 117 | public void getpageData() { |
| 67 | 118 | try { |
| @@ -234,7 +234,6 @@ | ||
| 234 | 234 | }//GEN-LAST:event_jBtnRowInsActionPerformed |
| 235 | 235 | |
| 236 | 236 | private void jBtnRowDelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnRowDelActionPerformed |
| 237 | - //System.out.println(jTable1.getSelectedRow()); | |
| 238 | 237 | int SelectedRow = jTable1.getSelectedRow(); |
| 239 | 238 | if(!(SelectedRow < 0)) { |
| 240 | 239 | this.serachDataList.remove(SelectedRow); |
| @@ -259,9 +258,6 @@ | ||
| 259 | 258 | }//GEN-LAST:event_jMenuSaveActionPerformed |
| 260 | 259 | |
| 261 | 260 | private void jMenu2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu2MouseClicked |
| 262 | - | |
| 263 | - System.out.println("jMenu2MouseClicked"); | |
| 264 | - | |
| 265 | 261 | HtmlParser par = new HtmlParser(jTxtUrl.getText()); |
| 266 | 262 | for (Object slist1 : slist) { |
| 267 | 263 | String rtn = par.search((serachData)slist1); |
| @@ -18,6 +18,9 @@ | ||
| 18 | 18 | */ |
| 19 | 19 | public class HtmlParserCallback extends HTMLEditorKit.ParserCallback { |
| 20 | 20 | |
| 21 | + // デバック情報表示フラグ | |
| 22 | + final boolean DEBUG = false; | |
| 23 | + | |
| 21 | 24 | // Tag毎の階層 |
| 22 | 25 | HashMap<HTML.Tag,Integer> tagMap = new HashMap<>(); |
| 23 | 26 |
| @@ -61,23 +64,25 @@ | ||
| 61 | 64 | tagMap.put(tag, count); |
| 62 | 65 | |
| 63 | 66 | //--- DEBUG OUT ---- start --- |
| 64 | - StringBuffer strBuf = new StringBuffer(); | |
| 65 | - String ret; | |
| 67 | + if(DEBUG) { | |
| 68 | + StringBuffer strBuf = new StringBuffer(); | |
| 69 | + String ret; | |
| 66 | 70 | |
| 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); | |
| 71 | 85 | } |
| 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); | |
| 81 | 86 | //--- DEBUG OUT ---- end --- |
| 82 | 87 | |
| 83 | 88 | if(bufCount == 0) { |
| @@ -101,11 +106,11 @@ | ||
| 101 | 106 | } |
| 102 | 107 | |
| 103 | 108 | //--- DEBUG OUT ---- start --- |
| 104 | - System.out.println(count + " : E : " + tag.toString()); | |
| 109 | + if(DEBUG) { | |
| 110 | + System.out.println(count + " : E : " + tag.toString()); | |
| 111 | + } | |
| 105 | 112 | //--- DEBUG OUT ---- end --- |
| 106 | 113 | |
| 107 | - //if(tag.equals(bufSerchTag) && bufSerchCount >= count) { | |
| 108 | - | |
| 109 | 114 | if(tag.equals(bufTag) && count <= bufCount) { |
| 110 | 115 | |
| 111 | 116 | // 溜め込んだ一致情報をリストへ格納 |
| @@ -124,14 +129,15 @@ | ||
| 124 | 129 | |
| 125 | 130 | @Override |
| 126 | 131 | public void handleText(char[] data, int pos){ |
| 127 | - | |
| 128 | 132 | //--- 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 | + } | |
| 131 | 137 | //--- DEBUG OUT ---- end --- |
| 132 | - | |
| 138 | + String splitchar = " | "; | |
| 133 | 139 | if(bufCount > 0) { |
| 134 | - bufText.append(new String(data)).append(" | "); | |
| 140 | + bufText.append(new String(data)).append(splitchar); | |
| 135 | 141 | } |
| 136 | 142 | |
| 137 | 143 | } |
| @@ -139,18 +145,24 @@ | ||
| 139 | 145 | @Override |
| 140 | 146 | public void handleSimpleTag(HTML.Tag tag, MutableAttributeSet attr, int pos){ |
| 141 | 147 | //--- 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); | |
| 149 | 157 | } |
| 150 | - System.out.println(strBuf); | |
| 151 | 158 | //--- DEBUG OUT ---- end --- |
| 152 | 159 | } |
| 153 | 160 | |
| 161 | + /** | |
| 162 | + * ページ内のID/CLASS値と検索キーを比較する。 | |
| 163 | + * @param attr ページのMutableAttributeSet | |
| 164 | + * @return boolean 検索キーと一致の時、true | |
| 165 | + */ | |
| 154 | 166 | public boolean serachAttribute(MutableAttributeSet attr) { |
| 155 | 167 | String currentID = (String)attr.getAttribute(HTML.Attribute.ID); |
| 156 | 168 | String currentClass = (String)attr.getAttribute(HTML.Attribute.CLASS); |