List of usage examples for java.lang SecurityException getMessage
public String getMessage()
From source file:org.apache.directory.fortress.core.ReviewMgrConsole.java
/** * Description of the Method//w w w. j av a 2 s.c om */ void findUsers() { String userVal; ReaderUtil.clearScreen(); try { System.out.println("Enter User Search Value"); userVal = ReaderUtil.readLn(); User ue = new User(); ue.setUserId(userVal); ArrayList list = (ArrayList) rm.findUsers(ue); int size = list.size(); for (int i = 0; i < size; i++) { ue = (User) list.get(i); System.out.println("USER[" + i + "]"); System.out.println(" userId [" + ue.getUserId() + "]"); System.out.println(" internalId [" + ue.getInternalId() + "]"); System.out.println(" description [" + ue.getDescription() + "]"); System.out.println(" common name [" + ue.getCn() + "]"); System.out.println(" surname [" + ue.getSn() + "]"); System.out.println(" orgUnitId [" + ue.getOu() + "]"); System.out.println(" pwpolicy [" + ue.getPwPolicy() + "]"); System.out.println(" seqId [" + ue.getSequenceId() + "]"); printTemporal(ue, "USER"); printPosixAccount(ue, "POSIX"); printAddress(ue.getAddress(), "ADDRESS"); printPhone(ue.getPhones(), "PHONES"); printPhone(ue.getMobiles(), "MOBILES"); if (ue.getRoles() != null) { for (UserRole ur : ue.getRoles()) { printTemporal(ur, "RBACROLE"); } } if (ue.getAdminRoles() != null) { for (UserAdminRole ur : ue.getAdminRoles()) { printAdminRole(ur); printTemporal(ur, "ADMINROLE"); } } if (ue.getProperties() != null && ue.getProperties().size() > 0) { int ctr = 0; for (Enumeration e = ue.getProperties().propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); String val = ue.getProperty(key); System.out.println("prop key[" + ctr + "]=" + key); System.out.println("prop value[" + ctr++ + "]=" + val); } } System.out.println(); } System.out.println("ENTER to continue"); } catch (SecurityException e) { LOG.error("findUsers caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e); } ReaderUtil.readChar(); }
From source file:com.fiveamsolutions.nci.commons.audit.AuditLogInterceptor.java
private boolean collectionNeedsAuditing(Object auditableObj, Object newValue, Object oldValue, String property) {/*from w ww . j a v a 2 s.co m*/ // PO-6030: this method has undesirable side-effect that may impact // performance: it initializes lazy // collections on the auditableObj entity even if the collections don't // need to be audited. // Initialization happens during the CollectionUtils.isEqualCollection // check below. We should skip the check at least // when oldValue and newValue point to the same uninitialized collection // instance, because in such case it is obvious that the collection hasn't been touched. try { if (!sameNonInitializedCollection(newValue, oldValue)) { String cn = ProxyUtils.unEnhanceCGLIBClassName(auditableObj.getClass()); Method getter = getHibernateHelper().getConfiguration().getClassMapping(cn).getProperty(property) .getGetter(auditableObj.getClass()).getMethod(); if (getter.getAnnotation(MapKey.class) != null || getter.getAnnotation(MapKeyManyToMany.class) != null) { // this is some sort of map Map<?, ?> oldMap = (Map<?, ?>) oldValue; Map<?, ?> newMap = (Map<?, ?>) newValue; oldMap = oldMap == null ? Collections.emptyMap() : oldMap; newMap = newMap == null ? Collections.emptyMap() : newMap; return !equalsMap(oldMap, newMap); } else if (getter.getAnnotation(JoinTable.class) != null || getter.getAnnotation(OneToMany.class) != null) { Collection<?> oldSet = (Collection<?>) oldValue; Collection<?> newSet = (Collection<?>) newValue; return !CollectionUtils.isEqualCollection(oldSet == null ? Collections.emptySet() : oldSet, newSet == null ? Collections.emptySet() : newSet); } } } catch (SecurityException e) { LOG.error(e.getMessage(), e); } return false; }
From source file:org.apache.directory.fortress.core.ReviewMgrConsole.java
/** * *///from ww w . j a va2s . c o m void findUsersByOrg() { String szOu; ReaderUtil.clearScreen(); try { System.out.println("Enter OrgUnit name"); szOu = ReaderUtil.readLn(); OrgUnit ou = new OrgUnit(szOu); ou.setType(OrgUnit.Type.USER); List<User> list = rm.findUsers(ou); int ctr = 0; for (User ue : list) { System.out.println("USER[" + ++ctr + "]"); System.out.println(" userId [" + ue.getUserId() + "]"); System.out.println(" internalId [" + ue.getInternalId() + "]"); System.out.println(" description [" + ue.getDescription() + "]"); System.out.println(" common name [" + ue.getCn() + "]"); System.out.println(" surname [" + ue.getSn() + "]"); System.out.println(" orgUnitId [" + ue.getOu() + "]"); System.out.println(" pwpolicy [" + ue.getPwPolicy() + "]"); printTemporal(ue, "USER"); printAddress(ue.getAddress(), "ADDRESS"); printPhone(ue.getPhones(), "PHONES"); printPhone(ue.getMobiles(), "MOBILES"); if (ue.getRoles() != null) { for (UserRole ur : ue.getRoles()) { printTemporal(ur, "RBACROLE"); } } if (ue.getAdminRoles() != null) { for (UserAdminRole ur : ue.getAdminRoles()) { printAdminRole(ur); printTemporal(ur, "ADMINROLE"); } } if (ue.getProperties() != null && ue.getProperties().size() > 0) { int pctr = 0; for (Enumeration e = ue.getProperties().propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); String val = ue.getProperty(key); System.out.println("prop key[" + pctr + "]=" + key); System.out.println("prop value[" + pctr++ + "]=" + val); } } System.out.println(); } System.out.println("ENTER to continue"); } catch (SecurityException e) { LOG.error("findUsersByOrg caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e); } ReaderUtil.readChar(); }
From source file:org.apache.directory.fortress.core.ReviewMgrConsole.java
/** * Description of the Method//from w w w . j av a2 s . co m */ void readPermission() { Permission pe; try { Permission permission = new Permission(); ReaderUtil.clearScreen(); System.out.println("Enter perm object name:"); String name = ReaderUtil.readLn(); permission.setObjName(name); System.out.println("Enter perm object id or null for none:"); String oid = ReaderUtil.readLn(); permission.setObjId(oid); System.out.println("Enter perm operation name:"); String op = ReaderUtil.readLn(); permission.setOpName(op); pe = rm.readPermission(permission); if (pe != null) { //System.out.println("perm operation [" + pe.operation + "]"); System.out.println("object name [" + pe.getObjName() + "]"); System.out.println("object id [" + pe.getObjId() + "]"); System.out.println("operation name [" + pe.getOpName() + "]"); System.out.println("abstract perm name [" + pe.getAbstractName() + "]"); System.out.println("internalId [" + pe.getInternalId() + "]"); if (pe.getUsers() != null && pe.getUsers().size() > 0) { int ctr = 0; for (String user : pe.getUsers()) { System.out.println("user[" + ctr++ + "]=" + user); } } if (pe.getRoles() != null && pe.getRoles().size() > 0) { int ctr = 0; for (String role : pe.getRoles()) { System.out.println("name[" + ctr++ + "]=" + role); } } if (pe.getProperties() != null && pe.getProperties().size() > 0) { int ctr = 0; for (Enumeration e = pe.getProperties().propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); String val = pe.getProperty(key); System.out.println("prop key[" + ctr + "]=" + key); System.out.println("prop value[" + ctr++ + "]=" + val); } } System.out.println("**"); System.out.println("read operation complete"); System.out.println("ENTER to continue"); } } catch (SecurityException e) { LOG.error("readPermission caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e); } ReaderUtil.readChar(); }
From source file:com.cws.esolutions.core.processors.impl.DNSServiceRequestProcessorImpl.java
/** * @see com.cws.esolutions.core.processors.interfaces.IDNSServiceRequestProcessor#createNewService(com.cws.esolutions.core.processors.dto.DNSServiceRequest) *///from ww w . j av a 2s . c om public DNSServiceResponse createNewService(final DNSServiceRequest request) throws DNSServiceException { final String methodName = IDNSServiceRequestProcessor.CNAME + "#createNewService(final DNSServiceRequest request) throws DNSServiceException"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("DNSServiceRequest: {}" + request); } DNSServiceResponse response = new DNSServiceResponse(); final DNSEntry entry = request.getDnsEntry(); final UserAccount userAccount = request.getUserAccount(); final RequestHostInfo reqInfo = request.getRequestInfo(); if (DEBUG) { DEBUGGER.debug("DNSEntry: {}", entry); DEBUGGER.debug("UserAccount: {}", userAccount); DEBUGGER.debug("RequestHostInfo: {}", reqInfo); } try { // this will require admin and service authorization AccessControlServiceRequest accessRequest = new AccessControlServiceRequest(); accessRequest.setUserAccount(userAccount); accessRequest.setServiceGuid(request.getServiceId()); if (DEBUG) { DEBUGGER.debug("AccessControlServiceRequest: {}", accessRequest); } AccessControlServiceResponse accessResponse = accessControl.isUserAuthorized(accessRequest); if (DEBUG) { DEBUGGER.debug("AccessControlServiceResponse accessResponse: {}", accessResponse); } if (!(accessResponse.getIsUserAuthorized())) { // unauthorized response.setRequestStatus(CoreServicesStatus.UNAUTHORIZED); // audit try { AuditEntry auditEntry = new AuditEntry(); auditEntry.setHostInfo(reqInfo); auditEntry.setAuditType(AuditType.CREATEDNSRECORD); auditEntry.setAuthorized(Boolean.FALSE); auditEntry.setUserAccount(userAccount); auditEntry.setApplicationId(request.getApplicationId()); auditEntry.setApplicationName(request.getApplicationName()); if (DEBUG) { DEBUGGER.debug("AuditEntry: {}", auditEntry); } AuditRequest auditRequest = new AuditRequest(); auditRequest.setAuditEntry(auditEntry); if (DEBUG) { DEBUGGER.debug("AuditRequest: {}", auditRequest); } auditor.auditRequest(auditRequest); } catch (AuditServiceException asx) { ERROR_RECORDER.error(asx.getMessage(), asx); } return response; } // here we're going to generate the actual file given the provided // data. at this point everything should already be in the database // we could generate the zone file without having a "zone data" field, // but the zone data field makes it somewhat easier, since its already // been created for presentation/approval to the requestor List<DNSRecord> apexRecords = entry.getApexRecords(); if (DEBUG) { DEBUGGER.debug("apexRecords: {}", apexRecords); } StringBuilder pBuilder = new StringBuilder() .append("$ORIGIN " + entry.getOrigin() + CoreServiceConstants.LINE_BREAK) .append("$TTL " + entry.getLifetime() + CoreServiceConstants.LINE_BREAK) .append(entry.getSiteName() + " IN SOA " + entry.getMaster() + " " + entry.getOwner() + " (" + CoreServiceConstants.LINE_BREAK) .append(" " + entry.getSerialNumber() + "," + CoreServiceConstants.LINE_BREAK) .append(" " + entry.getRefresh() + "," + CoreServiceConstants.LINE_BREAK) .append(" " + entry.getRetry() + "," + CoreServiceConstants.LINE_BREAK) .append(" " + entry.getExpiry() + "," + CoreServiceConstants.LINE_BREAK) .append(" " + entry.getMinimum() + "," + CoreServiceConstants.LINE_BREAK) .append(" )" + CoreServiceConstants.LINE_BREAK); for (DNSRecord record : apexRecords) { if (DEBUG) { DEBUGGER.debug("DNSRecord: {}", record); } switch (record.getRecordType()) { case MX: pBuilder.append(" " + record.getRecordClass() + " " + record.getRecordType() + " " + record.getRecordPriority() + " " + record.getRecordAddress() + CoreServiceConstants.LINE_BREAK); break; default: pBuilder.append(" " + record.getRecordClass() + " " + record.getRecordType() + " " + record.getRecordAddress() + CoreServiceConstants.LINE_BREAK); break; } } if ((entry.getSubRecords() != null) && (entry.getSubRecords().size() != 0)) { pBuilder.append(CoreServiceConstants.LINE_BREAK); pBuilder.append("$ORIGIN " + entry.getSiteName() + "." + CoreServiceConstants.LINE_BREAK); // always put the site name as the initial origin for (DNSRecord record : entry.getSubRecords()) { if (DEBUG) { DEBUGGER.debug("DNSRecord: {}", record); } if (!(StringUtils.equals(record.getRecordOrigin(), ".")) || StringUtils.equals(record.getRecordOrigin(), entry.getSiteName())) { if (!(StringUtils.contains(pBuilder.toString(), record.getRecordOrigin()))) { pBuilder.append(CoreServiceConstants.LINE_BREAK); pBuilder.append( "$ORIGIN " + record.getRecordOrigin() + "." + CoreServiceConstants.LINE_BREAK); } } switch (record.getRecordType()) { case MX: pBuilder.append(" " + record.getRecordClass() + " " + record.getRecordType() + " " + record.getRecordPriority() + " " + record.getRecordAddress() + CoreServiceConstants.LINE_BREAK); break; case SRV: if (StringUtils.isNotEmpty(record.getRecordName())) { pBuilder.append(record.getRecordService() + "." + record.getRecordProtocol() + " " + record.getRecordName() + " " + record.getRecordLifetime() + " " + record.getRecordClass() + " " + record.getRecordType() + " " + record.getRecordPriority() + " " + record.getRecordWeight() + " " + record.getRecordPort() + " " + record.getRecordAddress() + CoreServiceConstants.LINE_BREAK); } else { pBuilder.append(record.getRecordService() + "." + record.getRecordProtocol() + " " + record.getRecordLifetime() + " " + record.getRecordClass() + " " + record.getRecordType() + " " + record.getRecordPriority() + " " + record.getRecordWeight() + " " + record.getRecordPort() + " " + record.getRecordAddress() + CoreServiceConstants.LINE_BREAK); } break; default: if ((record.getRecordAddress() != null) && (record.getRecordAddresses() == null)) { pBuilder.append(record.getRecordName() + " " + record.getRecordClass() + " " + record.getRecordType() + " " + record.getRecordAddress() + CoreServiceConstants.LINE_BREAK); } else { pBuilder.append(record.getRecordName() + " " + record.getRecordClass() + " " + record.getRecordType() + " " + record.getRecordAddresses().get(0) + CoreServiceConstants.LINE_BREAK); for (int x = 1; x != record.getRecordAddresses().size(); x++) { if (DEBUG) { DEBUGGER.debug("recordAddress: {}: ", record.getRecordAddresses().get(x)); } pBuilder.append(" " + record.getRecordClass() + " " + record.getRecordType() + " " + record.getRecordAddresses().get(x) + CoreServiceConstants.LINE_BREAK); } } break; } } } // return the successful response back and the zone data response.setRequestStatus(CoreServicesStatus.SUCCESS); response.setZoneData(pBuilder); } catch (SecurityException sx) { ERROR_RECORDER.error(sx.getMessage(), sx); throw new DNSServiceException(sx.getMessage(), sx); } catch (AccessControlServiceException acsx) { ERROR_RECORDER.error(acsx.getMessage(), acsx); throw new DNSServiceException(acsx.getMessage(), acsx); } finally { // audit try { AuditEntry auditEntry = new AuditEntry(); auditEntry.setHostInfo(reqInfo); auditEntry.setAuditType(AuditType.CREATEDNSRECORD); auditEntry.setUserAccount(userAccount); auditEntry.setAuthorized(Boolean.TRUE); auditEntry.setApplicationId(request.getApplicationId()); auditEntry.setApplicationName(request.getApplicationName()); if (DEBUG) { DEBUGGER.debug("AuditEntry: {}", auditEntry); } AuditRequest auditRequest = new AuditRequest(); auditRequest.setAuditEntry(auditEntry); if (DEBUG) { DEBUGGER.debug("AuditRequest: {}", auditRequest); } auditor.auditRequest(auditRequest); } catch (AuditServiceException asx) { ERROR_RECORDER.error(asx.getMessage(), asx); } } return response; }
From source file:org.cerberus.crud.dao.impl.ApplicationObjectDAO.java
@Override public Answer uploadFile(int id, FileItem file) { MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED) .resolveDescription("DESCRIPTION", "cerberus_applicationobject_path Parameter not found"); AnswerItem a = parameterService.readByKey("", "cerberus_applicationobject_path"); if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) { Parameter p = (Parameter) a.getItem(); String uploadPath = p.getValue(); File appDir = new File(uploadPath + "/" + id); if (!appDir.exists()) { try { appDir.mkdirs();/* w w w. j a v a 2s .c om*/ } catch (SecurityException se) { LOG.warn("Unable to create application dir: " + se.getMessage()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED) .resolveDescription("DESCRIPTION", se.toString()); a.setResultMessage(msg); } } if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) { deleteFolder(appDir, false); File picture = new File(uploadPath + "/" + id + "/" + file.getName()); try { file.write(picture); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("DESCRIPTION", "Application Object file uploaded"); msg.setDescription(msg.getDescription().replace("%ITEM%", "Application Object") .replace("%OPERATION%", "Upload")); } catch (Exception e) { LOG.warn("Unable to upload application object file: " + e.getMessage()); msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED) .resolveDescription("DESCRIPTION", e.toString()); } } } else { LOG.warn("cerberus_applicationobject_path Parameter not found"); } a.setResultMessage(msg); return a; }
From source file:org.apache.directory.fortress.core.AuditMgrConsole.java
void getAdminModReport() { ReaderUtil.clearScreen();//from w w w . j ava 2 s.c o m try { UserAudit uAudit = new UserAudit(); System.out.println("Enter userId to search Audit Mods with or NULL for skip:"); String val = ReaderUtil.readLn(); if (StringUtils.isNotEmpty(val)) { uAudit.setUserId(val); System.out.println("size=" + val.length() + " val=" + val); } System.out.println("Check within the last n hours? Enter number of hours or null for unlimited"); val = ReaderUtil.readLn(); if (val != null && val.length() > 0) { int hours = Integer.parseInt(val); Date date = new Date(); long millis = date.getTime(); millis = millis - (1000 * 60 * 60 * hours); Date date2 = new Date(millis); uAudit.setBeginDate(date2); } /* System.out.println("Enter begin time and date - format YYYYMMDDHHMM or null for unlimited"); val = ReaderUtil.readLn(); if (val != null && val.length() > 0) { //int hours = Integer.parseInt(val); int year = new Integer(val.substring(0, 3)); int month = new Integer(val.substring(0, 3)); int day = new Integer(val.substring(0, 3)); Date date = new Date(); java.sql.Date date2 = new java.sql.Date(2011, 11, 25); date2.getTime(); long millis = date.getTime(); millis = millis - (1000 * 60 * 60 * hours); Date date2 = new Date(millis); uAudit.setBeginDate(date2); } */ System.out.println("Enter admin object name to search Audit Mods with or NULL for skip:"); val = ReaderUtil.readLn(); if (StringUtils.isNotEmpty(val)) { uAudit.setObjName(val); System.out.println("size=" + val.length() + " val=" + val); } System.out.println("Enter admin operation name to search Audit Mods with or NULL for skip:"); val = ReaderUtil.readLn(); if (StringUtils.isNotEmpty(val)) { uAudit.setOpName(val); System.out.println("size=" + val.length() + " val=" + val); } List<Mod> list = am.searchAdminMods(uAudit); printMods(list); System.out.println("ENTER to continue"); } catch (SecurityException e) { LOG.error("getAdminModReport caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e); } ReaderUtil.readChar(); }
From source file:org.apache.directory.fortress.core.AuditMgrConsole.java
void getAuthNInvalidReport() { ReaderUtil.clearScreen();//w w w . j a va 2s. c o m try { UserAudit uAudit = new UserAudit(); System.out.println("Enter userId to search Audit AuthZs with:"); String val = ReaderUtil.readLn(); if (StringUtils.isNotEmpty(val)) { uAudit.setUserId(val); System.out.println("size=" + val.length() + " val=" + val); } else { System.out.println("val is empty or null"); } //uAudit.setUserId(val); //System.out.println("Check for failed only? (Enter 'Y' for yes or 'N' for no"); //val = ReaderUtil.readLn(); //if (val.equalsIgnoreCase("Y")) uAudit.setFailedOnly(true); System.out.println("Check within the last n hours? Enter number of hours or null for unlimited"); val = ReaderUtil.readLn(); if (val != null && val.length() > 0) { int hours = Integer.parseInt(val); Date date = new Date(); long millis = date.getTime(); millis = millis - (1000 * 60 * 60 * hours); Date date2 = new Date(millis); uAudit.setBeginDate(date2); } List<AuthZ> list = am.searchInvalidUsers(uAudit); printfailedAuthNReport(list); System.out.println("ENTER to continue"); } catch (SecurityException e) { LOG.error("getAuthNInvalidReport caught SecurityException rc=" + e.getErrorId() + ", msg=" + e.getMessage(), e); } ReaderUtil.readChar(); }
From source file:com.ephesoft.dcma.imagemagick.MultiPageExecutor.java
/** * This method creates multi page pdf using ghost script command. * /*from www . j a va2s . co m*/ * @param batchInstanceThread {@link BatchInstanceThread} * @param pages11 {@link String []} * @param gsCmdParam {@link String} * @param ghostScriptCommand {@link String} * @param maxFilesProcessedPerLoop {@link Integer} * @param documentIdInt {@link String} */ public MultiPageExecutor(BatchInstanceThread batchInstanceThread, final String[] pages11, final String gsCmdParam, final String ghostScriptCommand, final Integer maxFilesProcessedPerLoop, final String documentIdInt) { if (pages11 != null && pages11.length > 0) { this.pages = new String[pages11.length]; this.pages = pages11.clone(); this.documentId = documentIdInt; batchInstanceThread.add(new AbstractRunnable() { @Override public void run() { String ghostScriptPath = System.getenv(IImageMagickCommonConstants.GHOSTSCRIPT_ENV_VARIABLE); List<String> ghostScriptCommandList = new ArrayList<String>(); File systemFileFolderPath = new File(pages[0]); String systemFolderPath = systemFileFolderPath.getParent(); String outputFileName = ""; String[] gsCmdParams = gsCmdParam.split(SPACE); int noOfPages = pages.length; int currPageNo = 0; int counter = 1; File fileToBeDeleted = null; String prevTempFilePath = null; String nextTempFilePath = null; String tempFilePath = pages[noOfPages - 1].substring(0, pages[noOfPages - 1].lastIndexOf('.') == -1 ? pages[noOfPages].length() : pages[noOfPages - 1].lastIndexOf('.')); boolean isLastPage = false; boolean isDBatchAddedToGSCmd = false; while (!isLastPage) { ghostScriptCommandList.clear(); LOGGER.info("creating ghostscript command for multipage pdf creation."); int maxNoOfPages = counter * maxFilesProcessedPerLoop; for (String param : gsCmdParams) { if (!isDBatchAddedToGSCmd && param.trim().equalsIgnoreCase(GHOST_SCRIPT_COMMAND_OUTPUT_PARAMETERS)) { isDBatchAddedToGSCmd = true; } ghostScriptCommandList.add(param); } if (!isDBatchAddedToGSCmd) { ghostScriptCommandList.add(GHOST_SCRIPT_COMMAND_OUTPUT_PARAMETERS); } if (maxNoOfPages >= noOfPages - 1) { if (OSUtil.isWindows()) { outputFileName = pages[noOfPages - 1] .substring(pages[noOfPages - 1].lastIndexOf(File.separator) + 1); ghostScriptCommandList.add(GHOST_SCRIPT_COMMAND_OUTPUT_FILE_PARAM + outputFileName); } else if (OSUtil.isUnix()) { ghostScriptCommandList .add(GHOST_SCRIPT_COMMAND_OUTPUT_FILE_PARAM + pages[noOfPages - 1]); } isLastPage = true; } else { nextTempFilePath = tempFilePath + '_' + '_' + counter + documentId + FileType.PDF.getExtensionWithDot(); outputFileName = nextTempFilePath .substring(nextTempFilePath.lastIndexOf(File.separator) + 1); if (OSUtil.isWindows()) { ghostScriptCommandList.add(DOUBLE_QUOTES + GHOST_SCRIPT_COMMAND_OUTPUT_FILE_PARAM + outputFileName + DOUBLE_QUOTES); } else if (OSUtil.isUnix()) { ghostScriptCommandList .add(GHOST_SCRIPT_COMMAND_OUTPUT_FILE_PARAM + nextTempFilePath); } } if (prevTempFilePath != null) { ghostScriptCommandList.add(prevTempFilePath); fileToBeDeleted = new File(prevTempFilePath); } prevTempFilePath = nextTempFilePath; counter++; for (; currPageNo < noOfPages - 1 && currPageNo < maxNoOfPages; currPageNo++) { if (OSUtil.isWindows()) { ghostScriptCommandList .add(DOUBLE_QUOTES + pages[currPageNo].substring( pages[currPageNo].lastIndexOf(File.separator) + 1) + DOUBLE_QUOTES); } else if (OSUtil.isUnix()) { ghostScriptCommandList.add(pages[currPageNo]); } } List<String> commandList = new ArrayList<String>(); if (OSUtil.isWindows()) { String absoluteFilePath = systemFolderPath + File.separator + outputFileName; String absoluteGhostScriptParametersFilePath = absoluteFilePath.substring(0, absoluteFilePath.lastIndexOf('.')) + FileType.SER.getExtensionWithDot(); File ghostScriptCommandParametersFile = new File(absoluteGhostScriptParametersFilePath); writeGhosScriptParametersToFile(ghostScriptCommandParametersFile, ghostScriptCommandList); makeCommandForWindows(commandList, ghostScriptPath, systemFolderPath, absoluteGhostScriptParametersFilePath); } else if (OSUtil.isUnix()) { commandList.add(ghostScriptPath + File.separator + ghostScriptCommand); commandList.addAll(ghostScriptCommandList); } LOGGER.info("Command for multi page pdf creation : " + commandList); String[] cmds = (String[]) commandList.toArray(new String[commandList.size()]); executeCreatePdfCommand(fileToBeDeleted, cmds); } if (fileToBeDeleted != null && fileToBeDeleted.exists()) { LOGGER.info("Deleting temporary file : " + fileToBeDeleted.getAbsolutePath()); fileToBeDeleted.delete(); } } private void executeCreatePdfCommand(File fileToBeDeleted, String[] cmds) { try { Process process = Runtime.getRuntime().exec(cmds); InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream()); BufferedReader input = new BufferedReader(inputStreamReader); String line = null; do { line = input.readLine(); LOGGER.info(line); } while (line != null); int exitValue = process.exitValue(); if (exitValue != 0) { LOGGER.error("Process exited with an invalid exit value : " + exitValue); setDcmaApplicationException( new DCMAApplicationException(MULTIPAGE_PDF_CREATION_ERROR_MSG)); } if (fileToBeDeleted != null && fileToBeDeleted.exists()) { LOGGER.info("Deleting temporary file : " + fileToBeDeleted.getAbsolutePath()); fileToBeDeleted.delete(); } } catch (IOException e) { LOGGER.error(MULTIPAGE_PDF_CREATION_ERROR_MSG + e.getMessage(), e); setDcmaApplicationException( new DCMAApplicationException(MULTIPAGE_PDF_CREATION_ERROR_MSG + e.getMessage(), e)); } catch (SecurityException se) { LOGGER.error("Cannot delete the temporary file : " + fileToBeDeleted.getAbsolutePath() + se.getMessage(), se); } } private void writeGhosScriptParametersToFile(File file, List<String> ghostScriptCommandList) { LOGGER.info("Writing ghostscript parameters to :" + file.getAbsolutePath()); StringBuffer ghostScriptParametersBuffer = new StringBuffer(); for (String command : ghostScriptCommandList) { ghostScriptParametersBuffer.append(command); ghostScriptParametersBuffer.append(SPACE); } try { FileUtils.writeStringToFile(file, ghostScriptParametersBuffer.toString()); } catch (IOException e) { LOGGER.error(e.getMessage(), e); } } private void makeCommandForWindows(List<String> commandList, String ghostScriptPath, String systemFolderPath, String ghostScriptParametersFileAbsolutePath) { LOGGER.info("Forming Command for Ghostscript Executor(Windows)."); commandList.add(System.getenv(GS_PDF_EXECUTOR_PATH)); commandList.add( DOUBLE_QUOTES + ghostScriptPath + File.separator + ghostScriptCommand + DOUBLE_QUOTES); commandList.add(DOUBLE_QUOTES + systemFolderPath + DOUBLE_QUOTES); commandList.add(DOUBLE_QUOTES + ghostScriptParametersFileAbsolutePath + DOUBLE_QUOTES); } }); } }
From source file:com.klaasnotfound.locationassistant.LocationAssistant.java
protected void checkInitialLocation() { if (!googleApiClient.isConnected() || !permissionGranted || !locationRequested || !locationStatusOk) return;// w w w .j a v a 2 s. com try { Location location = LocationServices.FusedLocationApi.getLastLocation(googleApiClient); onLocationChanged(location); } catch (SecurityException e) { if (!quiet) Log.e(getClass().getSimpleName(), "Error while requesting last location:\n " + e.toString()); if (listener != null) listener.onError(ErrorType.RETRIEVAL, "Could not retrieve initial location:\n" + e.getMessage()); } }