Package org.h2.util

Examples of org.h2.util.SortedProperties


        return "admin.jsp";
    }

    private String adminSave() {
        try {
            Properties prop = new SortedProperties();
            int port = Integer.decode((String) attributes.get("port"));
            prop.setProperty("webPort", String.valueOf(port));
            server.setPort(port);
            boolean allowOthers = Boolean.valueOf((String) attributes.get("allowOthers")).booleanValue();
            prop.setProperty("webAllowOthers", String.valueOf(allowOthers));
            server.setAllowOthers(allowOthers);
            boolean ssl = Boolean.valueOf((String) attributes.get("ssl")).booleanValue();
            prop.setProperty("webSSL", String.valueOf(ssl));
            server.setSSL(ssl);
            server.saveProperties(prop);
        } catch (Exception e) {
            trace(e.toString());
        }
View Full Code Here


     */
    synchronized void saveProperties(Properties prop) {
        try {
            if (prop == null) {
                Properties old = loadProperties();
                prop = new SortedProperties();
                prop.setProperty("webPort", "" + SortedProperties.getIntProperty(old, "webPort", port));
                prop.setProperty("webAllowOthers", "" + SortedProperties.getBooleanProperty(old, "webAllowOthers", allowOthers));
                prop.setProperty("webSSL", "" + SortedProperties.getBooleanProperty(old, "webSSL", ssl));
            }
            ArrayList<ConnectionInfo> settings = getSettings();
View Full Code Here

        }

        public void run() {
            while (!stopNow) {
                try {
                    SortedProperties sp = new SortedProperties();
                    if (file.exists()) {
                        InputStream in = IOUtils.openFileInputStream(file.getName());
                        sp.load(in);
                        translation.putAll(sp);
                    } else {
                        OutputStream out = IOUtils.openFileOutputStream(file.getName(), false);
                        sp.putAll(translation);
                        sp.store(out, "Translation");
                    }
                    Thread.sleep(1000);
                } catch (Exception e) {
                    traceError(e);
                }
View Full Code Here

    private static String extract(String documentName, File f, String target) throws Exception {
        String xml = IOUtils.readStringAndClose(new InputStreamReader(new FileInputStream(f), "UTF-8"), -1);
        // the template contains ${} instead of text
        StringBuilder template = new StringBuilder(xml.length());
        int id = 0;
        SortedProperties prop = new SortedProperties();
        XMLParser parser = new XMLParser(xml);
        StringBuilder buff = new StringBuilder();
        Stack<String> stack = new Stack<String>();
        String tag = "";
        boolean ignoreEnd = false;
        String nextKey = "";
        // for debugging
        boolean templateIsCopy = false;
        while (true) {
            int event = parser.next();
            if (event == XMLParser.END_DOCUMENT) {
                break;
            } else if (event == XMLParser.CHARACTERS) {
                String s = parser.getText();
                if (s.trim().length() == 0) {
                    if (buff.length() > 0) {
                        buff.append(s);
                    } else {
                        template.append(s);
                    }
                } else if ("p".equals(tag) || "li".equals(tag) || "a".equals(tag) || "td".equals(tag)
                        || "th".equals(tag) || "h1".equals(tag) || "h2".equals(tag) || "h3".equals(tag)
                        || "h4".equals(tag) || "body".equals(tag) || "b".equals(tag) || "code".equals(tag)
                        || "form".equals(tag) || "span".equals(tag) || "em".equals(tag) || "div".equals(tag)
                        || "label".equals(tag)) {
                    if (buff.length() == 0) {
                        nextKey = documentName + "_" + (1000 + id++) + "_" + tag;
                        template.append(getSpace(s, true));
                    } else if (templateIsCopy) {
                        buff.append(getSpace(s, true));
                    }
                    buff.append(s);
                } else if ("pre".equals(tag) || "title".equals(tag) || "script".equals(tag) || "style".equals(tag)) {
                    // ignore, don't translate
                    template.append(s);
                } else {
                    System.out.println(f.getName() + " invalid wrapper tag for text: " + tag + " text: " + s);
                    System.out.println(parser.getRemaining());
                    throw new Exception();
                }
            } else if (event == XMLParser.START_ELEMENT) {
                stack.add(tag);
                String name = parser.getName();
                if ("code".equals(name) || "a".equals(name) || "b".equals(name) || "span".equals(name)) {
                    // keep tags if wrapped, but not if this is the wrapper
                    if (buff.length() > 0) {
                        buff.append(parser.getToken());
                        ignoreEnd = false;
                    } else {
                        ignoreEnd = true;
                        template.append(parser.getToken());
                    }
                } else if ("p".equals(tag) || "li".equals(tag) || "td".equals(tag) || "th".equals(tag)
                        || "h1".equals(tag) || "h2".equals(tag) || "h3".equals(tag) || "h4".equals(tag)
                        || "body".equals(tag) || "form".equals(tag)) {
                    if (buff.length() > 0) {
                        if (templateIsCopy) {
                            template.append(buff.toString());
                        } else {
                            template.append("${" + nextKey + "}");
                        }
                        add(prop, nextKey, buff);
                    }
                    template.append(parser.getToken());
                } else {
                    template.append(parser.getToken());
                }
                tag = name;
            } else if (event == XMLParser.END_ELEMENT) {
                String name = parser.getName();
                if ("code".equals(name) || "a".equals(name) || "b".equals(name) || "span".equals(name)
                        || "em".equals(name)) {
                    if (ignoreEnd) {
                        if (buff.length() > 0) {
                            if (templateIsCopy) {
                                template.append(buff.toString());
                            } else {
                                template.append("${" + nextKey + "}");
                            }
                            add(prop, nextKey, buff);
                        }
                        template.append(parser.getToken());
                    } else {
                        if (buff.length() > 0) {
                            buff.append(parser.getToken());
                        }
                    }
                } else {
                    if (buff.length() > 0) {
                        if (templateIsCopy) {
                            template.append(buff.toString());
                        } else {
                            template.append("${" + nextKey + "}");
                        }
                        add(prop, nextKey, buff);
                    }
                    template.append(parser.getToken());
                }
                tag = stack.pop();
            } else if (event == XMLParser.DTD) {
                template.append(parser.getToken());
            } else if (event == XMLParser.COMMENT) {
                template.append(parser.getToken());
            } else {
                int eventType = parser.getEventType();
                throw new Exception("Unexpected event " + eventType + " at " + parser.getRemaining());
            }
            // if(!xml.startsWith(template.toString())) {
            // System.out.println(nextKey);
            // System.out.println(template.substring(template.length()-60)
            // +";");
            // System.out.println(xml.substring(template.length()-60,
            // template.length()));
            // System.out.println(template.substring(template.length()-55)
            // +";");
            // System.out.println(xml.substring(template.length()-55,
            // template.length()));
            // break;
            // }
        }
        new File(target).mkdirs();
        String propFileName = target + "/_docs_" + MAIN_LANGUAGE + ".properties";
        Properties old = load(propFileName, false);
        prop.putAll(old);
        store(prop, propFileName, false);
        String t = template.toString();
        if (templateIsCopy && !t.equals(xml)) {
            for (int i = 0; i < Math.min(t.length(), xml.length()); i++) {
                if (t.charAt(i) != xml.charAt(i)) {
View Full Code Here

                } else {
                    translations.add(f);
                }
            }
        }
        SortedProperties p = load(main.getAbsolutePath(), utf8);
        Properties base = load(baseDir + "/" + main.getName(), utf8);
        store(p, main.getAbsolutePath(), utf8);
        for (File trans : translations) {
            String language = trans.getName();
            language = language.substring(language.lastIndexOf('_') + 1, language.lastIndexOf('.'));
View Full Code Here

            p.store(fileName);
        }
    }

    private static void prepare(Properties main, Properties base, File trans, boolean utf8) throws IOException {
        SortedProperties p = load(trans.getAbsolutePath(), utf8);
        Properties oldTranslations = new Properties();
        for (Object k : base.keySet()) {
            String key = (String) k;
            String m = base.getProperty(key);
            String t = p.getProperty(key);
            if (t != null && !t.startsWith("#")) {
                oldTranslations.setProperty(m, t);
            }
        }
        HashSet<String> toTranslate = new HashSet<String>();
        // add missing keys, using # and the value from the main file
        for (Object k : main.keySet()) {
            String key = (String) k;
            String now = main.getProperty(key);
            if (!p.containsKey(key)) {
                String t = oldTranslations.getProperty(now);
                if (t == null) {
                    // System.out.println(trans.getName() +
                    // ": key " + key + " not found in " +
                    // "translation file; added # 'translation'");
                    t = "#" + now;
                    p.put(key, t);
                } else {
                    p.put(key, t);
                }
            } else {
                String t = p.getProperty(key);
                String last = base.getProperty(key);
                if (t.startsWith("#") && !t.startsWith("##")) {
                    // not translated before
                    t = oldTranslations.getProperty(now);
                    if (t == null) {
                        t = "#" + now;
                    }
                    p.put(key, t);
                } else if (last != null && !last.equals(now)) {
                    t = oldTranslations.getProperty(now);
                    if (t == null) {
                        // main data changed since the last run: review translation
                        System.out.println(trans.getName() + ": key " + key + " changed, please review; last=" + last
                                + " now=" + now);
                        String old = p.getProperty(key);
                        t = "#" + now + " #" + old;
                        p.put(key, t);
                    } else {
                        p.put(key, t);
                    }
                }
            }
        }
        for (String key : toTranslate) {
            String now = main.getProperty(key);
            String t;
            System.out.println(trans.getName() + ": key " + key + " not found in translation file; added dummy # 'translation'");
            t = "#" + now;
            p.put(key, t);
        }
        // remove keys that don't exist in the main file (deleted or typo in the key)
        for (Object k : new ArrayList<Object>(p.keySet())) {
            String key = (String) k;
            if (!main.containsKey(key)) {
                p.remove(key);
            }
        }
        store(p, trans.getAbsolutePath(), utf8);
    }
View Full Code Here

        if (!new File(source).exists()) {
            return;
        }
        LineNumberReader reader = new LineNumberReader(new InputStreamReader(new FileInputStream(source), "UTF-8"));
        try {
            SortedProperties prop = new SortedProperties();
            StringBuilder buff = new StringBuilder();
            String key = null;
            boolean found = false;
            while (true) {
                String line = reader.readLine();
                if (line == null) {
                    break;
                }
                line = line.trim();
                if (line.length() == 0) {
                    continue;
                }
                if (line.startsWith("@")) {
                    if (key != null) {
                        prop.setProperty(key, buff.toString());
                        buff.setLength(0);
                    }
                    found = true;
                    key = line.substring(1);
                } else {
                    if (buff.length() > 0) {
                        buff.append(System.getProperty("line.separator"));
                    }
                    buff.append(line);
                }
            }
            if (found) {
                prop.setProperty(key, buff.toString());
            }
            prop.store(target);
        } finally {
            reader.close();
        }
    }
View Full Code Here

    private static String remapURL(String url) {
        String urlMap = SysProperties.URL_MAP;
        if (urlMap != null && urlMap.length() > 0) {
            try {
                SortedProperties prop;
                prop = SortedProperties.loadProperties(urlMap);
                String url2 = prop.getProperty(url);
                if (url2 == null) {
                    prop.put(url, "");
                    prop.store(urlMap);
                } else {
                    url2 = url2.trim();
                    if (url2.length() > 0) {
                        return url2;
                    }
View Full Code Here

    private void lockSerialized() {
        method = SERIALIZED;
        FileUtils.createDirectories(FileUtils.getParent(fileName));
        if (FileUtils.createFile(fileName)) {
            properties = new SortedProperties();
            properties.setProperty("method", String.valueOf(method));
            setUniqueId();
            save();
        } else {
            while (true) {
View Full Code Here

        }
    }

    private void lockFile() {
        method = FILE;
        properties = new SortedProperties();
        properties.setProperty("method", String.valueOf(method));
        setUniqueId();
        FileUtils.createDirectories(FileUtils.getParent(fileName));
        if (!FileUtils.createFile(fileName)) {
            waitUntilOld();
View Full Code Here

TOP

Related Classes of org.h2.util.SortedProperties

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.