Search in sources :

Example 66 with ArrayList

use of java.util.ArrayList in project Japid by branaway.

the class DirUtil method mkdir.

/**
		 * create the basic layout: app/japidviews/_javatags app/japidviews/_layouts
		 * app/japidviews/_tags
		 * 
		 * then create a dir for each controller. //TODO
		 * 
		 * @throws IOException
		 * 
		 */
public static List<File> mkdir(String root) throws IOException {
    String sep = File.separator;
    String japidViews = root + sep + JAPIDVIEWS_ROOT + sep;
    File javatags = new File(japidViews + JAVATAGS);
    if (!javatags.exists()) {
        boolean mkdirs = javatags.mkdirs();
        assert mkdirs;
        JapidFlags.info("created: " + japidViews + JAVATAGS);
    }
    //		File webutil = new File(javatags, "JapidWebUtil.java");
    //		if (!webutil.exists()) {
    //			DirUtil.writeStringToFile(webutil, JapidWebUtil);
    //			JapidFlags.log("created JapidWebUtil.java.");
    //		}
    // add the place-holder for utility class for use in templates
    File layouts = new File(japidViews + LAYOUTDIR);
    if (!layouts.exists()) {
        boolean mkdirs = layouts.mkdirs();
        assert mkdirs;
        JapidFlags.info("created: " + japidViews + LAYOUTDIR);
    }
    File tags = new File(japidViews + TAGSDIR);
    if (!tags.exists()) {
        boolean mkdirs = tags.mkdirs();
        assert mkdirs;
        JapidFlags.info("created: " + japidViews + TAGSDIR);
    }
    // email notifiers
    File notifiers = new File(japidViews + "_notifiers");
    if (!notifiers.exists()) {
        boolean mkdirs = notifiers.mkdirs();
        assert mkdirs;
        JapidFlags.info("created: " + japidViews + "_notifiers");
    }
    File[] dirs = new File[] { javatags, layouts, tags };
    List<File> res = new ArrayList<File>();
    res.addAll(Arrays.asList(dirs));
    //		JapidFlags.log("JapidCommands: check default template packages for controllers.");
    try {
        String controllerPath = root + sep + "controllers";
        File controllerPathFile = new File(controllerPath);
        if (controllerPathFile.exists()) {
            String[] controllers = DirUtil.getAllJavaFilesInDir(controllerPathFile);
            for (String f : controllers) {
                String cp = japidViews + f;
                File ff = new File(cp);
                if (!ff.exists()) {
                    boolean mkdirs = ff.mkdirs();
                    assert mkdirs == true;
                    res.add(ff);
                    JapidFlags.info("created: " + cp);
                }
            }
        }
    } catch (Exception e) {
        JapidFlags.error(e.toString());
    }
    //		JapidFlags.log("JapidCommands:  check default template packages for email notifiers.");
    try {
        String notifiersDir = root + sep + "notifiers";
        File notifiersDirFile = new File(notifiersDir);
        if (!notifiersDirFile.exists()) {
            if (notifiersDirFile.mkdir()) {
                JapidFlags.info("created the email notifiers directory. ");
            } else {
                JapidFlags.info("email notifiers directory did not exist and could not be created for unknow reason. ");
            }
        }
        String[] controllers = DirUtil.getAllJavaFilesInDir(notifiersDirFile);
        for (String f : controllers) {
            // note: we keep the notifiers dir to differentiate those from the controller
            // however this means we cannot have a controller with package like "controllers.notifiers"
            // so we now use "_notifiers"
            String cp = japidViews + "_notifiers" + sep + f;
            File ff = new File(cp);
            if (!ff.exists()) {
                boolean mkdirs = ff.mkdirs();
                assert mkdirs == true;
                res.add(ff);
                JapidFlags.info("created: " + cp);
            }
        }
    } catch (Exception e) {
        JapidFlags.error(e.toString());
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 67 with ArrayList

use of java.util.ArrayList in project Japid by branaway.

the class DirUtil method findChangedSrcFiles.

public static List<File> findChangedSrcFiles(File srcDir) {
    //		if (target == null)
    //			target = src;
    //		String srcPath = src.getPath();
    Set<File> allSrc = new HashSet<File>();
    allSrc = getAllFiles(srcDir, ALL_EXTS, allSrc);
    // <name, last modified time>
    Map<String, Long> javaFiles = new HashMap<String, Long>();
    Map<String, Long> scriptFiles = new HashMap<String, Long>();
    long now = System.currentTimeMillis();
    boolean hasFutureTimestamp = false;
    for (File f : allSrc) {
        String path = f.getPath();
        long modi = f.lastModified();
        //			System.out.println("file: " + path + ":" + modi);
        if (path.endsWith(".java")) {
            if (modi > now) {
                // for some reason(e.g., copies from other file system), the last modified time is in the future
                // let's reset it.
                hasFutureTimestamp = true;
                f.setLastModified(now - 1);
            }
            javaFiles.put(path, modi);
        } else {
            // validate file name to filter out dubious files such as temporary files
            if (fileNameIsValidClassName(f)) {
                if (modi > now) {
                    // for some reason(e.g., copies from other file system), the last modified time is in the future
                    // let's reset it.
                    hasFutureTimestamp = true;
                    f.setLastModified(now);
                }
                scriptFiles.put(path, modi);
            }
        }
    }
    if (hasFutureTimestamp) {
        JapidFlags.warn("Some of the Japid files have a timestamp in the future. It could have been caused by out-of-synch system time.");
    }
    List<File> changedScripts = new ArrayList<File>();
    boolean japidVersionChecked = versionCheckedDirs.contains(srcDir);
    for (String script : scriptFiles.keySet()) {
        String javaFileName = mapSrcToJava(script);
        File javaFile = new File(javaFileName);
        Long javaTimestamp = javaFiles.get(javaFileName);
        if (javaTimestamp == null) {
            // how can this happen?
            //				javaFile.delete();
            changedScripts.add(new File(script));
        } else {
            Long srcStamp = scriptFiles.get(script);
            if (srcStamp.compareTo(javaTimestamp) > 0) {
                //					javaFile.delete();
                changedScripts.add(new File(script));
            } else {
                //					if (firstTimeDetectingChanges) {
                if (!japidVersionChecked) {
                    // check the japid version that the java code was generated by
                    if (javaFile.exists()) {
                        String firstLine = JapidRenderer.readFirstLine(javaFile);
                        if (firstLine.startsWith(AbstractTemplateClassMetaData.VERSION_HEADER)) {
                            firstLine = firstLine.substring(AbstractTemplateClassMetaData.VERSION_HEADER.length()).trim();
                            if (!JapidRenderer.VERSION.equals(firstLine)) {
                                JapidFlags.debug("japid version mismatch. to refresh " + javaFileName);
                                //									javaFile.delete();
                                changedScripts.add(new File(script));
                            }
                        } else {
                            JapidFlags.debug("japid version mismatch. to refresh " + javaFileName);
                            //								javaFile.delete();
                            changedScripts.add(new File(script));
                        }
                    }
                }
            }
        }
    }
    versionCheckedDirs.add(srcDir);
    //		firstTimeDetectingChanges = false;
    return changedScripts;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) File(java.io.File) HashSet(java.util.HashSet)

Example 68 with ArrayList

use of java.util.ArrayList in project apn-proxy by apn-proxy.

the class ApnProxyConfigReader method realReadProcess.

@Override
protected void realReadProcess(Element rootElement) {
    Elements listenTypeElements = rootElement.getChildElements("listen-type");
    if (listenTypeElements.size() == 1) {
        String _listenType = listenTypeElements.get(0).getValue();
        ApnProxyListenType listenType = ApnProxyListenType.fromString(_listenType);
        ApnProxyConfig.getConfig().setListenType(listenType);
        if (listenType == ApnProxyListenType.AES) {
            Elements keyElements = rootElement.getChildElements("key");
            if (keyElements.size() != 1) {
                throw new ApnProxyConfigException("Wrong config for: key");
            }
            String _key = keyElements.get(0).getValue();
            Elements ivElements = rootElement.getChildElements("iv");
            if (keyElements.size() != 1) {
                throw new ApnProxyConfigException("Wrong config for: iv ");
            }
            String iv = ivElements.get(0).getValue();
            ApnProxyConfig.getConfig().setKey(_key.getBytes(Charset.forName("UTF-8")));
            ApnProxyConfig.getConfig().setIv(iv.getBytes(Charset.forName("UTF-8")));
        }
    }
    Elements keyStoreElements = rootElement.getChildElements("key-store");
    if (keyStoreElements.size() == 1) {
        Elements keyStorePathElements = keyStoreElements.get(0).getChildElements("path");
        if (keyStorePathElements.size() == 1) {
            ApnProxyConfig.getConfig().setKeyStorePath(keyStorePathElements.get(0).getValue());
        }
        Elements keyStorePasswordElements = keyStoreElements.get(0).getChildElements("password");
        if (keyStorePasswordElements.size() == 1) {
            ApnProxyConfig.getConfig().setKeyStroePassword(keyStorePasswordElements.get(0).getValue());
        }
    }
    Elements trustStoreElements = rootElement.getChildElements("trust-store");
    if (trustStoreElements.size() == 1) {
        ApnProxyConfig.getConfig().setUseTrustStore(true);
        Elements trustStorePathElements = trustStoreElements.get(0).getChildElements("path");
        if (trustStorePathElements.size() == 1) {
            ApnProxyConfig.getConfig().setTrustStorePath(trustStorePathElements.get(0).getValue());
        }
        Elements trustStorePasswordElements = trustStoreElements.get(0).getChildElements("password");
        if (trustStorePasswordElements.size() == 1) {
            ApnProxyConfig.getConfig().setTrustStorePassword(trustStorePasswordElements.get(0).getValue());
        }
    }
    Elements portElements = rootElement.getChildElements("port");
    if (portElements.size() == 1) {
        try {
            ApnProxyConfig.getConfig().setPort(Integer.parseInt(portElements.get(0).getValue()));
        } catch (NumberFormatException nfe) {
            throw new ApnProxyConfigException("Invalid format for: port", nfe);
        }
    }
    Elements threadCountElements = rootElement.getChildElements("thread-count");
    if (threadCountElements.size() == 1) {
        Elements bossElements = threadCountElements.get(0).getChildElements("boss");
        if (bossElements.size() == 1) {
            try {
                ApnProxyConfig.getConfig().setBossThreadCount(Integer.parseInt(bossElements.get(0).getValue()));
            } catch (NumberFormatException nfe) {
                throw new ApnProxyConfigException("Invalid format for: boss", nfe);
            }
        }
        Elements workerElements = threadCountElements.get(0).getChildElements("worker");
        if (workerElements.size() == 1) {
            try {
                ApnProxyConfig.getConfig().setWorkerThreadCount(Integer.parseInt(workerElements.get(0).getValue()));
            } catch (NumberFormatException nfe) {
                throw new ApnProxyConfigException("Invalid format for: worker", nfe);
            }
        }
    }
    Elements pacHostElements = rootElement.getChildElements("pac-host");
    if (pacHostElements.size() == 1) {
        ApnProxyConfig.getConfig().setPacHost(pacHostElements.get(0).getValue());
    }
    Elements useIpv6Elements = rootElement.getChildElements("use-ipv6");
    if (useIpv6Elements.size() == 1) {
        ApnProxyConfig.getConfig().setUseIpV6(Boolean.parseBoolean(useIpv6Elements.get(0).getValue()));
    }
    Elements localIpRulesElements = rootElement.getChildElements("local-ip-rules");
    if (localIpRulesElements.size() == 1) {
        Elements ruleElements = localIpRulesElements.get(0).getChildElements("rule");
        for (int i = 0; i < ruleElements.size(); i++) {
            ApnProxyLocalIpRule apnProxyLocalIpRule = new ApnProxyLocalIpRule();
            Element ruleElement = ruleElements.get(i);
            Elements localIpElements = ruleElement.getChildElements("local-ip");
            if (localIpElements.size() != 1) {
                throw new ApnProxyConfigException("Wrong config for: local-ip");
            }
            String localIp = localIpElements.get(0).getValue();
            apnProxyLocalIpRule.setLocalIp(localIp);
            Elements applyListElements = ruleElement.getChildElements("apply-list");
            if (applyListElements.size() == 1) {
                Elements originalHostElements = applyListElements.get(0).getChildElements("original-host");
                List<String> originalHostList = new ArrayList<String>();
                for (int j = 0; j < originalHostElements.size(); j++) {
                    String originalHost = originalHostElements.get(j).getValue();
                    originalHostList.add(originalHost);
                }
                apnProxyLocalIpRule.setOriginalHostList(originalHostList);
            }
            ApnProxyConfig.getConfig().addLocalIpRuleList(apnProxyLocalIpRule);
        }
    }
}
Also used : Element(nu.xom.Element) ArrayList(java.util.ArrayList) Elements(nu.xom.Elements)

Example 69 with ArrayList

use of java.util.ArrayList in project apn-proxy by apn-proxy.

the class ApnProxyRemoteRulesConfigReader method realReadProcess.

@Override
protected void realReadProcess(Element rootElement) {
    Element remoteRulesElement = rootElement;
    Elements ruleElements = remoteRulesElement.getChildElements("rule");
    for (int i = 0; i < ruleElements.size(); i++) {
        Element ruleElement = ruleElements.get(i);
        Elements remoteListenTypeElements = ruleElement.getChildElements("remote-listen-type");
        if (remoteListenTypeElements.size() != 1) {
            throw new ApnProxyConfigException("Wrong config for: remote-listen-type");
        }
        String _remoteListenType = remoteListenTypeElements.get(0).getValue();
        ApnProxyListenType remoteListenType = ApnProxyListenType.fromString(_remoteListenType);
        ApnProxyRemoteRule apnProxyRemoteRule = null;
        if (remoteListenType == ApnProxyListenType.AES) {
            apnProxyRemoteRule = new ApnProxyAESRemoteRule();
            Elements remoteKeyElements = ruleElement.getChildElements("key");
            if (remoteKeyElements.size() != 1) {
                throw new ApnProxyConfigException("Wrong config for: key of AES remote");
            }
            String _remoteKey = remoteKeyElements.get(0).getValue();
            Elements remoteIVElements = ruleElement.getChildElements("iv");
            if (remoteKeyElements.size() != 1) {
                throw new ApnProxyConfigException("Wrong config for: iv of AES remote");
            }
            String _remoteIV = remoteIVElements.get(0).getValue();
            ((ApnProxyAESRemoteRule) apnProxyRemoteRule).setKey(_remoteKey.getBytes(Charset.forName("UTF-8")));
            ((ApnProxyAESRemoteRule) apnProxyRemoteRule).setIv(_remoteIV.getBytes(Charset.forName("UTF-8")));
        } else {
            apnProxyRemoteRule = new ApnProxyRemoteRule();
        }
        apnProxyRemoteRule.setRemoteListenType(remoteListenType);
        Elements remoteHostElements = ruleElement.getChildElements("remote-host");
        if (remoteHostElements.size() != 1) {
            throw new ApnProxyConfigException("Wrong config for: remote-host");
        }
        String remoteHost = remoteHostElements.get(0).getValue();
        apnProxyRemoteRule.setRemoteHost(remoteHost);
        Elements remotePortElements = ruleElement.getChildElements("remote-port");
        if (remoteHostElements.size() != 1) {
            throw new ApnProxyConfigException("Wrong config for: remote-port");
        }
        int remotePort = -1;
        try {
            remotePort = Integer.parseInt(remotePortElements.get(0).getValue());
        } catch (NumberFormatException nfe) {
            throw new ApnProxyConfigException("Invalid format for: remote-port", nfe);
        }
        apnProxyRemoteRule.setRemotePort(remotePort);
        Elements proxyUserNameElements = ruleElement.getChildElements("proxy-username");
        if (proxyUserNameElements.size() == 1) {
            String proxyUserName = proxyUserNameElements.get(0).getValue();
            apnProxyRemoteRule.setProxyUserName(proxyUserName);
        }
        Elements proxyPasswordElements = ruleElement.getChildElements("proxy-password");
        if (proxyPasswordElements.size() == 1) {
            String proxyPassword = proxyPasswordElements.get(0).getValue();
            apnProxyRemoteRule.setProxyPassword(proxyPassword);
        }
        Elements applyListElements = ruleElement.getChildElements("apply-list");
        if (applyListElements.size() == 1) {
            Elements originalHostElements = applyListElements.get(0).getChildElements("original-host");
            List<String> originalHostList = new ArrayList<String>();
            for (int j = 0; j < originalHostElements.size(); j++) {
                String originalHost = originalHostElements.get(j).getValue();
                originalHostList.add(originalHost);
            }
            apnProxyRemoteRule.setOriginalHostList(originalHostList);
        }
        ApnProxyConfig.getConfig().addRemoteRule(apnProxyRemoteRule);
    }
}
Also used : Element(nu.xom.Element) ArrayList(java.util.ArrayList) Elements(nu.xom.Elements)

Example 70 with ArrayList

use of java.util.ArrayList in project coursera-android by aporter.

the class DataTransferActivity method selectServer.

private void selectServer() {
    setButtonsEnabled(false);
    Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
    ArrayList<String> pairedDeviceStrings = new ArrayList<String>();
    if (pairedDevices.size() > 0) {
        for (BluetoothDevice device : pairedDevices) {
            pairedDeviceStrings.add(device.getName() + "\n" + device.getAddress());
        }
    }
    Intent showDevicesIntent = new Intent(this, ShowDevices.class);
    showDevicesIntent.putStringArrayListExtra("devices", pairedDeviceStrings);
    startActivityForResult(showDevicesIntent, SELECT_SERVER);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ArrayList(java.util.ArrayList) Intent(android.content.Intent)

Aggregations

ArrayList (java.util.ArrayList)66688 Test (org.junit.Test)10926 List (java.util.List)8600 HashMap (java.util.HashMap)7604 IOException (java.io.IOException)5211 Map (java.util.Map)3776 File (java.io.File)3552 HashSet (java.util.HashSet)2622 Iterator (java.util.Iterator)1783 Test (org.testng.annotations.Test)1379 SQLException (java.sql.SQLException)1319 ResultSet (java.sql.ResultSet)1285 KieSession (org.kie.api.runtime.KieSession)1130 Date (java.util.Date)1109 Set (java.util.Set)1104 PreparedStatement (java.sql.PreparedStatement)1055 LinkedHashMap (java.util.LinkedHashMap)1046 Collection (java.util.Collection)925 URL (java.net.URL)816 LinkedList (java.util.LinkedList)813