List of usage examples for java.util Hashtable get
@SuppressWarnings("unchecked") public synchronized V get(Object key)
From source file:edu.ku.brc.specify.tasks.RecordSetTask.java
/** * Merge two RecordSets removes duplicates and saves the destination RecordSet to the database * @param srcObj the source data (better be a RecordSet) * @param dstObj the destination data (better be a RecordSet) *//* w w w . j a va 2s.c om*/ protected void mergeRecordSets(final Object srcObj, final Object dstObj) { UsageTracker.incrUsageCount("RS.MERGE"); String MERGE_ERR = "RecordSetTask.MERGE_ERROR"; if (srcObj != dstObj && srcObj != null && dstObj != null && srcObj instanceof RecordSetIFace && dstObj instanceof RecordSetIFace) { RecordSetIFace srcRecordSet = srcObj instanceof RecordSetProxy ? ((RecordSetProxy) srcObj).getRecordSet() : (RecordSetIFace) srcObj; RecordSetIFace dstRecordSet = dstObj instanceof RecordSetProxy ? ((RecordSetProxy) dstObj).getRecordSet() : (RecordSetIFace) dstObj; if (srcRecordSet != null && dstRecordSet != null) { // It' just easier to build this up front DBTableInfo srcTI = DBTableIdMgr.getInstance().getInfoById(srcRecordSet.getDbTableId()); DBTableInfo dstTI = DBTableIdMgr.getInstance().getInfoById(dstRecordSet.getDbTableId()); String mergeErrStr = String.format(getResourceString(MERGE_ERR), new Object[] { srcTI.getShortClassName(), dstTI.getShortClassName() }); if (srcRecordSet.getDbTableId().equals(dstRecordSet.getDbTableId())) { List<Integer> dstIdList = RecordSet.getIdList(dstRecordSet.getRecordSetId(), null); List<Integer> srcIdList; if (srcRecordSet.getRecordSetId() == null) { srcIdList = new Vector<Integer>(); for (RecordSetItemIFace rsi : srcRecordSet.getOrderedItems()) { srcIdList.add(rsi.getRecordId()); } } else { srcIdList = RecordSet.getIdList(srcRecordSet.getRecordSetId(), null); } boolean debug = true; if (debug) { log.debug("Source:"); for (Integer id : srcIdList) { log.debug(" " + id); } log.debug("Dest:"); for (Integer id : dstIdList) { log.debug(" " + id); } log.debug(""); } Hashtable<Integer, Boolean> dupHash = new Hashtable<Integer, Boolean>(); for (Integer id : dstIdList) { dupHash.put(id, true); } List<Integer> newIdsList = new ArrayList<Integer>(srcIdList.size() + dstIdList.size()); for (Integer id : srcIdList) { if (dupHash.get(id) == null) { //dstRecordSet.addItem(id); // for saving with Hibernate newIdsList.add(id); } } if (debug) { log.debug(""); log.debug("New Dest:"); for (RecordSetItemIFace rsi : dstRecordSet.getItems()) { log.debug(" " + rsi.getRecordId()); } log.debug(""); } if (newIdsList.size() > 0) { //long start = System.currentTimeMillis(); boolean success = false; if (true) // Use SQL to save the merge RecordSets { boolean doRollback = false; Connection connection = DBConnection.getInstance().getConnection(); Statement stmt = null; try { connection.setAutoCommit(false); stmt = connection.createStatement(); for (int i = 0; i < newIdsList.size(); i++) { stmt.executeUpdate( "INSERT INTO recordsetitem (RecordSetID, RecordID, OrderNumber) VALUES (" + dstRecordSet.getRecordSetId() + "," + newIdsList.get(i) + "," + i + ")"); } connection.commit(); success = true; } catch (SQLException ex) { edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(RecordSetTask.class, ex); ex.printStackTrace(); doRollback = true; } finally { try { if (doRollback) { connection.rollback(); } if (stmt != null) { stmt.close(); } connection.setAutoCommit(true); } catch (SQLException ex2) { edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance() .capture(RecordSetTask.class, ex2); ex2.printStackTrace(); } } //} else //{ // success = persistRecordSet(dstRecordSet); } //System.err.println("Time: "+(System.currentTimeMillis() - start)); if (success) { String msg = String.format(getResourceString("RecordSetTask.MERGE_SUCCESS"), new Object[] { srcTI.getShortClassName(), dstTI.getShortClassName() }); UIRegistry.displayStatusBarText(msg); } else { JOptionPane.showMessageDialog(UIRegistry.getTopWindow(), mergeErrStr, getResourceString("Error"), JOptionPane.ERROR_MESSAGE); } } } else { JOptionPane.showMessageDialog(UIRegistry.getTopWindow(), mergeErrStr, getResourceString("Error"), JOptionPane.ERROR_MESSAGE); } } else { log.error("The src or the dst RecordSet were null src[" + srcRecordSet + "] dst[" + dstRecordSet + "]"); } } }
From source file:hu.sztaki.lpds.pgportal.portlets.workflow.EasyWorkflowPortlet.java
@Override public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException { String key;/*from w ww . jav a 2 s. co m*/ if ("editgraphURL".equals(request.getResourceID()) && request.getParameter("wfId") != null) { GraphEditorUtil.jnpl(request, response); return; } if ("refreshConfigURL".equals(request.getResourceID())) { List<String> graphs = new ArrayList<String>(); Enumeration<String> enm = PortalCacheService.getInstance().getUser(request.getRemoteUser()) .getAbstactWorkflows().keys(); while (enm.hasMoreElements()) graphs.add(enm.nextElement()); request.setAttribute("graphs", graphs); request.setAttribute("workflow", request.getPortletSession().getAttribute("cworkflow")); getPortletContext().getRequestDispatcher("/jsp/workflow/accepteditedgraph.jsp").include(request, response); return; } // ajax help if (request.getParameter("helptext") != null) { super.serveResource(request, response); return; } //output download if (request.getParameter("downloadType") != null) { response.setContentType("application/zip"); response.setProperty("Content-Disposition", "inline; filename=\"" + request.getParameter("workflowID") + "_" + request.getParameter("jobID") + "_" + request.getParameter("pidID") + "_outputs.zip\""); try { HttpDownload.fileDownload(request.getParameter("downloadType"), request, response); } catch (Exception e) { e.printStackTrace(); throw new PortletException("com error"); } return; } // logs download if (request.getParameter("fileID") != null) { response.setContentType("application/text"); response.setProperty("Content-Disposition", "inline; filename=\"" + request.getParameter("workflowID") + "_" + request.getParameter("jobID") + "_" + request.getParameter("pidID") + "_" + request.getParameter("fileID") + ".txt\""); try { HttpDownload.fileView(request, response); } catch (Exception e) { e.printStackTrace(); throw new PortletException("com error"); } return; } // file upload status if (request.getParameter("uploadStatus") != null) { PortletSession ps = request.getPortletSession(); // end of download if (ps.getAttribute("finaluploads") != null) { ps.removeAttribute("finaluploads"); ps.removeAttribute("uploaded"); ps.removeAttribute("upload"); ps.removeAttribute("uploading"); response.getWriter().write("Upload"); } else { try { Vector<String> tmp = (Vector<String>) ps.getAttribute("uploaded"); response.getWriter().write(" <br/>"); for (String t : tmp) response.getWriter().write("uploaded:" + t + "<br/>"); FileUploadProgressListener lisener = (FileUploadProgressListener) ((PortletFileUpload) ps .getAttribute("upload")).getProgressListener(); byte uplStatus = Byte.parseByte(lisener.getFileuploadstatus()); response.getWriter() .write("uploading:" + ps.getAttribute("uploading") + "->" + "<div style=\"width:" + uplStatus + "px;background-color:blue; \" >" + uplStatus + "%<br/>"); } catch (Exception ee) { System.out.println("file upload has not yet begun " + ps.getId()); ee.printStackTrace(); } } return; } // configuration Hashtable reqhash = new Hashtable(); Enumeration enm0 = request.getParameterNames(); while (enm0.hasMoreElements()) { key = "" + enm0.nextElement(); reqhash.put(key, request.getParameter(key)); } reqhash.put("sid", request.getPortletSession().getId()); try { ActionHandler t = null; try { String sid = request.getPortletSession().getId(); String workflowName = "" + request.getPortletSession().getAttribute("cworkflow"); String username = request.getRemoteUser(); String wftype = PortalCacheService.getInstance().getUser(username).getWorkflow(workflowName) .getWorkflowType(); reqhash.put("ws-pgrade.wftype", wftype); t = (ActionHandler) Class.forName( "hu.sztaki.lpds.pgportal.servlet.ajaxactions." + wftype + "." + request.getParameter("m")) .newInstance(); // System.out.println("***SERVE-RESOURCE:"+t.getClass().getName()); } catch (Exception e) { try { t = (ActionHandler) Class .forName("hu.sztaki.lpds.pgportal.servlet.ajaxactions." + request.getParameter("m")) .newInstance(); // System.out.println("***SERVE-RESOURCE:"+t.getClass().getName()); } catch (ClassNotFoundException e0) { System.out.println("classnotfound"); e0.printStackTrace(); } catch (InstantiationException e0) { e0.printStackTrace(); System.out.println("---Init error:hu.sztaki.lpds.pgportal.servlet.ajaxactions." + request.getParameter("m")); e0.printStackTrace(); } catch (IllegalAccessException e0) { e0.printStackTrace(); System.out.println("---Illegal Access:hu.sztaki.lpds.pgportal.servlet.ajaxactions." + request.getParameter("m")); e0.printStackTrace(); } } try { // Session transfer t.setSessionVariables(request.getPortletSession()); // Parameter setting reqhash.put("user", request.getRemoteUser()); if (request.getPortletSession().getAttribute("cworkflow") != null) reqhash.put("workflow", request.getPortletSession().getAttribute("cworkflow")); if (request.getPortletSession().getAttribute("detailsruntime") != null) reqhash.put("detailsruntime", request.getPortletSession().getAttribute("detailsruntime")); } catch (Exception e) { e.printStackTrace(); } // Content transfer if (t.getDispacher(reqhash) == null) { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { out.print(t.getOutput(reqhash)); } catch (Exception e) { e.printStackTrace(); } out.close(); } // Transfer of controlling else { Hashtable res = t.getParameters(reqhash); Enumeration enm = res.keys(); while (enm.hasMoreElements()) { key = "" + enm.nextElement(); request.setAttribute(key, res.get(key)); } PortletRequestDispatcher dispatcher = getPortletContext() .getRequestDispatcher(t.getDispacher(reqhash)); dispatcher.include(request, response); } } catch (Exception e) { e.printStackTrace(); System.out.println("-----------------------Can not be initialized:" + request.getParameter("m")); } }
From source file:org.hdiv.filter.ValidatorHelperRequest.java
/** * Checks if the cookies received in the request are correct. For that, it checks if they are in the user session. * /*from w w w .j a v a2 s. co m*/ * @param request * HttpServletRequest to validate * @param target * Part of the url that represents the target action * @return valid result if all the cookies received in the request are correct. They must have been previously * stored in the user session by HDIV to be correct. False otherwise. * @since HDIV 1.1 */ public ValidatorHelperResult validateRequestCookies(HttpServletRequest request, String target) { Cookie[] requestCookies = request.getCookies(); if ((requestCookies == null) || (requestCookies.length == 0)) { return ValidatorHelperResult.VALID; } Hashtable sessionCookies = (Hashtable) request.getSession().getAttribute(Constants.HDIV_COOKIES_KEY); if (sessionCookies == null) { return ValidatorHelperResult.VALID; } boolean cookiesConfidentiality = Boolean.TRUE.equals(this.hdivConfig.getConfidentiality()) && this.hdivConfig.isCookiesConfidentialityActivated(); for (int i = 0; i < requestCookies.length; i++) { boolean found = false; if (requestCookies[i].getName().equals(Constants.JSESSIONID)) { continue; } if (sessionCookies.containsKey(requestCookies[i].getName())) { SavedCookie savedCookie = (SavedCookie) sessionCookies.get(requestCookies[i].getName()); if (savedCookie.equals(requestCookies[i], cookiesConfidentiality)) { found = true; if (cookiesConfidentiality) { if (savedCookie.getValue() != null) { requestCookies[i].setValue(savedCookie.getValue()); } } } } if (!found) { this.logger.log(HDIVErrorCodes.COOKIE_INCORRECT, target, "cookie:" + requestCookies[i].getName(), requestCookies[i].getValue()); return new ValidatorHelperResult(HDIVErrorCodes.COOKIE_INCORRECT); } } return ValidatorHelperResult.VALID; }
From source file:eu.stratosphere.pact.runtime.sort.CombiningUnilateralSortMergerITCase.java
@Test public void testSortAndValidate() throws Exception { final Hashtable<TestData.Key, Integer> countTable = new Hashtable<TestData.Key, Integer>(KEY_MAX); for (int i = 1; i <= KEY_MAX; i++) { countTable.put(new TestData.Key(i), new Integer(0)); }//from ww w. java 2 s . c om // comparator final Comparator<TestData.Key> keyComparator = new TestData.KeyComparator(); // reader MockRecordReader reader = new MockRecordReader(); // merge iterator LOG.debug("initializing sortmerger"); TestCountCombiner2 comb = new TestCountCombiner2(); Sorter<Record> merger = new CombiningUnilateralSortMerger<Record>(comb, this.memoryManager, this.ioManager, reader, this.parentTask, this.serializerFactory, this.comparator, 64 * 1024 * 1024, 2, 0.7f); // emit data LOG.debug("emitting data"); TestData.Generator generator = new TestData.Generator(SEED, KEY_MAX, VALUE_LENGTH, KeyMode.RANDOM, ValueMode.FIX_LENGTH); Record rec = new Record(); final TestData.Value value = new TestData.Value("1"); for (int i = 0; i < NUM_PAIRS; i++) { Assert.assertTrue((rec = generator.next(rec)) != null); final TestData.Key key = rec.getField(0, TestData.Key.class); rec.setField(1, value); reader.emit(rec); countTable.put(new TestData.Key(key.getKey()), countTable.get(key) + 1); } reader.close(); rec = null; // check order MutableObjectIterator<Record> iterator = merger.getIterator(); LOG.debug("checking results"); Record rec1 = new Record(); Record rec2 = new Record(); Assert.assertTrue((rec1 = iterator.next(rec1)) != null); countTable.put(new TestData.Key(rec1.getField(0, TestData.Key.class).getKey()), countTable.get(rec1.getField(0, TestData.Key.class)) - (Integer.parseInt(rec1.getField(1, TestData.Value.class).toString()))); while ((rec2 = iterator.next(rec2)) != null) { final Key k1 = rec1.getField(0, TestData.Key.class); final Key k2 = rec2.getField(0, TestData.Key.class); Assert.assertTrue(keyComparator.compare(k1, k2) <= 0); countTable.put(new TestData.Key(k2.getKey()), countTable.get(k2) - (Integer.parseInt(rec2.getField(1, TestData.Value.class).toString()))); Record tmp = rec1; rec1 = rec2; k1.setKey(k2.getKey()); rec2 = tmp; } for (Integer cnt : countTable.values()) { Assert.assertTrue(cnt == 0); } merger.close(); // if the combiner was opened, it must have been closed Assert.assertTrue(comb.opened == comb.closed); }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerXMLHelper.java
@Override public boolean isLocaleInUse(final Locale locale) { Hashtable<String, Boolean> localeHash = new Hashtable<String, Boolean>(); for (SpLocaleContainer container : tables) { checkForLocales(container, localeHash); for (LocalizableItemIFace f : container.getContainerItems()) { checkForLocales(f, localeHash); }//from w ww . j a va 2 s .c o m } return localeHash.get(makeLocaleKey(locale)) != null; }
From source file:metabest.transformations.MetaModel2Use.java
private String simultaneousCompositionConstraint(List<Reference> references) { String constraints = ""; // obtain the containment references that can contain each class Hashtable<String, List<Reference>> containers = new Hashtable<String, List<Reference>>(); for (Reference ref : references) { if (ref.isAnnotated(Composition.NAME)) { String classname = ref.getReference().getName(); if (!containers.containsKey(classname)) containers.put(classname, new ArrayList<Reference>()); containers.get(classname).add(ref); }/* w w w.j a va2 s . c om*/ if (ref.getOpposite() != null && ref.getOpposite().isAnnotated(Composition.NAME)) { String classname = ref.getOpposite().getReference().getName(); if (!containers.containsKey(classname)) containers.put(classname, new ArrayList<Reference>()); containers.get(classname).add(ref.getOpposite()); } } // if a class can potentially be in more than two containers, add a constraint for (Entry<String, List<Reference>> entry : containers.entrySet()) { if (entry.getValue().size() > 1) { constraints += "\n\ncontext " + entry.getKey() + "\n\tinv single_container: "; constraints += "\n"; for (Reference ref : entry.getValue()) constraints += "\t" + ((MetaClass) ref.eContainer()).getName() + ".allInstances()->collect(o | o." + ref.getName() + ")->count(self) +\n"; constraints = constraints.substring(0, constraints.lastIndexOf("+")) + "<= 1"; } } if (!constraints.isEmpty()) constraints += "\n"; return constraints; }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerXMLHelper.java
@Override public List<PickList> getPickLists(final String disciplineName) { List<PickList> pickLists = new Vector<PickList>(); List<BldrPickList> bdlrPickLists; if (disciplineName == null) { bdlrPickLists = DataBuilder.getBldrPickLists("common"); Hashtable<String, Boolean> nameHash = new Hashtable<String, Boolean>(); for (DisciplineType dt : DisciplineType.getDisciplineList()) { List<BldrPickList> list = DataBuilder.getBldrPickLists(dt.getName()); if (list != null) { for (BldrPickList bpl : list) { if (nameHash.get(bpl.getName()) == null) { nameHash.put(bpl.getName(), true); bdlrPickLists.add(bpl); }/*from w ww.ja v a 2 s.co m*/ } } } } else { bdlrPickLists = DataBuilder.getBldrPickLists(disciplineName != null ? disciplineName : "common"); } for (BldrPickList pl : bdlrPickLists) { PickList pickList = createPickList(pl.getName(), pl.getType(), pl.getTableName(), pl.getFieldName(), pl.getFormatter(), pl.getReadOnly(), pl.getSizeLimit(), pl.getIsSystem(), pl.getSortType(), null); for (BldrPickListItem item : pl.getItems()) { pickList.addItem(item.getTitle(), item.getValue()); } pickLists.add(pickList); } return pickLists; }
From source file:fr.gouv.finances.dgfip.xemelios.data.impl.sqlconfig.TCriteria.java
protected String getSubstituteClause(String clause, CritereModel cm, Hashtable<String, FunctionEvaluator> evaluators, PropertiesExpansion applicationProperties) throws DataConfigurationException { String expr = clause;//from ww w . j a v a 2 s . c o m // search for ##OPERATEUR:id##-like tokens int ix = expr.indexOf("##"); while (ix >= 0) { //String left = expr.substring(0, ix); String sTmp = expr.substring(ix + 2); int pos = sTmp.indexOf("##"); if (pos < 0) { throw new DataConfigurationException(clause + " is not valid"); } //String right = sTmp.substring(pos + 2); String middle = sTmp.substring(0, pos); String property = cm.getProperty(middle); if (property == null) { throw new DataConfigurationException( "Property ##" + middle + "## not found in criteria " + cm.getId()); } expr = expr.replace("##" + middle + "##", StringEscapeUtils.escapeSql(property)); ix = expr.indexOf("##"); } // search for fn:xxx(args)-like tokens ix = expr.indexOf("fn:"); while (ix >= 0) { int openningParenthesisPos = expr.indexOf("(", ix); String functionName = expr.substring(ix + 3, openningParenthesisPos); try { int closingParenthesisPos = StringUtilities.getClosingParenthesisPos(expr, openningParenthesisPos); String args = expr.substring(openningParenthesisPos + 1, closingParenthesisPos); String ret = evaluators.get(functionName).evaluate(args, cm, applicationProperties); expr = expr.substring(0, ix) + ret + expr.substring(closingParenthesisPos + 1); } catch (ParseException pEx) { throw new DataConfigurationException("expression " + clause + " has unbalanced parenthesis"); } ix = expr.indexOf("fn:"); } return expr; }
From source file:ffx.ui.KeywordPanel.java
private void configToKeywords(FFXSystem newSystem) { CompositeConfiguration properties = newSystem.getProperties(); Hashtable<String, Keyword> keywordHash = new Hashtable<>(); // Create the "Comments" property. Keyword keyword = new Keyword("COMMENTS"); keywordHash.put("COMMENTS", keyword); // Loop over properties from the keyword file. Configuration config = properties.getConfiguration(0); if (config instanceof PropertiesConfiguration) { PropertiesConfiguration prop = (PropertiesConfiguration) config; Iterator<String> keys = prop.getKeys(); while (keys.hasNext()) { String key = keys.next(); if (keywordHash.contains(key)) { keyword = keywordHash.get(key); keyword.append(prop.getStringArray(key)); } else { String[] values = prop.getStringArray(key); keyword = new Keyword(key, values); keywordHash.put(key, keyword); }/*ww w. ja v a 2 s . co m*/ } } newSystem.setKeywords(keywordHash); }
From source file:dpfmanager.conformancechecker.tiff.reporting.PdfReport.java
/** * Parse an individual report to PDF.//from www . j av a 2 s .c om * * @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)); } }