    @Override
    public boolean insert(String consulta, boolean autocommit, int transactionIsolation, Connection cx) throws SQLException {
        filasInsert = 0;
        if (!consulta.contains(";")) {
            this.tipoConsulta = new Scanner(consulta);
            if (this.tipoConsulta.hasNext()) {
                execConsulta = this.tipoConsulta.next();
                if (execConsulta.equalsIgnoreCase("insert")) {
                    Connection conexion = cx;
                    Statement st = null;
                    try {
                        conexion.setAutoCommit(autocommit);
                        if (transactionIsolation == 1 || transactionIsolation == 2 || transactionIsolation == 4 || transactionIsolation == 8) {
                            conexion.setTransactionIsolation(transactionIsolation);
                        } else {
                            throw new IllegalArgumentException("Valor invalido sobre TransactionIsolation,\n TRANSACTION_NONE no es soportado por MySQL");
                        }
                        st = (Statement) conexion.createStatement(ResultSetImpl.TYPE_SCROLL_SENSITIVE, ResultSetImpl.CONCUR_UPDATABLE);
                        conexion.setReadOnly(false);
                        filasInsert = st.executeUpdate(consulta.trim(), Statement.RETURN_GENERATED_KEYS);
                        if (filasInsert > -1) {
                            if (autocommit == false) {
                                conexion.commit();
                            }
                            return true;
                        } else {
                            return false;
                        }
                    } catch (MySQLIntegrityConstraintViolationException e) {
                        System.out.println("Posible duplicacion de DATOS");
                        if (autocommit == false) {
                            try {
                                conexion.rollback();
                                System.out.println("Se ejecuto un Rollback");
                            } catch (MySQLTransactionRollbackException sqlE) {
                                System.out.println("No se ejecuto un Rollback");
                                sqlE.printStackTrace();
                            } catch (SQLException se) {
                                se.printStackTrace();
                            }
                        }
                        e.printStackTrace();
                        return false;
                    } catch (MySQLNonTransientConnectionException e) {
                        if (autocommit == false) {
                            try {
                                conexion.rollback();
                                System.out.println("Se ejecuto un Rollback");
                            } catch (MySQLTransactionRollbackException sqlE) {
                                System.out.println("No se ejecuto un Rollback");
                                sqlE.printStackTrace();
                            } catch (SQLException se) {
                                se.printStackTrace();
                            }
                        }
                        e.printStackTrace();
                        return false;
                    } catch (MySQLDataException e) {
                        System.out.println("Datos incorrectos");
                        if (autocommit == false) {
                            try {
                                conexion.rollback();
                                System.out.println("Se ejecuto un Rollback");
                            } catch (MySQLTransactionRollbackException sqlE) {
                                System.out.println("No se ejecuto un Rollback");
                                sqlE.printStackTrace();
                            } catch (SQLException se) {
                                se.printStackTrace();
                            }
                        }
                        return false;
                    } catch (MySQLSyntaxErrorException e) {
                        System.out.println("Error en la sintaxis de la Consulta en MySQL");
                        if (autocommit == false) {
                            try {
                                conexion.rollback();
                                System.out.println("Se ejecuto un Rollback");
                            } catch (MySQLTransactionRollbackException sqlE) {
                                System.out.println("No se ejecuto un Rollback");
                                sqlE.printStackTrace();
                            } catch (SQLException se) {
                                se.printStackTrace();
                            }
                        }
                        return false;
                    } catch (SQLException e) {
                        if (autocommit == false) {
                            try {
                                conexion.rollback();
                                System.out.println("Se ejecuto un Rollback");
                            } catch (MySQLTransactionRollbackException sqlE) {
                                System.out.println("No se ejecuto un Rollback");
                                sqlE.printStackTrace();
                            } catch (SQLException se) {
                                se.printStackTrace();
                            }
                        }
                        e.printStackTrace();
                        return false;
                    } finally {
                        try {
                            if (st != null) {
                                if (!st.isClosed()) {
                                    st.close();
                                }
                            }
                            if (!conexion.isClosed()) {
                                conexion.close();
                            }
                        } catch (NullPointerException ne) {
                            ne.printStackTrace();
                        } catch (SQLException e) {
                            e.printStackTrace();
                        }
                    }
                } else {
                    throw new IllegalArgumentException("No es una instruccion Insert");
                }
            } else {
                try {
                    throw new JMySQLException("Error Grave , notifique al departamento de Soporte Tecnico \n" + email);
                } catch (JMySQLException ex) {
                    Logger.getLogger(JMySQL.class.getName()).log(Level.SEVERE, null, ex);
                    return false;
                }
            }
        } else {
            throw new IllegalArgumentException("No estan permitidas las MultiConsultas en este metodo");
        }
    }


    @Override
    public boolean delete(String consulta, boolean autocommit, int transactionIsolation, Connection cx) throws SQLException {
        filasDelete = 0;
        if (!consulta.contains(";")) {
            this.tipoConsulta = new Scanner(consulta);
            if (this.tipoConsulta.hasNext()) {
                execConsulta = this.tipoConsulta.next();
                if (execConsulta.equalsIgnoreCase("delete")) {
                    Connection conexion = cx;
                    Statement st = null;
                    try {
                        conexion.setAutoCommit(autocommit);
                        if (transactionIsolation == 1 || transactionIsolation == 2 || transactionIsolation == 4 || transactionIsolation == 8) {
                            conexion.setTransactionIsolation(transactionIsolation);
                        } else {
                            throw new IllegalArgumentException("Valor invalido sobre TransactionIsolation,\n TRANSACTION_NONE no es soportado por MySQL");
                        }
                        st = (Statement) conexion.createStatement(ResultSetImpl.TYPE_SCROLL_SENSITIVE, ResultSetImpl.CONCUR_UPDATABLE);
                        conexion.setReadOnly(false);
                        filasDelete = st.executeUpdate(consulta.trim(), Statement.RETURN_GENERATED_KEYS);
                        if (filasDelete > -1) {
                            if (autocommit == false) {
                                conexion.commit();
                            }
                            return true;
                        } else {
                            return false;
                        }
                    } catch (MySQLIntegrityConstraintViolationException e) {
                        if (autocommit == false) {
                            try {
                                conexion.rollback();
                                System.out.println("Se ejecuto un Rollback");
                            } catch (MySQLTransactionRollbackException sqlE) {
                                System.out.println("No se ejecuto un Rollback");
                                sqlE.printStackTrace();
                            } catch (SQLException se) {
                                se.printStackTrace();
                            }
                        }
                        e.printStackTrace();
                        return false;
                    } catch (MySQLNonTransientConnectionException e) {
                        if (autocommit == false) {
                            try {
                                conexion.rollback();
                                System.out.println("Se ejecuto un Rollback");
                            } catch (MySQLTransactionRollbackException sqlE) {
                                System.out.println("No se ejecuto un Rollback");
                                sqlE.printStackTrace();
                            } catch (SQLException se) {
                                se.printStackTrace();
                            }
                        }
                        e.printStackTrace();
                        return false;
                    } catch (MySQLDataException e) {
                        System.out.println("Datos incorrectos");
                        if (autocommit == false) {
                            try {
                                conexion.rollback();
                                System.out.println("Se ejecuto un Rollback");
                            } catch (MySQLTransactionRollbackException sqlE) {
                                System.out.println("No se ejecuto un Rollback");
                                sqlE.printStackTrace();
                            } catch (SQLException se) {
                                se.printStackTrace();
                            }
                        }
                        return false;
                    } catch (MySQLSyntaxErrorException e) {
                        System.out.println("Error en la sintaxis de la Consulta en MySQL");
                        if (autocommit == false) {
                            try {
                                conexion.rollback();
                                System.out.println("Se ejecuto un Rollback");
                            } catch (MySQLTransactionRollbackException sqlE) {
                                System.out.println("No se ejecuto un Rollback");
                                sqlE.printStackTrace();
                            } catch (SQLException se) {
                                se.printStackTrace();
                            }
                        }
                        return false;
                    } catch (SQLException e) {
                        if (autocommit == false) {
                            try {
                                conexion.rollback();
                                System.out.println("Se ejecuto un Rollback");
                            } catch (MySQLTransactionRollbackException sqlE) {
                                System.out.println("No se ejecuto un Rollback");
                                sqlE.printStackTrace();
                            } catch (SQLException se) {
                                se.printStackTrace();
                            }
                        }
                        e.printStackTrace();
                        return false;
                    } finally {
                        try {
                            if (st != null) {
                                if (!st.isClosed()) {
                                    st.close();
                                }
                            }
                            if (!conexion.isClosed()) {
                                conexion.close();
                            }
                        } catch (NullPointerException ne) {
                            ne.printStackTrace();
                        } catch (SQLException e) {
                            e.printStackTrace();
                        }
                    }
                } else {
                    throw new IllegalArgumentException("No es una instruccion Delete");
                }
            } else {
                try {
                    throw new JMySQLException("Error Grave , notifique al departamento de Soporte Tecnico \n" + email);
                } catch (JMySQLException ex) {
                    Logger.getLogger(JMySQL.class.getName()).log(Level.SEVERE, null, ex);
                    return false;
                }
            }
        } else {
            throw new IllegalArgumentException("No estan permitidas las MultiConsultas en este metodo");
        }
    }


    public String getWebPage(String url) {
        String content = "";
        URL urlObj = null;
        try {
            urlObj = new URL(url);
        } catch (MalformedURLException urlEx) {
            urlEx.printStackTrace();
            throw new Error("URL creation failed.");
        }
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(urlObj.openStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                content += line;
            }
        } catch (IOException e) {
            e.printStackTrace();
            throw new Error("Page retrieval failed.");
        }
        return content;
    }


    public void copyFile(File from, File to) {
        try {
            InputStream in = new FileInputStream(from);
            OutputStream out = new FileOutputStream(to);
            int readCount;
            byte[] bytes = new byte[1024];
            while ((readCount = in.read(bytes)) != -1) {
                out.write(bytes, 0, readCount);
            }
            out.flush();
            in.close();
            out.close();
        } catch (Exception ex) {
            throw new BuildException(ex.getMessage(), ex);
        }
    }


    public IOCacheArray(final File file, int capacity, final IIOCacheArrayObjectMaker iomaker, int chunkSize, String name) {
        super(capacity, null, chunkSize, name);
        generator = new ICacheArrayObjectMaker() {

            FileOutputStream outStream;

            FileInputStream inStream;

            FileChannel outChannel;

            FileChannel inChannel;

            boolean inited = false;

            private synchronized void init() {
                if (!inited) {
                    try {
                        outStream = new FileOutputStream(file);
                        inStream = new FileInputStream(file);
                        outChannel = outStream.getChannel();
                        inChannel = inStream.getChannel();
                    } catch (FileNotFoundException foe) {
                        Logging.errorln("IOCacheArray constuctor error: Could not open file " + file + ".  Exception " + foe);
                        Logging.errorln("outStream " + outStream + "  inStream " + inStream + "  outchan " + outChannel + "  inchannel " + inChannel);
                    }
                }
                inited = true;
            }

            public Object make(int itemIndex, int baseIndex, Object[] data) {
                init();
                return iomaker.read(inChannel, itemIndex, baseIndex, data);
            }

            public boolean flush(int baseIndex, Object[] data) {
                init();
                return iomaker.write(outChannel, baseIndex, data);
            }

            public CacheArrayBlockSummary summarize(int baseIndex, Object[] data) {
                init();
                return iomaker.summarize(baseIndex, data);
            }
        };
    }


    @SuppressWarnings("unchecked")
    public void execute() throws MojoExecutionException {
        List<Dependency> dependencies = project.getDependencies();
        File file = new File(this.localRepository.getBasedir());
        File dojoArtifact = null;
        for (Dependency dependency : dependencies) {
            if (!dependency.getGroupId().equals("org.dojotoolkit") && !dependency.getArtifactId().equals("dojo")) continue;
            File file2 = new File(file, dependency.getGroupId().replace('.', File.separatorChar));
            file2 = new File(file2, dependency.getArtifactId());
            file2 = new File(file2, dependency.getVersion());
            file2 = new File(file2, dependency.getArtifactId() + '-' + dependency.getVersion() + '.' + dependency.getType());
            if (!file2.exists()) throw new MojoExecutionException("No artifact found in base repository " + file2);
            dojoArtifact = file2;
        }
        if (dojoArtifact == null) throw new MojoExecutionException("No dojo dependencies found");
        Plugin plugin = (Plugin) project.getBuild().getPluginsAsMap().get("org.apache.maven.plugins:maven-war-plugin");
        if (plugin == null) return;
        String webappDirectory = null;
        Xpp3Dom dom = (Xpp3Dom) plugin.getConfiguration();
        if (dom != null) webappDirectory = dom.getChild("webappDirectory").getValue();
        if (webappDirectory == null) webappDirectory = project.getBuild().getDirectory() + File.separatorChar + project.getArtifactId() + '-' + project.getVersion();
        try {
            File webAppDojoDir = new File(webappDirectory, this.dojoDir);
            if (!webAppDojoDir.exists()) webAppDojoDir.mkdirs();
            ZipInputStream inputStream = new ZipInputStream(new FileInputStream(dojoArtifact));
            ZipEntry zipentry = inputStream.getNextEntry();
            byte[] buf = new byte[1024];
            while (zipentry != null) {
                File entry = new File(webAppDojoDir, zipentry.getName());
                if (zipentry.isDirectory()) {
                    entry.mkdirs();
                } else {
                    int n;
                    FileOutputStream fileoutputstream;
                    if (entry.getParent() != null) {
                        entry.getParentFile().mkdirs();
                    }
                    fileoutputstream = new FileOutputStream(entry);
                    while ((n = inputStream.read(buf, 0, 1024)) > -1) fileoutputstream.write(buf, 0, n);
                    fileoutputstream.close();
                    inputStream.closeEntry();
                }
                zipentry = inputStream.getNextEntry();
            }
            inputStream.close();
        } catch (Exception e) {
            throw new MojoExecutionException("Error to extract the dojo artifact ", e);
        }
    }


    private AccessControlContext getAccessControlContext(final URL codebase) {
        PermissionCollection perms = (PermissionCollection) AccessController.doPrivileged(new PrivilegedAction() {

            public Object run() {
                Policy p = java.security.Policy.getPolicy();
                if (p != null) {
                    return p.getPermissions(new CodeSource(null, null));
                } else {
                    return null;
                }
            }
        });
        if (perms == null) perms = new Permissions();
        perms.add(new RuntimePermission("createClassLoader"));
        Permission p;
        java.net.URLConnection urlConnection = null;
        try {
            urlConnection = codebase.openConnection();
            p = urlConnection.getPermission();
        } catch (java.io.IOException ioe) {
            p = null;
        }
        if (p != null) perms.add(p);
        if (p instanceof FilePermission) {
            String path = p.getName();
            int endIndex = path.lastIndexOf(File.separatorChar);
            if (endIndex != -1) {
                path = path.substring(0, endIndex + 1);
                if (path.endsWith(File.separator)) {
                    path += "-";
                }
                perms.add(new FilePermission(path, "read"));
            }
        } else {
            URL locUrl = codebase;
            if (urlConnection instanceof JarURLConnection) {
                locUrl = ((JarURLConnection) urlConnection).getJarFileURL();
            }
            String host = locUrl.getHost();
            if (host != null && (host.length() > 0)) perms.add(new SocketPermission(host, "connect, accept"));
        }
        ProtectionDomain domain = new ProtectionDomain(new CodeSource(codebase, null), perms);
        AccessControlContext acc = new AccessControlContext(new ProtectionDomain[] { domain });
        return acc;
    }


        void execute(HttpClient client, MonitoredService svc) {
            try {
                URI uri = getURI(svc);
                PageSequenceHttpMethod method = getMethod();
                method.setURI(uri);
                if (getVirtualHost() != null) {
                    method.getParams().setVirtualHost(getVirtualHost());
                }
                if (getUserAgent() != null) {
                    method.addRequestHeader("User-Agent", getUserAgent());
                }
                if (m_parms.length > 0) {
                    method.setParameters(m_parms);
                }
                if (m_page.getUserInfo() != null) {
                    String userInfo = m_page.getUserInfo();
                    String[] streetCred = userInfo.split(":", 2);
                    if (streetCred.length == 2) {
                        client.getState().setCredentials(new AuthScope(AuthScope.ANY), new UsernamePasswordCredentials(streetCred[0], streetCred[1]));
                        method.setDoAuthentication(true);
                    }
                }
                int code = client.executeMethod(method);
                if (!getRange().contains(code)) {
                    throw new PageSequenceMonitorException("response code out of range for uri:" + uri + ".  Expected " + getRange() + " but received " + code);
                }
                InputStream inputStream = method.getResponseBodyAsStream();
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                try {
                    IOUtils.copy(inputStream, outputStream);
                } finally {
                    IOUtils.closeQuietly(inputStream);
                    IOUtils.closeQuietly(outputStream);
                }
                String responseString = outputStream.toString();
                if (getFailurePattern() != null) {
                    Matcher matcher = getFailurePattern().matcher(responseString);
                    if (matcher.find()) {
                        throw new PageSequenceMonitorException(getResolvedFailureMessage(matcher));
                    }
                }
                if (getSuccessPattern() != null) {
                    Matcher matcher = getSuccessPattern().matcher(responseString);
                    if (!matcher.find()) {
                        throw new PageSequenceMonitorException("failed to find '" + getSuccessPattern() + "' in page content at " + uri);
                    }
                }
            } catch (URIException e) {
                throw new IllegalArgumentException("unable to construct URL for page: " + e, e);
            } catch (HttpException e) {
                throw new PageSequenceMonitorException("HTTP Error " + e, e);
            } catch (IOException e) {
                throw new PageSequenceMonitorException("I/O Error " + e, e);
            }
        }


    public void startElement(String uri, String tag, String qName, org.xml.sax.Attributes attributes) throws SAXException {
        wabclient.Attributes prop = new wabclient.Attributes(attributes);
        try {
            if (tag.equals("app")) {
                if (prop == null) {
                    System.err.println("app without properties");
                    return;
                }
                String appname = prop.getValue("name", "");
                String lookandfeel = prop.getValue("lookandfeel", "");
                global.setAppName(appname);
                if (lookandfeel.length() > 0) {
                    if (lookandfeel.equalsIgnoreCase("Windows")) lookandfeel = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; else if (lookandfeel.equalsIgnoreCase("Motif")) lookandfeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel"; else if (lookandfeel.equalsIgnoreCase("Mac")) lookandfeel = "com.sun.java.swing.plaf.mac.MacLookAndFeel";
                    UIManager.setLookAndFeel(lookandfeel);
                }
            } else if (tag.equals("script")) {
                WABClient c = (WABClient) global;
                c.beginScript();
                String url = prop.getValue("src");
                if (url.length() > 0) {
                    try {
                        BufferedReader r = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
                        String buffer;
                        while (true) {
                            buffer = r.readLine();
                            if (buffer == null) break;
                            c.script += buffer + "\n";
                        }
                        r.close();
                        c.endScript();
                    } catch (IOException ioe) {
                        System.err.println("[IOError] " + ioe.getMessage());
                        System.exit(0);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }
    }


    public static void main(String[] args) {
        FTPClient client = new FTPClient();
        try {
            client.connect("192.168.1.10");
            boolean login = client.login("a", "123456");
            if (login) {
                System.out.println("Dang nhap thanh cong...");
                boolean logout = client.logout();
                if (logout) {
                    System.out.println("Da Logout khoi FTP Server...");
                }
            } else {
                System.out.println("Dang nhap that bai...");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                client.disconnect();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }


    public static void copy(String sourceFile, String targetFile) throws IOException {
        FileChannel sourceChannel = new FileInputStream(sourceFile).getChannel();
        FileChannel targetChannel = new FileOutputStream(targetFile).getChannel();
        targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
        sourceChannel.close();
        targetChannel.close();
    }


    public static void bubble_sort(Sortable[] objects) {
        for (int i = objects.length; --i >= 0; ) {
            boolean flipped = false;
            for (int j = 0; j < i; j++) {
                if (objects[j].greater_than(objects[j + 1])) {
                    Sortable tmp = objects[j];
                    objects[j] = objects[j + 1];
                    objects[j + 1] = tmp;
                    flipped = true;
                }
            }
            if (!flipped) return;
        }
    }


    public static void bubble_sort(int[] objects, int len) {
        for (int i = len; --i >= 0; ) {
            boolean flipped = false;
            for (int j = 0; j < i; j++) {
                if (objects[j + 1] < objects[j]) {
                    int tmp = objects[j];
                    objects[j] = objects[j + 1];
                    objects[j + 1] = tmp;
                    flipped = true;
                }
            }
            if (!flipped) return;
        }
    }


    public static void copia(File nombreFuente, File nombreDestino) throws IOException {
        FileInputStream fis = new FileInputStream(nombreFuente);
        FileOutputStream fos = new FileOutputStream(nombreDestino);
        FileChannel canalFuente = fis.getChannel();
        FileChannel canalDestino = fos.getChannel();
        canalFuente.transferTo(0, canalFuente.size(), canalDestino);
        fis.close();
        fos.close();
    }


    private void addFilesToExistingZip(File zipFile, String[] dirs, File[] files) throws IOException {
        File tempFile = new File(zipFile.getAbsoluteFile() + ".temp");
        if (tempFile.exists()) tempFile.delete();
        boolean renameOk = zipFile.renameTo(tempFile);
        if (!renameOk) {
            throw new RuntimeException("Could not rename the file " + zipFile.getAbsolutePath() + " to " + tempFile.getAbsolutePath());
        }
        ZipInputStream zin = new ZipInputStream(new FileInputStream(tempFile));
        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile));
        ZipEntry entry = zin.getNextEntry();
        byte[] buf = new byte[1024];
        while (entry != null) {
            String entryName = entry.getName();
            boolean inFiles = false;
            for (int i = 0; i < files.length; i++) {
                String fileName = dirs[i] + "/" + files[i].getName();
                if (fileName.equals(entryName)) {
                    inFiles = true;
                    break;
                }
            }
            if (!inFiles) {
                out.putNextEntry(new ZipEntry(entryName));
                int len;
                while ((len = zin.read(buf)) > 0) out.write(buf, 0, len);
            }
            entry = zin.getNextEntry();
        }
        zin.close();
        for (int i = 0; i < files.length; i++) {
            InputStream in = new FileInputStream(files[i]);
            out.putNextEntry(new ZipEntry(dirs[i] + "/" + files[i].getName()));
            int len;
            while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
            out.closeEntry();
            in.close();
        }
        out.close();
        tempFile.delete();
    }


    public String uploadReport(Collection c) {
        try {
            String id = generateRandomId();
            Iterator iter = c.iterator();
            URL url = new URL(ZorobotSystem.props.getProperty("zoro.url") + "auplo2.jsp");
            URLConnection connection = url.openConnection();
            connection.setDoOutput(true);
            PrintWriter out = new PrintWriter(connection.getOutputStream());
            out.print("id=" + id + "&");
            StringBuffer sb = new StringBuffer();
            int gg = 0;
            while (iter.hasNext()) {
                if (gg++ >= 500) break;
                Question tq = (Question) iter.next();
                sb.append("a=");
                sb.append(URLEncoder.encode(tq.question, "UTF-8"));
                sb.append("*");
                StringBuffer ss = new StringBuffer();
                String[] ans;
                if (tq.ansDisplay != null) {
                    ans = tq.ansDisplay;
                } else {
                    ans = tq.answer;
                }
                for (int j = 0; j < ans.length; j++) {
                    if (j > 0) ss.append("*");
                    ss.append(ans[j]);
                }
                sb.append(URLEncoder.encode(ss.toString(), "UTF-8"));
                if (iter.hasNext() && gg < 500) sb.append("&");
            }
            out.println(sb.toString());
            out.close();
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String inputLine;
            if ((inputLine = in.readLine()) != null) {
                if (!inputLine.equals("OK!") && inputLine.length() > 3) {
                    System.out.println("Not OK: " + inputLine);
                    return "xxxxxxxxxx";
                }
            }
            in.close();
            return id;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    private final void copyTargetFileToSourceFile(File sourceFile, File targetFile) throws MJProcessorException {
        if (!targetFile.exists()) {
            targetFile.getParentFile().mkdirs();
            try {
                if (!targetFile.exists()) {
                    targetFile.createNewFile();
                }
            } catch (IOException e) {
                throw new MJProcessorException(e.getMessage(), e);
            }
        }
        FileChannel in = null, out = null;
        try {
            in = new FileInputStream(sourceFile).getChannel();
            out = new FileOutputStream(targetFile).getChannel();
            long size = in.size();
            MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
            out.write(buf);
        } catch (IOException e) {
            log.error(e);
        } finally {
            if (in != null) try {
                in.close();
            } catch (IOException e) {
                log.error(e);
            }
            if (out != null) try {
                out.close();
            } catch (IOException e) {
                log.error(e);
            }
        }
    }


    public static void copy(File src, File dest) throws IOException {
        if (dest.exists() && dest.isFile()) {
            logger.fine("cp " + src + " " + dest + " -- Destination file " + dest + " already exists. Deleting...");
            dest.delete();
        }
        final File parent = dest.getParentFile();
        if (!parent.exists()) {
            logger.info("Directory to contain destination does not exist. Creating...");
            parent.mkdirs();
        }
        final FileInputStream fis = new FileInputStream(src);
        final FileOutputStream fos = new FileOutputStream(dest);
        final byte[] b = new byte[2048];
        int n;
        while ((n = fis.read(b)) != -1) fos.write(b, 0, n);
        fis.close();
        fos.close();
    }


    private void downloadPage(final URL url, final File file) {
        try {
            long size = 0;
            final byte[] buffer = new byte[BotUtil.BUFFER_SIZE];
            final File tempFile = new File(file.getParentFile(), "temp.tmp");
            int length;
            int lastUpdate = 0;
            FileOutputStream fos = new FileOutputStream(tempFile);
            final InputStream is = url.openStream();
            do {
                length = is.read(buffer);
                if (length >= 0) {
                    fos.write(buffer, 0, length);
                    size += length;
                }
                if (lastUpdate > UPDATE_TIME) {
                    report(0, (int) (size / Format.MEMORY_MEG), "Downloading... " + Format.formatMemory(size));
                    lastUpdate = 0;
                }
                lastUpdate++;
            } while (length >= 0);
            fos.close();
            if (url.toString().toLowerCase().endsWith(".gz")) {
                final FileInputStream fis = new FileInputStream(tempFile);
                final GZIPInputStream gis = new GZIPInputStream(fis);
                fos = new FileOutputStream(file);
                size = 0;
                lastUpdate = 0;
                do {
                    length = gis.read(buffer);
                    if (length >= 0) {
                        fos.write(buffer, 0, length);
                        size += length;
                    }
                    if (lastUpdate > UPDATE_TIME) {
                        report(0, (int) (size / Format.MEMORY_MEG), "Uncompressing... " + Format.formatMemory(size));
                        lastUpdate = 0;
                    }
                    lastUpdate++;
                } while (length >= 0);
                fos.close();
                fis.close();
                gis.close();
                tempFile.delete();
            } else {
                file.delete();
                tempFile.renameTo(file);
            }
        } catch (final IOException e) {
            throw new AnalystError(e);
        }
    }


    public static boolean filecopy(final File source, final File target) {
        boolean out = false;
        if (source.isDirectory() || !source.exists() || target.isDirectory() || source.equals(target)) return false;
        try {
            target.getParentFile().mkdirs();
            target.createNewFile();
            FileChannel sourceChannel = new FileInputStream(source).getChannel();
            try {
                FileChannel targetChannel = new FileOutputStream(target).getChannel();
                try {
                    targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
                    out = true;
                } finally {
                    targetChannel.close();
                }
            } finally {
                sourceChannel.close();
            }
        } catch (IOException e) {
            out = false;
        }
        return out;
    }


    public static String getMD5(String _pwd) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(_pwd.getBytes());
            return toHexadecimal(new String(md.digest()).getBytes());
        } catch (NoSuchAlgorithmException x) {
            x.printStackTrace();
            return "";
        }
    }


    static void copyFile(File file, File file1) throws IOException {
        byte abyte0[] = new byte[512];
        FileInputStream fileinputstream = new FileInputStream(file);
        FileOutputStream fileoutputstream = new FileOutputStream(file1);
        int i;
        while ((i = fileinputstream.read(abyte0)) > 0) fileoutputstream.write(abyte0, 0, i);
        fileinputstream.close();
        fileoutputstream.close();
    }


    private static String readGeoJSON(String feature) {
        StringBuffer content = new StringBuffer();
        try {
            URL url = new URL(feature);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.connect();
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) {
                content.append(line);
            }
            conn.disconnect();
        } catch (Exception e) {
        }
        return content.toString();
    }


    public void run() {
        for (int i = 0; i < iClNumberOfCycles; i++) {
            try {
                long lStartTime = System.currentTimeMillis();
                InputStream in = urlClDestinationURL.openStream();
                byte buf[] = new byte[1024];
                int num;
                while ((num = in.read(buf)) > 0) ;
                in.close();
                long lStopTime = System.currentTimeMillis();
                Node.getLogger().write((lStopTime - lStartTime) + " ms");
                avgCalls.update(lStopTime - lStartTime);
                System.out.print("*");
                System.out.flush();
                calls.update();
            } catch (Exception e) {
                cntErrors.update();
                System.out.print("X");
                System.out.flush();
            }
        }
    }


    protected HttpResponse executeRequest(AbstractHttpRequest request) throws ConnectionException, RequestCancelledException {
        try {
            HttpResponse response = getHttpClient().execute(request);
            if (!response.is2xxSuccess()) {
                throw new ConnectionException();
            }
            return response;
        } catch (IOException ex) {
            throw new ConnectionException();
        } catch (TimeoutException ex) {
            throw new ConnectionException();
        }
    }


    public DocumentSummary parseDocument(URL url) throws IOException, DocumentHandlerException {
        try {
            DocumentSummary documentSummary = new DocumentSummary();
            SaxTextContentParser saxParser = new SaxTextContentParser();
            InputSource inputSource = new InputSource(url.openStream());
            documentSummary.contentReader = new StringReader(saxParser.parse(inputSource));
            return documentSummary;
        } catch (SAXException e) {
            throw new DocumentHandlerException(GuiMessages.getString("XmlDocumentHandler.xmlParsingErrorMessage.header") + e.getMessage(), e);
        } catch (ParserConfigurationException e) {
            throw new DocumentHandlerException(GuiMessages.getString("XmlDocumentHandler.xmlParsingErrorMessage.header") + e.getMessage(), e);
        }
    }


    @Override
    public void copy(File source, File dest) throws IOException {
        FileChannel in = null;
        FileChannel out = null;
        try {
            in = (new FileInputStream(source)).getChannel();
            out = (new FileOutputStream(dest)).getChannel();
            in.transferTo(0, source.length(), out);
        } catch (FileNotFoundException e) {
            throw new IOException("Wrong source or destination path for backup operation!");
        } finally {
            if (out != null) {
                out.close();
            }
            if (in != null) {
                in.close();
            }
        }
    }


    public static boolean downloadFile(String urlString, String outputFile, int protocol) {
        InputStream is = null;
        File file = new File(outputFile);
        FileOutputStream fos = null;
        if (protocol == HTTP_PROTOCOL) {
            try {
                URL url = new URL(urlString);
                URLConnection ucnn = null;
                if (BlueXStatics.proxy == null || url.getProtocol().equals("file")) ucnn = url.openConnection(); else ucnn = url.openConnection(BlueXStatics.proxy);
                is = ucnn.getInputStream();
                fos = new FileOutputStream(file);
                byte[] data = new byte[4096];
                int offset;
                while ((offset = is.read(data)) != -1) {
                    fos.write(data, 0, offset);
                }
                return true;
            } catch (Exception ex) {
            } finally {
                try {
                    is.close();
                } catch (Exception e) {
                }
                try {
                    fos.close();
                } catch (Exception e) {
                }
            }
        } else throw new ProtocolNotSupportedException("The protocol selected is not supported by this version of downloadFile() method.");
        return false;
    }


private void send(java.awt.event.ActionEvent evt) {
        String url = this.getURL();
        if (url != null) {
            String tinyurl = "";
            try {
                URLConnection conn = new URL("http://tinyurl.com/api-create.php?url=" + url).openConnection();
                conn.setDoInput(true);
                conn.connect();
                BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                tinyurl = br.readLine();
            } catch (SocketTimeoutException ste) {
                ste.printStackTrace();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
            String addresses = (String) this._model.getElementAt(0);
            for (int i = 1; i < this._model.getSize(); i++) addresses += "," + (String) this._model.getElementAt(i);
            SendDialog dialog = new SendDialog("Web Image Browser view", "To view, click the URL below\n\n" + url + "\n\n" + ((tinyurl != null) ? ("or\n\n" + tinyurl) : ""), addresses);
            dialog.setVisible(true);
        } else JOptionPane.showMessageDialog(this, "" + "Sorry, but the file in
" + "\"" + this.path.getText() + "\"
" + "doesn't seem to be a valid " + "WIBShare-able file." + "", "WIBShare Error", JOptionPane.ERROR_MESSAGE);
    }


    protected static void writeFileToStream(FileWrapper file, String filename, ZipOutputStream zipStream) throws CausedIOException, IOException {
        InputStream in;
        try {
            in = file.getInputStream();
        } catch (Exception e) {
            throw new CausedIOException("Could not obtain InputStream for " + filename, e);
        }
        try {
            IOUtils.copy(in, zipStream);
        } finally {
            IOUtils.closeQuietly(in);
        }
    }


    public static void readAsFile(String fileName, String url) {
        BufferedInputStream in = null;
        BufferedOutputStream out = null;
        URLConnection conn = null;
        try {
            conn = new URL(url).openConnection();
            conn.setDoInput(true);
            in = new BufferedInputStream(conn.getInputStream());
            out = new BufferedOutputStream(new FileOutputStream(fileName));
            int b;
            while ((b = in.read()) != -1) {
                out.write(b);
            }
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        } finally {
            if (null != in) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
            if (null != out) {
                try {
                    out.flush();
                    out.close();
                } catch (IOException e) {
                }
            }
        }
    }


    public static byte[] findHead(String url) {
        byte[] result = new byte[0];
        InputStream in = null;
        try {
            in = new URL(appendSlash(url)).openStream();
            byte[] buffer = new byte[1024];
            int len = -1;
            while ((len = in.read(buffer)) != -1) {
                byte[] temp = new byte[result.length + len];
                System.arraycopy(result, 0, temp, 0, result.length);
                System.arraycopy(buffer, 0, temp, result.length, len);
                result = temp;
                if (DEBUG) {
                    log.debug(String.format("len=%d, result.length=%d", len, result.length));
                }
                if (result.length > 4096) {
                    break;
                }
                if (result.length > 1024) {
                    String s = new String(result).replaceAll("\\s+", " ");
                    Matcher m = P_HEAD.matcher(s);
                    if (m.find()) {
                        break;
                    }
                }
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        } finally {
            try {
                if (null != in) in.close();
            } catch (IOException e) {
            }
        }
        return result;
    }


    public static void copyFile(File dest, File src) throws IOException {
        FileChannel srcChannel = new FileInputStream(src).getChannel();
        FileChannel dstChannel = new FileOutputStream(dest).getChannel();
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();
    }


    public void run_two() {
        System.out.println("Waiting to see if server has logged in");
        if (rept != null) {
            rept.post("Checking if RegServer is online..");
        }
        try {
            boolean waiting = true;
            while (waiting) {
                String con = "";
                String s;
                URL url = new URL(where);
                BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
                System.out.print("Checking for xRegistry..");
                if (rept != null) {
                    rept.post("Searching for xRegistryServer..");
                }
                while ((s = br.readLine()) != null) {
                    con = con + s;
                }
                err_catch = con;
                try {
                    br.close();
                } catch (IOException ioe) {
                    System.out.print("..b_r wouldn't close..");
                }
                servers = xls.split("SERVER", con);
                if (servers.length < 1) {
                    System.out.println("-->Server not available yet.");
                    if (rept != null) {
                        rept.post("-->Server currently unavailable..");
                    }
                    try {
                        Thread.sleep(read_delay);
                    } catch (Exception inter) {
                    }
                    if (read_delay < 20000) {
                        read_delay = read_delay * 2;
                        if (debug == true) {
                            System.out.println("Set read_delay to:" + read_delay);
                        }
                    } else {
                        read_delay = read_delay + 3000;
                    }
                    if (read_delay > 90000) {
                        waiting = false;
                    }
                }
                if (servers.length > 0) {
                    waiting = false;
                }
            }
            String[] regip = xls.split("IP", servers[0]);
            String[] regport = xls.split("PORT", servers[0]);
            int rp = 0;
            try {
                rp = Integer.parseInt(regport[0]);
            } catch (NumberFormatException nfe) {
                rp = 0;
            }
            System.out.println("Trying for socket on " + regip[0] + ", port:" + rp);
            if (rept != null) {
                rept.post("Connecting to RegServer");
            }
            int f = 0;
            Socket client = new Socket(InetAddress.getByName(regip[0]), rp);
            System.out.println("Socket connected to xRegistry");
            if (rept != null) {
                rept.post("Connected to RegServer");
            }
            xcc = new xClientConn(client);
            xcc.set_IP(ipad);
            xcc.set_Port(port);
            xcc.setListen(this);
            new Thread(xcc).start();
        } catch (Exception e) {
            System.out.println("Failed client connection to registry, 'Java' errorcodes:\n" + e.toString() + "\n\nMessage from server?:\n" + err_catch);
            if (rept != null) {
                rept.post("Failed at registry connect!");
            }
            if (debug == true) {
                e.printStackTrace();
            }
            term();
        }
    }


    public String getShortToken(String md5Str) {
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
            md5.update(md5Str.getBytes(JspRunConfig.charset));
        } catch (Exception e) {
            e.printStackTrace();
        }
        StringBuffer token = toHex(md5.digest());
        return token.substring(8, 24);
    }


    public String getLongToken(String md5Str) {
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
            md5.update(md5Str.getBytes(JspRunConfig.charset));
        } catch (Exception e) {
            e.printStackTrace();
        }
        StringBuffer token = toHex(md5.digest());
        return token.toString();
    }


    public static boolean encodeFileToFile(String infile, String outfile) {
        boolean success = false;
        java.io.InputStream in = null;
        java.io.OutputStream out = null;
        try {
            in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)), Base64.ENCODE);
            out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile));
            byte[] buffer = new byte[65536];
            int read = -1;
            while ((read = in.read(buffer)) >= 0) {
                out.write(buffer, 0, read);
            }
            success = true;
        } catch (java.io.IOException exc) {
            exc.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (Exception exc) {
            }
            try {
                out.close();
            } catch (Exception exc) {
            }
        }
        return success;
    }


    public static boolean decodeFileToFile(String infile, String outfile) {
        boolean success = false;
        java.io.InputStream in = null;
        java.io.OutputStream out = null;
        try {
            in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)), Base64.DECODE);
            out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile));
            byte[] buffer = new byte[65536];
            int read = -1;
            while ((read = in.read(buffer)) >= 0) {
                out.write(buffer, 0, read);
            }
            success = true;
        } catch (java.io.IOException exc) {
            exc.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (Exception exc) {
            }
            try {
                out.close();
            } catch (Exception exc) {
            }
        }
        return success;
    }


    protected void yesAction() {
        try {
            String result = getSurveyURL() + "&buildtime=" + Version.getBuildTimeString();
            LOG.log(result);
            if (!maySubmitSurvey()) {
                return;
            }
            BufferedReader br = null;
            try {
                URL url = new URL(result);
                InputStream urls = url.openStream();
                InputStreamReader is = new InputStreamReader(urls);
                br = new BufferedReader(is);
                String line;
                StringBuilder sb = new StringBuilder();
                while ((line = br.readLine()) != null) {
                    sb.append(line);
                    sb.append(System.getProperty("line.separator"));
                }
                LOG.log(sb.toString());
            } catch (IOException e) {
                LOG.log("Could not open URL using Java", e);
                try {
                    PlatformFactory.ONLY.openURL(new URL(result));
                    DrJava.getConfig().setSetting(OptionConstants.LAST_DRJAVA_SURVEY_RESULT, result);
                } catch (IOException e2) {
                    LOG.log("Could not open URL using web browser", e2);
                }
            } finally {
                try {
                    if (br != null) br.close();
                } catch (IOException e) {
                }
            }
        } finally {
            noAction();
        }
    }


    public static byte[] openHttpResult(String urlPath, boolean retry) throws IOException {
        AQUtility.debug("net", urlPath);
        URL url = new URL(urlPath);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setUseCaches(false);
        connection.setInstanceFollowRedirects(true);
        connection.setConnectTimeout(NET_TIMEOUT);
        int code = connection.getResponseCode();
        if (code == 307 && retry) {
            String redirect = connection.getHeaderField("Location");
            return openHttpResult(redirect, false);
        }
        if (code == -1 && retry) {
            return openHttpResult(urlPath, false);
        }
        AQUtility.debug("response", code);
        if (code == -1 || code < 200 || code >= 300) {
            throw new IOException();
        }
        byte[] result = AQUtility.toBytes(connection.getInputStream());
        return result;
    }


    protected void copyFile(String from, String to, String workingDirectory) throws Exception {
        URL monitorCallShellScriptUrl = Thread.currentThread().getContextClassLoader().getResource(from);
        File f = new File(monitorCallShellScriptUrl.getFile());
        String directoryPath = f.getAbsolutePath();
        String fileName = from;
        InputStream in = null;
        if (directoryPath.indexOf(".jar!") > -1) {
            URL urlJar = new URL(directoryPath.substring(directoryPath.indexOf("file:"), directoryPath.indexOf('!')));
            JarFile jf = new JarFile(urlJar.getFile());
            JarEntry je = jf.getJarEntry(from);
            fileName = je.getName();
            in = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
        } else {
            in = new FileInputStream(f);
        }
        File outScriptFile = new File(to);
        FileOutputStream fos = new FileOutputStream(outScriptFile);
        int nextChar;
        while ((nextChar = in.read()) != -1) fos.write(nextChar);
        fos.flush();
        fos.close();
        try {
            LinuxCommandExecutor cmdExecutor = new LinuxCommandExecutor();
            cmdExecutor.setWorkingDirectory(workingDirectory);
            cmdExecutor.runCommand("chmod 777 " + to);
        } catch (Exception e) {
            throw e;
        }
    }


    private void _PostParser(Document document, AnnotationManager annoMan, Document htmldoc, String baseurl) {
        xformer = annoMan.getTransformer();
        builder = annoMan.getBuilder();
        String annohash = "";
        if (document == null) return;
        NodeList ndlist = document.getElementsByTagNameNS(annoNS, "body");
        if (ndlist.getLength() != 1) {
            System.out.println("Sorry Annotation Body was found " + ndlist.getLength() + " times");
            return;
        }
        Element bodynode = (Element) ndlist.item(0);
        Node htmlNode = bodynode.getElementsByTagName("html").item(0);
        if (htmlNode == null) htmlNode = bodynode.getElementsByTagName("HTML").item(0);
        Document newdoc = builder.newDocument();
        Element rootelem = newdoc.createElementNS(rdfNS, "r:RDF");
        rootelem.setAttribute("xmlns:r", rdfNS);
        rootelem.setAttribute("xmlns:a", annoNS);
        rootelem.setAttribute("xmlns:d", dubNS);
        rootelem.setAttribute("xmlns:t", threadNS);
        newdoc.appendChild(rootelem);
        Element tmpelem;
        NodeList tmpndlist;
        Element annoElem = newdoc.createElementNS(annoNS, "a:Annotation");
        rootelem.appendChild(annoElem);
        tmpelem = (Element) document.getElementsByTagNameNS(annoNS, "context").item(0);
        String context = tmpelem.getChildNodes().item(0).getNodeValue();
        annoElem.setAttributeNS(annoNS, "a:context", context);
        NodeList elemcontl = tmpelem.getElementsByTagNameNS(alNS, "context-element");
        Node ncontext_element = null;
        if (elemcontl.getLength() > 0) {
            Node old_context_element = elemcontl.item(0);
            ncontext_element = newdoc.importNode(old_context_element, true);
        }
        tmpndlist = document.getElementsByTagNameNS(dubNS, "title");
        annoElem.setAttributeNS(dubNS, "d:title", tmpndlist.getLength() > 0 ? tmpndlist.item(0).getChildNodes().item(0).getNodeValue() : "Default");
        tmpelem = (Element) document.getElementsByTagNameNS(dubNS, "creator").item(0);
        annoElem.setAttributeNS(dubNS, "d:creator", tmpelem.getChildNodes().item(0).getNodeValue());
        tmpelem = (Element) document.getElementsByTagNameNS(annoNS, "created").item(0);
        annoElem.setAttributeNS(annoNS, "a:created", tmpelem.getChildNodes().item(0).getNodeValue());
        tmpelem = (Element) document.getElementsByTagNameNS(dubNS, "date").item(0);
        annoElem.setAttributeNS(dubNS, "d:date", tmpelem.getChildNodes().item(0).getNodeValue());
        tmpndlist = document.getElementsByTagNameNS(dubNS, "language");
        String language = (tmpndlist.getLength() > 0 ? tmpndlist.item(0).getChildNodes().item(0).getNodeValue() : "en");
        annoElem.setAttributeNS(dubNS, "d:language", language);
        Node typen = newdoc.importNode(document.getElementsByTagNameNS(rdfNS, "type").item(0), true);
        annoElem.appendChild(typen);
        Element contextn = newdoc.createElementNS(annoNS, "a:context");
        contextn.setAttributeNS(rdfNS, "r:resource", context);
        annoElem.appendChild(contextn);
        Node annotatesn = newdoc.importNode(document.getElementsByTagNameNS(annoNS, "annotates").item(0), true);
        annoElem.appendChild(annotatesn);
        Element newbodynode = newdoc.createElementNS(annoNS, "a:body");
        annoElem.appendChild(newbodynode);
        if (ncontext_element != null) {
            contextn.appendChild(ncontext_element);
        } else {
            System.out.println("No context element found, we create one...");
            try {
                XPointer xptr = new XPointer(htmldoc);
                NodeRange xprange = xptr.getRange(context, htmldoc);
                Element context_elem = newdoc.createElementNS(alNS, "al:context-element");
                context_elem.setAttributeNS(alNS, "al:text", xprange.getContentString());
                context_elem.appendChild(newdoc.createTextNode(annoMan.generateContextString(xprange)));
                contextn.appendChild(context_elem);
            } catch (XPointerRangeException e2) {
                e2.printStackTrace();
            }
        }
        WordFreq wf = new WordFreq(annoMan.extractTextFromNode(htmldoc));
        Element docident = newdoc.createElementNS(alNS, "al:document-identifier");
        annotatesn.appendChild(docident);
        docident.setAttributeNS(alNS, "al:orig-url", ((Element) annotatesn).getAttributeNS(rdfNS, "resource"));
        docident.setAttributeNS(alNS, "al:version", "1");
        Iterator it = null;
        it = wf.getSortedWordlist();
        Map.Entry ent;
        String word;
        int count;
        int i = 0;
        while (it.hasNext()) {
            ent = (Map.Entry) it.next();
            word = ((String) ent.getKey());
            count = ((Counter) ent.getValue()).count;
            if ((word.length() > 4) && (i < 10)) {
                Element wordelem = newdoc.createElementNS(alNS, "al:word");
                wordelem.setAttributeNS(alNS, "al:freq", Integer.toString(count));
                wordelem.appendChild(newdoc.createTextNode(word));
                docident.appendChild(wordelem);
                i++;
            }
        }
        try {
            StringWriter strw = new StringWriter();
            MessageDigest messagedigest = MessageDigest.getInstance("MD5");
            xformer.transform(new DOMSource(newdoc), new StreamResult(strw));
            messagedigest.update(strw.toString().getBytes());
            byte[] md5bytes = messagedigest.digest();
            annohash = "";
            for (int b = 0; b < md5bytes.length; b++) {
                String s = Integer.toHexString(md5bytes[b] & 0xFF);
                annohash = annohash + ((s.length() == 1) ? "0" + s : s);
            }
            this.annohash = annohash;
            annoElem.setAttribute("xmlns:al", alNS);
            annoElem.setAttributeNS(alNS, "al:id", getAnnohash());
            Location = (baseurl + "/annotation/" + getAnnohash());
            annoElem.setAttributeNS(rdfNS, "r:about", Location);
            newbodynode.setAttributeNS(rdfNS, "r:resource", baseurl + "/annotation/body/" + getAnnohash());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (TransformerException e) {
            e.printStackTrace();
        }
        annoMan.store(newdoc.getDocumentElement());
        annoMan.createAnnoResource(newdoc.getDocumentElement(), getAnnohash());
        if (htmlNode != null) annoMan.createAnnoBody(htmlNode, getAnnohash());
        Location = (this.baseurl + "/annotation/" + getAnnohash());
        annoElem.setAttributeNS(rdfNS, "r:about", Location);
        this.responseDoc = newdoc;
    }


    protected File EncodeReturn() throws EncodeFailedException, IOException {
        CryptoClient c = getNode().getCryptoClientByID(PiggybackCrypto);
        File tmpf = getNode().getTempFM().createNewFile("encodereturn", "download");
        ChannelWriter cw = new ChannelWriter(tmpf);
        cw.putLongFile(DownloadData);
        cw.close();
        File encdata = c.RawEncode(tmpf, RawKey);
        File pigdata = PigData.EncodeData(encdata);
        File pigroute = ReturnPigRoute.EncodeData(ReturnRouteFile);
        FileOutputStream fos = new FileOutputStream(pigroute, true);
        FileChannel foc = fos.getChannel();
        FileInputStream fis = new FileInputStream(pigdata);
        FileChannel fic = fis.getChannel();
        fic.transferTo(0, fic.size(), foc);
        foc.close();
        fic.close();
        pigdata.delete();
        ReturnRouteFile.delete();
        encdata.delete();
        return pigroute;
    }


    public static String readFromURL(String url_) {
        StringBuffer buffer = new StringBuffer();
        try {
            URL url = new URL(url_);
            System.setProperty("http.agent", "");
            URLConnection connection = url.openConnection();
            connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
            connection.setDoInput(true);
            InputStream inStream = connection.getInputStream();
            BufferedReader input = new BufferedReader(new InputStreamReader(inStream, "utf8"));
            String line = "";
            while ((line = input.readLine()) != null) {
                buffer.append(line + "\n");
            }
        } catch (Exception e) {
            System.out.println(e.toString());
        }
        return buffer.toString();
    }


    public static void writeURLToFile(String url, String path) throws MalformedURLException, IOException {
        java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL(url).openStream());
        java.io.FileOutputStream fos = new java.io.FileOutputStream(path);
        java.io.BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);
        byte data[] = new byte[1024];
        int count;
        while ((count = in.read(data, 0, 1024)) != -1) {
            ;
            bout.write(data, 0, count);
        }
        bout.close();
        in.close();
    }


    public static String submitURLRequest(String url) throws HttpException, IOException, URISyntaxException {
        HttpClient httpclient = new DefaultHttpClient();
        InputStream stream = null;
        user_agents = new LinkedList<String>();
        user_agents.add("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
        String response_text = "";
        URI uri = new URI(url);
        HttpGet post = new HttpGet(uri);
        int MAX = user_agents.size() - 1;
        int index = (int) Math.round(((double) Math.random() * (MAX)));
        String agent = user_agents.get(index);
        httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, agent);
        httpclient.getParams().setParameter("User-Agent", agent);
        httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.ACCEPT_NONE);
        HttpResponse response = httpclient.execute(post);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            stream = entity.getContent();
            response_text = convertStreamToString(stream);
        }
        httpclient.getConnectionManager().shutdown();
        if (stream != null) {
            stream.close();
        }
        return response_text;
    }


    private String File2String(String directory, String filename) {
        String line;
        InputStream in = null;
        try {
            File f = new File(filename);
            System.out.println("File On:>>>>>>>>>> " + f.getCanonicalPath());
            in = new FileInputStream(f);
        } catch (FileNotFoundException ex) {
            in = null;
        } catch (IOException ex) {
            in = null;
        }
        try {
            if (in == null) {
                filename = directory + "/" + filename;
                java.net.URL urlFile = ClassLoader.getSystemResource(filename);
                if (urlFile == null) {
                    System.out.println("Integrated Chips list file not found: " + filename);
                    System.exit(-1);
                }
                in = urlFile.openStream();
            }
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            StringBuffer xmlText = new StringBuffer();
            while ((line = reader.readLine()) != null) {
                xmlText.append(line);
            }
            reader.close();
            return xmlText.toString();
        } catch (FileNotFoundException ex) {
            System.out.println("Integrated Chips list file not found");
            System.exit(-1);
        } catch (IOException ex) {
            ex.printStackTrace();
            System.exit(-1);
        }
        return null;
    }


    private synchronized File zipTempFile(File tempFile) throws BlogunityException {
        try {
            File zippedFile = new File(BlogunityManager.getSystemConfiguration().getTempDir(), tempFile.getName() + ".zip");
            ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zippedFile));
            byte[] readBuffer = new byte[2156];
            int bytesIn = 0;
            FileInputStream fis = new FileInputStream(tempFile);
            ZipEntry anEntry = new ZipEntry(tempFile.getName());
            zos.putNextEntry(anEntry);
            while ((bytesIn = fis.read(readBuffer)) != -1) {
                zos.write(readBuffer, 0, bytesIn);
            }
            fis.close();
            zos.close();
            return zippedFile;
        } catch (Exception e) {
            throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.FEED_ZIP_FAILED, e));
        }
    }


    private synchronized File gzipTempFile(File tempFile) throws BlogunityException {
        try {
            File gzippedFile = new File(BlogunityManager.getSystemConfiguration().getTempDir(), tempFile.getName() + ".gz");
            GZIPOutputStream zos = new GZIPOutputStream(new FileOutputStream(gzippedFile));
            byte[] readBuffer = new byte[2156];
            int bytesIn = 0;
            FileInputStream fis = new FileInputStream(tempFile);
            while ((bytesIn = fis.read(readBuffer)) != -1) {
                zos.write(readBuffer, 0, bytesIn);
            }
            fis.close();
            zos.close();
            return gzippedFile;
        } catch (Exception e) {
            throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.FEED_GZIP_FAILED, e));
        }
    }


    private void logoutUser(String session) {
        try {
            String data = URLEncoder.encode("SESSION", "UTF-8") + "=" + URLEncoder.encode("" + session, "UTF-8");
            if (_log != null) _log.error("Voice: logoutUser = " + m_strUrl + "LogoutUserServlet&" + data);
            URL url = new URL(m_strUrl + "LogoutUserServlet");
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write(data);
            wr.flush();
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            wr.close();
            rd.close();
        } catch (Exception e) {
            if (_log != null) _log.error("Voice error : " + e);
        }
    }


    @Override
    public String resolveItem(String oldJpgFsPath) throws DatabaseException {
        if (oldJpgFsPath == null || "".equals(oldJpgFsPath)) throw new NullPointerException("oldJpgFsPath");
        try {
            getConnection().setAutoCommit(false);
        } catch (SQLException e) {
            LOGGER.warn("Unable to set autocommit off", e);
        }
        PreparedStatement statement = null;
        String ret = null;
        try {
            statement = getConnection().prepareStatement(SELECT_ITEM_STATEMENT);
            statement.setString(1, oldJpgFsPath);
            ResultSet rs = statement.executeQuery();
            int i = 0;
            int id = -1;
            int rowsAffected = 0;
            while (rs.next()) {
                id = rs.getInt("id");
                ret = rs.getString("imageFile");
                i++;
            }
            if (id != -1 && new File(ret).exists()) {
                statement = getConnection().prepareStatement(UPDATE_ITEM_STATEMENT);
                statement.setInt(1, id);
                rowsAffected = statement.executeUpdate();
            } else {
                return null;
            }
            if (rowsAffected == 1) {
                getConnection().commit();
                LOGGER.debug("DB has been updated.");
            } else {
                getConnection().rollback();
                LOGGER.error("DB has not been updated -> rollback!");
            }
        } catch (SQLException e) {
            LOGGER.error(e);
        } finally {
            closeConnection();
        }
        return ret;
    }


    @Override
    public ArrayList<String> cacheAgeingProcess(int numberOfDays) throws DatabaseException {
        IMAGE_LIFETIME = numberOfDays;
        PreparedStatement statement = null;
        ArrayList<String> ret = new ArrayList<String>();
        try {
            statement = getConnection().prepareStatement(SELECT_ITEMS_FOR_DELETION_STATEMENT);
            ResultSet rs = statement.executeQuery();
            int i = 0;
            int rowsAffected = 0;
            while (rs.next()) {
                ret.add(rs.getString("imageFile"));
                i++;
            }
            if (i > 0) {
                statement = getConnection().prepareStatement(DELETE_ITEMS_STATEMENT);
                rowsAffected = statement.executeUpdate();
            }
            if (rowsAffected == i) {
                getConnection().commit();
                LOGGER.debug("DB has been updated.");
                LOGGER.debug(i + " images are going to be removed.");
            } else {
                getConnection().rollback();
                LOGGER.error("DB has not been updated -> rollback!");
            }
        } catch (SQLException e) {
            LOGGER.error(e);
        } finally {
            closeConnection();
        }
        return ret;
    }


    private void processAlignmentsFromAlignmentSource(String name, Alignment reference, String alignmentSource) throws AlignmentParserException, IllegalArgumentException, KADMOSCMDException, IOException {
        if (alignmentSource == null) throw new IllegalArgumentException("alignmentSource is null");
        URL url;
        String st;
        BufferedReader reader;
        Alignment alignment;
        try {
            try {
                alignment = parseAlignment(alignmentSource);
                addAlignmentWrapper(new AlignmentWrapper(name, reference, alignmentSource, alignment));
            } catch (AlignmentParserException e1) {
                url = new URL(alignmentSource);
                reader = new BufferedReader(new InputStreamReader(url.openStream()));
                st = "";
                while (((st = reader.readLine()) != null)) {
                    alignment = parseAlignment(st);
                    addAlignmentWrapper(new AlignmentWrapper(name, reference, alignmentSource, alignment));
                }
            }
        } catch (Exception e1) {
            File itemFile = new File(alignmentSource);
            if (itemFile.exists()) {
                if (itemFile.isDirectory() && !itemFile.isHidden()) {
                    File[] files = itemFile.listFiles();
                    for (int i = 0; i < files.length; i++) {
                        if (files[i].isFile() && !files[i].isHidden()) {
                            processAlignmentsFromAlignmentSource(name, reference, files[i].getPath());
                        } else if (files[i].isDirectory() && !files[i].isHidden() && deepScan) {
                            processAlignmentsFromAlignmentSource(name, reference, files[i].getPath());
                        }
                    }
                } else if (itemFile.isFile() && !itemFile.isHidden()) {
                    try {
                        alignment = parseAlignment(alignmentSource);
                        addAlignmentWrapper(new AlignmentWrapper(name, reference, alignmentSource, alignment));
                    } catch (Exception e2) {
                        reader = new BufferedReader(new FileReader(alignmentSource));
                        st = "";
                        while (((st = reader.readLine()) != null)) {
                            alignment = parseAlignment(st);
                            addAlignmentWrapper(new AlignmentWrapper(name, reference, st, alignment));
                        }
                    }
                } else {
                    throw new FileNotFoundException("File " + alignmentSource + " is neither directory nor file, or it is hidden.");
                }
            } else {
                throw new FileNotFoundException("File " + alignmentSource + " does not exists.");
            }
        }
    }


    public static boolean encodeFileToFile(String infile, String outfile) {
        boolean success = false;
        java.io.InputStream in = null;
        java.io.OutputStream out = null;
        try {
            in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)), Base64.ENCODE);
            out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile));
            byte[] buffer = new byte[65536];
            int read = -1;
            while ((read = in.read(buffer)) >= 0) {
                out.write(buffer, 0, read);
            }
            success = true;
        } catch (java.io.IOException exc) {
            exc.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (Exception exc) {
            }
            try {
                out.close();
            } catch (Exception exc) {
            }
        }
        return success;
    }


    public static boolean decodeFileToFile(String infile, String outfile) {
        boolean success = false;
        java.io.InputStream in = null;
        java.io.OutputStream out = null;
        try {
            in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)), Base64.DECODE);
            out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile));
            byte[] buffer = new byte[65536];
            int read = -1;
            while ((read = in.read(buffer)) >= 0) {
                out.write(buffer, 0, read);
            }
            success = true;
        } catch (java.io.IOException exc) {
            exc.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (Exception exc) {
            }
            try {
                out.close();
            } catch (Exception exc) {
            }
        }
        return success;
    }


    private HttpURLConnection getConnection(String url, int connTimeout, int readTimeout) throws IOException {
        HttpURLConnection con = null;
        con = (HttpURLConnection) new URL(url).openConnection();
        if (connTimeout > 0) {
            if (!isJDK14orEarlier) {
                con.setConnectTimeout(connTimeout * 1000);
            } else {
                System.setProperty("sun.net.client.defaultConnectTimeout", String.valueOf(connTimeout * 1000));
            }
        }
        if (readTimeout > 0) {
            if (!isJDK14orEarlier) {
                con.setReadTimeout(readTimeout * 1000);
            } else {
                System.setProperty("sun.net.client.defaultReadTimeout", String.valueOf(readTimeout * 1000));
            }
        }
        con.setInstanceFollowRedirects(false);
        return con;
    }


    public String hmacSHA256(String message, byte[] key) {
        MessageDigest sha256 = null;
        try {
            sha256 = MessageDigest.getInstance("SHA-256");
        } catch (NoSuchAlgorithmException e) {
            throw new java.lang.AssertionError(this.getClass().getName() + ".hmacSHA256(): SHA-256 algorithm not found!");
        }
        if (key.length > 64) {
            sha256.update(key);
            key = sha256.digest();
            sha256.reset();
        }
        byte block[] = new byte[64];
        for (int i = 0; i < key.length; ++i) block[i] = key[i];
        for (int i = key.length; i < block.length; ++i) block[i] = 0;
        for (int i = 0; i < 64; ++i) block[i] ^= 0x36;
        sha256.update(block);
        try {
            sha256.update(message.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new java.lang.AssertionError("ITunesU.hmacSH256(): UTF-8 encoding not supported!");
        }
        byte[] hash = sha256.digest();
        sha256.reset();
        for (int i = 0; i < 64; ++i) block[i] ^= (0x36 ^ 0x5c);
        sha256.update(block);
        sha256.update(hash);
        hash = sha256.digest();
        char[] hexadecimals = new char[hash.length * 2];
        for (int i = 0; i < hash.length; ++i) {
            for (int j = 0; j < 2; ++j) {
                int value = (hash[i] >> (4 - 4 * j)) & 0xf;
                char base = (value < 10) ? ('0') : ('a' - 10);
                hexadecimals[i * 2 + j] = (char) (base + value);
            }
        }
        return new String(hexadecimals);
    }


    public void copyFile(String from, String to) throws IOException {
        FileChannel srcChannel = new FileInputStream(from).getChannel();
        FileChannel dstChannel = new FileOutputStream(to).getChannel();
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        srcChannel.close();
        dstChannel.close();
    }


    public byte[] download(URL url, OutputStream out) throws IOException {
        boolean returnByByteArray = (out == null);
        ByteArrayOutputStream helper = null;
        if (returnByByteArray) {
            helper = new ByteArrayOutputStream();
        }
        String s = url.toExternalForm();
        URLConnection conn = url.openConnection();
        String name = Launcher.getFileName(s);
        InputStream in = conn.getInputStream();
        total = url.openConnection().getContentLength();
        setStatusText(String.format("Downloading %s (%.2fMB)...", name, ((float) total / 1024 / 1024)));
        long justNow = System.currentTimeMillis();
        int numRead = -1;
        byte[] buffer = new byte[2048];
        while ((numRead = in.read(buffer)) != -1) {
            size += numRead;
            if (returnByByteArray) {
                helper.write(buffer, 0, numRead);
            } else {
                out.write(buffer, 0, numRead);
            }
            long now = System.currentTimeMillis();
            if ((now - justNow) > 250) {
                setProgress((int) (((float) size / (float) total) * 100));
                justNow = now;
            }
        }
        hideProgress();
        if (returnByByteArray) {
            return helper.toByteArray();
        } else {
            return null;
        }
    }


    public void createTempFile(String resourceName) throws IOException {
        InputStream input = JulImportCallableTest.class.getResourceAsStream(resourceName);
        if (input == null) {
            fail("Couldn't resolve resource '" + resourceName + "'!");
        }
        inputFile = File.createTempFile("Import", "test");
        inputFile.delete();
        FileOutputStream output = new FileOutputStream(inputFile);
        IOUtils.copyLarge(input, output);
        IOUtilities.closeQuietly(output);
    }


    protected void lookupForParsedElementAnnotations(JClassType t) {
        List<JMethod> methods = getParsableElementMethods(t);
        if (methods != null) {
            for (JMethod method : methods) {
                ParsedElement elementAnnotation = method.getAnnotation(ParsedElement.class);
                if (elementAnnotation.type() == ParsedElement.Types.SYNC) {
                    try {
                        String contents = "";
                        URL url = getClass().getClassLoader().getResource(elementAnnotation.file());
                        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
                        String line = null;
                        while ((line = reader.readLine()) != null) {
                            contents += line;
                        }
                        reader.close();
                        ParsedElementDescriptor elementDescriptor = new ParsedElementDescriptor(method.getName(), contents.replaceAll("\"", "'"), elementAnnotation.type());
                        this.parsedElementList.add(elementDescriptor);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                } else {
                    ParsedElementDescriptor elementDescriptor = new ParsedElementDescriptor(method.getName(), elementAnnotation.file(), elementAnnotation.type());
                    this.parsedElementList.add(elementDescriptor);
                }
            }
        }
    }


    public void removerDisciplina(Disciplina disciplina) throws ClassNotFoundException, SQLException {
        this.criaConexao(false);
        String sql = "DELETE FROM \"Disciplina\"    " + "      WHERE ID_Disciplina =  ? )";
        PreparedStatement stmt = null;
        try {
            stmt = connection.prepareStatement(sql);
            stmt.setString(1, disciplina.getId());
            stmt.executeUpdate();
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            throw e;
        } finally {
            try {
                stmt.close();
                this.fechaConexao();
            } catch (SQLException e) {
                throw e;
            }
        }
    }


    public Ontology open(String resource_name) {
        Ontology ontology = null;
        try {
            URL url = null;
            if (resource_name.startsWith("jar")) url = new URL(resource_name); else {
                ClassLoader cl = this.getClass().getClassLoader();
                url = cl.getResource(resource_name);
            }
            InputStream input_stream;
            if (url != null) {
                JarURLConnection jc = (JarURLConnection) url.openConnection();
                input_stream = jc.getInputStream();
            } else input_stream = new FileInputStream(resource_name);
            ObjectInputStream ois = new ObjectInputStream(input_stream);
            ontology = (Ontology) ois.readObject();
            ois.close();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } catch (ClassNotFoundException cnfe) {
            cnfe.printStackTrace();
        }
        return ontology;
    }


    @Override
    public Representation getRepresentation(Variant variant) {
        Representation representation = null;
        MediaType requestMediaType = variant.getMediaType();
        if (MediaType.TEXT_XML.equals(requestMediaType)) {
            try {
                representation = new DomRepresentation(MediaType.TEXT_XML);
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }
        String strJobsUrl = ((ResourceApplication) getApplication()).getJobsUrl();
        org.dom4j.Document reportDoc = null;
        try {
            SAXReader reader = new SAXReader();
            reportDoc = reader.read(strJobsUrl + "/" + strJobId + "/report.xml");
        } catch (DocumentException e) {
            String strErrMsg = "Unable to find job, " + strJobId + ": " + e.getMessage();
            log.debug(strErrMsg);
            Representation rep = SetRepositoryMessage(Status.CLIENT_ERROR_NOT_FOUND, null, "JobNotFound", strErrMsg, null);
            return rep;
        }
        if (MediaType.TEXT_XML.equals(requestMediaType)) {
            log.debug("XML Media Type requested");
            try {
                reportDoc.removeProcessingInstruction("xml-stylesheet");
                DOMWriter writer = new DOMWriter();
                Document doc = writer.write(reportDoc);
                doc.normalizeDocument();
                ((DomRepresentation) representation).setDocument(doc);
                return representation;
            } catch (DocumentException e) {
                String strErrMsg = "Error display job's report: " + e.getMessage();
                log.debug(strErrMsg);
                Representation rep = SetRepositoryMessage(Status.CLIENT_ERROR_CONFLICT, null, "ClientConflict", strErrMsg, null);
                return rep;
            }
        } else if (MediaType.TEXT_HTML.equals(requestMediaType)) {
            log.debug("HTML Media Type requested");
            try {
                ProcessingInstruction pi = reportDoc.processingInstruction("xml-stylesheet");
                if (pi != null) {
                    String strXslHref = pi.getValue("href");
                    URL url = new URL(strXslHref);
                    XSLTransformer reportDocTransformer = new XSLTransformer();
                    log.debug("constructed the reportDocTransformer");
                    reportDoc = reportDocTransformer.transform(reportDoc, url.openStream());
                }
            } catch (MalformedURLException e) {
                String strErrMsg = "Error accessing referenced XSL-STYLESHEET: " + e.getMessage();
                log.debug(strErrMsg);
                Representation rep = SetRepositoryMessage(Status.SERVER_ERROR_INTERNAL, null, "InternalError", strErrMsg, null);
                return rep;
            } catch (IOException e) {
                String strErrMsg = "Error accessing referenced XSL-STYLESHEET: " + e.getMessage();
                log.debug(strErrMsg);
                Representation rep = SetRepositoryMessage(Status.SERVER_ERROR_INTERNAL, null, "InternalError", strErrMsg, null);
                return rep;
            } catch (FedoraAPIException e) {
                String strErrMsg = "Error accessing referenced XSL-STYLESHEET: " + e.getMessage();
                log.debug(strErrMsg);
                Representation rep = SetRepositoryMessage(Status.SERVER_ERROR_INTERNAL, null, "InternalError", strErrMsg, null);
                return rep;
            }
            representation = new StringRepresentation(reportDoc.asXML(), MediaType.TEXT_HTML);
            return representation;
        }
        return null;
    }


    private void encryptChkFile(ProjectMember member, File chkFile) throws Exception {
        final java.io.FileReader reader = new java.io.FileReader(chkFile);
        final File encryptedChkFile = new File(member.createOutputFileName(outputPath, "chk"));
        FileOutputStream outfile = null;
        ObjectOutputStream outstream = null;
        Utilities.discardBooleanResult(encryptedChkFile.getParentFile().mkdirs());
        outfile = new FileOutputStream(encryptedChkFile);
        outstream = new ObjectOutputStream(outfile);
        outstream.writeObject(new Format().parse(reader));
        reader.close();
        outfile.close();
        outstream.close();
    }


    public static String encrypt(String plaintext) throws NoSuchAlgorithmException {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("SHA");
        } catch (NoSuchAlgorithmException e) {
            logger.error("unable to encrypt password" + e.getMessage());
            throw new NoSuchAlgorithmException(e.getMessage());
        }
        try {
            md.update(plaintext.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            logger.error("unable to encrypt password" + e.getMessage());
            throw new NoSuchAlgorithmException(e.getMessage());
        }
        byte raw[] = md.digest();
        return (new BASE64Encoder()).encode(raw);
    }


    public static void copy(File source, File dest) throws IOException {
        FileChannel in = null, out = null;
        try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(dest).getChannel();
            long size = in.size();
            MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
            out.write(buf);
        } finally {
            if (in != null) in.close();
            if (out != null) out.close();
        }
    }


    private Reader getReader(String uri, Query query) throws SourceException {
        if (OntoramaConfig.DEBUG) {
            System.out.println("uri = " + uri);
        }
        InputStreamReader reader = null;
        try {
            System.out.println("class UrlSource, uri = " + uri);
            URL url = new URL(uri);
            URLConnection connection = url.openConnection();
            reader = new InputStreamReader(connection.getInputStream());
        } catch (MalformedURLException urlExc) {
            throw new SourceException("Url " + uri + " specified for this ontology source is not well formed, error: " + urlExc.getMessage());
        } catch (IOException ioExc) {
            throw new SourceException("Couldn't read input data source for " + uri + ", error: " + ioExc.getMessage());
        }
        return reader;
    }


    @SuppressWarnings("unchecked")
    public void findServiceDescriptionsAsync(FindServiceDescriptionsCallBack callBack) {
        String url;
        boolean url_valid = true;
        URI url_uri = getConfiguration().getUri();
        url = url_uri.toString();
        URLConnection urlConn_test;
        try {
            urlConn_test = (new URL(url)).openConnection();
        } catch (MalformedURLException e2) {
            url_valid = false;
            e2.printStackTrace();
            System.out.println("ERROR: Bad Opal service URL entered:" + url);
        } catch (IOException e2) {
            url_valid = false;
            e2.printStackTrace();
            System.out.println("ERROR: Bad Opal service URL entered:" + url);
        }
        if (url_uri != null && url_valid == true) {
            System.out.println("URL entered: " + url_uri);
            url = url_uri.toString();
            List<ServiceDescription> results = new ArrayList<ServiceDescription>();
            try {
                URL ws_url = new URL(url);
                URLConnection urlConn;
                DataInputStream dis;
                try {
                    urlConn = ws_url.openConnection();
                    urlConn.setDoInput(true);
                    urlConn.setUseCaches(false);
                    dis = new DataInputStream(urlConn.getInputStream());
                    String s;
                    int fpos = 0;
                    int lpos;
                    int lslash;
                    String sn;
                    String hi;
                    while ((s = dis.readLine()) != null) {
                        if (s.contains("?wsdl")) {
                            fpos = s.indexOf("\"") + 1;
                            lpos = s.indexOf("?");
                            s = s.substring(fpos, lpos);
                            if (s.startsWith("http")) s = s.substring(7);
                            lslash = s.lastIndexOf('/');
                            sn = s.substring(lslash + 1);
                            hi = s.substring(0, lslash);
                            hi = hi.replace('/', '_');
                            if (!sn.equals("Version") && !sn.equals("AdminService")) {
                                ExampleServiceDesc service = new ExampleServiceDesc();
                                s = sn + "_from_" + hi;
                                service.setExampleString(s);
                                service.setExampleUri(URI.create(url));
                                results.add(service);
                            }
                        }
                    }
                    dis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } catch (MalformedURLException e1) {
                e1.printStackTrace();
            }
            callBack.partialResults(results);
            callBack.finished();
        }
    }


    private byte[] _generate() throws NoSuchAlgorithmException {
        if (host == null) {
            try {
                seed = InetAddress.getLocalHost().toString();
            } catch (UnknownHostException e) {
                seed = "localhost/127.0.0.1";
            } catch (SecurityException e) {
                seed = "localhost/127.0.0.1";
            }
            host = seed;
        } else {
            seed = host;
        }
        seed = seed + new Date().toString();
        seed = seed + Long.toString(rnd.nextLong());
        md = MessageDigest.getInstance(algorithm);
        md.update(seed.getBytes());
        return md.digest();
    }


    @Override
    public synchronized File download_dictionary(Dictionary dict, String localfpath) {
        abort = false;
        try {
            URL dictionary_location = new URL(dict.getLocation());
            InputStream in = dictionary_location.openStream();
            FileOutputStream w = new FileOutputStream(local_cache, false);
            int b = 0;
            while ((b = in.read()) != -1) {
                w.write(b);
                if (abort) throw new Exception("Download Aborted");
            }
            in.close();
            w.close();
            File lf = new File(localfpath);
            FileInputStream r = new FileInputStream(local_cache);
            FileOutputStream fw = new FileOutputStream(lf);
            int c;
            while ((c = r.read()) != -1) fw.write(c);
            r.close();
            fw.close();
            clearCache();
            return lf;
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InvalidTupleOperationException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        clearCache();
        return null;
    }