Example usage for java.util Hashtable keySet

List of usage examples for java.util Hashtable keySet

Introduction

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

Prototype

Set keySet

To view the source code for java.util Hashtable keySet.

Click Source Link

Document

Each of these fields are initialized to contain an instance of the appropriate view the first time this view is requested.

Usage

From source file:org.masukomi.aspirin.core.MailQue.java

protected void service(MimeMessage mimeMessage, Collection<MailWatcher> watchers)
        throws AddressException, MessagingException {

    MailImpl sourceMail = new MailImpl(mimeMessage);
    // Do I want to give the internal key, or the message's Message ID
    if (log.isDebugEnabled()) {
        log.debug("Remotely delivering mail " + sourceMail.getName());
    }//from w  w w  . j ava  2s.co  m
    Collection recipients = sourceMail.getRecipients();
    // Must first organize the recipients into distinct servers (name made
    // case insensitive)
    Hashtable<String, Vector<MailAddress>> targets = new Hashtable<String, Vector<MailAddress>>();
    for (Iterator i = recipients.iterator(); i.hasNext();) {
        MailAddress target = (MailAddress) i.next();
        String targetServer = target.getHost().toLowerCase(Locale.US);
        //Locale.US because only ASCII supported in domains? -kate

        //got any for this domain yet?
        Vector<MailAddress> temp = targets.get(targetServer);
        if (temp == null) {
            temp = new Vector<MailAddress>();
            targets.put(targetServer, temp);
        }
        temp.add(target);
    }
    //We have the recipients organized into distinct servers... put them
    // into the
    //delivery store organized like this... this is ultra inefficient I
    // think...
    // Store the new message containers, organized by server, in the que
    // mail repository
    for (Iterator<String> i = targets.keySet().iterator(); i.hasNext();) {
        //make a copy of it for each recipient
        MailImpl uniqueMail = new MailImpl(mimeMessage);
        String name = uniqueMail.getName();
        String host = (String) i.next();
        Vector<MailAddress> rec = targets.get(host);
        if (log.isDebugEnabled()) {
            StringBuffer logMessageBuffer = new StringBuffer(128).append("Sending mail to ").append(rec)
                    .append(" on host ").append(host);
            log.debug(logMessageBuffer.toString());
        }
        uniqueMail.setRecipients(rec);
        StringBuffer nameBuffer = new StringBuffer(128).append(name).append("-to-").append(host);
        uniqueMail.setName(nameBuffer.toString());
        store(new QuedItem(uniqueMail));
        //Set it to try to deliver (in a separate thread) immediately
        // (triggered by storage)
        uniqueMail.setState(Mail.GHOST);
    }
}

From source file:org.socraticgrid.displaydataaggregator.DisplayDataAggregatorImpl.java

/**
 * Return data source list.//from  ww  w  . j a va2  s  .co m
 * 
 * @param getAvailableSourcesRequest
 * @return
 */
public org.socraticgrid.common.dda.GetAvailableSourcesResponseType getAvailableSources(
        org.socraticgrid.common.dda.GetAvailableSourcesRequestType getAvailableSourcesRequest) {
    GetAvailableSourcesResponseType response = new GetAvailableSourcesResponseType();
    Hashtable<String, String> sourceTable = new Hashtable<String, String>();

    try {
        ServiceError dataSourceError = getDataSources(sourceTable);
        if (dataSourceError != null) {
            throw new Exception("Error retrieving data sources.");
        }

        if (sourceTable.size() == 0) {
            throw new Exception("No data sources defined.");
        }

        for (String dataSource : sourceTable.keySet()) {
            response.getReturn().add(dataSource);
        }
    } catch (Exception e) {
        String errorMsg = "Error getting data sources.";
        log.error(errorMsg, e);
        response.getReturn().add(errorMsg + ". " + e.getMessage());
    }

    return response;
}

From source file:org.wandora.application.gui.topicpanels.webview.WebViewPanel.java

private Object[] getBrowserMenuStruct() {
    ArrayList topicMenuItems = new ArrayList();
    if (rootTopic != null) {
        try {/*from w w  w .  j  a  v  a  2  s  .co m*/
            if (rootTopic.getSubjectLocator() != null) {
                topicMenuItems.add(rootTopic.getSubjectLocator().toExternalForm());
                topicMenuItems.add("---");
            }
            for (Locator l : rootTopic.getSubjectIdentifiers()) {
                topicMenuItems.add(l.toExternalForm());
            }
            boolean firstOccurrence = true;
            for (Topic occurrenceType : rootTopic.getDataTypes()) {
                Hashtable<Topic, String> scopedOccurrences = rootTopic.getData(occurrenceType);
                for (Topic occurrenceScope : scopedOccurrences.keySet()) {
                    if (firstOccurrence) {
                        topicMenuItems.add("---");
                        firstOccurrence = false;
                    }
                    topicMenuItems.add("Open occurrence " + TopicToString.toString(occurrenceType) + " - "
                            + TopicToString.toString(occurrenceScope));
                    topicMenuItems.add(new OpenOccurrenceInWebView(rootTopic, occurrenceType, occurrenceScope));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    ArrayList browseServices = new ArrayList();
    Wandora wandora = Wandora.getWandora();
    if (wandora != null) {
        WandoraModulesServer httpServer = wandora.httpServer;

        ArrayList<ModulesWebApp> webApps = httpServer.getWebApps();
        HashMap<String, ModulesWebApp> webAppsMap = new HashMap<>();
        for (ModulesWebApp wa : webApps)
            webAppsMap.put(wa.getAppName(), wa);
        ArrayList<String> sorted = new ArrayList<>(webAppsMap.keySet());
        Collections.sort(sorted);

        for (String appName : sorted) {
            ModulesWebApp wa = webAppsMap.get(appName);

            if (wa.isRunning()) {
                String url = wa.getAppStartPage();
                if (url == null)
                    continue;

                browseServices.add(appName);
                browseServices.add(UIBox.getIcon("gui/icons/open_browser.png"));
                browseServices
                        .add(new HTTPServerTool(HTTPServerTool.OPEN_PAGE_IN_BROWSER_TOPIC_PANEL, wa, this));
            } else {
                browseServices.add(appName);
                browseServices.add(UIBox.getIcon("gui/icons/open_browser.png"));
                browseServices
                        .add(new HTTPServerTool(HTTPServerTool.OPEN_PAGE_IN_BROWSER_TOPIC_PANEL, wa, this));
            }
        }
    }

    ArrayList extractors = new ArrayList();
    if (browserExtractorManager != null) {
        T3<String, Integer, Integer> contentWithSelectionIndexes = getSourceWithSelectionIndexes();
        String content = contentWithSelectionIndexes.e1;
        int start = contentWithSelectionIndexes.e2.intValue();
        int end = contentWithSelectionIndexes.e3.intValue();
        String selection = null;
        try {
            if (start != -1 && end != -1) {
                selection = content.substring(start, end);
            }
        } catch (Exception e) {
        }
        BrowserExtractRequest extractRequest = new BrowserExtractRequest(getWebLocation(), content, null,
                "WebView", start, end, selection);
        String[] browserExtractors = browserExtractorManager.getExtractionMethods(extractRequest);

        for (String browserExtractorName : browserExtractors) {
            extractors.add(browserExtractorName);
            extractors.add((ActionListener) this);
        }
    }

    Object[] menuStruct = new Object[] { "Open current topic", topicMenuItems.toArray(),
            "Open Wandora's services", browseServices.toArray(), "---", "Open Firebug",
            new OpenFirebugInWebView(), "Open in external browser", new OpenWebLocationInExternalBrowser(),
            "---", "Add to current topic",
            new Object[] { "Add selection as an occurrence...", new AddWebSelectionAsOccurrence(),
                    "Add selection source as an occurrence...", new AddWebSourceAsOccurrence(true),
                    "Add source as an occurrence...", new AddWebSourceAsOccurrence(),
                    "Add location as an occurrence...", new AddWebLocationAsOccurrence(), "---",
                    "Add location as a subject locator", new AddWebLocationAsSubjectLocator(),
                    "Add location as a subject identifier", new AddWebLocationAsSubjectIdentifier(), "---",
                    "Add selection as a basename", new AddWebSelectionAsBasename(),
            // "---",
            // "Add links as associations",
            // "Add image locations as associations",
            }, "Create a topic",
            new Object[] { "Create topic from location", new CreateWebLocationTopic(), "---",
                    "Create topic from location and make instance",
                    new CreateWebLocationTopic(true, false, true, false),
                    "Create topic from location and make subclass",
                    new CreateWebLocationTopic(false, true, true, false),
                    "Create topic from location and associate",
                    new CreateWebLocationTopic(false, false, true, true), },
            "---", "Extract", extractors.toArray() };

    return menuStruct;
}

From source file:com.flexive.tests.browser.AdmContentTest.java

/**
 * searches for a type/*from  w  ww .  j  a va  2 s . co  m*/
 * @param typeName the name of the type
 * @param param the parameter which to fill in
 */
private void searchForType(String typeName, Hashtable<String, Object> param) {
    fillLUT(typeName);

    String link = CREATE_QUERY_LINK + propertyLUT.get(typeName).get("typeId");

    loadContentPage(link);
    navigateTo(NavigationTab.Structure);
    selectFrame(Frame.NavStructures);

    if (param != null) {
        String id;
        boolean isEditor;
        for (String pName : param.keySet()) {
            selectFrame(Frame.NavStructures);
            fillLUT(pName);
            id = propertyLUT.get(pName).get("propertyId");
            try {
                isEditor = selenium.getEval(WND + ".parent.frames[\"contentFrame\"].isQueryEditor")
                        .equals("true");
            } catch (Throwable t) {
                isEditor = false;
            }
            if (isEditor) {
                try {
                    selenium.getEval(WND + ".parent.frames[\"contentFrame\"].addPropertyQueryNode(" + id + ")");
                } catch (SeleniumException se) {
                    LOG.error(se.getMessage());
                }
            } else {
                link = ADD_PROPERTY_LINK + id;
                loadContentPage(link);
            }
            fillInQuery(pName, param.get(pName));
            //            writeHTMLtoHD("query", LOG);
            //            selenium.type("frm:nodeInput_1_input_", param.get(pName).toString());
        }
    }

    clickAndWait("link=Search");

    // TODO return value ? 
}

From source file:com.bt.aloha.fitnesse.InboundMediaCallFixture.java

private String waitForCallEndedEvent(Hashtable<String, AbstractCallEndedEvent> callEndedEvents,
        CallTerminationCause callTerminationCause, CallLegCausingTermination callLegCausingTermination,
        boolean zeroDuration, String targetId) {
    AbstractCallEndedEvent callEndedEvent = callEndedEvents.get(targetId);
    if (callEndedEvent != null && !callEndedEvent.getCallTerminationCause().equals(callTerminationCause)) {
        if ((zeroDuration && callEndedEvent.getDuration() == 0)
                || (!zeroDuration && callEndedEvent.getDuration() > 0))
            return callEndedEvent.getCallTerminationCause().toString();
        return String.format("Call duration: %d seconds", callEndedEvent.getDuration());
    } else if (callEndedEvent != null
            && !callEndedEvent.getCallLegCausingTermination().equals(callLegCausingTermination))
        return callEndedEvent.getCallLegCausingTermination().toString();
    else if (callEndedEvent != null)
        return "OK";
    else//ww w . j  a va  2 s . co m
        return callEndedEvents.keySet().toString();
}

From source file:dpfmanager.conformancechecker.tiff.reporting.PdfReport.java

/**
 * Parse an individual report to PDF.//  www.j  av a  2 s.  c o m
 *
 * @param ir the individual report.
 */
public void parseIndividual(IndividualReport ir) {
    try {
        PDFParams pdfParams = new PDFParams();
        pdfParams.init(PDPage.PAGE_SIZE_A4);
        PDFont font = PDType1Font.HELVETICA_BOLD;

        int pos_x = 200;
        pdfParams.y = 700;
        int font_size = 18;

        // Logo
        PDXObjectImage ximage;
        float scale = 3;
        synchronized (this) {
            InputStream inputStream = getFileStreamFromResources("images/logo.jpg");
            ximage = null;
            try {
                ximage = new PDJpeg(pdfParams.getDocument(), inputStream);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            if (ximage != null)
                pdfParams.getContentStream().drawXObject(ximage, pos_x, pdfParams.y, 645 / scale, 300 / scale);
        }

        // Report Title
        pdfParams.y -= 30;
        pdfParams = writeText(pdfParams, "INDIVIDUAL REPORT", pos_x, font, font_size);

        // Image
        pos_x = 50;
        int max_image_height = 130;
        int max_image_width = 200;
        pdfParams.y -= (max_image_height + 30);
        int image_pos_y = pdfParams.y;
        BufferedImage thumb = tiff2Jpg(ir.getFilePath());
        if (thumb == null) {
            thumb = ImageIO.read(getFileStreamFromResources("html/img/noise.jpg"));
        }
        int image_height = thumb.getHeight();
        int image_width = thumb.getWidth();
        if (image_height > max_image_height) {
            image_width = max_image_height * image_width / image_height;
            image_height = max_image_height;
        }
        if (image_width > max_image_width) {
            image_height = max_image_width * image_height / image_width;
            image_width = max_image_width;
        }
        ximage = new PDJpeg(pdfParams.getDocument(), thumb);
        pdfParams.getContentStream().drawXObject(ximage, pos_x, pdfParams.y, image_width, image_height);
        image_width = max_image_width;

        /**
         * Image name and path
         */
        font_size = 12;
        pdfParams.y += image_height - 12;
        pdfParams = writeText(pdfParams, ir.getFileName(), pos_x + image_width + 10, font, font_size);
        font_size = 11;
        pdfParams.y -= 32;
        List<String> linesPath = splitInLines(font_size, font, ir.getFilePath().replaceAll("\\\\", "/"),
                490 - image_width, "/");
        for (String line : linesPath) {
            pdfParams = writeText(pdfParams, line, pos_x + image_width + 10, font, font_size);
            pdfParams.y -= 10;
        }

        // Image alert
        pdfParams.y -= 30;
        font_size = 9;
        for (String iso : ir.getCheckedIsos()) {
            if (ir.hasValidation(iso) || ir.getNErrors(iso) == 0) {
                String name = ImplementationCheckerLoader.getIsoName(iso);
                pdfParams = makeConformSection(ir.getNErrors(iso), ir.getNWarnings(iso), name, pdfParams, pos_x,
                        image_width, font_size, font);
            }
        }
        pdfParams.y -= 10;

        /**
         * Summary table
         */
        font_size = 8;
        pdfParams = writeText(pdfParams, "Errors", pos_x + image_width + 170, font, font_size);
        pdfParams = writeText(pdfParams, "Warnings", pos_x + image_width + 210, font, font_size);
        String dif = "";

        for (String iso : ir.getCheckedIsos()) {
            if (ir.hasValidation(iso) || ir.getNErrors(iso) == 0) {
                String name = ImplementationCheckerLoader.getIsoName(iso);
                pdfParams.y -= 20;
                pdfParams.getContentStream().drawLine(pos_x + image_width + 10, pdfParams.y + 15,
                        pos_x + image_width + 260, pdfParams.y + 15);
                pdfParams = writeText(pdfParams, name, pos_x + image_width + 10, font, font_size);
                dif = ir.getCompareReport() != null
                        ? getDif(ir.getCompareReport().getNErrors(iso), ir.getNErrors(iso))
                        : "";
                pdfParams = writeText(pdfParams, ir.getNErrors(iso) + dif, pos_x + image_width + 180, font,
                        font_size, ir.getNErrors(iso) > 0 ? Color.red : Color.black);
                dif = ir.getCompareReport() != null
                        ? getDif(ir.getCompareReport().getNWarnings(iso), ir.getNWarnings(iso))
                        : "";
                pdfParams = writeText(pdfParams, ir.getNWarnings(iso) + dif, pos_x + image_width + 230, font,
                        font_size, ir.getNWarnings(iso) > 0 ? Color.orange : Color.black);
            }
        }

        if (pdfParams.y > image_pos_y)
            pdfParams.y = image_pos_y;

        /**
         * File structure
         */
        font_size = 10;
        pdfParams.y -= 40;
        pdfParams = writeTitle(pdfParams, "File Structure", "images/pdf/site.png", pos_x, font, font_size);
        TiffDocument td = ir.getTiffModel();
        IFD ifd = td.getFirstIFD();
        font_size = 7;
        while (ifd != null) {
            pdfParams.y -= 20;
            String typ = " - Main image";
            if (ifd.hasSubIFD() && ifd.getImageSize() < ifd.getsubIFD().getImageSize())
                typ = " - Thumbnail";
            ximage = new PDJpeg(pdfParams.getDocument(), getFileStreamFromResources("images/doc.jpg"));
            pdfParams.getContentStream().drawXObject(ximage, pos_x, pdfParams.y, 5, 7);
            pdfParams = writeText(pdfParams, ifd.toString() + typ, pos_x + 7, font, font_size);
            if (ifd.getsubIFD() != null) {
                pdfParams.y -= 18;
                if (ifd.getImageSize() < ifd.getsubIFD().getImageSize())
                    typ = " - Main image";
                else
                    typ = " - Thumbnail";
                pdfParams.getContentStream().drawXObject(ximage, pos_x + 15, pdfParams.y, 5, 7);
                pdfParams = writeText(pdfParams, "SubIFD" + typ, pos_x + 15 + 7, font, font_size);
            }
            if (ifd.containsTagId(34665)) {
                pdfParams.y -= 18;
                pdfParams.getContentStream().drawXObject(ximage, pos_x + 15, pdfParams.y, 5, 7);
                pdfParams = writeText(pdfParams, "EXIF", pos_x + 15 + 7, font, font_size);
            }
            if (ifd.containsTagId(700)) {
                pdfParams.y -= 18;
                pdfParams.getContentStream().drawXObject(ximage, pos_x + 15, pdfParams.y, 5, 7);
                pdfParams = writeText(pdfParams, "XMP", pos_x + 15 + 7, font, font_size);
            }
            if (ifd.containsTagId(33723)) {
                pdfParams.y -= 18;
                pdfParams.getContentStream().drawXObject(ximage, pos_x + 15, pdfParams.y, 5, 7);
                pdfParams = writeText(pdfParams, "IPTC", pos_x + 15 + 7, font, font_size);
            }
            ifd = ifd.getNextIFD();
        }

        /**
         * Tags
         */
        font_size = 7;
        Map<String, List<ReportTag>> tags = parseTags(ir);
        for (String key : sortByTag(tags.keySet())) {
            /**
             * IFD
             */
            if (key.startsWith("ifd") && !key.endsWith("e")) {
                pdfParams.y -= 40;
                pdfParams = writeTitle(pdfParams, "IFD Tags", "images/pdf/tag.png", pos_x, font, 10);
                pdfParams.y -= 20;
                Integer[] margins = { 2, 40, 180 };
                pdfParams = writeTableHeaders(pdfParams, pos_x, font_size, font,
                        Arrays.asList("ID", "Name", "Value"), margins);
                for (ReportTag tag : tags.get(key)) {
                    pdfParams.y -= 15;
                    String sDif = "";
                    if (tag.dif < 0)
                        sDif = "(-)";
                    else if (tag.dif > 0)
                        sDif = "(+)";
                    pdfParams = writeText(pdfParams, tag.tv.getId() + sDif, pos_x + margins[0], font,
                            font_size);
                    pdfParams = writeText(pdfParams,
                            (tag.tv.getName().equals(tag.tv.getId() + "") ? "Private tag" : tag.tv.getName()),
                            pos_x + margins[1], font, font_size);
                    pdfParams = writeText(pdfParams, tag.tv.getDescriptiveValue(), pos_x + margins[2], font,
                            font_size);
                }
            }
            /**
             * IFD  expert
             */
            else if (key.startsWith("ifd")) {
                pdfParams.y -= 40;
                pdfParams = writeTitle(pdfParams, "IFD Expert Tags", "images/pdf/tag.png", pos_x, font, 10);
                pdfParams.y -= 20;
                Integer[] margins = { 2, 40, 180 };
                pdfParams = writeTableHeaders(pdfParams, pos_x, font_size, font,
                        Arrays.asList("ID", "Name", "Value"), margins);
                for (ReportTag tag : tags.get(key)) {
                    pdfParams.y -= 15;
                    String sDif = "";
                    if (tag.dif < 0)
                        sDif = "(-)";
                    else if (tag.dif > 0)
                        sDif = "(+)";
                    pdfParams = writeText(pdfParams, tag.tv.getId() + sDif, pos_x + margins[0], font,
                            font_size);
                    pdfParams = writeText(pdfParams,
                            (tag.tv.getName().equals(tag.tv.getId() + "") ? "Private tag" : tag.tv.getName()),
                            pos_x + margins[1], font, font_size);
                    pdfParams = writeText(pdfParams, tag.tv.getDescriptiveValue(), pos_x + margins[2], font,
                            font_size);
                }
            }
            /**
             * SUB
             */
            if (key.startsWith("sub")) {
                for (ReportTag tag : tags.get(key)) {
                    pdfParams.y -= 40;
                    pdfParams = writeTitle(pdfParams, "Sub IFD Tags", "images/pdf/tag.png", pos_x, font, 10);
                    pdfParams.y -= 20;
                    Integer[] margins = { 2, 40, 180 };
                    pdfParams = writeTableHeaders(pdfParams, pos_x, font_size, font,
                            Arrays.asList("ID", "Name", "Value"), margins);
                    IFD sub = (IFD) tag.tv.getValue().get(0);
                    for (TagValue tv : sub.getTags().getTags()) {
                        pdfParams.y -= 15;
                        pdfParams = writeText(pdfParams, tv.getId() + "", pos_x + margins[0], font, font_size);
                        pdfParams = writeText(pdfParams,
                                (tv.getName().equals(tv.getId() + "") ? "Private tag" : tv.getName()),
                                pos_x + margins[1], font, font_size);
                        pdfParams = writeText(pdfParams, tv.getDescriptiveValue(), pos_x + margins[2], font,
                                font_size);
                    }
                }
            }
            /**
             * EXIF
             */
            if (key.startsWith("exi")) {
                for (ReportTag tag : tags.get(key)) {
                    pdfParams.y -= 40;
                    String index = (tag.index > 0) ? " (IFD " + tag.index + ")" : "";
                    pdfParams = writeTitle(pdfParams, "EXIF Tags" + index, "images/pdf/tag.png", pos_x, font,
                            10);
                    pdfParams.y -= 20;
                    Integer[] margins = { 2, 40, 180 };
                    pdfParams = writeTableHeaders(pdfParams, pos_x, font_size, font,
                            Arrays.asList("ID", "Name", "Value"), margins);
                    IFD exif = (IFD) tag.tv.getValue().get(0);
                    for (TagValue tv : exif.getTags().getTags()) {
                        pdfParams.y -= 15;
                        pdfParams = writeText(pdfParams, tv.getId() + "", pos_x + margins[0], font, font_size);
                        pdfParams = writeText(pdfParams,
                                (tv.getName().equals(tv.getId() + "") ? "Private tag" : tv.getName()),
                                pos_x + margins[1], font, font_size);
                        pdfParams = writeText(pdfParams, tv.getDescriptiveValue(), pos_x + margins[2], font,
                                font_size);
                    }
                }
            }
            /**
             * IPTC
             */
            if (key.startsWith("ipt")) {
                for (ReportTag tag : tags.get(key)) {
                    pdfParams.y -= 40;
                    String index = (tag.index > 0) ? " (IFD " + tag.index + ")" : "";
                    pdfParams = writeTitle(pdfParams, "IPTC Tags" + index, "images/pdf/tag.png", pos_x, font,
                            10);
                    pdfParams.y -= 20;
                    Integer[] margins = { 2, 180 };
                    pdfParams = writeTableHeaders(pdfParams, pos_x, font_size, font,
                            Arrays.asList("Name", "Value"), margins);
                    abstractTiffType obj = tag.tv.getValue().get(0);
                    if (obj instanceof IPTC) {
                        IPTC iptc = (IPTC) obj;
                        Metadata metadata = iptc.createMetadata();
                        for (String mKey : iptc.createMetadata().keySet()) {
                            pdfParams.y -= 15;
                            pdfParams = writeText(pdfParams, mKey, pos_x + margins[0], font, font_size);
                            pdfParams = writeText(pdfParams, metadata.get(mKey).toString().trim(),
                                    pos_x + margins[1], font, font_size);
                        }
                    }
                }
            }
            /**
             * XMP
             */
            if (key.startsWith("xmp")) {
                for (ReportTag tag : tags.get(key)) {
                    // Tags
                    pdfParams.y -= 40;
                    String index = (tag.index > 0) ? " (IFD " + tag.index + ")" : "";
                    pdfParams = writeTitle(pdfParams, "XMP Tags" + index, "images/pdf/tag.png", pos_x, font,
                            10);
                    pdfParams.y -= 20;
                    Integer[] margins = { 2, 180 };
                    pdfParams = writeTableHeaders(pdfParams, pos_x, font_size, font,
                            Arrays.asList("Name", "Value"), margins);
                    XMP xmp = (XMP) tag.tv.getValue().get(0);
                    Metadata metadata = xmp.createMetadata();
                    for (String xKey : metadata.keySet()) {
                        pdfParams.y -= 15;
                        pdfParams = writeText(pdfParams, xKey, pos_x + margins[0], font, font_size);
                        pdfParams = writeText(pdfParams, metadata.get(xKey).toString().trim(),
                                pos_x + margins[1], font, font_size);
                    }
                    // History
                    if (xmp.getHistory() != null) {
                        pdfParams.y -= 40;
                        pdfParams = writeTitle(pdfParams, "History" + index, "images/pdf/tag.png", pos_x, font,
                                10);
                        pdfParams.y -= 20;
                        pdfParams = writeTableHeaders(pdfParams, pos_x, font_size, font,
                                Arrays.asList("Attribute", "Value"), margins);
                        int nh = 0;
                        for (Hashtable<String, String> kv : xmp.getHistory()) {
                            // TODO WORKARROUND
                            String hKey = kv.keySet().iterator().next();
                            if (hKey.equals("action") && nh != 0) {
                                pdfParams.getContentStream().drawLine(pos_x, pdfParams.y - 5, pos_x + 490,
                                        pdfParams.y - 5);
                            }
                            pdfParams.y -= 15;
                            pdfParams = writeText(pdfParams, hKey, pos_x + margins[0], font, font_size);
                            pdfParams = writeText(pdfParams, kv.get(hKey).toString().trim(), pos_x + margins[1],
                                    font, font_size);
                            nh++;
                        }
                    }
                }
            }
        }

        /**
         * Metadata incoherencies
         */
        pdfParams.y -= 40;
        pdfParams = writeTitle(pdfParams, "Metadata analysis", "images/pdf/metadata.png", pos_x, font, 10);
        pdfParams.y -= 20;
        Integer[] margins = { 2, 30 };
        pdfParams = writeTableHeaders(pdfParams, pos_x, font_size, font, Arrays.asList("", "Description"),
                margins);
        IFD tdifd = td.getFirstIFD();
        int nifd = 1;
        List<String> rows = new ArrayList<>();
        while (tdifd != null) {
            XMP xmp = null;
            IPTC iptc = null;
            if (tdifd.containsTagId(TiffTags.getTagId("XMP")))
                xmp = (XMP) tdifd.getTag("XMP").getValue().get(0);
            if (tdifd.containsTagId(TiffTags.getTagId("IPTC"))) {
                abstractTiffType obj = tdifd.getTag("IPTC").getValue().get(0);
                if (obj instanceof IPTC) {
                    iptc = (IPTC) obj;
                }
            }

            // Author
            String authorTag = null;
            if (tdifd.containsTagId(TiffTags.getTagId("Artist")))
                authorTag = tdifd.getTag("Artist").toString();
            String authorIptc = null;
            if (iptc != null)
                authorIptc = iptc.getCreator();
            String authorXmp = null;
            if (xmp != null)
                authorXmp = xmp.getCreator();

            rows.addAll(detectIncoherency(authorTag, authorIptc, authorXmp, "Author", nifd));
            tdifd = tdifd.getNextIFD();
            nifd++;
        }
        if (rows.isEmpty()) {
            pdfParams.y -= 15;
            PDPixelMap titleImage = new PDPixelMap(pdfParams.getDocument(),
                    ImageIO.read(getFileStreamFromResources("images/pdf/check.png")));
            pdfParams.getContentStream().drawXObject(titleImage, pos_x + 5, pdfParams.y - 1, 9, 9);
            pdfParams = writeText(pdfParams, "No metadata incoherencies found", pos_x + margins[1], font,
                    font_size);
        }
        for (String row : rows) {
            pdfParams.y -= 15;
            PDPixelMap titleImage = new PDPixelMap(pdfParams.getDocument(),
                    ImageIO.read(getFileStreamFromResources("images/pdf/error.png")));
            pdfParams.getContentStream().drawXObject(titleImage, pos_x + 5, pdfParams.y - 1, 9, 9);
            pdfParams = writeText(pdfParams, row, pos_x + margins[1], font, font_size);
        }

        /**
         * Conformance checkers
         */
        pdfParams.y -= 40;
        font_size = 10;
        pdfParams = writeTitle(pdfParams, "Conformance checkers", "images/pdf/thumbs.png", pos_x, font,
                font_size);
        for (String iso : ir.getIsosCheck()) {
            if (ir.hasValidation(iso)) {
                String name = ImplementationCheckerLoader.getIsoName(iso);
                pdfParams = writeErrorsWarnings(pdfParams, font, ir.getErrors(iso), ir.getOnlyWarnings(iso),
                        ir.getOnlyInfos(iso), pos_x, name, iso.equals(TiffConformanceChecker.POLICY_ISO));
            }
        }

        pdfParams.getContentStream().close();

        ir.setPDF(pdfParams.getDocument());
    } catch (Exception tfe) {
        tfe.printStackTrace();
        ir.setPDF(null);
        //context.send(BasicConfig.MODULE_MESSAGE, new ExceptionMessage("Exception in ReportPDF", tfe));
    }
}

From source file:org.wandora.application.gui.OccurrenceTableSingleType.java

@Override
public void duplicateType() {
    try {//from  www  . ja va  2s .  c  om
        Point p = getTableModelPoint();
        if (p != null) {
            Topic selectedScope = langs[p.y];
            if (type != null && !type.isRemoved()) {
                Topic newType = wandora.showTopicFinder("Select new occurrence type");
                if (newType != null && !newType.isRemoved()) {
                    Hashtable<Topic, String> os = topic.getData(type);
                    if (os != null && !os.isEmpty()) {
                        for (Topic scope : os.keySet()) {
                            if (scope != null && !scope.isRemoved()) {
                                if (selectedScope == null) {
                                    String occurrenceText = os.get(scope);
                                    topic.setData(newType, scope, occurrenceText);
                                } else if (selectedScope.mergesWithTopic(scope)) {
                                    String occurrenceText = os.get(scope);
                                    topic.setData(newType, scope, occurrenceText);
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        if (wandora != null)
            wandora.handleError(e);
    }
}

From source file:org.wandora.application.gui.OccurrenceTableSingleType.java

@Override
public void changeType() {
    try {// w  w w . j  av a  2s.com
        Point p = getTableModelPoint();
        if (p != null) {
            Topic selectedScope = langs[p.y];
            if (type != null && !type.isRemoved()) {
                Topic newType = wandora.showTopicFinder("Select new occurrence type");
                if (newType != null && !newType.isRemoved()) {
                    Hashtable<Topic, String> os = topic.getData(type);
                    if (os != null && !os.isEmpty()) {
                        for (Topic scope : os.keySet()) {
                            if (scope != null && !scope.isRemoved()) {
                                if (selectedScope == null) {
                                    String occurrenceText = os.get(scope);
                                    topic.setData(newType, scope, occurrenceText);
                                } else if (selectedScope.mergesWithTopic(scope)) {
                                    String occurrenceText = os.get(scope);
                                    topic.setData(newType, scope, occurrenceText);
                                }
                            }
                        }
                        if (selectedScope == null) {
                            topic.removeData(type);
                        } else {
                            topic.removeData(type, selectedScope);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        if (wandora != null)
            wandora.handleError(e);
    }
}

From source file:org.gvsig.framework.web.service.impl.OGCInfoServiceImpl.java

public ServiceMetadata getMetadataInfoFromWMS(String urlServer) {

    ServiceMetadata servMetadata = new ServiceMetadata();

    try {/* w w  w .  j a  v a  2 s. c o m*/
        WMSClient wms = new WMSClient(urlServer);
        wms.connect(null);

        // set server information
        WMSServiceInformation serviceInfo = wms.getServiceInformation();

        servMetadata.setAbstractStr(serviceInfo.abstr);
        servMetadata.setFees(serviceInfo.fees);
        servMetadata.setKeywords(serviceInfo.keywords);
        servMetadata.setName(serviceInfo.name);
        servMetadata.setTitle(serviceInfo.title);
        servMetadata.setUrl(urlServer);
        servMetadata.setVersion(serviceInfo.version);
        // I can't get from service the accessConstraints value
        //servMetadata.setAccessConstraints(accessConstraints);

        // get layers
        TreeMap layers = wms.getLayers();
        if (layers != null) {
            List<Layer> lstLayers = new ArrayList<Layer>();
            Set<String> keys = layers.keySet();
            for (String key : keys) {
                WMSLayer wmsLayer = (WMSLayer) layers.get(key);
                Layer layer = new Layer();
                layer.setName(wmsLayer.getName());
                layer.setTitle(wmsLayer.getTitle());
                lstLayers.add(layer);
            }
            servMetadata.setLayers(lstLayers);
        }

        // get operations
        Hashtable supportedOperations = serviceInfo.getSupportedOperationsByName();
        if (supportedOperations != null) {
            List<OperationsMetadata> lstOperations = new ArrayList<OperationsMetadata>();
            Set<String> keys = supportedOperations.keySet();
            for (String key : keys) {
                OperationsMetadata opMetadata = new OperationsMetadata();
                opMetadata.setName(key);
                opMetadata.setUrl((String) supportedOperations.get(key));
                lstOperations.add(opMetadata);
            }
            servMetadata.setOperations(lstOperations);
        }
        // get contact address
        ContactAddressMetadata contactAddress = null;
        if (StringUtils.isNotEmpty(serviceInfo.address) || StringUtils.isNotEmpty(serviceInfo.addresstype)
                || StringUtils.isNotEmpty(serviceInfo.place) || StringUtils.isNotEmpty(serviceInfo.country)
                || StringUtils.isNotEmpty(serviceInfo.postcode)
                || StringUtils.isNotEmpty(serviceInfo.province)) {
            contactAddress = new ContactAddressMetadata();
            contactAddress.setAddress(serviceInfo.address);
            contactAddress.setAddressType(serviceInfo.addresstype);
            contactAddress.setCity(serviceInfo.place);
            contactAddress.setCountry(serviceInfo.country);
            contactAddress.setPostCode(serviceInfo.postcode);
            contactAddress.setStateProvince(serviceInfo.province);
        }

        // get contact info
        ContactMetadata contactMetadata = null;
        if (contactAddress != null || StringUtils.isNotEmpty(serviceInfo.email)
                || StringUtils.isNotEmpty(serviceInfo.fax) || StringUtils.isNotEmpty(serviceInfo.organization)
                || StringUtils.isNotEmpty(serviceInfo.personname)
                || StringUtils.isNotEmpty(serviceInfo.function) || StringUtils.isNotEmpty(serviceInfo.phone)) {
            contactMetadata = new ContactMetadata();
            contactMetadata.setContactAddress(contactAddress);
            contactMetadata.setEmail(serviceInfo.email);
            contactMetadata.setFax(serviceInfo.fax);
            contactMetadata.setOrganization(serviceInfo.organization);
            contactMetadata.setPerson(serviceInfo.personname);
            contactMetadata.setPosition(serviceInfo.function);
            contactMetadata.setTelephone(serviceInfo.phone);
        }
        servMetadata.setContact(contactMetadata);

    } catch (Exception exc) {
        // Show exception in log
        logger.error("Exception on getMetadataInfoFromWMS", exc);
        throw new ServerGeoException();
    }

    return servMetadata;
}

From source file:influent.server.clustering.EntityClustererTest.java

@SuppressWarnings("unused")
private FL_Cluster createClusterSummary(String name, Hashtable<String, Double> locationDist,
        Hashtable<String, Double> typeDist, int count, int indegree, int outdegree) {
    List<FL_Property> props = new ArrayList<FL_Property>();
    props.add(new PropertyHelper("inflowing", "inflowing", indegree,
            Arrays.asList(FL_PropertyTag.INFLOWING, FL_PropertyTag.AMOUNT, FL_PropertyTag.USD)));
    props.add(new PropertyHelper("outflowing", "outflowing", outdegree,
            Arrays.asList(FL_PropertyTag.OUTFLOWING, FL_PropertyTag.AMOUNT, FL_PropertyTag.USD)));
    props.add(new PropertyHelper("count", "count", count, FL_PropertyType.INTEGER, FL_PropertyTag.STAT));

    // create location dist prop
    List<FL_Frequency> freqs = new ArrayList<FL_Frequency>();

    for (String cc : locationDist.keySet()) {
        FL_GeoData geo = FL_GeoData.newBuilder().setText(null).setLat(null).setLon(null).setCc(cc).build();

        double freq = locationDist.get(cc);
        freqs.add(FL_Frequency.newBuilder().setRange(geo).setFrequency(freq).build());
    }/*w w w . j av a2  s .  c  o  m*/

    FL_DistributionRange range = FL_DistributionRange.newBuilder().setDistribution(freqs)
            .setRangeType(FL_RangeType.DISTRIBUTION).setType(FL_PropertyType.GEO).setIsProbability(false)
            .build();
    props.add(FL_Property.newBuilder().setKey("location-dist").setFriendlyText("location-dist").setRange(range)
            .setProvenance(null).setUncertainty(null).setTags(Arrays.asList(FL_PropertyTag.GEO)).build());

    // create type dist prop
    freqs = new ArrayList<FL_Frequency>();

    for (String type : typeDist.keySet()) {
        double freq = typeDist.get(type);
        freqs.add(FL_Frequency.newBuilder().setRange(type).setFrequency(freq).build());
    }

    range = FL_DistributionRange.newBuilder().setDistribution(freqs).setRangeType(FL_RangeType.DISTRIBUTION)
            .setType(FL_PropertyType.STRING).setIsProbability(false).build();
    props.add(FL_Property.newBuilder().setKey("type-dist").setFriendlyText("type-dist").setRange(range)
            .setProvenance(null).setUncertainty(null).setTags(Arrays.asList(FL_PropertyTag.TYPE)).build());

    return new ClusterHelper(
            InfluentId.fromNativeId(InfluentId.CLUSTER_SUMMARY, "cluster", name).getInfluentId(), name,
            Arrays.asList(FL_EntityTag.CLUSTER_SUMMARY), props, new ArrayList<String>(0),
            new ArrayList<String>(0), null, null, -1);
}