private void displayDiffResults() throws IOException {
        File outFile = File.createTempFile("diff", ".htm");
        outFile.deleteOnExit();
        FileOutputStream outStream = new FileOutputStream(outFile);
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(outStream));
        out.write("<title>LOC Differences</title>\n" + SCRIPT + "\n" + "\n" + "
\n");
        if (addedTable.length() > 0) {
            out.write("

Files Added:	" + "Add	Type
");
            out.write(addedTable.toString());
            out.write("

");
        }
        if (modifiedTable.length() > 0) {
            out.write("

Files Modified:	" + "Base	Del	Mod	Add	" + "Total	Type
");
            out.write(modifiedTable.toString());
            out.write("

");
        }
        if (deletedTable.length() > 0) {
            out.write("

Files Deleted:	" + "Del	Type
");
            out.write(deletedTable.toString());
            out.write("

");
        }
        out.write("
\n");
        if (modifiedTable.length() > 0 || deletedTable.length() > 0) {
            out.write("
Base: 	");
            out.write(Long.toString(base));
            out.write("
\n
Deleted: 	");
            out.write(Long.toString(deleted));
            out.write("
\n
Modified: 	");
            out.write(Long.toString(modified));
            out.write("
\n
Added: 	");
            out.write(Long.toString(added));
            out.write("
\n
New & Changed: 	");
            out.write(Long.toString(added + modified));
            out.write("
\n");
        }
        out.write("
Total: 	");
        out.write(Long.toString(total));
        out.write("
\n

");
        redlinesOut.close();
        out.flush();
        InputStream redlines = new FileInputStream(redlinesTempFile);
        byte[] buffer = new byte[4096];
        int bytesRead;
        while ((bytesRead = redlines.read(buffer)) != -1) outStream.write(buffer, 0, bytesRead);
        outStream.write("".getBytes());
        outStream.close();
        Browser.launch(outFile.toURL().toString());
    }


    public static String hashSHA1(String value) {
        try {
            MessageDigest digest = MessageDigest.getInstance("SHA-1");
            digest.update(value.getBytes());
            BigInteger hash = new BigInteger(1, digest.digest());
            return hash.toString(16);
        } catch (NoSuchAlgorithmException e) {
        }
        return null;
    }


    private static void readAndRewrite(File inFile, File outFile) throws IOException {
        ImageInputStream iis = ImageIO.createImageInputStream(new BufferedInputStream(new FileInputStream(inFile)));
        DcmParser dcmParser = DcmParserFactory.getInstance().newDcmParser(iis);
        Dataset ds = DcmObjectFactory.getInstance().newDataset();
        dcmParser.setDcmHandler(ds.getDcmHandler());
        dcmParser.parseDcmFile(null, Tags.PixelData);
        PixelDataReader pdReader = pdFact.newReader(ds, iis, dcmParser.getDcmDecodeParam().byteOrder, dcmParser.getReadVR());
        System.out.println("reading " + inFile + "...");
        pdReader.readPixelData(false);
        ImageOutputStream out = ImageIO.createImageOutputStream(new BufferedOutputStream(new FileOutputStream(outFile)));
        DcmEncodeParam dcmEncParam = DcmEncodeParam.IVR_LE;
        ds.writeDataset(out, dcmEncParam);
        ds.writeHeader(out, dcmEncParam, Tags.PixelData, dcmParser.getReadVR(), dcmParser.getReadLength());
        System.out.println("writing " + outFile + "...");
        PixelDataWriter pdWriter = pdFact.newWriter(pdReader.getPixelDataArray(), false, ds, out, dcmParser.getDcmDecodeParam().byteOrder, dcmParser.getReadVR());
        pdWriter.writePixelData();
        out.flush();
        out.close();
        System.out.println("done!");
    }


    private static void addFromResource(String resource, OutputStream out) {
        URL url = OpenOfficeDocumentCreator.class.getResource(resource);
        try {
            InputStream in = url.openStream();
            byte[] buffer = new byte[256];
            synchronized (in) {
                synchronized (out) {
                    while (true) {
                        int bytesRead = in.read(buffer);
                        if (bytesRead == -1) break;
                        out.write(buffer, 0, bytesRead);
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public void process(String number) {
        try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(Constants.TRAIN_INFO_URL.value());
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair(Constants.TRAIN_NUMBER_POST_PARAM_NAME.value(), number));
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httpPost);
            InputStream is = response.getEntity().getContent();
            Document doc = getDocument(is);
            XPathFactory factory = XPathFactory.newInstance();
            XPath xpath = factory.newXPath();
            XPathExpression expr = xpath.compile(Constants.XPATH_TRAIN_STOPS_INFO.value());
            Object result = expr.evaluate(doc, XPathConstants.NODESET);
            NodeList nodes = (NodeList) result;
            List<String> list = new ArrayList<String>();
            for (int i = 0; i < nodes.getLength(); i++) {
                list.add(nodes.item(i).getNodeValue());
            }
            parse(list);
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XPathExpressionException e) {
            e.printStackTrace();
        }
    }


    private void copyFile(File in, File out) throws Exception {
        FileChannel sourceChannel = new FileInputStream(in).getChannel();
        FileChannel destinationChannel = new FileOutputStream(out).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
        sourceChannel.close();
        destinationChannel.close();
    }


    @SuppressWarnings("unchecked")
    protected void processTransformAction(HttpServletRequest request, HttpServletResponse response, String action) throws Exception {
        File transformationFile = null;
        String tr = request.getParameter(Definitions.REQUEST_PARAMNAME_XSLT);
        if (StringUtils.isNotBlank(tr)) {
            transformationFile = new File(xslBase, tr);
            if (!transformationFile.isFile()) {
                response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameter \"" + Definitions.REQUEST_PARAMNAME_XSLT + "\" " + "with value \"" + tr + "\" refers to non existing file");
                return;
            }
        }
        StreamResult result;
        ByteArrayOutputStream baos = null;
        if (isDevelopmentMode) {
            baos = new ByteArrayOutputStream();
            if (StringUtils.equals(action, "get")) {
                result = new StreamResult(new Base64.OutputStream(baos, Base64.DECODE));
            } else {
                result = new StreamResult(baos);
            }
        } else {
            if (StringUtils.equals(action, "get")) {
                result = new StreamResult(new Base64.OutputStream(response.getOutputStream(), Base64.DECODE));
            } else {
                result = new StreamResult(response.getOutputStream());
            }
        }
        HashMap<String, Object> params = new HashMap<String, Object>();
        params.putAll(request.getParameterMap());
        params.put("{" + Definitions.CONFIGURATION_NAMESPACE + "}configuration", configuration);
        params.put("{" + Definitions.REQUEST_NAMESPACE + "}request", request);
        params.put("{" + Definitions.RESPONSE_NAMESPACE + "}response", response);
        params.put("{" + Definitions.SESSION_NAMESPACE + "}session", request.getSession());
        params.put("{" + Definitions.INFOFUZE_NAMESPACE + "}development-mode", new Boolean(Config.getInstance().isDevelopmentMode()));
        Transformer transformer = new Transformer();
        transformer.setTransformationFile(transformationFile);
        transformer.setParams(params);
        transformer.setTransformMode(TransformMode.NORMAL);
        transformer.setConfiguration(configuration);
        transformer.setErrorListener(new TransformationErrorListener(response));
        transformer.setLogInfo(false);
        String method = transformer.getOutputProperties().getProperty(OutputKeys.METHOD, "xml");
        String contentType;
        if (method.endsWith("html")) {
            contentType = Definitions.MIMETYPE_HTML;
        } else if (method.equals("xml")) {
            contentType = Definitions.MIMETYPE_XML;
        } else {
            contentType = Definitions.MIMETYPE_TEXTPLAIN;
        }
        String encoding = transformer.getOutputProperties().getProperty(OutputKeys.ENCODING, "UTF-8");
        response.setContentType(contentType + ";charset=" + encoding);
        DataSourceIf dataSource = new NullSource();
        transformer.transform((Source) dataSource, result);
        if (isDevelopmentMode) {
            IOUtils.copy(new ByteArrayInputStream(baos.toByteArray()), response.getOutputStream());
        }
    }


    private File extractUninstallFiles(File _destPath, boolean upgrade, String lastVer) {
        File oldlog = null;
        try {
            boolean oldClassCopied = false;
            File destPath = new File(_destPath, "vai_" + VAGlobals.APP_NAME + "_" + VAGlobals.APP_VERSION);
            if (upgrade) {
                File lastVerPath = new File(_destPath, "vai_" + VAGlobals.APP_NAME + "_" + lastVer);
                if (destPath.equals(lastVerPath)) {
                    File bkdir = new File(destPath.getAbsolutePath() + ".bak");
                    if (!destPath.renameTo(bkdir)) {
                        throw new IOException(VAGlobals.i18n("Setup_NotCreateDirectory") + " " + destPath);
                    }
                    oldlog = new File(bkdir.getAbsolutePath() + System.getProperty("file.separator") + "uninstall.vai");
                    lastVerPath = bkdir;
                } else {
                    oldlog = new File(lastVerPath.getAbsolutePath() + System.getProperty("file.separator") + "uninstall.vai");
                }
                if ((!destPath.exists()) && (!destPath.mkdirs())) {
                    throw new IOException(VAGlobals.i18n("Setup_NotCreateDirectory") + " " + destPath);
                }
                if (uInfo_.module) oldClassCopied = copyOldSetupClass(lastVerPath, destPath);
            } else {
                if ((!destPath.exists()) && (!destPath.mkdirs())) {
                    throw new IOException(VAGlobals.i18n("Setup_NotCreateDirectory") + " " + destPath);
                }
            }
            dirty_ = true;
            File[] ls = destPath.listFiles();
            for (int i = 0; i < ls.length; i++) {
                if (!oldClassCopied) ls[i].delete(); else if (!ls[i].getPath().equals(destPath.getAbsolutePath() + File.separator + installClassName_ + ".class")) ls[i].delete();
            }
            byte[] buf = new byte[0];
            int read = 0;
            if (!oldClassCopied && (installClassSize_ > 0 || jarOffset_ > 0)) {
                final File outClassFile = new File(destPath.getAbsolutePath() + File.separator + installClassName_ + ".class");
                if (outClassFile.exists() && !outClassFile.delete()) {
                    ui_.showError(new Exception(VAGlobals.i18n("Setup_FileNotCreated") + ":\n" + outClassFile.getName()));
                }
                final FileOutputStream out = new FileOutputStream(outClassFile);
                final FileInputStream in = new FileInputStream(fileWithArchive_);
                if (installClassOffset_ > 0) {
                    in.skip(installClassOffset_);
                }
                buf = new byte[0];
                if (installClassSize_ < 0) buf = new byte[(int) jarOffset_]; else buf = new byte[(int) installClassSize_];
                read = in.read(buf, 0, buf.length);
                out.write(buf, 0, read);
                out.close();
                in.close();
            }
            final FileInputStream in = new FileInputStream(fileWithArchive_);
            if (jarOffset_ > 0) {
                in.skip(jarOffset_);
            }
            JarInputStream jar = new JarInputStream(in);
            final File outJarFile = new File(destPath.getAbsolutePath() + File.separator + "install.jar");
            if (outJarFile.exists() && !outJarFile.delete()) {
                ui_.showError(new Exception(VAGlobals.i18n("Setup_FileNotCreated") + ":\n" + outJarFile.getName()));
            }
            JarOutputStream outJar = new JarOutputStream(new FileOutputStream(outJarFile));
            ZipEntry entry = jar.getNextEntry();
            final int bufSize = 32768;
            buf = new byte[bufSize];
            while (entry != null) {
                String entryName = entry.getName();
                if (entryName.equals("com/memoire/vainstall/resources/vainstall.properties")) {
                } else if (entryName.equals(installClassName_ + ".class") && !oldClassCopied) {
                    FileOutputStream out = null;
                    try {
                        out = new FileOutputStream(destPath.getAbsolutePath() + File.separator + installClassName_ + ".class");
                        VAGlobals.copyStream(jar, out, buf);
                    } catch (IOException e) {
                        throw e;
                    } finally {
                        if (out != null) out.close();
                    }
                } else if (!entryName.endsWith(".zip")) {
                    if (VAGlobals.DEBUG) VAGlobals.printDebug("jar entry name " + entryName);
                    ZipEntry outEntry = new ZipEntry(entryName);
                    CRC32 crc = new CRC32();
                    outJar.putNextEntry(outEntry);
                    int size = 0;
                    while ((read = jar.read(buf, 0, bufSize)) >= 0) {
                        size += read;
                        if (read == 0) {
                            Thread.yield();
                        } else {
                            outJar.write(buf, 0, read);
                            crc.update(buf, 0, read);
                        }
                    }
                    outEntry.setSize(size);
                    outEntry.setCrc(crc.getValue());
                    outJar.flush();
                    outJar.closeEntry();
                }
                jar.closeEntry();
                entry = jar.getNextEntry();
            }
            InputStream pin = getClass().getResourceAsStream("resources/vainstall.properties");
            Properties prop = new Properties();
            try {
                prop.load(pin);
            } catch (IOException exc) {
            }
            if (language == null) language = "default";
            prop.setProperty("vainstall.destination.language", language);
            ZipEntry outEntry = new ZipEntry("com/memoire/vainstall/resources/vainstall.properties");
            CRC32 crc = new CRC32();
            outEntry.setCrc(crc.getValue());
            outEntry.setSize(prop.size());
            outJar.putNextEntry(outEntry);
            prop.store(outJar, VAGlobals.NAME + " " + VAGlobals.VERSION);
            outEntry.setCrc(crc.getValue());
            outJar.closeEntry();
            jar.close();
            outJar.close();
            in.close();
        } catch (IOException e) {
            String message = e.getLocalizedMessage();
            message += "\n" + VAGlobals.i18n("Setup_ErrorUninstallScripts");
            e.printStackTrace();
            exitOnError(new IOException(message));
        }
        return oldlog;
    }


    private boolean copyOldSetupClass(File lastVerPath, File destPath) throws java.io.FileNotFoundException, IOException {
        byte[] buf;
        File oldClass = new File(lastVerPath.getAbsolutePath() + File.separator + installClassName_ + ".class");
        if (oldClass.exists()) {
            FileOutputStream out = new FileOutputStream(destPath.getAbsolutePath() + File.separator + installClassName_ + ".class");
            FileInputStream in = new FileInputStream(oldClass);
            buf = new byte[(new Long(oldClass.length())).intValue()];
            int read = in.read(buf, 0, buf.length);
            out.write(buf, 0, read);
            out.close();
            in.close();
            return true;
        }
        return false;
    }


    public static String generateHexadecimalCodedString(String stringToBeCoded) {
        MessageDigest digest;
        try {
            digest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
        digest.update(stringToBeCoded.getBytes());
        byte[] hashedKey = digest.digest();
        final int radix = 16;
        String result = "";
        for (byte b : hashedKey) {
            int unsignedByte = b + 128;
            result += Integer.toString(unsignedByte, radix);
        }
        return result;
    }


    public HogsCustomizer() {
        m_filename = PathFinder.getCustsFile();
        m_currenttaunts = new String[10];
        m_textfields = new JTextField[10];
        m_color = new Color(255, 255, 255);
        boolean exists = (new File(m_filename)).exists();
        m_inverted = false;
        m_chooser = new JColorChooser();
        AbstractColorChooserPanel[] panels = m_chooser.getChooserPanels();
        m_chooser.removeChooserPanel(panels[0]);
        m_chooser.removeChooserPanel(panels[2]);
        m_chooser.setPreviewPanel(new JPanel());
        Reader reader = null;
        if (exists) {
            try {
                reader = new FileReader(m_filename);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        } else {
            Object[] options = { "Yes", "No, Thanks" };
            int n = JOptionPane.showOptionDialog(this, "You do not have a customization file in your home directory.\n                 " + "Would you like to create one?", "Hogs Customization", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
            if (n == 0) {
                try {
                    FileChannel srcChannel = new FileInputStream(HogsConstants.CUSTS_TEMPLATE).getChannel();
                    FileChannel dstChannel = new FileOutputStream(m_filename).getChannel();
                    dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
                    srcChannel.close();
                    dstChannel.close();
                } catch (IOException e) {
                    e.printStackTrace();
                    System.exit(0);
                }
            } else {
                System.exit(0);
            }
            try {
                reader = new FileReader(m_filename);
            } catch (FileNotFoundException e1) {
                e1.printStackTrace();
                System.exit(0);
            }
        }
        try {
            readFromFile(reader);
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
        Box mainpanel = Box.createVerticalBox();
        mainpanel.add(buildTauntsPanel());
        mainpanel.add(buildMouseStylePanel());
        mainpanel.add(Box.createVerticalStrut(10));
        mainpanel.add(buildColorPanel());
        mainpanel.add(Box.createVerticalStrut(10));
        mainpanel.add(buildButtonsPanel());
        mainpanel.add(Box.createVerticalStrut(10));
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setContentPane(mainpanel);
        this.pack();
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation(dim.width / 2 - (this.getWidth() / 2), dim.height / 2 - (this.getHeight() / 2));
        this.setTitle("Hogs Customizer");
        this.setVisible(true);
    }


    @Override
    public void copyTo(ManagedFile other) throws ManagedIOException {
        try {
            if (other.getType() == ManagedFileType.FILE) {
                IOUtils.copy(this.getContent().getInputStream(), other.getContent().getOutputStream());
            } else {
                ManagedFile newFile = other.retrive(this.getPath());
                newFile.createFile();
                IOUtils.copy(this.getContent().getInputStream(), newFile.getContent().getOutputStream());
            }
        } catch (IOException ioe) {
            throw ManagedIOException.manage(ioe);
        }
    }


    public void testLocalUserAccountLocalRemoteRoles() throws SQLException {
        Statement st = null;
        Connection authedCon = null;
        try {
            saSt.executeUpdate("CREATE USER tlualrr PASSWORD 'wontuse'");
            saSt.executeUpdate("GRANT role3 TO tlualrr");
            saSt.executeUpdate("GRANT role4 TO tlualrr");
            saSt.executeUpdate("SET DATABASE AUTHENTICATION FUNCTION EXTERNAL NAME " + "'CLASSPATH:" + getClass().getName() + ".twoRolesFn'");
            try {
                authedCon = DriverManager.getConnection(jdbcUrl, "TLUALRR", "unusedPassword");
            } catch (SQLException se) {
                fail("Access with 'twoRolesFn' failed");
            }
            st = authedCon.createStatement();
            assertFalse("Positive test #1 failed", AuthFunctionUtils.updateDoesThrow(st, "INSERT INTO t1 VALUES(1)"));
            assertFalse("Positive test #2 failed", AuthFunctionUtils.updateDoesThrow(st, "INSERT INTO t2 VALUES(2)"));
            assertTrue("Negative test #3 failed", AuthFunctionUtils.updateDoesThrow(st, "INSERT INTO t3 VALUES(3)"));
            assertTrue("Negative test #4 failed", AuthFunctionUtils.updateDoesThrow(st, "INSERT INTO t4 VALUES(4)"));
            assertEquals(twoRolesSet, AuthUtils.getEnabledRoles(authedCon));
        } finally {
            if (st != null) try {
                st.close();
            } catch (SQLException se) {
                logger.error("Close of Statement failed:" + se);
            } finally {
                st = null;
            }
            if (authedCon != null) try {
                authedCon.rollback();
                authedCon.close();
            } catch (SQLException se) {
                logger.error("Close of Authed Conn. failed:" + se);
            } finally {
                authedCon = null;
            }
        }
    }


    public static void main(String[] args) {
        FTPClient client = new FTPClient();
        try {
            client.connect("192.168.1.10");
            client.login("a", "123456");
            String[] names = client.listNames();
            for (String name : names) {
                System.out.println("Name = " + name);
            }
            FTPFile[] ftpFiles = client.listFiles();
            for (FTPFile ftpFile : ftpFiles) {
                if (ftpFile.getType() == FTPFile.FILE_TYPE) {
                    System.out.println("FTPFile: " + ftpFile.getName() + "; " + FileUtils.byteCountToDisplaySize(ftpFile.getSize()));
                }
            }
            client.logout();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                client.disconnect();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }


    public static void copy(String fromFileName, String toFileName) throws IOException {
        File fromFile = new File(fromFileName);
        File toFile = new File(toFileName);
        if (!fromFile.exists()) throw new IOException("FileCopy: " + "no such source file: " + fromFileName);
        if (!fromFile.isFile()) throw new IOException("FileCopy: " + "can't copy directory: " + fromFileName);
        if (!fromFile.canRead()) throw new IOException("FileCopy: " + "source file is unreadable: " + fromFileName);
        if (toFile.isDirectory()) toFile = new File(toFile, fromFile.getName());
        if (toFile.exists()) {
            if (!toFile.canWrite()) throw new IOException("FileCopy: " + "destination file is unwriteable: " + toFileName);
            System.out.print("Overwrite existing file " + toFile.getName() + "? (Y/N): ");
            System.out.flush();
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            String response = in.readLine();
            if (!response.equals("Y") && !response.equals("y")) throw new IOException("FileCopy: " + "existing file was not overwritten.");
        } else {
            String parent = toFile.getParent();
            if (parent == null) parent = System.getProperty("user.dir");
            File dir = new File(parent);
            if (!dir.exists()) throw new IOException("FileCopy: " + "destination directory doesn't exist: " + parent);
            if (dir.isFile()) throw new IOException("FileCopy: " + "destination is not a directory: " + parent);
            if (!dir.canWrite()) throw new IOException("FileCopy: " + "destination directory is unwriteable: " + parent);
        }
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(fromFile);
            to = new FileOutputStream(toFile);
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead);
        } finally {
            if (from != null) try {
                from.close();
            } catch (IOException e) {
                ;
            }
            if (to != null) try {
                to.close();
            } catch (IOException e) {
                ;
            }
        }
    }


    private void createNodes() {
        try {
            URL url = this.getClass().getResource("NodesFile.txt");
            InputStreamReader inReader = new InputStreamReader(url.openStream());
            BufferedReader inNodes = new BufferedReader(inReader);

            // BufferedReader inNodes = new BufferedReader(new
            // FileReader("NodesFile.txt"));
            String s;
            while ((s = inNodes.readLine()) != null) {
                String label = inNodes.readLine();
                String fullText = inNodes.readLine();
                String type = inNodes.readLine();
                Node n = new Node(s, type);
                n.label = label;
                n.fullText = fullText;
                node.add(n);
            }
            inNodes.close();

            url = this.getClass().getResource("EdgesFile.txt");
            inReader = new InputStreamReader(url.openStream());
            BufferedReader inEdges = new BufferedReader(inReader);
            // BufferedReader inEdges = new BufferedReader(new
            // FileReader("EdgesFile.txt"));
            while ((s = inEdges.readLine()) != null)
                edge.add(new Edge(s, inEdges.readLine(), inEdges.readLine(),
                        inEdges.readLine()));
            inEdges.close();
        } catch (FileNotFoundException e) {
            // TODO ?????? catch ??
            e.printStackTrace();
        } catch (IOException e) {
            // TODO ?????? catch ??
            e.printStackTrace();
        }
        /*
         * for(Myparser.Nd x:FreeConnectTest.pNd){ Node n = new Node(x.id,
         * x.type); n.label = x.label; node.add(n); } for(Myparser.Ed
         * x:FreeConnectTest.pEd) edge.add(new Edge(x.id, x.source.id,
         * x.target.id));
         */
    }


    private boolean postLogin() {
        URL url = null;
        URLConnection urlConn = null;
        OutputStream out = null;
        int code = 0;
        boolean gotPhpsessid = false;
        try {
            url = new URL("http://" + m_host + "/forums/index.php?action=login2");
        } catch (MalformedURLException e) {
            e.printStackTrace();
            return false;
        }
        try {
            urlConn = url.openConnection();
            ((HttpURLConnection) urlConn).setRequestMethod("POST");
            ((HttpURLConnection) urlConn).setInstanceFollowRedirects(false);
            urlConn.setDoOutput(true);
            urlConn.setDoInput(true);
            urlConn.setRequestProperty("Host", m_host);
            urlConn.setRequestProperty("Accept", "*/*");
            urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            urlConn.setRequestProperty("Connection", "Keep-Alive");
            urlConn.setRequestProperty("Cache-Control", "no-cache");
            out = urlConn.getOutputStream();
            out.write(new String("user=" + m_username + "&passwrd=" + m_password + "&cookielength=60").getBytes());
            out.flush();
            out.close();
            do {
                readCookies(urlConn);
                m_referer = url.toString();
                code = ((HttpURLConnection) urlConn).getResponseCode();
                if (code == 301 || code == 302) {
                    url = new URL(urlConn.getHeaderField("Location"));
                    urlConn = url.openConnection();
                    ((HttpURLConnection) urlConn).setRequestMethod("GET");
                    ((HttpURLConnection) urlConn).setInstanceFollowRedirects(false);
                    urlConn.setDoOutput(true);
                    urlConn.setDoInput(true);
                    urlConn.setRequestProperty("Host", m_host);
                    urlConn.setRequestProperty("Accept", "*/*");
                    urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                    urlConn.setRequestProperty("Connection", "Keep-Alive");
                    urlConn.setRequestProperty("Cache-Control", "no-cache");
                    if (m_referer != null) urlConn.setRequestProperty("Referer", m_referer);
                    if (m_cookies != null) urlConn.setRequestProperty("Cookie", m_cookies);
                    continue;
                }
                if (code == 200) {
                    String refreshHdr = urlConn.getHeaderField("Refresh");
                    Pattern p_phpsessid = Pattern.compile(".*?\\?PHPSESSID=(\\w+).*");
                    Matcher match_phpsessid = p_phpsessid.matcher(refreshHdr);
                    if (match_phpsessid.matches()) {
                        gotPhpsessid = true;
                    }
                    urlConn = null;
                    continue;
                }
                String msg = ((HttpURLConnection) urlConn).getResponseMessage();
                m_turnSummaryRef = String.valueOf(code) + ": " + msg;
                return false;
            } while (urlConn != null);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        if (!gotPhpsessid) {
            m_turnSummaryRef = "Error: PHPSESSID not found after login. ";
            return false;
        }
        if (m_cookies == null) {
            m_turnSummaryRef = "Error: cookies not found after login. ";
            return false;
        }
        try {
            Thread.sleep(m_loginDelayInSeconds * 1000);
        } catch (InterruptedException ie) {
            ie.printStackTrace();
        }
        return true;
    }


private boolean goToForum() {
        URL url = null;
        URLConnection urlConn = null;
        int code = 0;
        boolean gotNumReplies = false;
        boolean gotMsgNum = false;
        try {
            url = new URL("http://" + m_host + "/forums/index.php?topic=" + m_gameId + ".new");
        } catch (MalformedURLException e) {
            e.printStackTrace();
            return false;
        }
        try {
            urlConn = url.openConnection();
            ((HttpURLConnection) urlConn).setRequestMethod("GET");
            ((HttpURLConnection) urlConn).setInstanceFollowRedirects(false);
            urlConn.setDoOutput(false);
            urlConn.setDoInput(true);
            urlConn.setRequestProperty("Host", m_host);
            urlConn.setRequestProperty("Accept", "*/*");
            urlConn.setRequestProperty("Connection", "Keep-Alive");
            urlConn.setRequestProperty("Cache-Control", "no-cache");
            if (m_referer != null) urlConn.setRequestProperty("Referer", m_referer);
            if (m_cookies != null) urlConn.setRequestProperty("Cookie", m_cookies);
            m_referer = url.toString();
            readCookies(urlConn);
            code = ((HttpURLConnection) urlConn).getResponseCode();
            if (code != 200) {
                String msg = ((HttpURLConnection) urlConn).getResponseMessage();
                m_turnSummaryRef = String.valueOf(code) + ": " + msg;
                return false;
            }
            BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
            String line = "";
            Pattern p_numReplies = Pattern.compile(".*?;num_replies=(\\d+)\".*");
            Pattern p_msgNum = Pattern.compile(".*?.*");
            Pattern p_attachId = Pattern.compile(".*?action=dlattach;topic=" + m_gameId + ".0;attach=(\\d+)\">.*");
            while ((line = in.readLine()) != null) {
                if (!gotNumReplies) {
                    Matcher match_numReplies = p_numReplies.matcher(line);
                    if (match_numReplies.matches()) {
                        m_numReplies = match_numReplies.group(1);
                        gotNumReplies = true;
                        continue;
                    }
                }
                if (!gotMsgNum) {
                    Matcher match_msgNum = p_msgNum.matcher(line);
                    if (match_msgNum.matches()) {
                        m_msgNum = match_msgNum.group(1);
                        gotMsgNum = true;
                        continue;
                    }
                }
                Matcher match_attachId = p_attachId.matcher(line);
                if (match_attachId.matches()) m_attachId = match_attachId.group(1);
            }
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        if (!gotNumReplies || !gotMsgNum) {
            m_turnSummaryRef = "Error: ";
            if (!gotNumReplies) m_turnSummaryRef += "No num_replies found in A&A.org forum topic. ";
            if (!gotMsgNum) m_turnSummaryRef += "No msgXXXXXX found in A&A.org forum topic. ";
            return false;
        }
        return true;
    }


    public DataRecord addRecord(InputStream input) throws DataStoreException {
        File temporary = null;
        try {
            temporary = newTemporaryFile();
            DataIdentifier tempId = new DataIdentifier(temporary.getName());
            usesIdentifier(tempId);
            long length = 0;
            MessageDigest digest = MessageDigest.getInstance(DIGEST);
            OutputStream output = new DigestOutputStream(new FileOutputStream(temporary), digest);
            try {
                length = IOUtils.copyLarge(input, output);
            } finally {
                output.close();
            }
            DataIdentifier identifier = new DataIdentifier(digest.digest());
            File file;
            synchronized (this) {
                usesIdentifier(identifier);
                file = getFile(identifier);
                if (!file.exists()) {
                    File parent = file.getParentFile();
                    parent.mkdirs();
                    if (temporary.renameTo(file)) {
                        temporary = null;
                    } else {
                        throw new IOException("Can not rename " + temporary.getAbsolutePath() + " to " + file.getAbsolutePath() + " (media read only?)");
                    }
                } else {
                    long now = System.currentTimeMillis();
                    if (getLastModified(file) < now + ACCESS_TIME_RESOLUTION) {
                        setLastModified(file, now + ACCESS_TIME_RESOLUTION);
                    }
                }
                if (file.length() != length) {
                    if (!file.isFile()) {
                        throw new IOException("Not a file: " + file);
                    }
                    throw new IOException(DIGEST + " collision: " + file);
                }
            }
            inUse.remove(tempId);
            return new FileDataRecord(identifier, file);
        } catch (NoSuchAlgorithmException e) {
            throw new DataStoreException(DIGEST + " not available", e);
        } catch (IOException e) {
            throw new DataStoreException("Could not add record", e);
        } finally {
            if (temporary != null) {
                temporary.delete();
            }
        }
    }


    public static Element retrieveFromCache(String cacheName, Object key) {
        URL url = null;
        HttpURLConnection connection = null;
        InputStream is = null;
        OutputStream os = null;
        int result = 0;
        StringBuilder sb = null;
        Element cacheElement = null;
        try {
            url = new URL(EHCACHE_SERVER_BASE + "/" + cacheName + "/" + key);
            connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.connect();
            is = connection.getInputStream();
            byte[] response = new byte[4096];
            result = is.read(response);
            while (result != -1) {
                sb.append(response);
                result = is.read(response);
            }
            if (is != null) {
                try {
                    is.close();
                } catch (Exception ignore) {
                }
            }
            if (connection != null) {
                connection.disconnect();
            }
            cacheElement = new Element(key, sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (Exception ignore) {
                }
            }
            if (is != null) {
                try {
                    is.close();
                } catch (Exception ignore) {
                }
            }
            if (connection != null) {
                connection.disconnect();
            }
        }
        return cacheElement;
    }


    public void writeTo(OutputStream out) throws IOException {
        if (!closed) {
            throw new IOException("Stream not closed");
        }
        if (isInMemory()) {
            memoryOutputStream.writeTo(out);
        } else {
            FileInputStream fis = new FileInputStream(outputFile);
            try {
                IOUtils.copy(fis, out);
            } finally {
                IOUtils.closeQuietly(fis);
            }
        }
    }


    protected Object openDialogBox(Control cellEditorWindow) {
        FileDialog dialog = new FileDialog(parent.getShell(), SWT.OPEN);
        dialog.setFilterExtensions(new String[] { "*.jpg;*.JPG;*.JPEG;*.gif;*.GIF;*.png;*.PNG", "*.jpg;*.JPG;*.JPEG", "*.gif;*.GIF", "*.png;*.PNG" });
        dialog.setFilterNames(new String[] { "All", "Joint Photographic Experts Group (JPEG)", "Graphics Interchange Format (GIF)", "Portable Network Graphics (PNG)" });
        String imagePath = dialog.open();
        if (imagePath == null) return null;
        IProject project = ProjectManager.getInstance().getCurrentProject();
        String projectFolderPath = project.getLocation().toOSString();
        File imageFile = new File(imagePath);
        String fileName = imageFile.getName();
        ImageData imageData = null;
        try {
            imageData = new ImageData(imagePath);
        } catch (SWTException e) {
            UserErrorException error = new UserErrorException(PropertyHandler.getInstance().getProperty("_invalid_image_title"), PropertyHandler.getInstance().getProperty("_invalid_image_text"));
            UserErrorService.INSTANCE.showError(error);
            return null;
        }
        if (imageData == null) {
            UserErrorException error = new UserErrorException(PropertyHandler.getInstance().getProperty("_invalid_image_title"), PropertyHandler.getInstance().getProperty("_invalid_image_text"));
            UserErrorService.INSTANCE.showError(error);
            return null;
        }
        File copiedImageFile = new File(projectFolderPath + File.separator + imageFolderPath + File.separator + fileName);
        if (copiedImageFile.exists()) {
            Path path = new Path(copiedImageFile.getPath());
            copiedImageFile = new File(projectFolderPath + File.separator + imageFolderPath + File.separator + UUID.randomUUID().toString() + "." + path.getFileExtension());
        }
        try {
            copiedImageFile.createNewFile();
        } catch (IOException e1) {
            ExceptionHandlingService.INSTANCE.handleException(e1);
            copiedImageFile = null;
        }
        if (copiedImageFile == null) {
            copiedImageFile = new File(projectFolderPath + File.separator + imageFolderPath + File.separator + UUID.randomUUID().toString());
            try {
                copiedImageFile.createNewFile();
            } catch (IOException e) {
                ExceptionHandlingService.INSTANCE.handleException(e);
                return "";
            }
        }
        FileReader in = null;
        FileWriter out = null;
        try {
            in = new FileReader(imageFile);
            out = new FileWriter(copiedImageFile);
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.close();
        } catch (FileNotFoundException e) {
            ExceptionHandlingService.INSTANCE.handleException(e);
            return "";
        } catch (IOException e) {
            ExceptionHandlingService.INSTANCE.handleException(e);
            return "";
        }
        return imageFolderPath + File.separator + copiedImageFile.getName();
    }


    public void reqservmodif(HttpServletRequest req, HttpServletResponse resp, SessionCommand command) {
        try {
            System.err.println(req.getSession().getServletContext().getRealPath("WEB-INF/syncWork"));
            File tempFile = File.createTempFile("localmodif-", ".medoorequest");
            OutputStream fos = new FileOutputStream(tempFile);
            syncServer.getServerModifications(command.getSession(), fos);
            InputStream fis = new FileInputStream(tempFile);
            resp.setContentLength(fis.available());
            while (fis.available() > 0) {
                resp.getOutputStream().write(fis.read());
            }
            resp.getOutputStream().flush();
            resp.flushBuffer();
            tempFile.delete();
        } catch (IOException ioe) {
            logger.error(ioe.getMessage());
        } catch (ImogSerializationException ex) {
            logger.error(ex.getMessage());
        }
    }


    @Override
    protected HttpResponse<HttpURLConnection> execute(HttpRequest<HttpURLConnection> con) throws HttpRequestException {
        HttpURLConnection unwrap = con.unwrap();
        try {
            unwrap.connect();
        } catch (IOException e) {
            throw new HttpRequestException(e);
        }
        return new UrlHttpResponse(unwrap);
    }


    public void convert(File src, File dest) throws IOException {
        InputStream in = new BufferedInputStream(new FileInputStream(src));
        DcmParser p = pfact.newDcmParser(in);
        Dataset ds = fact.newDataset();
        p.setDcmHandler(ds.getDcmHandler());
        try {
            FileFormat format = p.detectFileFormat();
            if (format != FileFormat.ACRNEMA_STREAM) {
                System.out.println("\n" + src + ": not an ACRNEMA stream!");
                return;
            }
            p.parseDcmFile(format, Tags.PixelData);
            if (ds.contains(Tags.StudyInstanceUID) || ds.contains(Tags.SeriesInstanceUID) || ds.contains(Tags.SOPInstanceUID) || ds.contains(Tags.SOPClassUID)) {
                System.out.println("\n" + src + ": contains UIDs!" + " => probable already DICOM - do not convert");
                return;
            }
            boolean hasPixelData = p.getReadTag() == Tags.PixelData;
            boolean inflate = hasPixelData && ds.getInt(Tags.BitsAllocated, 0) == 12;
            int pxlen = p.getReadLength();
            if (hasPixelData) {
                if (inflate) {
                    ds.putUS(Tags.BitsAllocated, 16);
                    pxlen = pxlen * 4 / 3;
                }
                if (pxlen != (ds.getInt(Tags.BitsAllocated, 0) >>> 3) * ds.getInt(Tags.Rows, 0) * ds.getInt(Tags.Columns, 0) * ds.getInt(Tags.NumberOfFrames, 1) * ds.getInt(Tags.NumberOfSamples, 1)) {
                    System.out.println("\n" + src + ": mismatch pixel data length!" + " => do not convert");
                    return;
                }
            }
            ds.putUI(Tags.StudyInstanceUID, uid(studyUID));
            ds.putUI(Tags.SeriesInstanceUID, uid(seriesUID));
            ds.putUI(Tags.SOPInstanceUID, uid(instUID));
            ds.putUI(Tags.SOPClassUID, classUID);
            if (!ds.contains(Tags.NumberOfSamples)) {
                ds.putUS(Tags.NumberOfSamples, 1);
            }
            if (!ds.contains(Tags.PhotometricInterpretation)) {
                ds.putCS(Tags.PhotometricInterpretation, "MONOCHROME2");
            }
            if (fmi) {
                ds.setFileMetaInfo(fact.newFileMetaInfo(ds, UIDs.ImplicitVRLittleEndian));
            }
            OutputStream out = new BufferedOutputStream(new FileOutputStream(dest));
            try {
            } finally {
                ds.writeFile(out, encodeParam());
                if (hasPixelData) {
                    if (!skipGroupLen) {
                        out.write(PXDATA_GROUPLEN);
                        int grlen = pxlen + 8;
                        out.write((byte) grlen);
                        out.write((byte) (grlen >> 8));
                        out.write((byte) (grlen >> 16));
                        out.write((byte) (grlen >> 24));
                    }
                    out.write(PXDATA_TAG);
                    out.write((byte) pxlen);
                    out.write((byte) (pxlen >> 8));
                    out.write((byte) (pxlen >> 16));
                    out.write((byte) (pxlen >> 24));
                }
                if (inflate) {
                    int b2, b3;
                    for (; pxlen > 0; pxlen -= 3) {
                        out.write(in.read());
                        b2 = in.read();
                        b3 = in.read();
                        out.write(b2 & 0x0f);
                        out.write(b2 >> 4 | ((b3 & 0x0f) << 4));
                        out.write(b3 >> 4);
                    }
                } else {
                    for (; pxlen > 0; --pxlen) {
                        out.write(in.read());
                    }
                }
                out.close();
            }
            System.out.print('.');
        } finally {
            in.close();
        }
    }


    public Properties load() {
        Properties lvProperties = new Properties();
        try {
            InputStream lvInputStream = url.openStream();
            lvProperties.load(lvInputStream);
        } catch (Exception e) {
            throw new PropertiesLoadException("Error in load-method:", e);
        }
        return lvProperties;
    }


    public static boolean copyFileCover(String srcFileName, String descFileName, boolean coverlay) {
        File srcFile = new File(srcFileName);
        if (!srcFile.exists()) {
            System.out.println("复制文件失败，源文件" + srcFileName + "不存在!");
            return false;
        } else if (!srcFile.isFile()) {
            System.out.println("复制文件失败，" + srcFileName + "不是一个文件!");
            return false;
        }
        File descFile = new File(descFileName);
        if (descFile.exists()) {
            if (coverlay) {
                System.out.println("目标文件已存在，准备删除!");
                if (!FileOperateUtils.delFile(descFileName)) {
                    System.out.println("删除目标文件" + descFileName + "失败!");
                    return false;
                }
            } else {
                System.out.println("复制文件失败，目标文件" + descFileName + "已存在!");
                return false;
            }
        } else {
            if (!descFile.getParentFile().exists()) {
                System.out.println("目标文件所在的目录不存在，创建目录!");
                if (!descFile.getParentFile().mkdirs()) {
                    System.out.println("创建目标文件所在的目录失败!");
                    return false;
                }
            }
        }
        int readByte = 0;
        InputStream ins = null;
        OutputStream outs = null;
        try {
            ins = new FileInputStream(srcFile);
            outs = new FileOutputStream(descFile);
            byte[] buf = new byte[1024];
            while ((readByte = ins.read(buf)) != -1) {
                outs.write(buf, 0, readByte);
            }
            System.out.println("复制单个文件" + srcFileName + "到" + descFileName + "成功!");
            return true;
        } catch (Exception e) {
            System.out.println("复制文件失败：" + e.getMessage());
            return false;
        } finally {
            if (outs != null) {
                try {
                    outs.close();
                } catch (IOException oute) {
                    oute.printStackTrace();
                }
            }
            if (ins != null) {
                try {
                    ins.close();
                } catch (IOException ine) {
                    ine.printStackTrace();
                }
            }
        }
    }


    protected static String getBiopaxId(Reaction reaction) {
        String id = null;
        if (reaction.getId() > Reaction.NO_ID_ASSIGNED) {
            id = reaction.getId().toString();
        } else {
            try {
                MessageDigest md = MessageDigest.getInstance("MD5");
                md.update(reaction.getTextualRepresentation().getBytes());
                byte[] digestBytes = md.digest();
                StringBuilder digesterSb = new StringBuilder(32);
                for (int i = 0; i < digestBytes.length; i++) {
                    int intValue = digestBytes[i] & 0xFF;
                    if (intValue < 0x10) digesterSb.append('0');
                    digesterSb.append(Integer.toHexString(intValue));
                }
                id = digesterSb.toString();
            } catch (NoSuchAlgorithmException e) {
            }
        }
        return id;
    }


    @Override
    public TDSModel loadModel(URL url, String skin) throws IOException, IncorrectFormatException, ParsingErrorException {
        boolean baseURLWasNull = setBaseURLFromModelURL(url);
        TDSModel model = loadModel(url.openStream(), skin);
        if (baseURLWasNull) {
            popBaseURL();
        }
        return (model);
    }


    @Override
    public TDSScene loadScene(URL url) throws IOException, IncorrectFormatException, ParsingErrorException {
        boolean baseURLWasNull = setBaseURLFromModelURL(url);
        TDSScene scene = loadScene(url.openStream());
        if (baseURLWasNull) {
            popBaseURL();
        }
        return (scene);
    }


        @Override
        protected final Boolean doInBackground(Void... v) {
            Bitmap bmp = ((BitmapDrawable) ((ImageView) findViewById(R.id.post_img)).getDrawable()).getBitmap();
            HttpURLConnection con;
            try {
                URL url = new URL(POST_URL);
                con = (HttpURLConnection) url.openConnection();
                con.setRequestMethod("POST");
                con.setDoOutput(true);
                con.setRequestProperty("Accept-Language", "multipart/form-data");
                con.setRequestProperty("X-RAW", "true");
            } catch (MalformedURLException e) {
                e.printStackTrace();
                finish();
                return false;
            } catch (IOException e) {
                e.printStackTrace();
                finish();
                return false;
            }
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bmp.compress(CompressFormat.JPEG, 100, bos);
            OutputStream os = null;
            try {
                os = con.getOutputStream();
                os.write(bos.toByteArray());
                os.flush();
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
                try {
                    os.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
                return false;
            }
            InputStream is = null;
            BufferedReader reader;
            try {
                is = con.getInputStream();
                reader = new BufferedReader(new InputStreamReader(is));
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
                try {
                    is.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
                return false;
            }
            String s;
            try {
                while ((s = reader.readLine()) != null) {
                    Log.v(TAG, s);
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return true;
        }


    protected boolean doRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String path = request.getPathInfo();
        if (!path.startsWith(alias)) {
            throw new ServletException("Path '" + path + "' does not start with registered alias '" + alias + "'");
        }
        String internal;
        if (alias.equals("/")) {
            internal = name + path;
        } else {
            internal = name + path.substring(alias.length(), path.length());
        }
        URL resource = httpContext.getResource(internal);
        if (resource == null) {
            return false;
        }
        String mimeType = servletContext.getMimeType(internal);
        if (mimeType != null) {
            response.setContentType(mimeType);
        }
        InputStream is = resource.openStream();
        OutputStream os = response.getOutputStream();
        IOUtils.copyAndClose(is, os);
        return true;
    }


    public void elimina(Cliente cli) throws errorSQL, errorConexionBD {
        System.out.println("GestorCliente.elimina()");
        int id = cli.getId();
        String sql;
        Statement stmt = null;
        try {
            gd.begin();
            sql = "DELETE FROM cliente WHERE cod_cliente =" + id;
            System.out.println("Ejecutando: " + sql);
            stmt = gd.getConexion().createStatement();
            stmt.executeUpdate(sql);
            System.out.println("executeUpdate");
            sql = "DELETE FROM persona WHERE id =" + id;
            System.out.println("Ejecutando: " + sql);
            stmt.executeUpdate(sql);
            gd.commit();
            System.out.println("commit");
            stmt.close();
        } catch (SQLException e) {
            gd.rollback();
            throw new errorSQL(e.toString());
        } catch (errorConexionBD e) {
            System.err.println("Error en GestorCliente.elimina(): " + e);
        } catch (errorSQL e) {
            System.err.println("Error en GestorCliente.elimina(): " + e);
        }
    }


    public Configuration(URL url) {
        InputStream in = null;
        try {
            load(in = url.openStream());
        } catch (Exception e) {
            throw new RuntimeException("Could not load configuration from " + url, e);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException ignore) {
                }
            }
        }
    }


    private void exportJar(File root, List<File> list, Manifest manifest) throws Exception {
        JarOutputStream jarOut = null;
        FileInputStream fin = null;
        try {
            jarOut = new JarOutputStream(new FileOutputStream(jarFile), manifest);
            for (int i = 0; i < list.size(); i++) {
                String filename = list.get(i).getAbsolutePath();
                filename = filename.substring(root.getAbsolutePath().length() + 1);
                fin = new FileInputStream(list.get(i));
                JarEntry entry = new JarEntry(filename.replace('\\', '/'));
                jarOut.putNextEntry(entry);
                byte[] buf = new byte[4096];
                int read;
                while ((read = fin.read(buf)) != -1) {
                    jarOut.write(buf, 0, read);
                }
                jarOut.closeEntry();
                jarOut.flush();
            }
        } finally {
            if (fin != null) {
                try {
                    fin.close();
                } catch (Exception e) {
                    ExceptionOperation.operate(e);
                }
            }
            if (jarOut != null) {
                try {
                    jarOut.close();
                } catch (Exception e) {
                }
            }
        }
    }


    public static void main(String[] args) throws Exception {
        String st = "http://www.kmzlinks.com/redirect.asp?id=113&file=HeartShapedIsland.kmz";
        URL url = new URL(st);
        InputStream fis = null;
        if ("file".equals(url.getProtocol())) fis = new FileInputStream(url.getFile()); else if ("http".equals(url.getProtocol())) fis = url.openStream();
        ZipInputStream zis = new ZipInputStream(fis);
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            System.out.println("Extracting: " + entry);
            int count;
            byte data[] = new byte[BUFFER];
            FileOutputStream fos = new FileOutputStream(entry.getName());
            BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
            while ((count = zis.read(data, 0, BUFFER)) != -1) dest.write(data, 0, count);
            dest.flush();
            dest.close();
        }
        zis.close();
    }


    public void load() throws IOException {
        File file = new File(filename);
        URL url = file.toURI().toURL();
        Properties temp = new Properties();
        temp.load(url.openStream());
        if (temp.getProperty("Width") != null) try {
            width = Integer.valueOf(temp.getProperty("Width"));
        } catch (Exception e) {
            System.out.println("Error loading Calibration Sheet Width - leaving as default: " + e);
        }
        if (temp.getProperty("Height") != null) try {
            height = Integer.valueOf(temp.getProperty("Height"));
        } catch (Exception e) {
            System.out.println("Error loading Calibration Sheet Height - leaving as default: " + e);
        }
        if (temp.getProperty("CircleRadius") != null) try {
            circleradius = Double.valueOf(temp.getProperty("CircleRadius"));
        } catch (Exception e) {
            System.out.println("Error loading Calibration Sheet Circle Radius - leaving as default: " + e);
        }
        ArrayList<Ellipse> calibrationcircleslist = new ArrayList<Ellipse>();
        int i = 0;
        while ((temp.getProperty("Circle" + i + "CenterX") != null) && (temp.getProperty("Circle" + i + "CenterY") != null)) {
            Point2d circlecenter = new Point2d(0, 0);
            circlecenter.x = Double.valueOf(temp.getProperty("Circle" + i + "CenterX"));
            circlecenter.y = Double.valueOf(temp.getProperty("Circle" + i + "CenterY"));
            Ellipse element = new Ellipse(circlecenter, circleradius, circleradius, 0);
            calibrationcircleslist.add(element);
            i++;
        }
        calibrationcircles = new Ellipse[0];
        calibrationcircles = calibrationcircleslist.toArray(calibrationcircles);
    }


    public void uploadFile(File inputFile, String targetFile) throws IOException {
        System.out.println("Uploading " + inputFile.getName() + " to " + targetFile);
        File outputFile = new File(targetFile);
        if (targetFile.endsWith("/")) {
            outputFile = new File(outputFile, inputFile.getName());
        } else if (outputFile.getParentFile().exists() == false) {
            outputFile.getParentFile().mkdirs();
        }
        if (inputFile.renameTo(outputFile) == false) {
            InputStream in = new FileInputStream(inputFile);
            OutputStream out = new FileOutputStream(outputFile);
            byte[] line = new byte[16384];
            int bytes = -1;
            while ((bytes = in.read(line)) != -1) out.write(line, 0, bytes);
            in.close();
            out.close();
        }
    }


    private static File copyFileTo(File file, File directory) throws IOException {
        File newFile = new File(directory, file.getName());
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(file);
            fos = new FileOutputStream(newFile);
            byte buff[] = new byte[1024];
            int val;
            while ((val = fis.read(buff)) > 0) fos.write(buff, 0, val);
        } finally {
            if (fis != null) fis.close();
            if (fos != null) fos.close();
        }
        return newFile;
    }


    public void method31() {
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = 0; i < anInt772 - 1; i++) if (anIntArray774[i] < anIntArray774[i + 1]) {
                int j = anIntArray774[i];
                anIntArray774[i] = anIntArray774[i + 1];
                anIntArray774[i + 1] = j;
                long l = aLongArray773[i];
                aLongArray773[i] = aLongArray773[i + 1];
                aLongArray773[i + 1] = l;
                flag = true;
            }
        }
    }


    private void unzipData(ZipFile zipfile, ZipEntry entry) {
        if (entry.getName().equals("backUpExternalInfo.out")) {
            File outputFile = new File("temp", entry.getName());
            if (!outputFile.getParentFile().exists()) {
                outputFile.getParentFile().mkdirs();
            }
            try {
                BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry));
                BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
                IOUtils.copy(inputStream, outputStream);
                outputStream.close();
                inputStream.close();
            } catch (IOException e) {
                throw new BackupException(e.getMessage());
            }
        }
    }


    public static int getNextID(int AD_Client_ID, String TableName, String trxName) {
        if (TableName == null || TableName.length() == 0) throw new IllegalArgumentException("TableName missing");
        int retValue = -1;
        boolean adempiereSys = Ini.isPropertyBool(Ini.P_ADEMPIERESYS);
        if (adempiereSys && AD_Client_ID > 11) adempiereSys = false;
        if (CLogMgt.isLevel(LOGLEVEL)) s_log.log(LOGLEVEL, TableName + " - AdempiereSys=" + adempiereSys + " [" + trxName + "]");
        String selectSQL = null;
        if (DB.isPostgreSQL()) {
            selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, AD_Sequence_ID " + "FROM AD_Sequence " + "WHERE Name=?" + " AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' " + " FOR UPDATE OF AD_Sequence ";
            USE_PROCEDURE = false;
        } else if (DB.isOracle()) {
            selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, AD_Sequence_ID " + "FROM AD_Sequence " + "WHERE Name=?" + " AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' " + "FOR UPDATE";
            USE_PROCEDURE = true;
        } else {
            selectSQL = "SELECT CurrentNext, CurrentNextSys, IncrementNo, AD_Sequence_ID " + "FROM AD_Sequence " + "WHERE Name=?" + " AND IsActive='Y' AND IsTableID='Y' AND IsAutoSequence='Y' ";
            USE_PROCEDURE = false;
        }
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        for (int i = 0; i < 3; i++) {
            try {
                conn = DB.getConnectionID();
                if (conn == null) return -1;
                pstmt = conn.prepareStatement(selectSQL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
                pstmt.setString(1, TableName);
                if (!USE_PROCEDURE && DB.getDatabase().isQueryTimeoutSupported()) pstmt.setQueryTimeout(QUERY_TIME_OUT);
                rs = pstmt.executeQuery();
                if (CLogMgt.isLevelFinest()) s_log.finest("AC=" + conn.getAutoCommit() + ", RO=" + conn.isReadOnly() + " - Isolation=" + conn.getTransactionIsolation() + "(" + Connection.TRANSACTION_READ_COMMITTED + ") - RSType=" + pstmt.getResultSetType() + "(" + ResultSet.TYPE_SCROLL_SENSITIVE + "), RSConcur=" + pstmt.getResultSetConcurrency() + "(" + ResultSet.CONCUR_UPDATABLE + ")");
                if (rs.next()) {
                    MTable table = MTable.get(Env.getCtx(), TableName);
                    int AD_Sequence_ID = rs.getInt(4);
                    boolean gotFromHTTP = false;
                    if (adempiereSys) {
                        String isUseCentralizedID = MSysConfig.getValue("DICTIONARY_ID_USE_CENTRALIZED_ID", "Y");
                        if ((!isUseCentralizedID.equals("N")) && (!isExceptionCentralized(TableName))) {
                            retValue = getNextOfficialID_HTTP(TableName);
                            if (retValue > 0) {
                                PreparedStatement updateSQL;
                                updateSQL = conn.prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = ? + 1 WHERE AD_Sequence_ID = ?");
                                try {
                                    updateSQL.setInt(1, retValue);
                                    updateSQL.setInt(2, AD_Sequence_ID);
                                    updateSQL.executeUpdate();
                                } finally {
                                    updateSQL.close();
                                }
                            }
                            gotFromHTTP = true;
                        }
                    }
                    boolean queryProjectServer = false;
                    if (table.getColumn("EntityType") != null) queryProjectServer = true;
                    if (!queryProjectServer && MSequence.Table_Name.equalsIgnoreCase(TableName)) queryProjectServer = true;
                    if (queryProjectServer && (adempiereSys) && (!isExceptionCentralized(TableName))) {
                        String isUseProjectCentralizedID = MSysConfig.getValue("PROJECT_ID_USE_CENTRALIZED_ID", "N");
                        if (isUseProjectCentralizedID.equals("Y")) {
                            retValue = getNextProjectID_HTTP(TableName);
                            if (retValue > 0) {
                                PreparedStatement updateSQL;
                                updateSQL = conn.prepareStatement("UPDATE AD_Sequence SET CurrentNext = GREATEST(CurrentNext, ? + 1) WHERE AD_Sequence_ID = ?");
                                try {
                                    updateSQL.setInt(1, retValue);
                                    updateSQL.setInt(2, AD_Sequence_ID);
                                    updateSQL.executeUpdate();
                                } finally {
                                    updateSQL.close();
                                }
                            }
                            gotFromHTTP = true;
                        }
                    }
                    if (!gotFromHTTP) {
                        if (USE_PROCEDURE) {
                            retValue = nextID(conn, AD_Sequence_ID, adempiereSys);
                        } else {
                            PreparedStatement updateSQL;
                            int incrementNo = rs.getInt(3);
                            if (adempiereSys) {
                                updateSQL = conn.prepareStatement("UPDATE AD_Sequence SET CurrentNextSys = CurrentNextSys + ? WHERE AD_Sequence_ID = ?");
                                retValue = rs.getInt(2);
                            } else {
                                updateSQL = conn.prepareStatement("UPDATE AD_Sequence SET CurrentNext = CurrentNext + ? WHERE AD_Sequence_ID = ?");
                                retValue = rs.getInt(1);
                            }
                            try {
                                updateSQL.setInt(1, incrementNo);
                                updateSQL.setInt(2, AD_Sequence_ID);
                                updateSQL.executeUpdate();
                            } finally {
                                updateSQL.close();
                            }
                        }
                    }
                    conn.commit();
                } else s_log.severe("No record found - " + TableName);
                break;
            } catch (Exception e) {
                s_log.log(Level.SEVERE, TableName + " - " + e.getMessage(), e);
                try {
                    if (conn != null) conn.rollback();
                } catch (SQLException e1) {
                }
            } finally {
                DB.close(rs, pstmt);
                pstmt = null;
                rs = null;
                if (conn != null) {
                    try {
                        conn.close();
                    } catch (SQLException e) {
                    }
                    conn = null;
                }
            }
            Thread.yield();
        }
        return retValue;
    }


    @Override
    protected Object transform(Row inputs) throws FunctionException {
        StringBuffer buffer = new StringBuffer();
        for (IColumn c : inputs.getColumns()) {
            buffer.append(c.getValueAsString() + "|");
        }
        try {
            MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(buffer.toString().getBytes());
            byte[] hash = digest.digest();
            return getHex(hash);
        } catch (Exception e) {
            throw new FunctionException(e);
        }
    }


    private File downloadPDB(String pdbId) {
        File tempFile = new File(path + "/" + pdbId + ".pdb.gz");
        File pdbHome = new File(path);
        if (!pdbHome.canWrite()) {
            System.err.println("can not write to " + pdbHome);
            return null;
        }
        String ftp = String.format("ftp://ftp.ebi.ac.uk/pub/databases/msd/pdb_uncompressed/pdb%s.ent", pdbId.toLowerCase());
        System.out.println("Fetching " + ftp);
        try {
            URL url = new URL(ftp);
            InputStream conn = url.openStream();
            System.out.println("writing to " + tempFile);
            FileOutputStream outPut = new FileOutputStream(tempFile);
            GZIPOutputStream gzOutPut = new GZIPOutputStream(outPut);
            PrintWriter pw = new PrintWriter(gzOutPut);
            BufferedReader fileBuffer = new BufferedReader(new InputStreamReader(conn));
            String line;
            while ((line = fileBuffer.readLine()) != null) {
                pw.println(line);
            }
            pw.flush();
            pw.close();
            outPut.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return tempFile;
    }


    private static void readAndRewrite(File inFile, File outFile) throws IOException {
        ImageInputStream iis = ImageIO.createImageInputStream(new BufferedInputStream(new FileInputStream(inFile)));
        DcmParser dcmParser = DcmParserFactory.getInstance().newDcmParser(iis);
        Dataset ds = DcmObjectFactory.getInstance().newDataset();
        dcmParser.setDcmHandler(ds.getDcmHandler());
        dcmParser.parseDcmFile(null, Tags.PixelData);
        PixelDataReader pdReader = pdFact.newReader(ds, iis, dcmParser.getDcmDecodeParam().byteOrder, dcmParser.getReadVR());
        System.out.println("reading " + inFile + "...");
        pdReader.readPixelData(false);
        ImageOutputStream out = ImageIO.createImageOutputStream(new BufferedOutputStream(new FileOutputStream(outFile)));
        DcmEncodeParam dcmEncParam = DcmEncodeParam.IVR_LE;
        ds.writeDataset(out, dcmEncParam);
        ds.writeHeader(out, dcmEncParam, Tags.PixelData, dcmParser.getReadVR(), dcmParser.getReadLength());
        System.out.println("writing " + outFile + "...");
        PixelDataWriter pdWriter = pdFact.newWriter(pdReader.getPixelDataArray(), false, ds, out, dcmParser.getDcmDecodeParam().byteOrder, dcmParser.getReadVR());
        pdWriter.writePixelData();
        out.flush();
        out.close();
        System.out.println("done!");
    }


    public void convert(File src, File dest) throws IOException {
        InputStream in = new BufferedInputStream(new FileInputStream(src));
        DcmParser p = pfact.newDcmParser(in);
        Dataset ds = fact.newDataset();
        p.setDcmHandler(ds.getDcmHandler());
        try {
            FileFormat format = p.detectFileFormat();
            if (format != FileFormat.ACRNEMA_STREAM) {
                System.out.println("\n" + src + ": not an ACRNEMA stream!");
                return;
            }
            p.parseDcmFile(format, Tags.PixelData);
            if (ds.contains(Tags.StudyInstanceUID) || ds.contains(Tags.SeriesInstanceUID) || ds.contains(Tags.SOPInstanceUID) || ds.contains(Tags.SOPClassUID)) {
                System.out.println("\n" + src + ": contains UIDs!" + " => probable already DICOM - do not convert");
                return;
            }
            boolean hasPixelData = p.getReadTag() == Tags.PixelData;
            boolean inflate = hasPixelData && ds.getInt(Tags.BitsAllocated, 0) == 12;
            int pxlen = p.getReadLength();
            if (hasPixelData) {
                if (inflate) {
                    ds.putUS(Tags.BitsAllocated, 16);
                    pxlen = pxlen * 4 / 3;
                }
                if (pxlen != (ds.getInt(Tags.BitsAllocated, 0) >>> 3) * ds.getInt(Tags.Rows, 0) * ds.getInt(Tags.Columns, 0) * ds.getInt(Tags.NumberOfFrames, 1) * ds.getInt(Tags.NumberOfSamples, 1)) {
                    System.out.println("\n" + src + ": mismatch pixel data length!" + " => do not convert");
                    return;
                }
            }
            ds.putUI(Tags.StudyInstanceUID, uid(studyUID));
            ds.putUI(Tags.SeriesInstanceUID, uid(seriesUID));
            ds.putUI(Tags.SOPInstanceUID, uid(instUID));
            ds.putUI(Tags.SOPClassUID, classUID);
            if (!ds.contains(Tags.NumberOfSamples)) {
                ds.putUS(Tags.NumberOfSamples, 1);
            }
            if (!ds.contains(Tags.PhotometricInterpretation)) {
                ds.putCS(Tags.PhotometricInterpretation, "MONOCHROME2");
            }
            if (fmi) {
                ds.setFileMetaInfo(fact.newFileMetaInfo(ds, UIDs.ImplicitVRLittleEndian));
            }
            OutputStream out = new BufferedOutputStream(new FileOutputStream(dest));
            try {
            } finally {
                ds.writeFile(out, encodeParam());
                if (hasPixelData) {
                    if (!skipGroupLen) {
                        out.write(PXDATA_GROUPLEN);
                        int grlen = pxlen + 8;
                        out.write((byte) grlen);
                        out.write((byte) (grlen >> 8));
                        out.write((byte) (grlen >> 16));
                        out.write((byte) (grlen >> 24));
                    }
                    out.write(PXDATA_TAG);
                    out.write((byte) pxlen);
                    out.write((byte) (pxlen >> 8));
                    out.write((byte) (pxlen >> 16));
                    out.write((byte) (pxlen >> 24));
                }
                if (inflate) {
                    int b2, b3;
                    for (; pxlen > 0; pxlen -= 3) {
                        out.write(in.read());
                        b2 = in.read();
                        b3 = in.read();
                        out.write(b2 & 0x0f);
                        out.write(b2 >> 4 | ((b3 & 0x0f) << 4));
                        out.write(b3 >> 4);
                    }
                } else {
                    for (; pxlen > 0; --pxlen) {
                        out.write(in.read());
                    }
                }
                out.close();
            }
            System.out.print('.');
        } finally {
            in.close();
        }
    }


    public static void extractFile(String input, String output) throws ZipException, IOException {
        FileReader reader = new FileReader(input);
        InputStream in = reader.getInputStream();
        OutputStream out = new FileOutputStream(new File(output));
        byte[] buf = new byte[512];
        int len;
        while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
        reader.close();
        out.close();
    }


    public static DataElement createMD5Sum(int type, String data) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(data.getBytes());
            byte[] dt = md.digest();
            return new DataElement(type, hexEncode(dt));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new DataElement(type);
    }


    public static byte[] hash(String plainTextValue) {
        MessageDigest msgDigest;
        try {
            msgDigest = MessageDigest.getInstance("MD5");
            msgDigest.update(plainTextValue.getBytes("UTF-8"));
            byte[] digest = msgDigest.digest();
            return digest;
        } catch (Exception e) {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }


    static void invalidSlave(String msg, Socket sock) throws IOException {
        BufferedReader _sinp = null;
        PrintWriter _sout = null;
        try {
            _sout = new PrintWriter(sock.getOutputStream(), true);
            _sinp = new BufferedReader(new InputStreamReader(sock.getInputStream()));
            _sout.println(msg);
            logger.info("NEW< " + msg);
            String txt = AsyncSlaveListener.readLine(_sinp, 30);
            String sname = "";
            String spass = "";
            String shash = "";
            try {
                String[] items = txt.split(" ");
                sname = items[1].trim();
                spass = items[2].trim();
                shash = items[3].trim();
            } catch (Exception e) {
                throw new IOException("Slave Inititalization Faailed");
            }
            String pass = sname + spass + _pass;
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.reset();
            md5.update(pass.getBytes());
            String hash = AsyncSlaveListener.hash2hex(md5.digest()).toLowerCase();
            if (!hash.equals(shash)) {
                throw new IOException("Slave Inititalization Faailed");
            }
        } catch (Exception e) {
        }
        throw new IOException("Slave Inititalization Faailed");
    }


    public static String readAsString(final URL url) throws java.io.IOException {
        InputStream inputStream = url.openStream();
        try {
            return readAsString(inputStream);
        } finally {
            try {
                inputStream.close();
            } catch (Throwable t) {
            }
        }
    }


    @Before
    public void BeforeTheTest() throws Exception {
        URL url = ProfileParserTest.class.getClassLoader().getResource("ca/uhn/hl7v2/conf/parser/tests/example_ack.xml");
        URLConnection conn = url.openConnection();
        InputStream instream = conn.getInputStream();
        if (instream == null) throw new Exception("can't find the xml file");
        BufferedReader in = new BufferedReader(new InputStreamReader(instream));
        int tmp = 0;
        StringBuffer buf = new StringBuffer();
        while ((tmp = in.read()) != -1) {
            buf.append((char) tmp);
        }
        profileString = buf.toString();
    }


    private String getPrefsKey(String key) {
        try {
            if (MD5 == null) MD5 = MessageDigest.getInstance("MD5");
            MD5.reset();
            MD5.update(key.getBytes("UTF-8"));
            byte[] resultBytes = MD5.digest();
            return toHexString(resultBytes);
        } catch (Exception nsae) {
            return key;
        }
    }


    public static void copy(File in, File out) throws IOException {
        FileChannel ic = new FileInputStream(in).getChannel();
        FileChannel oc = new FileOutputStream(out).getChannel();
        ic.transferTo(0, ic.size(), oc);
        ic.close();
        oc.close();
    }


    public Configuration(URL url) {
        InputStream in = null;
        try {
            load(in = url.openStream());
        } catch (Exception e) {
            throw new RuntimeException("Could not load configuration from " + url, e);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException ignore) {
                }
            }
        }
    }


public void run() {
        String s;
        s = "";
        try {
            URL url = new URL("http://www.m-w.com/dictionary/" + word);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            while (((str = in.readLine()) != null) && (!stopped)) {
                s = s + str;
            }
            in.close();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        Pattern pattern = Pattern.compile("Main Entry:.+?
(.+?)	", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
        Matcher matcher = pattern.matcher(s);
        java.io.StringWriter wr = new java.io.StringWriter();
        HTMLDocument doc = null;
        HTMLEditorKit kit = (HTMLEditorKit) editor.getEditorKit();
        try {
            doc = (HTMLDocument) editor.getDocument();
        } catch (Exception e) {
        }
        System.out.println(wr);
        editor.setContentType("text/html");
        if (matcher.find()) try {
            kit.insertHTML(doc, editor.getCaretPosition(), "
" + matcher.group(1) + "
", 0, 0, null);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        } else try {
            kit.insertHTML(doc, editor.getCaretPosition(), "
NOT FOUND!!
", 0, 0, null);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
        button.setEnabled(true);
    }


    public static boolean downloadFile(String url, String destination) throws Exception {
        BufferedInputStream bi = null;
        BufferedOutputStream bo = null;
        File destfile;
        java.net.URL fileurl;
        fileurl = new java.net.URL(url);
        bi = new BufferedInputStream(fileurl.openStream());
        destfile = new File(destination);
        if (!destfile.createNewFile()) {
            destfile.delete();
            destfile.createNewFile();
        }
        bo = new BufferedOutputStream(new FileOutputStream(destfile));
        int readedbyte;
        while ((readedbyte = bi.read()) != -1) {
            bo.write(readedbyte);
        }
        bi.close();
        bo.close();
        return true;
    }


    public String encodePassword(String password, byte[] salt) throws Exception {
        if (salt == null) {
            salt = new byte[12];
            secureRandom.nextBytes(salt);
        }
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(salt);
        md.update(password.getBytes("UTF8"));
        byte[] digest = md.digest();
        byte[] storedPassword = new byte[digest.length + 12];
        System.arraycopy(salt, 0, storedPassword, 0, 12);
        System.arraycopy(digest, 0, storedPassword, 12, digest.length);
        return new String(Base64.encode(storedPassword));
    }


    private String sendMail() throws IOException {
        String msg = StringEscapeUtils.escapeHtml(message.getText());
        StringBuffer buf = new StringBuffer();
        buf.append(encode("n", name.getText()));
        buf.append("&").append(encode("e", email.getText()));
        buf.append("&").append(encode("r", recpt.getText()));
        buf.append("&").append(encode("m", msg));
        buf.append("&").append(encode("s", score));
        buf.append("&").append(encode("i", calcScoreImage()));
        buf.append("&").append(encode("c", digest(recpt.getText() + "_" + score)));
        URL url = new URL("http://www.enerjy.com/share/mailit.php");
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        OutputStreamWriter writer = null;
        BufferedReader reader = null;
        boolean haveOk = false;
        try {
            writer = new OutputStreamWriter(conn.getOutputStream());
            writer.write(buf.toString());
            writer.flush();
            reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            for (String line = reader.readLine(); null != line; line = reader.readLine()) {
                if (line.startsWith("err:")) {
                    return line.substring(4);
                } else if (line.equals("ok")) {
                    haveOk = true;
                }
            }
        } finally {
            StreamUtils.close(writer);
            StreamUtils.close(reader);
        }
        if (!haveOk) {
            return "The server did not return a response.";
        }
        return null;
    }


    private static String digest(String val) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(val.trim().getBytes());
            byte[] digest = md.digest();
            StringBuffer buf = new StringBuffer();
            for (byte b : digest) {
                String hexString = Integer.toHexString(b);
                int length = hexString.length();
                if (length > 2) {
                    hexString = hexString.substring(length - 2, length);
                } else if (length < 2) {
                    hexString = "0" + hexString;
                }
                buf.append(hexString);
            }
            return buf.toString();
        } catch (NoSuchAlgorithmException e) {
            throw new EnerjyException("Could not create digest: MD5", e);
        }
    }


    private String readScriptFromURL(URL context, String s) {
        Object content = null;
        URL url;
        try {
            url = new URL(context, s);
        } catch (MalformedURLException e) {
            return null;
        }
        try {
            content = url.getContent();
        } catch (UnknownServiceException e) {
            Class jar_class;
            try {
                jar_class = Class.forName("java.net.JarURLConnection");
            } catch (Exception e2) {
                return null;
            }
            Object jar;
            try {
                jar = url.openConnection();
            } catch (IOException e2) {
                return null;
            }
            if (jar == null) {
                return null;
            }
            try {
                Method m = jar_class.getMethod("openConnection", ((java.lang.Class[]) null));
                content = m.invoke(jar, ((java.lang.Object[]) null));
            } catch (Exception e2) {
                return null;
            }
        } catch (IOException e) {
            return null;
        } catch (SecurityException e) {
            return null;
        }
        if (content instanceof String) {
            return (String) content;
        } else if (content instanceof InputStream) {
            InputStream fs = (InputStream) content;
            try {
                byte charArray[] = new byte[fs.available()];
                fs.read(charArray);
                return new String(charArray);
            } catch (IOException e2) {
                return null;
            } finally {
                closeInputStream(fs);
            }
        } else {
            return null;
        }
    }


    protected static void clearTables() throws SQLException {
        Connection conn = null;
        Statement stmt = null;
        try {
            conn = FidoDataSource.getConnection();
            conn.setAutoCommit(false);
            stmt = conn.createStatement();
            ClearData.clearTables(stmt);
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (2, '')");
            stmt.executeUpdate("insert into Objects (ObjectId, Description) values (3, '')");
            conn.commit();
        } catch (SQLException e) {
            if (conn != null) conn.rollback();
            throw e;
        } finally {
            if (stmt != null) stmt.close();
            if (conn != null) conn.close();
        }
    }


    private String getXML(String url) throws ClientProtocolException, IOException {
        HttpClient client = new DefaultHttpClient();
        HttpGet get = new HttpGet(url);
        HttpResponse responseGet = client.execute(get);
        HttpEntity resEntityGet = responseGet.getEntity();
        BufferedReader in = new BufferedReader(new InputStreamReader(resEntityGet.getContent()));
        StringBuffer sb = new StringBuffer("");
        String line = "";
        String NL = System.getProperty("line.separator");
        while ((line = in.readLine()) != null) {
            sb.append(line + NL);
        }
        in.close();
        String xml = sb.toString();
        return xml;
    }


private void createHomeTab() {
        Tabpanel homeTab = new Tabpanel();
        windowContainer.addWindow(homeTab, Msg.getMsg(EnvWeb.getCtx(), "Home").replaceAll("&", ""), false);
        Portallayout portalLayout = new Portallayout();
        portalLayout.setWidth("100%");
        portalLayout.setHeight("100%");
        portalLayout.setStyle("position: absolute; overflow: auto");
        homeTab.appendChild(portalLayout);
        Portalchildren portalchildren = null;
        int currentColumnNo = 0;
        String sql = "SELECT COUNT(DISTINCT COLUMNNO) " + "FROM PA_DASHBOARDCONTENT " + "WHERE (AD_CLIENT_ID=0 OR AD_CLIENT_ID=?) AND ISACTIVE='Y'";
        int noOfCols = DB.getSQLValue(null, sql, EnvWeb.getCtx().getAD_Client_ID());
        int width = noOfCols <= 0 ? 100 : 100 / noOfCols;
        sql = "SELECT x.*, m.AD_MENU_ID " + "FROM PA_DASHBOARDCONTENT x " + "LEFT OUTER JOIN AD_MENU m ON x.AD_WINDOW_ID=m.AD_WINDOW_ID " + "WHERE (x.AD_CLIENT_ID=0 OR x.AD_CLIENT_ID=?) AND x.ISACTIVE='Y' " + "ORDER BY x.COLUMNNO, x.AD_CLIENT_ID, x.LINE ";
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            pstmt = DB.prepareStatement(sql, null);
            pstmt.setInt(1, EnvWeb.getCtx().getAD_Client_ID());
            rs = pstmt.executeQuery();
            while (rs.next()) {
                int columnNo = rs.getInt("ColumnNo");
                if (portalchildren == null || currentColumnNo != columnNo) {
                    portalchildren = new Portalchildren();
                    portalLayout.appendChild(portalchildren);
                    portalchildren.setWidth(width + "%");
                    portalchildren.setStyle("padding: 5px");
                    currentColumnNo = columnNo;
                }
                Panel panel = new Panel();
                panel.setStyle("margin-bottom:10px");
                panel.setTitle(rs.getString("Name"));
                String description = rs.getString("Description");
                if (description != null) panel.setTooltiptext(description);
                String collapsible = rs.getString("IsCollapsible");
                panel.setCollapsible(collapsible.equals("Y"));
                panel.setBorder("normal");
                portalchildren.appendChild(panel);
                Panelchildren content = new Panelchildren();
                panel.appendChild(content);
                boolean panelEmpty = true;
                String htmlContent = rs.getString("HTML");
                if (htmlContent != null) {
                    StringBuffer result = new StringBuffer("");
                    URL url = getClass().getClassLoader().getResource("org/compiere/images/PAPanel.css");
                    InputStreamReader ins;
                    try {
                        ins = new InputStreamReader(url.openStream());
                        BufferedReader bufferedReader = new BufferedReader(ins);
                        String cssLine;
                        while ((cssLine = bufferedReader.readLine()) != null) result.append(cssLine + "\n");
                    } catch (IOException e1) {
                        logger.log(Level.SEVERE, e1.getLocalizedMessage(), e1);
                    }
                    result.append("
\n");
                    result.append(stripHtml(htmlContent, false) + "
\n");
                    result.append("
\n\n\n");
                    Html html = new Html();
                    html.setContent(result.toString());
                    content.appendChild(html);
                    panelEmpty = false;
                }
                int AD_Window_ID = rs.getInt("AD_Window_ID");
                if (AD_Window_ID > 0) {
                    int AD_Menu_ID = rs.getInt("AD_Menu_ID");
                    ToolBarButton btn = new ToolBarButton(String.valueOf(AD_Menu_ID));
                    MMenu menu = new MMenu(EnvWeb.getCtx(), AD_Menu_ID, null);
                    btn.setLabel(menu.getName());
                    btn.addEventListener(Events.ON_CLICK, this);
                    content.appendChild(btn);
                    panelEmpty = false;
                }
                int PA_Goal_ID = rs.getInt("PA_Goal_ID");
                if (PA_Goal_ID > 0) {
                    StringBuffer result = new StringBuffer("");
                    URL url = getClass().getClassLoader().getResource("org/compiere/images/PAPanel.css");
                    InputStreamReader ins;
                    try {
                        ins = new InputStreamReader(url.openStream());
                        BufferedReader bufferedReader = new BufferedReader(ins);
                        String cssLine;
                        while ((cssLine = bufferedReader.readLine()) != null) result.append(cssLine + "\n");
                    } catch (IOException e1) {
                        logger.log(Level.SEVERE, e1.getLocalizedMessage(), e1);
                    }
                    result.append("
\n");
                    result.append(renderGoals(PA_Goal_ID, content));
                    result.append("
\n\n\n");
                    Html html = new Html();
                    html.setContent(result.toString());
                    content.appendChild(html);
                    panelEmpty = false;
                }
                String url = rs.getString("ZulFilePath");
                if (url != null) {
                    try {
                        Component component = Executions.createComponents(url, content, null);
                        if (component != null) {
                            if (component instanceof DashboardPanel) {
                                DashboardPanel dashboardPanel = (DashboardPanel) component;
                                if (!dashboardPanel.getChildren().isEmpty()) {
                                    content.appendChild(dashboardPanel);
                                    dashboardRunnable.add(dashboardPanel);
                                    panelEmpty = false;
                                }
                            } else {
                                content.appendChild(component);
                                panelEmpty = false;
                            }
                        }
                    } catch (Exception e) {
                        logger.log(Level.WARNING, "Failed to create components. zul=" + url, e);
                    }
                }
                if (panelEmpty) panel.detach();
            }
        } catch (Exception e) {
            logger.log(Level.WARNING, "Failed to create dashboard content", e);
        } finally {
            Util.closeCursor(pstmt, rs);
        }
        registerWindow(homeTab);
        if (!portalLayout.getDesktop().isServerPushEnabled()) portalLayout.getDesktop().enableServerPush(true);
        dashboardRunnable.refreshDashboard();
        dashboardThread = new Thread(dashboardRunnable, "UpdateInfo");
        dashboardThread.setDaemon(true);
        dashboardThread.start();
    }