/** @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ // <editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(RegisterUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(RegisterUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(RegisterUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(RegisterUI.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } // </editor-fold> // </editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater( new Runnable() { public void run() { new RegisterUI().setVisible(true); } }); }
/** * 依存先 * * <p> * * @param namespace 名前空間 URI * @param localName ローカル名 * @param name 修飾名 * @param attr 属性 */ @Override public void startElement(String namespace, String localName, String name, Attributes attr) { // 名前空間が一致しなければ何もしない if (!this.namespaceUri.equals(namespace)) { return; } // ローカル名が一致し href 属性を持つ場合 if (this.localNames.contains(localName) && attr.getIndex("href") >= 0) { String href = attr.getValue("href"); try { URI uri = new URI(href); if (!uri.isAbsolute()) { uri = baseUri.resolve(uri); } this.dependUri.add(uri); } catch (URISyntaxException ex) { logger.finest("unrecognized uri: " + href + "; " + ex); } } return; }
public void bad() throws Throwable { if (IO.static_returns_t_or_f()) { java.util.logging.Logger log_bs = java.util.logging.Logger.getLogger("local-logger"); Socket sock = null; PrintWriter out = null; try { sock = new Socket("remote_host", 1337); out = new PrintWriter(sock.getOutputStream(), true); /* FLAW: sending over an unencrypted (non-SSL) channel */ out.println("plaintext send"); } catch (Exception ex) { IO.writeLine("Error writing to the socket"); } finally { try { if (out != null) { out.close(); } } catch (Exception e) { log_bs.warning("Error closing out"); } try { if (sock != null) { sock.close(); } } catch (Exception e) { log_bs.warning("Error closing sock"); } } } else { java.util.logging.Logger log_gs = java.util.logging.Logger.getLogger("local-logger"); OutputStream outStream = null; BufferedWriter bWriter = null; OutputStreamWriter outStreamWriter = null; SSLSocketFactory sslssocketfactory = null; SSLSocket sslsocket = null; try { sslssocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault(); sslsocket = (SSLSocket) sslssocketfactory.createSocket("remote_host", 1337); outStream = sslsocket.getOutputStream(); outStreamWriter = new OutputStreamWriter(outStream); bWriter = new BufferedWriter(outStreamWriter); /* FIX: sending over an SSL encrypted channel */ bWriter.write("encrypted send"); bWriter.flush(); } catch (Exception ex) { IO.writeLine("Error writing to the socket"); } finally { try { if (bWriter != null) { bWriter.close(); } } catch (IOException e) { log_gs.warning("Error closing bWriter"); } finally { try { if (outStreamWriter != null) { outStreamWriter.close(); } } catch (IOException e) { log_gs.warning("Error closing outStreamWriter"); } } try { if (sslsocket != null) { sslsocket.close(); } } catch (Exception e) { log_gs.warning("Error closing sslsocket"); } } } }
/** * ドキュメント内から依存先 URI を取得するためのハンドラです。 * * <p> * * @version $Revision: 1.1 $ $Date: 2009/04/16 19:30:59 $ * @author torao * @since 2009/04/14 Java SE 6 */ final class DependencyCapture extends DefaultHandler { // ====================================================================== // ログ出力先 // ====================================================================== /** * このクラスのログ出力先です。 * * <p> */ private static final java.util.logging.Logger logger = java.util.logging.Logger.getLogger(DependencyCapture.class.getName()); // ====================================================================== // 名前空間 URI // ====================================================================== /** * 対象の名前空間 URI です。 * * <p> */ private final String namespaceUri; // ====================================================================== // ローカル名 // ====================================================================== /** * 対象要素のローカル名です。 * * <p> */ private final Set<String> localNames = new HashSet<String>(); // ====================================================================== // ベース URI // ====================================================================== /** * 相対パスの基準となる URI です。 * * <p> */ private final URI baseUri; // ====================================================================== // 依存先 URI // ====================================================================== /** * 解析によって取り込んだ依存先 URI です。 * * <p> */ private final Set<URI> dependUri; // ====================================================================== // コンストラクタ // ====================================================================== /** * コンストラクタは何も行いません。 * * <p> * * @param base 相対パスの基準 URI * @param dependUri 依存先 URI の格納先 * @param ns 対象の名前空間 URI * @param localNames 対象のローカル名 */ public DependencyCapture(URI base, Set<URI> dependUri, String ns, String... localNames) { this.baseUri = base; this.dependUri = dependUri; this.namespaceUri = ns; this.localNames.addAll(Arrays.asList(localNames)); return; } // ====================================================================== // 要素の開始通知 // ====================================================================== /** * 依存先 * * <p> * * @param namespace 名前空間 URI * @param localName ローカル名 * @param name 修飾名 * @param attr 属性 */ @Override public void startElement(String namespace, String localName, String name, Attributes attr) { // 名前空間が一致しなければ何もしない if (!this.namespaceUri.equals(namespace)) { return; } // ローカル名が一致し href 属性を持つ場合 if (this.localNames.contains(localName) && attr.getIndex("href") >= 0) { String href = attr.getValue("href"); try { URI uri = new URI(href); if (!uri.isAbsolute()) { uri = baseUri.resolve(uri); } this.dependUri.add(uri); } catch (URISyntaxException ex) { logger.finest("unrecognized uri: " + href + "; " + ex); } } return; } }