Example usage for org.apache.commons.collections.map HashedMap put

List of usage examples for org.apache.commons.collections.map HashedMap put

Introduction

In this page you can find the example usage for org.apache.commons.collections.map HashedMap put.

Prototype

public Object put(Object key, Object value) 

Source Link

Document

Puts a key-value mapping into this map.

Usage

From source file:com.danidemi.templategeneratormavenplugin.maven.JuelRowFilterTest.java

private IRowModel newContextWithA(int a) {
    HashedMap context = new HashedMap();
    context.put("a", a);
    InMemoryRowModel rowModel = new InMemoryRowModel(context, new RowMetaModel(1, 2));
    return rowModel;
}

From source file:com.pureinfo.srm.reports.attendant.EnglishSubjectsOfProductFilter.java

/**
 * @see com.pureinfo.report.element.INeedRequestParameter#addParameters(java.util.Set)
 *//*w w w .  ja  v a 2  s  . co  m*/
public void addParameters(Set _sArg0) throws PureException {
    Parameter param = new Parameter();
    param.setHints(new String[] { "" });
    param.setType(ParameterHelper.TYPE_SELECT);
    param.setName(m_subject.makeParamName());
    HashedMap infos = new HashedMap(1);
    List subjects = EnglishSubjectHelper.enumSubjects();

    String options = StringUtils.join(subjects.iterator(), "###");
    infos.put("values", "###" + options);
    infos.put("names", "----###" + options);
    infos.put("separtor", "###");
    param.setInfos(infos);
    _sArg0.add(param);
}

From source file:com.userweave.csv.AbstractModuleCsvConverter.java

@SuppressWarnings({ "rawtypes", "unchecked" })
protected List<AbstractCsvCell> getRowForSurveyExecution(HashedMap map, Object result) {
    List<AbstractCsvCell> row;

    // is there already a row?
    if (map.containsKey(result)) {
        row = (List<AbstractCsvCell>) map.get(result);
    } else {// w ww .j a  v a2  s  .co m
        row = new LinkedList<AbstractCsvCell>();
        map.put(result, row);
    }

    return row;
}

From source file:it.eng.spagobi.engines.exporters.KpiExporter.java

public File getKpiReportPDF(List<KpiResourceBlock> kpiBlocks, BIObject obj, String userId) throws Exception {
    logger.debug("IN");

    //Build report template
    String docName = (obj != null) ? obj.getName() : "";
    BasicTemplateBuilder basic = new BasicTemplateBuilder(docName);
    String template2 = "";
    List templates = basic.buildTemplate(kpiBlocks);
    boolean first = true;

    //String template2=basic.buildTemplate(kpiBlocks);

    //System.out.println(template2);

    String outputType = "PDF";
    HashedMap parameters = new HashedMap();
    parameters.put("PARAM_OUTPUT_FORMAT", outputType);

    //parameters.put("SBI_HTTP_SESSION", session);   ???

    JREmptyDataSource conn = new JREmptyDataSource(1);

    // identity string for object execution
    UUIDGenerator uuidGen = UUIDGenerator.getInstance();
    UUID uuid_local = uuidGen.generateTimeBasedUUID();
    String executionId = uuid_local.toString();
    executionId = executionId.replaceAll("-", "");

    //Creta etemp file
    String dirS = System.getProperty("java.io.tmpdir");
    File dir = new File(dirS);
    dir.mkdirs();//w  w w  .j a v a2  s .c o  m

    List filesToDelete = new ArrayList();
    logger.debug("Create Temp File");
    String fileName = "report" + executionId;
    File tmpFile = File.createTempFile(fileName, "." + outputType, dir);
    OutputStream out = new FileOutputStream(tmpFile);
    try {
        if (templates != null && !templates.isEmpty()) {
            int subreports = 0;
            Iterator it = templates.iterator();
            while (it.hasNext()) {
                String template = (String) it.next();
                if (first)
                    template2 = template;
                else {

                    File f = new File(dirS + File.separatorChar + "Detail" + subreports + ".jasper");
                    logger.debug("Compiling subtemplate file: " + f);
                    filesToDelete.add(f);

                    File file = new File(dirS + File.separatorChar + "Detail" + subreports + ".jrxml");
                    if (file.exists()) {
                        boolean deleted = file.delete();
                        file = new File(dirS + File.separatorChar + "Detail" + subreports + ".jrxml");
                    }
                    FileOutputStream stream = new FileOutputStream(file);
                    stream.write(template.getBytes());
                    stream.flush();
                    stream.close();
                    filesToDelete.add(file);

                    JasperCompileManager.compileReportToFile(
                            dirS + File.separatorChar + "Detail" + subreports + ".jrxml",
                            dirS + File.separatorChar + "Detail" + subreports + ".jasper");
                    subreports++;
                }
                first = false;
            }
        }

        File f = new File(dirS + File.separatorChar + "Master.jasper");
        logger.debug("Compiling subtemplate file: " + f);
        filesToDelete.add(f);

        File file = new File(dirS + File.separatorChar + "Master.jrxml");
        if (file.exists()) {
            boolean deleted = file.delete();
            file = new File(dirS + File.separatorChar + "Master.jrxml");
        }
        FileOutputStream stream = new FileOutputStream(file);
        stream.write(template2.getBytes());
        stream.flush();
        stream.close();
        filesToDelete.add(file);

        StringBufferInputStream sbis = new StringBufferInputStream(template2);
        JasperCompileManager.compileReportToFile(dirS + File.separatorChar + "Master.jrxml",
                dirS + File.separatorChar + "Master.jasper");

        logger.debug("Filling report ...");
        Context ctx = new InitialContext();
        Session aSession = HibernateUtil.currentSession();
        JasperPrint jasperPrint = null;
        try {
            Transaction tx = aSession.beginTransaction();
            //Connection jdbcConnection = aSession.connection();
            Connection jdbcConnection = HibernateUtil.getConnection(aSession);
            jasperPrint = JasperFillManager.fillReport(dirS + File.separatorChar + "Master.jasper", parameters,
                    jdbcConnection);
            logger.debug("Report filled succesfully");
        } finally {
            if (aSession != null) {
                if (aSession.isOpen())
                    aSession.close();
            }
        }
        logger.debug("Exporting report: Output format is [" + outputType + "]");
        JRExporter exporter = null;
        //JRExporter exporter = ExporterFactory.getExporter(outputType);   
        // Set the PDF exporter
        exporter = (JRExporter) Class.forName("net.sf.jasperreports.engine.export.JRPdfExporter").newInstance();

        if (exporter == null)
            exporter = new JRPdfExporter();

        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
        exporter.exportReport();
        logger.debug("Report exported succesfully");
        //in = new BufferedInputStream(new FileInputStream(tmpFile));
        logger.debug("OUT");
        return tmpFile;

    } catch (Throwable e) {
        logger.error("An exception has occured", e);
        throw new Exception(e);
    } finally {
        out.flush();
        out.close();
        if (filesToDelete != null && !filesToDelete.isEmpty()) {
            Iterator it = filesToDelete.iterator();
            while (it.hasNext()) {
                File temp = (File) it.next();
                temp.delete();
            }
        }
        //tmpFile.delete();

    }

}

From source file:it.eng.spagobi.analiticalmodel.execution.service.PrintNotesAction.java

public void doService() {
    logger.debug("IN");

    ExecutionInstance executionInstance;
    executionInstance = getContext().getExecutionInstance(ExecutionInstance.class.getName());
    String executionIdentifier = new BIObjectNotesManager()
            .getExecutionIdentifier(executionInstance.getBIObject());
    Integer biobjectId = executionInstance.getBIObject().getId();
    List globalObjNoteList = null;
    try {//from w  ww  .j  a v  a2  s .  co  m
        globalObjNoteList = DAOFactory.getObjNoteDAO().getListExecutionNotes(biobjectId, executionIdentifier);
    } catch (EMFUserError e1) {
        logger.error("Error in retrieving obj notes", e1);
        return;
    } catch (Exception e1) {
        logger.error("Error in retrieving obj notes", e1);
        return;
    }
    //mantains only the personal notes and others one only if they have PUBLIC status
    List objNoteList = new ArrayList();
    UserProfile profile = (UserProfile) this.getUserProfile();
    String userId = (String) profile.getUserId();
    for (int i = 0, l = globalObjNoteList.size(); i < l; i++) {
        ObjNote objNote = (ObjNote) globalObjNoteList.get(i);
        if (objNote.getIsPublic()) {
            objNoteList.add(objNote);
        } else if (objNote.getOwner().equalsIgnoreCase(userId)) {
            objNoteList.add(objNote);
        }
    }

    String outputType = "PDF";
    RequestContainer requestContainer = getRequestContainer();
    SourceBean sb = requestContainer.getServiceRequest();
    outputType = (String) sb.getAttribute(SBI_OUTPUT_TYPE);
    if (outputType == null)
        outputType = "PDF";

    String templateStr = getTemplateTemplate();

    //JREmptyDataSource conn=new JREmptyDataSource(1);
    //Connection conn = getConnection("SpagoBI",getHttpSession(),profile,obj.getId().toString());      
    JRBeanCollectionDataSource datasource = new JRBeanCollectionDataSource(objNoteList);

    HashedMap parameters = new HashedMap();
    parameters.put("PARAM_OUTPUT_FORMAT", outputType);
    parameters.put("TITLE", executionInstance.getBIObject().getLabel());

    UUIDGenerator uuidGen = UUIDGenerator.getInstance();
    UUID uuid_local = uuidGen.generateTimeBasedUUID();
    String executionId = uuid_local.toString();
    executionId = executionId.replaceAll("-", "");
    //Creta etemp file
    String dirS = System.getProperty("java.io.tmpdir");
    File dir = new File(dirS);
    dir.mkdirs();
    String fileName = "notes" + executionId;
    OutputStream out = null;
    File tmpFile = null;
    try {
        tmpFile = File.createTempFile(fileName, "." + outputType, dir);
        out = new FileOutputStream(tmpFile);
        StringBufferInputStream sbis = new StringBufferInputStream(templateStr);
        logger.debug("compiling report");
        JasperReport report = JasperCompileManager.compileReport(sbis);
        //report.setProperty("", )
        logger.debug("filling report");
        JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, datasource);
        JRExporter exporter = null;
        if (outputType.equalsIgnoreCase("PDF")) {
            exporter = (JRExporter) Class.forName("net.sf.jasperreports.engine.export.JRPdfExporter")
                    .newInstance();
            if (exporter == null)
                exporter = new JRPdfExporter();
        } else {
            exporter = (JRExporter) Class.forName("net.sf.jasperreports.engine.export.JRRtfExporter")
                    .newInstance();
            if (exporter == null)
                exporter = new JRRtfExporter();
        }

        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
        logger.debug("exporting report");
        exporter.exportReport();

    } catch (Throwable e) {
        logger.error("An exception has occured", e);
        return;
    } finally {
        try {
            out.flush();
            out.close();
        } catch (IOException e) {
            logger.error("Error closing output", e);
        }
    }

    String mimeType;
    if (outputType.equalsIgnoreCase("RTF")) {
        mimeType = "application/rtf";
    } else {
        mimeType = "application/pdf";
    }

    HttpServletResponse response = getHttpResponse();
    response.setContentType(mimeType);
    response.setHeader("Content-Disposition", "filename=\"report." + outputType + "\";");
    response.setContentLength((int) tmpFile.length());
    try {
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(tmpFile));
        int b = -1;
        while ((b = in.read()) != -1) {
            response.getOutputStream().write(b);
        }
        response.getOutputStream().flush();
        in.close();
    } catch (Exception e) {
        logger.error("Error while writing the content output stream", e);
    } finally {
        tmpFile.delete();
    }

    logger.debug("OUT");

}

From source file:com.octo.captcha.engine.bufferedengine.manager.QuartzBufferedEngineManager.java

/**
 * @see com.octo.captcha.engine.bufferedengine.manager.BufferedEngineContainerManager#getVolatileBufferSizeByLocales
 *///from   w  ww .jav a2s  .  com
public HashedMap getVolatileBufferSizeByLocales() {
    HashedMap map = new HashedMap();

    Iterator it = container.getVolatileBuffer().getLocales().iterator();
    while (it.hasNext()) {
        Locale locale = (Locale) it.next();
        map.put(locale, new Integer(container.getVolatileBuffer().size(locale)));
    }
    return map;
}

From source file:com.octo.captcha.engine.bufferedengine.manager.QuartzBufferedEngineManager.java

/**
 * @see com.octo.captcha.engine.bufferedengine.manager.BufferedEngineContainerManager#getPersistentBufferSizesByLocales
 *///from   w  w  w .j  a  v  a 2  s  .co  m
public HashedMap getPersistentBufferSizesByLocales() {
    HashedMap map = new HashedMap();

    Iterator it = container.getPersistentBuffer().getLocales().iterator();
    while (it.hasNext()) {
        Locale locale = (Locale) it.next();
        map.put(locale, new Integer(container.getPersistentBuffer().size(locale)));
    }
    return map;
}

From source file:herddb.model.Transaction.java

public void registerLockOnTable(String tableName, LockHandle handle) {
    HashedMap ll = locks.get(tableName);
    if (ll == null) {
        ll = new HashedMap();
        locks.put(tableName, ll);//from   w w  w.j a  v  a2  s.com
    }
    ll.put(handle.key, handle);
}

From source file:com.orange.mmp.api.helpers.DefaultApiContainer.java

public Api addApi(Api api, Object apiImpl) throws MMPApiException {
    //Check if DefinitionClass is an interface
    if (!api.getDefinitionClass().isInterface()) {
        throw new MMPApiException("Definition class " + api.getDefinitionClass() + " of api " + api.getName()
                + " is not an interface");
    }/*from  w w  w  . j  ava 2s .  c o  m*/
    //List method of service for caching purpose
    HashedMap methodsMap = new HashedMap();
    for (Method method : api.getDefinitionClass().getMethods()) {
        // TODO Fix this to find a way to add multiple methods with same name
        //if(methodsMap.containsKey(method.getName())) throw new MMPApiException("Duplicated method name "+method.getName()+" in api "+api.getName());
        methodsMap.put(method.getName(), method);
    }

    synchronized (this.apiCache) {
        //Add it to service cache
        this.apiCache.put(api, new Element(api, new Element(apiImpl, methodsMap)));

        //Notify ServiceObservers of new service availability
        ApiEvent apiEvent = new ApiEvent(ApiEvent.API_ADDED, api);
        for (ApiObserver serviceObserver : this.apiObservers) {
            serviceObserver.onApiEvent(apiEvent);
        }
    }

    return api;
}

From source file:com.octo.captcha.engine.bufferedengine.BufferedEngineContainer.java

/**
 * Method launch by a scheduler to swap captcha from disk buffer to the memory buffer. The ratio of swaping for each
 * locale is defined in the configuration component.
 *//*from  ww  w  . ja  v a 2s  .  c  om*/
public void swapCaptchasFromPersistentToVolatileMemory() {

    log.debug("entering swapCaptchasFromDiskBufferToMemoryBuffer()");

    MapIterator it = config.getLocaleRatio().mapIterator();

    //construct the map of swap size by locales;
    HashedMap captchasRatios = new HashedMap();
    while (it.hasNext()) {

        Locale locale = (Locale) it.next();
        double ratio = ((Double) it.getValue()).doubleValue();
        int ratioCount = (int) Math.round(config.getSwapSize().intValue() * ratio);

        //get the reminding size corresponding to the ratio
        int diff = (int) Math
                .round((config.getMaxVolatileMemorySize().intValue() - this.volatileBuffer.size()) * ratio);

        diff = diff < 0 ? 0 : diff;
        int toSwap = (diff < ratioCount) ? diff : ratioCount;

        captchasRatios.put(locale, new Integer(toSwap));
    }
    //get them from persistent buffer
    Iterator captchasRatiosit = captchasRatios.mapIterator();

    while (captchasRatiosit.hasNext() && !shutdownCalled) {
        Locale locale = (Locale) captchasRatiosit.next();
        int swap = ((Integer) captchasRatios.get(locale)).intValue();
        if (log.isDebugEnabled()) {
            log.debug("try to swap  " + swap + " Captchas from persistent to volatile memory with locale : "
                    + locale.toString());
        }

        Collection temp = this.persistentBuffer.removeCaptcha(swap, locale);

        this.volatileBuffer.putAllCaptcha(temp, locale);
        if (log.isDebugEnabled()) {
            log.debug("swaped  " + temp.size() + " Captchas from persistent to volatile memory with locale : "
                    + locale.toString());
        }
        //stats
        persistentMemoryHits += temp.size();
    }

    if (log.isDebugEnabled()) {
        log.debug("new volatil Buffer size : " + volatileBuffer.size());
    }
    // stats
    persistentToVolatileSwaps++;
}