Example usage for java.util Hashtable put

List of usage examples for java.util Hashtable put

Introduction

In this page you can find the example usage for java.util Hashtable put.

Prototype

public synchronized V put(K key, V value) 

Source Link

Document

Maps the specified key to the specified value in this hashtable.

Usage

From source file:net.giovannicapuano.visualnovel.Memory.java

public static Hashtable<String, String> getKeyValues(Context context) {
    Hashtable<String, String> keyvalues = new Hashtable<String, String>();

    try {//  www.  j  a  v a  2s.c  o  m
        StringBuffer buffer = new StringBuffer();

        InputStreamReader input = new InputStreamReader(context.openFileInput(KEYVALUES));
        BufferedReader reader = new BufferedReader(input);

        String line;
        while ((line = reader.readLine()) != null)
            buffer.append(line);

        JSONObject json = new JSONObject(buffer.toString());
        Iterator<?> keys = json.keys();

        while (keys.hasNext()) {
            String key = (String) keys.next();
            keyvalues.put(key, json.getString(key));
        }
    } catch (Exception e) {
        Utils.error(e);
    }

    return keyvalues;
}

From source file:edu.ku.brc.dbsupport.DatabaseDriverInfo.java

/**
 * Reads the Form Registry. The forms are loaded when needed and onlu one ViewSet can be the "core" ViewSet which is where most of the forms
 * reside. This could also be thought of as the "default" set of forms.
 * @return the list of info objects//www.ja  v a  2s  .c o m
 */
protected static Vector<DatabaseDriverInfo> loadDatabaseDriverInfo() {
    Vector<DatabaseDriverInfo> dbDrivers = new Vector<DatabaseDriverInfo>();
    try {
        Element root = XMLHelper
                .readFileToDOM4J(new FileInputStream(XMLHelper.getConfigDirPath("dbdrivers.xml"))); //$NON-NLS-1$
        if (root != null) {
            Hashtable<String, String> hash = new Hashtable<String, String>();

            for (Iterator<?> i = root.elementIterator("db"); i.hasNext();) //$NON-NLS-1$
            {
                Element dbElement = (Element) i.next();
                String name = getAttr(dbElement, "name", null); //$NON-NLS-1$

                if (hash.get(name) == null) {
                    hash.put(name, name);

                    String driver = getAttr(dbElement, "driver", null); //$NON-NLS-1$
                    String dialect = getAttr(dbElement, "dialect", null); //$NON-NLS-1$
                    String port = getAttr(dbElement, "port", null); //$NON-NLS-1$
                    boolean isEmbedded = getAttr(dbElement, "embedded", false); //$NON-NLS-1$

                    if (UIRegistry.isEmbedded() || UIRegistry.isMobile()) // Application is Embedded
                    {
                        if (!isEmbedded) {
                            continue;
                        }
                    } else if (isEmbedded) {
                        continue;
                    }

                    // these can go away once we validate the XML
                    if (StringUtils.isEmpty(driver)) {
                        throw new RuntimeException("Driver cannot be null!"); //$NON-NLS-1$
                    }
                    if (StringUtils.isEmpty(driver)) {
                        throw new RuntimeException("Dialect cannot be null!"); //$NON-NLS-1$
                    }

                    DatabaseDriverInfo drv = new DatabaseDriverInfo(name, driver, dialect, isEmbedded, port);

                    // Load up the Connection Types
                    for (Iterator<?> connIter = dbElement.elementIterator("connection"); connIter.hasNext();) //$NON-NLS-1$
                    {
                        Element connElement = (Element) connIter.next();
                        String typeStr = getAttr(connElement, "type", null); //$NON-NLS-1$
                        String connFormat = connElement.getTextTrim();
                        ConnectionType type = ConnectionType.valueOf(StringUtils.capitalize(typeStr));
                        drv.addFormat(type, connFormat);
                    }

                    /*if (drv.getConnectionStr(DatabaseDriverInfo.ConnectionType.Open, " ", " ", " ", " ", " ") == null) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
                    {
                    log.error("Meg might've screwed up generating connection strings, contact her if you get this error"); //$NON-NLS-1$
                    throw new RuntimeException("Dialect ["+name+"] has no 'Open' connection type!"); //$NON-NLS-1$ //$NON-NLS-2$
                    }*/

                    dbDrivers.add(drv);

                } else {
                    log.error("Database Driver Name[" + name + "] is in use."); //$NON-NLS-1$ //$NON-NLS-2$
                }
            }
        } else {
            String msg = "The root element for the document was null!"; //$NON-NLS-1$
            log.error(msg);
            throw new ConfigurationException(msg);
        }
    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DatabaseDriverInfo.class, ex);
        ex.printStackTrace();
        log.error(ex);
    }
    Collections.sort(dbDrivers);
    return dbDrivers;
}

From source file:io.card.development.recording.Recording.java

private static Hashtable<String, byte[]> unzipFiles(InputStream recordingStream) throws IOException {
    ZipEntry zipEntry;/* ww w. j  a  v  a2 s  .  co m*/
    ZipInputStream zis = new ZipInputStream(recordingStream);
    Hashtable<String, byte[]> fileHash = new Hashtable<String, byte[]>();
    byte[] buffer = new byte[512];

    while ((zipEntry = zis.getNextEntry()) != null) {
        if (!zipEntry.isDirectory()) {
            int read = 0;
            ByteArrayOutputStream fileStream = new ByteArrayOutputStream();

            do {
                read = zis.read(buffer, 0, buffer.length);
                if (read != -1) {
                    fileStream.write(buffer, 0, read);
                }
            } while (read != -1);

            byte[] fileData = fileStream.toByteArray();
            fileHash.put(zipEntry.getName(), fileData);
        }
    }

    return fileHash;
}

From source file:com.flexive.shared.EJBLookup.java

/**
 * Adjust the environment with strategy/application server specific settings
 *
 * @param strat       strategy/*from ww w.  j a  v a2s . c o  m*/
 * @param environment environment
 */
private static void prepareEnvironment(STRATEGY strat, Hashtable<String, String> environment) {
    if (strat == STRATEGY.GERONIMO_LOCAL || strat == STRATEGY.GERONIMO_REMOTE) {
        environment.put("java.naming.factory.initial",
                strat == STRATEGY.GERONIMO_LOCAL ? "org.apache.openejb.client.LocalInitialContextFactory"
                        : "org.apache.openejb.client.RemoteInitialContextFactory");
        if (!StringUtils.isEmpty(System.getProperty("java.naming.provider.url")))
            environment.put("java.naming.provider.url", System.getProperty("java.naming.provider.url"));
        else
            environment.put("java.naming.provider.url", "localhost:4201");
    }
}

From source file:info.magnolia.cms.module.ModuleUtil.java

/**
 * Register a servlet based on the definition of the modules xml descriptor
 * @param servlet/*from   ww w.j a  v a 2 s  .  com*/
 * @throws JDOMException
 * @throws IOException
 */
public static boolean registerServlet(ServletDefinition servlet) throws JDOMException, IOException {
    String[] urlPatterns = (String[]) servlet.getMappings().toArray(new String[servlet.getMappings().size()]);
    Hashtable params = new Hashtable();
    for (Iterator iter = servlet.getParams().iterator(); iter.hasNext();) {
        ServletParameterDefinition param = (ServletParameterDefinition) iter.next();
        params.put(param.getName(), param.getValue());
    }
    return registerServlet(servlet.getName(), servlet.getClassName(), urlPatterns, servlet.getComment(),
            params);
}

From source file:com.icesoft.faces.webapp.parser.JspPageToDocument.java

/**
 * @param input//from   ww  w .  j a  v a  2  s. c  o  m
 * @return String
 */
public static String transform(String input) {
    String result = input;

    Pattern jspDeclarationPattern = Pattern.compile(JSP_DECL_PATTERN, Pattern.DOTALL);
    Matcher jspDeclarationMatcher = jspDeclarationPattern.matcher(result);
    if (!jspDeclarationMatcher.find()) {
        //no JSP declarations, must be a JSP Document, not a page
        return (preprocessJspDocument(result));
    }

    result = performStaticInclude(STATIC_INCLUDE_PATTERN, input);

    result = toLowerHTML(result);

    Pattern jspTaglibPattern = Pattern.compile(JSP_TAGLIB_PATTERN, Pattern.DOTALL);
    Pattern openTagPattern = Pattern.compile(OPEN_TAG_PATTERN, Pattern.DOTALL);
    Pattern attributePattern = Pattern.compile(ATTRIBUTE_PATTERN, Pattern.DOTALL);
    Pattern prefixPattern = Pattern.compile(PREFIX_PATTERN, Pattern.DOTALL);
    Pattern uriPattern = Pattern.compile(URI_PATTERN, Pattern.DOTALL);

    Hashtable declarationsTable = new Hashtable();
    Matcher jspTaglibMatcher = jspTaglibPattern.matcher(result);
    declarationsTable.put("xmlns:jsp", "jsp");
    declarationsTable.put("xmlns:icefaces", "http://www.icesoft.com/icefaces");

    while (jspTaglibMatcher.find()) {
        String attributes = jspTaglibMatcher.group(1);
        Matcher prefixMatcher = prefixPattern.matcher(attributes);
        Matcher uriMatcher = uriPattern.matcher(attributes);
        prefixMatcher.find();
        uriMatcher.find();
        String prefix = prefixMatcher.group(1);
        String url = uriMatcher.group(1);
        declarationsTable.put("xmlns:" + prefix, url);
    }

    Matcher openTagMatcher = openTagPattern.matcher(result);
    openTagMatcher.find();
    String tag = openTagMatcher.group(1);
    String attributes = openTagMatcher.group(2);

    Matcher attributeMatcher = attributePattern.matcher(attributes);
    while (attributeMatcher.find()) {
        String name = attributeMatcher.group(1);
        String value = attributeMatcher.group(2);
        declarationsTable.put(name, value);
    }

    Enumeration declarations = declarationsTable.keys();
    String namespaceDeclarations = "";
    while (declarations.hasMoreElements()) {
        String prefix = (String) declarations.nextElement();
        String url = (String) declarationsTable.get(prefix);
        namespaceDeclarations += prefix + "=\"" + url + "\" ";
    }

    jspDeclarationMatcher = jspDeclarationPattern.matcher(result);
    result = jspDeclarationMatcher.replaceAll("");

    //ensure single root tag for all JSPs as per bug 361
    result = "<icefaces:root " + namespaceDeclarations + ">" + result + "</icefaces:root>";

    Pattern jspIncludePattern = Pattern.compile(JSP_INCLUDE_PATTERN);
    Matcher jspIncludeMatcher = jspIncludePattern.matcher(result);
    StringBuffer jspIncludeBuf = new StringBuffer();
    while (jspIncludeMatcher.find()) {
        String args = jspIncludeMatcher.group(1);
        jspIncludeMatcher.appendReplacement(jspIncludeBuf,
                "<icefaces:include" + args + " isDynamic=\"#{true}\" />");
    }
    jspIncludeMatcher.appendTail(jspIncludeBuf);
    result = jspIncludeBuf.toString();

    //Fix HTML
    result = toSingletonTag(P_TAG_PATTERN, result);
    result = toSingletonTag(LINK_TAG_PATTERN, result);
    result = toSingletonTag(META_TAG_PATTERN, result);
    result = toSingletonTag(IMG_TAG_PATTERN, result);
    result = toSingletonTag(INPUT_TAG_PATTERN, result);

    Pattern brTagPattern = Pattern.compile(BR_TAG_PATTERN);
    Matcher brTagMatcher = brTagPattern.matcher(result);
    result = brTagMatcher.replaceAll("<br/>");

    Pattern hrTagPattern = Pattern.compile(HR_TAG_PATTERN);
    Matcher hrTagMatcher = hrTagPattern.matcher(result);
    result = hrTagMatcher.replaceAll("<hr/>");

    Pattern nbspEntityPattern = Pattern.compile(NBSP_ENTITY_PATTERN);
    Matcher nbspEntityMatcher = nbspEntityPattern.matcher(result);
    //  result = nbspEntityMatcher.replaceAll("&nbsp;");
    result = nbspEntityMatcher.replaceAll("&amp;nbsp");

    Pattern copyEntityPattern = Pattern.compile(COPY_ENTITY_PATTERN);
    Matcher copyEntityMatcher = copyEntityPattern.matcher(result);
    result = copyEntityMatcher.replaceAll("&#169;");

    Pattern docDeclPattern = Pattern.compile(DOC_DECL_PATTERN);
    Matcher docDeclMatcher = docDeclPattern.matcher(result);
    result = docDeclMatcher.replaceAll("");

    result = unescapeBackslash(result);

    return result;
}

From source file:com.greenpepper.server.rpc.xmlrpc.XmlRpcDataMarshaller.java

/**
 * Wraps the error message id into a Hashtable where exception is the key and
 * the value is a Vector of Vector of String.<br>
 * Structure of the error:<br>/*w w w  .j  a va 2  s . c  o m*/
 * Hashtable[TAG_ERROR, Vector[Vector[TAG_ERROR errorId]]]
 * </p>
 *
 * @param msgId a {@link java.lang.String} object.
 * @return the error message id as a Hashtable.
 */
public static Hashtable<String, Vector<Object>> errorAsHastable(String msgId) {
    Hashtable<String, Vector<Object>> table = new Hashtable<String, Vector<Object>>();
    table.put(GreenPepperServerErrorKey.ERROR, errorAsVector(msgId));
    return table;
}

From source file:edu.ucsb.nceas.MCTestCase.java

protected static Vector<Hashtable<String, Object>> dbSelect(String sqlStatement, String methodName)
        throws SQLException {
    Vector<Hashtable<String, Object>> resultVector = new Vector<Hashtable<String, Object>>();

    DBConnectionPool connPool = DBConnectionPool.getInstance();
    DBConnection dbconn = DBConnectionPool.getDBConnection(methodName);
    int serialNumber = dbconn.getCheckOutSerialNumber();

    PreparedStatement pstmt = null;

    debug("Selecting from db: " + sqlStatement);
    pstmt = dbconn.prepareStatement(sqlStatement);
    pstmt.execute();/*from  www  .  j a v a 2s. c  om*/

    ResultSet resultSet = pstmt.getResultSet();
    ResultSetMetaData rsMetaData = resultSet.getMetaData();
    int numColumns = rsMetaData.getColumnCount();
    debug("Number of data columns: " + numColumns);
    while (resultSet.next()) {
        Hashtable<String, Object> hashTable = new Hashtable<String, Object>();
        for (int i = 1; i <= numColumns; i++) {
            if (resultSet.getObject(i) != null) {
                hashTable.put(rsMetaData.getColumnName(i), resultSet.getObject(i));
            }
        }
        debug("adding data row to result vector");
        resultVector.add(hashTable);
    }

    resultSet.close();
    pstmt.close();
    DBConnectionPool.returnDBConnection(dbconn, serialNumber);

    return resultVector;
}

From source file:net.daimonin.client3d.editor.main.Editor3D.java

/**
* Builds image groups/categories by file name, creates and writes the XML
* containing all images with their attributes.
* 
* @param fileNameImageSet Name of resulting PNG.
* @param fileNameXML Name of the XML./*  w  w  w  . j  av  a  2  s  .c  o  m*/
* @throws IOException IOException.
*/
private static void writeXML(final String fileNameImageSet, final String fileNameXML) throws IOException {

    // group ImageSetImages by name/category.
    // the left side of the image file name up to the '_' is taken as the
    // category
    Hashtable<String, List<ImageSetImage>> names = new Hashtable<String, List<ImageSetImage>>();
    for (int i = 0; i < images.size(); i++) {
        if (!names.containsKey(images.get(i).getName())) {
            List<ImageSetImage> values = new ArrayList<ImageSetImage>();
            values.add(images.get(i));
            names.put(images.get(i).getName(), values);
        } else {
            names.get(images.get(i).getName()).add(images.get(i));
        }
    }

    // check if every category has a default state (except FontExtensions)
    Enumeration<String> keys2 = names.keys();
    while (keys2.hasMoreElements()) {
        List<ImageSetImage> img2 = names.get(keys2.nextElement());
        if (!"fontextensions".equals(img2.get(0).getName())) {
            boolean hasDefault = false;
            for (int i = 0; i < img2.size(); i++) {
                if ("default".equals(img2.get(i).getState().toLowerCase())) {
                    hasDefault = true;
                }
            }
            if (!hasDefault) {
                printError("WARNING: image category '" + img2.get(0).getName()
                        + "' has no image with a default state!");
            }
        }
    }

    // create the XML structure
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("ImageSet").addAttribute("file", fileNameImageSet);

    List<ImageSetImage> fntex = names.get("fontextensions");
    if (fntex != null) {
        Element category = root.addElement("ImageFntExt").addAttribute("name", fntex.get(0).getName());
        for (int i = 0; i < fntex.size(); i++) {
            category.addElement("State").addAttribute("name", fntex.get(i).getState())
                    .addAttribute("posX", String.valueOf(fntex.get(i).getPosX() + fntex.get(i).getBorderSize()))
                    .addAttribute("posY", String.valueOf(fntex.get(i).getPosY() + fntex.get(i).getBorderSize()))
                    .addAttribute("width", String.valueOf(fntex.get(i).getWidth()))
                    .addAttribute("height", String.valueOf(fntex.get(i).getHeight()));
        }
        names.remove("fontextensions");
    }

    List<ImageSetImage> mouse = names.get("mousecursor");
    if (mouse != null) {
        Element category = root.addElement("Image").addAttribute("name", mouse.get(0).getName())
                .addAttribute("width", String.valueOf(mouse.get(0).getImage().getWidth()))
                .addAttribute("height", String.valueOf(mouse.get(0).getImage().getHeight()))
                .addAttribute("alpha", mouse.get(0).getImage().getColorModel().hasAlpha() ? String.valueOf(1)
                        : String.valueOf(0));

        for (int i = 0; i < mouse.size(); i++) {
            checkImageSameDimension(mouse.get(0), mouse.get(i),
                    "Images of same category have different dimension");
            checkImageSameAlpha(mouse.get(0), mouse.get(i), "Images of same category have different alpha");
            category.addElement("State").addAttribute("name", mouse.get(i).getState())
                    .addAttribute("posX", String.valueOf(mouse.get(i).getPosX() + mouse.get(i).getBorderSize()))
                    .addAttribute("posY",
                            String.valueOf(mouse.get(i).getPosY() + mouse.get(i).getBorderSize()));
        }
        names.remove("mousecursor");
    }

    Enumeration<String> keys = names.keys();
    while (keys.hasMoreElements()) {
        List<ImageSetImage> img = names.get(keys.nextElement());
        Element category = root.addElement("Image").addAttribute("name", img.get(0).getName())
                .addAttribute("width", String.valueOf(img.get(0).getImage().getWidth()))
                .addAttribute("height", String.valueOf(img.get(0).getImage().getHeight()))
                .addAttribute("alpha", img.get(0).getImage().getColorModel().hasAlpha() ? String.valueOf(1)
                        : String.valueOf(0));

        for (int i = 0; i < img.size(); i++) {
            checkImageSameDimension(img.get(0), img.get(i), "Images of same category have different dimension");
            checkImageSameAlpha(img.get(0), img.get(i), "Images of same category have different alpha");
            category.addElement("State").addAttribute("name", img.get(i).getState())
                    .addAttribute("posX", String.valueOf(img.get(i).getPosX() + img.get(i).getBorderSize()))
                    .addAttribute("posY", String.valueOf(img.get(i).getPosY() + img.get(i).getBorderSize()));
        }
    }

    // write the XML
    OutputFormat format = OutputFormat.createPrettyPrint();
    XMLWriter writer = new XMLWriter(new FileWriter(fileNameXML), format);
    writer.write(document);
    writer.close();
    printInfo(System.getProperty("user.dir") + "/" + imagesetxml + " created");
}

From source file:edu.ku.brc.specify.extras.ViewToSchemaReview.java

/**
 * /*  w  w w . j  av a2 s  .  c o m*/
 */
public static void dumpFormFieldList(final boolean doShowInBrowser) {
    List<ViewIFace> viewList = ((SpecifyAppContextMgr) AppContextMgr.getInstance()).getEntirelyAllViews();
    Hashtable<String, ViewIFace> hash = new Hashtable<String, ViewIFace>();

    for (ViewIFace view : viewList) {
        hash.put(view.getName(), view);
    }
    Vector<String> names = new Vector<String>(hash.keySet());
    Collections.sort(names);

    try {
        File file = new File("FormFields.html");
        PrintWriter pw = new PrintWriter(file);

        pw.println(
                "<HTML><HEAD><TITLE>Form Fields</TITLE><link rel=\"stylesheet\" href=\"http://specify6.specifysoftware.org/schema/specify6.css\" type=\"text/css\"/></HEAD><BODY>");
        pw.println("<center>");
        pw.println("<H2>Forms and Fields</H2>");
        pw.println("<center><table class=\"brdr\" border=\"0\" cellspacing=\"0\">");

        int formCnt = 0;
        int fieldCnt = 0;
        for (String name : names) {
            ViewIFace view = hash.get(name);
            boolean hasEdit = false;
            for (AltViewIFace altView : view.getAltViews()) {
                if (altView.getMode() != AltViewIFace.CreationMode.EDIT) {
                    hasEdit = true;
                    break;
                }
            }

            //int numViews = view.getAltViews().size();
            for (AltViewIFace altView : view.getAltViews()) {
                //AltView av = (AltView)altView;
                if ((hasEdit && altView.getMode() == AltViewIFace.CreationMode.VIEW)) {
                    ViewDefIFace vd = altView.getViewDef();
                    if (vd instanceof FormViewDef) {
                        formCnt++;
                        FormViewDef fvd = (FormViewDef) vd;
                        pw.println("<tr><td class=\"brdrodd\">");
                        pw.println(fvd.getName());
                        pw.println("</td></tr>");
                        int r = 1;
                        for (FormRowIFace fri : fvd.getRows()) {
                            FormRow fr = (FormRow) fri;
                            for (FormCellIFace cell : fr.getCells()) {
                                if (StringUtils.isNotEmpty(cell.getName())) {
                                    if (cell.getType() == FormCellIFace.CellType.panel) {
                                        FormCellPanelIFace panelCell = (FormCellPanelIFace) cell;
                                        for (String fieldName : panelCell.getFieldNames()) {
                                            pw.print("<tr><td ");
                                            pw.print("class=\"");
                                            pw.print(r % 2 == 0 ? "brdrodd" : "brdreven");
                                            pw.print("\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + fieldName);
                                            pw.println("</td></tr>");
                                            fieldCnt++;
                                        }

                                    } else if (cell.getType() == FormCellIFace.CellType.field
                                            || cell.getType() == FormCellIFace.CellType.subview) {
                                        pw.print("<tr><td ");
                                        pw.print("class=\"");
                                        pw.print(r % 2 == 0 ? "brdrodd" : "brdreven");
                                        pw.print("\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + cell.getName());
                                        pw.println("</td></tr>");
                                        fieldCnt++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        pw.println("</table></center><br>");
        pw.println("Number of Forms: " + formCnt + "<br>");
        pw.println("Number of Fields: " + fieldCnt + "<br>");
        pw.println("</body></html>");
        pw.close();

        try {
            if (doShowInBrowser) {
                AttachmentUtils.openURI(file.toURI());
            } else {
                JOptionPane.showMessageDialog(getTopWindow(),
                        String.format(getResourceString("FormDisplayer.OUTPUT"), file.getCanonicalFile()));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}