Example usage for java.util Hashtable elements

List of usage examples for java.util Hashtable elements

Introduction

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

Prototype

public synchronized Enumeration<V> elements() 

Source Link

Document

Returns an enumeration of the values in this hashtable.

Usage

From source file:org.accada.reader.rprm.core.ReaderDevice.java

/**
 * Conversion of Hashtable of notification channels to a notification.
 * channels array/*from   w w w . j  a va  2s.  c  o  m*/
 * @param h
 *           The hashtable to convert
 * @return The array
 */
public final NotificationChannel[] notificationChannelsToArray(final Hashtable h) {

    NotificationChannel[] array = new NotificationChannel[h.size()];
    Enumeration iterator = h.elements();
    int i = 0;
    while (iterator.hasMoreElements()) {
        array[i] = (NotificationChannel) iterator.nextElement();
        i++;
    }

    return array;

}

From source file:org.accada.reader.rprm.core.ReaderDevice.java

/**
 * Conversion of Hashtable of tag fields to a tag field array.
 * @param h//from   ww  w.  j a v a2 s.  c om
 *           The hashtable to convert
 * @return The array
 */
public final TagField[] tagFieldsToArray(final Hashtable h) {

    TagField[] array = new TagField[h.size()];
    Enumeration iterator = h.elements();
    int i = 0;
    while (iterator.hasMoreElements()) {
        array[i] = (TagField) iterator.nextElement();
        i++;
    }

    return array;

}

From source file:org.accada.reader.rprm.core.Source.java

/**
 * Writes the specified TagFieldValues to one or more tags. A list of
 * TagSelector objects can be used to select a set of tags, in the readers
 * field of view, for writing.//from w ww .  java  2s .  co  m
 * @param tagFieldValueList
 *           The date to write on the tag
 * @param passwords
 *           An optional list of one or more passwords (or lock code). The
 *          use of passwords is dependent upon the tag's RF protocol
 * @param tagSelectorList
 *           The tag selectors
 * @throws ReaderProtocolException
 *            "ERROR_UNKNOWN"
 */
public void write(TagFieldValue[] tagFieldValueList, final String[] passwords,
        final TagSelector[] tagSelectorList) throws ReaderProtocolException {

    Hashtable tagSelectors;
    if (tagSelectorList == null) {
        tagSelectors = this.tagSelectors;
    } else {
        tagSelectors = new Hashtable();
        for (int i = 0; i < tagSelectorList.length; i++) {
            tagSelectors.put(tagSelectorList[i].getName(), tagSelectorList[i]);
        }
    }

    Hashtable tagFieldValues = new Hashtable();
    for (int i = 0; i < tagFieldValueList.length; i++) {
        tagFieldValues.put(tagFieldValueList[i].getTagField().getName(), tagFieldValueList[i]);
    }

    // get all tags in range
    ReadReport report = rawReadIDs(null);

    // possible exceptions : TagMemoryServiceException, HardwareException
    try {

        // get relevant readers and their readpoints
        Vector closure = getReaderAndReadPoints();

        // get relevant tags out of the report
        Hashtable tags = getRelevantTags(report, tagSelectors, closure);

        // tags
        Enumeration tagIterator = tags.elements();
        TagType curTag;
        while (tagIterator.hasMoreElements()) {
            curTag = (TagType) tagIterator.nextElement();

            // closure
            Enumeration closureIterator = closure.elements();
            ReaderAndReadPoints curClosure;
            while (closureIterator.hasMoreElements()) {
                curClosure = (ReaderAndReadPoints) closureIterator.nextElement();

                HardwareAbstraction reader = curClosure.getReader();
                String[] readPointNames = curClosure.getAllReadPointsAsArray();
                for (int i = 0; i < readPointNames.length; i++) {
                    Enumeration tagFieldIterator = tagFieldValues.elements();
                    TagFieldValue curTagFieldValue;
                    while (tagFieldIterator.hasMoreElements()) {
                        curTagFieldValue = (TagFieldValue) tagFieldIterator.nextElement();
                        try {
                            // assemble byte array to write
                            String readPointName = readPointNames[i];
                            String id = curTag.getId();
                            int memoryBank = curTagFieldValue.getTagField().getMemoryBank();
                            int offset = curTagFieldValue.getTagField().getOffset();
                            int length = curTagFieldValue.getTagField().getLength();
                            byte[] data = HexUtil.hexToByteArray(curTagFieldValue.getValue());
                            int byteoffset = offset / 8;
                            int bytelength = ((offset % 8) + length + 7) / 8;
                            int shift = (8 - ((offset + length) % 8)) % 8;
                            byte first;
                            if ((offset % 8) == 0) {
                                first = 0x00;
                            } else {
                                first = reader
                                        .readBytes(readPointName, id, memoryBank, byteoffset, 1, passwords)
                                        .toByteArray()[0];
                            }
                            byte last;
                            if (shift == 0) {
                                last = 0x00;
                            } else if (bytelength == 1) {
                                last = first;
                            } else {
                                last = reader.readBytes(readPointName, id, memoryBank,
                                        (byteoffset + bytelength - 1), 1, passwords).toByteArray()[0];
                            }
                            byte[] bytes = HexUtil.bitarrayShiftAndFill(data, length, shift, first, last);
                            reader.writeBytes(readPointName, id, memoryBank, byteoffset,
                                    new UnsignedByteArray(bytes), passwords);
                            increaseAntennaReadPointWriteCount(readPointNames[i]);
                        } catch (HardwareException he) {
                            ReadPoint readPoint = (ReadPoint) readPoints.get(readPointNames[i]);
                            if (readPoint instanceof AntennaReadPoint) {
                                ((AntennaReadPoint) readPoint).writeFailureOccurred();
                            }
                        }
                    }
                }

            }

        }

    } catch (Exception e) {
        throw new ReaderProtocolException("ERROR_UNKNOWN", MessagingConstants.ERROR_UNKNOWN);
    }

}

From source file:org.accada.reader.rprm.core.Source.java

/**
 * Kills the specified tag or group of tags. An list of TagSelector objects
 * can be specified with this command.//from   ww w .  j  av a 2s. c o m
 * @param passwords
 *           Not yet supported
 * @param tagSelectorList
 *           The tag selectors
 * @throws ReaderProtocolException
 *            "ERROR_MULTIPLE_TAGS", "ERROR_NO_TAG", "ERROR_UNKNOWN"
 */
public void kill(final String[] passwords, final TagSelector[] tagSelectorList) throws ReaderProtocolException {

    // passwords not supported in HardwareAbstraction

    Hashtable tagSelectors;
    if (tagSelectorList == null) {
        tagSelectors = this.tagSelectors;
    } else {
        tagSelectors = new Hashtable();
        for (int i = 0; i < tagSelectorList.length; i++) {
            tagSelectors.put(tagSelectorList[i].getName(), tagSelectorList[i]);
        }
    }

    // get all tags in range
    ReadReport report = rawReadIDs(null);

    if (report.getAllTags().size() >= 1) {
        throw new ReaderProtocolException("ERROR_MULTIPLE_TAGS", MessagingConstants.ERROR_MULTIPLE_TAGS);
    }

    if (report.getAllTags().size() < 1) {
        throw new ReaderProtocolException("ERROR_NO_TAG", MessagingConstants.ERROR_NO_TAG);
    }

    // possible exceptions : TagMemoryServiceException, HardwareException
    try {

        // get relevant readers
        Vector closure = getReaderAndReadPoints();

        // get relevant tags out of the report
        Hashtable tags = getRelevantTags(report, tagSelectors, closure);

        // tags
        Enumeration tagIterator = tags.elements();
        TagType curTag;
        while (tagIterator.hasMoreElements()) {
            curTag = (TagType) tagIterator.nextElement();

            // readers
            Enumeration readerIterator = closure.elements();
            HardwareAbstraction curHardwareAbstraction;
            ReaderAndReadPoints curClosure;
            while (readerIterator.hasMoreElements()) {
                curClosure = (ReaderAndReadPoints) readerIterator.nextElement();
                curHardwareAbstraction = curClosure.getReader();

                try {
                    // Where is the tag?
                    Observation[] observations = curHardwareAbstraction
                            .identify(curClosure.getAllReadPointsAsArray());
                    String readPointName = null;
                    for (int i = 0; i < observations.length; i++) {
                        if (observations[i].containsId(curTag.getId()))
                            readPointName = observations[i].getReadPointName();
                        break;
                    }

                    // Kill
                    curHardwareAbstraction.kill(readPointName, curTag.getId(), passwords);

                    // Increase the counter
                    if (readPointName != null) {
                        increaseAntennaReadPointKillCount(readPointName);
                    }
                } catch (HardwareException he) {
                    ReadPoint readPoint = (ReadPoint) readPoints.get(he.getMessage());
                    if ((readPoint != null) && (readPoint instanceof AntennaReadPoint)) {
                        ((AntennaReadPoint) readPoint).killFailureOccurred();
                    }
                    /*
                    ReadPoint readPoint = (ReadPoint) readPoints.get(he.getReadPointName());
                    if (readPoint instanceof AntennaReadPoint) {
                       ((AntennaReadPoint) readPoint).killFailureOccurred();
                    }
                    int errorCode = he.getReaderProtocolErrorCode();
                    switch(errorCode) {
                        case MessagingConstants.ERROR_MULTIPLE_TAGS:
                           throw new ReaderProtocolException("ERROR_MULTIPLE_TAGS", errorCode);
                        case MessagingConstants.ERROR_NO_TAG:
                           throw new ReaderProtocolException("ERROR_NO_TAG", errorCode);
                    }*/
                    throw new ReaderProtocolException("ERROR_UNKNOWN", MessagingConstants.ERROR_UNKNOWN);
                }

            }

        }

    } catch (Exception e) {
        throw new ReaderProtocolException("ERROR_UNKNOWN", MessagingConstants.ERROR_UNKNOWN);
    }

}

From source file:org.accada.reader.rprm.core.Source.java

/**
 * Checks if a tag is relevant (dependant of the TagSelectors).
 * @param tagId//from   ww  w  .jav  a 2  s  .  c  o  m
 *           The tag to check
 * @param allTagSelectors
 *           The TagSelectors
 * @param closure
 *           The reader and its readpoints
 * @return Returns 'true' if the tag is relevant, 'false' otherwise
 * @throws ReaderProtocolException
 *            "ERROR_UNKNOWN"
 */
protected boolean isRelevantTag(final String tagId, final Hashtable allTagSelectors, final Vector closure)
        throws ReaderProtocolException {

    Hashtable tagSelectors = new Hashtable();

    if (allTagSelectors.size() == 0) {
        try {
            tagSelectors.put(readerDevice.getTagSelector("defaultTagSelector").getName(),
                    readerDevice.getTagSelector("defaultTagSelector"));
        } catch (ReaderProtocolException e) {
            throw new ReaderProtocolException("ERROR_UNKNOWN", MessagingConstants.ERROR_UNKNOWN);
        }
    } else {
        tagSelectors = allTagSelectors;
    }

    // indicates if tag is relevant
    boolean relevantInc = false;
    boolean relevantExc = false;

    // special case, if zero inclusive/exclusive patterns are defined
    boolean moreThanZeroIncs = false;
    boolean moreThanZeroExcs = false;

    // tag selectors
    Enumeration tagSelectorIterator = tagSelectors.elements();
    TagSelector curTagSelector;
    String tagValue = "";
    while (tagSelectorIterator.hasMoreElements()) {
        curTagSelector = (TagSelector) tagSelectorIterator.nextElement();

        if (curTagSelector.getTagField().getMemoryBank() == 2) {
            // id
            tagValue = tagId;
        } else {
            // tagField
            tagValue = readTagField(tagId, closure, curTagSelector.getTagField());

        }

        // check value
        if (curTagSelector.validate(tagValue) && curTagSelector.getInclusiveFlag()) { // inlusive
            // relevant, the tag should be reported
            relevantInc = true;
        } else if (!curTagSelector.validate(tagValue) && !curTagSelector.getInclusiveFlag()) { // exclusive
            // relevant, the tag should be reported
            relevantExc = true;
        }
        if (curTagSelector.getInclusiveFlag()) {
            moreThanZeroIncs = true;
        }
        if (!curTagSelector.getInclusiveFlag()) {
            moreThanZeroExcs = true;
        }

    }

    // return true if tag is relevant
    if (relevantInc && relevantExc) {
        return true;
    } else if (!moreThanZeroIncs && relevantExc) {
        return true;
    } else if (!moreThanZeroExcs && relevantInc) {
        return true;
    }

    return false;

}

From source file:org.apache.nutch.parse.mspowerpoint.ContentReaderListener.java

/**
 * Reads the internal PowerPoint document stream.
 * //  www. j  av a 2 s .  c  o m
 * @see org.apache.poi.poifs.eventfilesystem.POIFSReaderListener#processPOIFSReaderEvent(org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent)
 */
public void processPOIFSReaderEvent(final POIFSReaderEvent event) {

    if (event == null || event.getName() == null
            || !event.getName().startsWith(PPTConstants.POWERPOINT_DOCUMENT)) {
        if (LOG.isWarnEnabled()) {
            LOG.warn("Stream not processed. It is not a PowerPoint document: : " + event.getName());
        }
        return;
    }

    try {
        final DocumentInputStream dis = event.getStream();
        final byte pptdata[] = new byte[dis.available()];
        dis.read(pptdata, 0, dis.available());
        int offset = 0;
        long offsetPD = 0;

        /*
         * Traverse Bytearray to get CurrentUserEditAtom Call to extract the Text
         * in all PlaceHolders to hold PPTClientTextBox objects for mapping into
         * Slide Objects
         */
        Hashtable/* <Long, TextBox> */ containerTextBox = new Hashtable/*
                                                                        * <Long,
                                                                        * TextBox>
                                                                        */();
        // Traverse ByteArray to identiy edit paths of ClientTextBoxes
        long n = pptdata.length - 20;
        for (long i = 0; i < n; i++) {

            final long type = LittleEndian.getUShort(pptdata, (int) i + 2);
            // final long size = LittleEndian.getUInt(pptdata, (int) i + 4);

            if (PPTConstants.PPT_ATOM_USEREDIT == type) {
                /*
                 * Checking the Record Header (UserEditAtom)
                 */
                // final long lastSlideID = LittleEndian.getInt(pptdata, (int) i + 8);
                // final long version = LittleEndian.getUInt(pptdata, (int) i + 12);
                offset = (int) LittleEndian.getUInt(pptdata, (int) i + 16);
                offsetPD = LittleEndian.getUInt(pptdata, (int) i + 20);

                /*
                 * Call to extract ClientTextBox text in each UserEditAtom
                 */
                containerTextBox = extractTextBoxes(containerTextBox, offset, pptdata, offsetPD);
            } else if (PPTConstants.PPT_ATOM_DRAWINGGROUP == type) {
                // if (LOG.isTraceEnabled()) {
                //   LOG.trace("PPT_DRAWINGGROUP_ATOM ignored: " + type);
                // }
            } else if (PPTConstants.PPT_ATOM_TEXTBYTE == type) {
                // if (LOG.isTraceEnabled()) {
                //   LOG.trace("PPT_TEXTBYTE_ATOM ignored: " + type);
                // }
            } else if (PPTConstants.PPT_ATOM_TEXTCHAR == type) {
                // if (LOG.isTraceEnabled()) {
                //   LOG.trace("PPT_TEXTCHAR_ATOM ignored: " + type);
                // }
            } else {
                // no action
                // if (LOG.isTraceEnabled()) {
                //   LOG.trace("type not handled: " + type);
                // }
            }
        }

        final List/* <PPTSlide> */ slides = extractSlides(offset, pptdata, offsetPD);

        if (slides.size() == 0) {
            if (LOG.isInfoEnabled()) {
                LOG.info("No slides extracted!");
            }

        } else {
            Slide slide = (Slide) slides.get(slides.size() - 1);

            for (Enumeration enumeration = containerTextBox.elements(); enumeration.hasMoreElements();) {
                final TextBox textBox = (TextBox) enumeration.nextElement();
                slide.addContent(textBox.getContent());
            }

            /*
             * Merging TextBox data with Slide Data Printing the text from Slides
             * vector object.
             */
            List scontent;
            for (int i = 0; i < slides.size(); i++) {
                slide = (Slide) slides.get(i);
                scontent = slide.getContent();
                String contentText;

                for (int j = 0; j < scontent.size(); j++) {
                    contentText = scontent.get(j).toString();
                    this.buf.append(contentText);

                    // to avoid concatinated words we add a blank additional
                    if (contentText.length() > 0
                            && !(contentText.endsWith("\r") || contentText.endsWith("\n"))) {
                        this.buf.append(" ");
                    }
                }
            }
        }
    } catch (Throwable ex) {
        // because of not killing complete crawling all Throwables are catched.
        if (LOG.isErrorEnabled()) {
            LOG.error("processPOIFSReaderEvent", ex);
        }
    }
}

From source file:org.asimba.engine.attribute.gather.processor.file.AsimbaUsersXmlGatherer.java

public void process(String sUserId, IAttributes oAttributes) throws AttributeException {
    if (oAttributes == null)
        throw new IllegalArgumentException("IAttributes was not provided");
    try {//from   w ww  . j  a v a  2 s.  c o m
        ConfigurationManager oCM = getConfiguration();

        // First, process global attributes
        Enumeration<FileAttribute> oEnumGlobal = _htGlobal.elements();
        while (oEnumGlobal.hasMoreElements()) {
            FileAttribute fAttr = oEnumGlobal.nextElement();
            String sName = fAttr.getName();
            List<?> listValues = fAttr.getValues();
            String sMappedName = _htMapper.get(sName);
            if (sMappedName != null)
                sName = sMappedName;

            if (_listGather.isEmpty() || _listGather.contains(sName)) {
                // Ignore multi-value, only return the first value
                if (listValues.size() > 1)
                    oAttributes.put(sName, fAttr.getFormat(), listValues);
                else
                    oAttributes.put(sName, fAttr.getFormat(), listValues.get(0));
            }
        }

        Element elUser = oCM.getSection(null, "user", "id=" + sUserId);
        if (elUser != null) {
            Hashtable<String, FileAttribute> htAttributes = getFileAttributes(oCM, elUser);
            if (!htAttributes.isEmpty()) {
                Enumeration<FileAttribute> enumAttributes = htAttributes.elements();
                while (enumAttributes.hasMoreElements()) {
                    FileAttribute fAttr = enumAttributes.nextElement();
                    String sName = fAttr.getName();
                    List<?> listValues = fAttr.getValues();
                    String sMappedName = _htMapper.get(sName);
                    if (sMappedName != null)
                        sName = sMappedName;

                    if (_listGather.isEmpty() || _listGather.contains(sName)) {
                        // Ignore multi-value, only return the first value
                        if (listValues.size() > 1)
                            oAttributes.put(sName, fAttr.getFormat(), listValues);
                        else
                            oAttributes.put(sName, fAttr.getFormat(), listValues.get(0));

                    }
                }
            } else
                _oLogger.debug("No user specific attributes found");
        } else
            _oLogger.debug("No user found in attributes file");
    } catch (AttributeException e) {
        throw e;
    } catch (Exception e) {
        _oLogger.fatal("Internal error during attribute processing", e);
        throw new AttributeException(SystemErrors.ERROR_INTERNAL);
    }
}

From source file:org.ecoinformatics.seek.datasource.eml.eml2.Eml200DataSource.java

/**
 * get the data based on the contents of the package
 * //from   www. j a v a2 s  .  com
 * @param parser
 *            the parser that has already parsed the package.
 */
private void getData(Eml200Parser parser) throws IllegalActionException {
    if (parser != null) {
        _numberOfEntities = parser.getEntityCount();
        _entityCountDown = new CountDown(_numberOfEntities);
        /*
         * if (parser.getEntityCount() > 1) { throw new
         * IllegalActionException(
         * "Currently this parser only deals with one entity. " +
         * "Please use a package with only one entity.");
         */
        if (_numberOfEntities == 0) {
            throw new IllegalActionException("There must be at least one entity in the EML package.");
        }
        Hashtable entityList = parser.getEntityHash();
        // initialize selected entity
        _selectedTableEntity = (Entity) entityList.get(entityList.keys().nextElement());
        // log.debug("entityhash: " + _entityList.toString());

        // start a thread to get data chachedItem
        Enumeration enu = entityList.elements();
        while (enu.hasMoreElements()) {

            Entity singleEntity = (Entity) enu.nextElement();
            log.debug("Adding Entity " + singleEntity);
            // System.out.println("Data URL = "+singleEntity.getURL());
            String dataurl = dataFilePath.getExpression();
            // check for absolute path - relative was not resolving correctly
            try {
                URL url = dataFilePath.asURL();
                if (url != null) {
                    dataurl = url.getPath();
                }
            } catch (Exception e) {
                // do nothing - just ignore it
            }
            // use the dataurl parameter if it has been entered
            // ie replace the url in the Entity object
            // use: to set local data file
            if (dataurl != null && dataurl.length() > 0) {
                if (dataurl.startsWith("/")) {
                    dataurl = "file://" + dataurl;
                } else if (dataurl.startsWith("file:/")) {
                    if ((!dataurl.startsWith("file://")) && (!dataurl.startsWith("file:///"))) {
                        dataurl = dataurl.replaceFirst("file:/", "file:///");
                    }
                } else {
                    dataurl = "file:///" + dataurl;
                }
                singleEntity.setURL(dataurl);
                // System.out.println("Data URL(1) = "+singleEntity.getURL());
            }
            _entityList.add(singleEntity);
            getDataItemFromCache(singleEntity);
        }

    }
}

From source file:org.hdiv.upload.HDIVMultipartRequestHandler.java

/**
 * Parses the input stream and partitions the parsed items into a set of form
 * fields and a set of file items. In the process, the parsed items are
 * translated from Commons FileUpload <code>FileItem</code> instances to Struts
 * <code>FormFile</code> instances.
 * //from   w  w w  .j  a  v a  2  s  .  com
 * @param request The multipart request to be processed.
 * @throws ServletException if an unrecoverable error occurs.
 */
public void handleRequest(HttpServletRequest request) throws ServletException {

    // Create the hash tables to be populated.
    elementsText = new Hashtable();
    elementsFile = new Hashtable();
    elementsAll = new Hashtable();

    if (request instanceof MultipartRequestWrapper) {

        MultipartRequestWrapper wrapper = (MultipartRequestWrapper) request;
        RequestWrapper requestWrapper = (RequestWrapper) wrapper.getRequest();

        Boolean maxLengthExceeded = (Boolean) request.getAttribute(ATTRIBUTE_MAX_LENGTH_EXCEEDED);
        if ((maxLengthExceeded != null) && (maxLengthExceeded.booleanValue())) {
            return;
        }

        Exception multipartException = (Exception) request.getAttribute(IMultipartConfig.FILEUPLOAD_EXCEPTION);
        if (multipartException != null) {
            throw new ServletException(multipartException.getMessage());
        }

        // file items
        Hashtable items = requestWrapper.getFileElements();

        Enumeration fileElements = items.elements();
        while (fileElements.hasMoreElements()) {

            List currentItems = (List) fileElements.nextElement();
            if (items != null) {
                addFileParameter(currentItems);
            }
        }

        // text items
        items = requestWrapper.getTextElements();

        Enumeration fileKeys = items.keys();
        while (fileKeys.hasMoreElements()) {

            String currentTextKey = (String) fileKeys.nextElement();
            String[] currentTextValue = (String[]) items.get(currentTextKey);
            this.addTextParameter(wrapper, currentTextKey, currentTextValue);
        }
    }
}

From source file:org.hdiv.util.HDIVRequestUtils.java

/**
 * Checks if <code>path</code> has an action extension or a jsp page
 * extension.//from  ww w  .ja v a 2  s  .  co  m
 * 
 * @param path path
 * @param extensions extensions table
 * @return True if <code>path</code> is an action or references a jsp
 *         page.
 */
public static boolean hasActionOrServletExtension(String path, Hashtable extensions) {

    if (path.indexOf("?") > 0) {
        path = path.substring(0, path.indexOf("?"));
    }

    if (path.charAt(path.length() - 1) == '/') {
        return true;
    }

    int pound = path.indexOf("#");
    if (pound >= 0) {
        path = path.substring(0, pound);
    }

    // strip a servlet session ID from
    path = HDIVUtil.stripSession(path);

    if (path.endsWith(".jsp")) {
        return true;
    }

    if (extensions != null) {

        for (Enumeration extensionsIds = extensions.elements(); extensionsIds.hasMoreElements();) {

            Pattern extensionPattern = (Pattern) extensionsIds.nextElement();
            Matcher m = extensionPattern.matcher(path);

            if (m.matches()) {
                return true;
            }
        }
    }

    return (!path.startsWith("/")) && (path.indexOf(".") == -1);
}