List of usage examples for org.apache.commons.lang StringUtils rightPad
public static String rightPad(String str, int size)
Right pad a String with spaces (' ').
From source file:de.codesourcery.planning.demo.SimulationDemo.java
private static void printResources(List<IFactory> factories, IResourceManager manager) { final Set<IProductionLocation> locations = new HashSet<IProductionLocation>(); for (IFactory f : factories) { for (IFactorySlot slot : f.getSlots()) { locations.add(slot.getInputLocation()); locations.add(slot.getOutputLocation()); }//from ww w. ja va 2 s.co m } for (IProductionLocation location : locations) { final List<IResource> r = new ArrayList<IResource>(manager.getResourcesAt(location)); // Collections.sort( r , new Comparator<IResource>() { // // @Override // public int compare(IResource o1, IResource o2) // { // return o1.getType().compareTo( o2.getType() ); // } // } ); System.out.println("\nResources at " + location + ":\n\n"); for (IResource resource : r) { System.out.println(StringUtils.rightPad(resource.getType().toString(), 25) + " " + StringUtils.leftPad("" + resource.getAmount(), 15)); } } }
From source file:de.codesourcery.eve.skills.ui.components.impl.OreChartComponent.java
protected void saveSummaryToClipboard() { final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); final StringBuffer buffer = new StringBuffer(); buffer.append("Current date: " + DateHelper.format(new Date()) + "\n"); buffer.append("Region: " + getDefaultRegion().getName() + "\n"); buffer.append("\n"); for (int i = 0; i < mineralPriceTableModel.getRowCount(); i++) { final MineralPrice minPrice = mineralPriceTableModel.getRow(i); buffer.append(StringUtils.rightPad(minPrice.itemName(), 13)).append(" : "); buffer.append(StringUtils.leftPad(AmountHelper.formatISKAmount(minPrice.getSellPrice()), 10) + " ISK"); buffer.append("\n"); }/*from www . j ava 2 s. co m*/ buffer.append("\n"); final List<CsvRow> data = new ArrayList<CsvRow>(); for (int i = 0; i < tableModel.getRowCount(); i++) { final TableRow row = tableModel.getRow(i); final ISKAmount amount = tableModel.getISKperM3(row); data.add(new CsvRow(row.oreName, amount)); } Collections.sort(data); for (CsvRow r : data) { buffer.append(StringUtils.rightPad(r.oreName, 13)).append(" : "); buffer.append(StringUtils.leftPad(AmountHelper.formatISKAmount(r.iskPerM3), 10) + " ISK / m3"); buffer.append("\n"); } clipboard.setContents(new PlainTextTransferable(buffer.toString()), null); }
From source file:com.asp.tranlog.TsvImporterMapper.java
/** * To create rowkey byte array, the rule is like this: row key can be * composed by several columns change every columns values to String, if * column type is date, change to long first if column values are "kv1 ", * "kv2", " kv3", ... then the row key string will be "kv1 +kv2+ kv3", * that means the space char will be kept * /*from w w w . jav a 2 s . co m*/ * @param lineBytes * @param parsed * @return * @throws BadTsvLineException */ protected byte[] createRowkeyByteArray(byte[] lineBytes, ImportTsv.TsvParser.ParsedLine parsed) throws BadTsvLineException { try { byte[] colBytes = null; Date tmpDate = null; StringBuffer sb = new StringBuffer(); for (int i = 0; i < keyColIndex.length; i++) { if (i > 0 && hbase_rowkey_separator.length() > 0) sb.append(hbase_rowkey_separator); colBytes = getInputColBytes(lineBytes, parsed, keyColIndex[i]); if (colBytes == null) throw new BadTsvLineException("Failed to get column bytes for " + keyColIndex[i]); String rowCol; if (columnTypes[keyColIndex[i]] == ImportTsv.COL_TYPE_DATETIME) { tmpDate = parseTimestamp(colBytes, keyColIndex[i]); rowCol = Long.toString(tmpDate.getTime()); sb.append(rowCol); } else if (columnTypes[keyColIndex[i]] == ImportTsv.COL_TYPE_STRING) { // String lineStr = new String(value.getBytes(), 0, // value.getLength(), "gb18030"); // byte[] lineBytes = new Text(lineStr).getBytes(); if (StringUtils.isEmpty(charset)) charset = HConstants.UTF8_ENCODING; String lineStr = new String(colBytes, charset); colBytes = new Text(lineStr).getBytes(); rowCol = Bytes.toString(colBytes); // if original string len < specified string len, then use // substring, else using space to right pad. if (keyColLen[i] != 0 && rowCol.length() > keyColLen[i]) sb.append(rowCol.substring(0, keyColLen[i])); else sb.append(StringUtils.rightPad(rowCol, keyColLen[i])); } else if (columnTypes[keyColIndex[i]] == ImportTsv.COL_TYPE_INT) { int intVal = Integer.parseInt(Bytes.toString(colBytes)); rowCol = Integer.toString(intVal); sb.append(StringUtils.leftPad(rowCol, keyColLen[i], '0')); } else if (columnTypes[keyColIndex[i]] == ImportTsv.COL_TYPE_DOUBLE) { double dbval = Double.parseDouble(Bytes.toString(colBytes)); rowCol = Double.toString(dbval); sb.append(rowCol); } else if (columnTypes[keyColIndex[i]] == ImportTsv.COL_TYPE_LONG) { long longVal = Long.parseLong(Bytes.toString(colBytes)); rowCol = Long.toString(longVal); sb.append(StringUtils.leftPad(rowCol, keyColLen[i], '0')); } else { rowCol = Bytes.toString(colBytes); // if original string len < specified string len, then use // substring, else using space to right pad. if (keyColLen[i] != 0 && rowCol.length() > keyColLen[i]) sb.append(rowCol.substring(0, keyColLen[i])); else sb.append(StringUtils.rightPad(rowCol, keyColLen[i])); } } return sb.toString().getBytes(); } catch (Exception e) { throw new BadTsvLineException(e.getMessage()); } }
From source file:com.tesora.dve.tools.CLIBuilder.java
public void cmd_help() { if (currentCommandMap.isDefaultMap()) { println("Available commands are:"); } else {/*from ww w . j a v a 2 s . co m*/ println("Available commands in '" + currentCommandMap.getMode() + "' mode are:"); } // Indent the description, but put it on a new line if it's too long. final int maxCmdLen = 30; final int maxDescLen = 71; final int initialIndentSize = 2; final int gapSize = 2; final String cmdIndent = StringUtils.rightPad("", initialIndentSize); final String descIndent = StringUtils.rightPad("", initialIndentSize + maxCmdLen + gapSize); final ArrayList<CommandType> fullSet = new ArrayList<CommandType>(globalCommandMap.values()); fullSet.addAll(currentCommandMap.values()); for (final CommandType command : fullSet) { if (!command.m_internal || debugMode) { String remainingDesc = command.m_desc; String cmd = command.toString(); boolean moreDesc = true; int index = -1; do { String desc; if (remainingDesc.length() <= maxDescLen) { desc = remainingDesc; moreDesc = false; } else { int tempIndex = remainingDesc.indexOf(" ", index); while (((tempIndex = remainingDesc.indexOf(" ", tempIndex + 1)) > -1) && (tempIndex < maxDescLen)) { index = tempIndex; } desc = remainingDesc.substring(0, index); remainingDesc = remainingDesc.substring(index + 1); } if (cmd.length() > maxCmdLen) { println(cmdIndent + cmd); println(descIndent + desc); } else { println(cmdIndent + StringUtils.rightPad(cmd, maxCmdLen + gapSize) + desc); } cmd = ""; } while (moreDesc); } } }
From source file:com.rsmart.kuali.kfs.cr.document.service.impl.GlTransactionServiceImpl.java
/** * Generate GlPendingTransaction/*from w w w . j a va2s . c o m*/ * * @param paymentGroup * @param financialDocumentTypeCode * @param stale */ private void generateGlPendingTransaction(PaymentGroup paymentGroup, String financialDocumentTypeCode, boolean stale) { List<PaymentAccountDetail> accountListings = new ArrayList<PaymentAccountDetail>(); for (PaymentDetail paymentDetail : paymentGroup.getPaymentDetails()) { accountListings.addAll(paymentDetail.getAccountDetail()); } GeneralLedgerPendingEntrySequenceHelper sequenceHelper = new GeneralLedgerPendingEntrySequenceHelper(); for (PaymentAccountDetail paymentAccountDetail : accountListings) { GlPendingTransaction glPendingTransaction = new GlPendingTransaction(); glPendingTransaction.setSequenceNbr(new KualiInteger(sequenceHelper.getSequenceCounter())); glPendingTransaction .setFdocRefTypCd(paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode()); glPendingTransaction .setFsRefOriginCd(paymentAccountDetail.getPaymentDetail().getFinancialSystemOriginCode()); glPendingTransaction.setFinancialBalanceTypeCode(KFSConstants.BALANCE_TYPE_ACTUAL); Date transactionTimestamp = new Date(dateTimeService.getCurrentDate().getTime()); glPendingTransaction.setTransactionDt(transactionTimestamp); AccountingPeriod fiscalPeriod = accountingPeriodService .getByDate(new java.sql.Date(transactionTimestamp.getTime())); glPendingTransaction.setUniversityFiscalYear(fiscalPeriod.getUniversityFiscalYear()); glPendingTransaction.setUnivFiscalPrdCd(fiscalPeriod.getUniversityFiscalPeriodCode()); glPendingTransaction.setSubAccountNumber(paymentAccountDetail.getSubAccountNbr()); glPendingTransaction.setChartOfAccountsCode(paymentAccountDetail.getFinChartCode()); glPendingTransaction.setFdocNbr(paymentGroup.getDisbursementNbr().toString()); // Set doc type and origin code glPendingTransaction.setFinancialDocumentTypeCode(financialDocumentTypeCode); glPendingTransaction.setFsOriginCd(CRConstants.CR_FDOC_ORIGIN_CODE); String clAcct = parameterService.getParameterValueAsString(CheckReconciliationImportStep.class, CRConstants.CLEARING_ACCOUNT); String obCode = parameterService.getParameterValueAsString(CheckReconciliationImportStep.class, CRConstants.CLEARING_OBJECT_CODE); String coaCode = parameterService.getParameterValueAsString(CheckReconciliationImportStep.class, CRConstants.CLEARING_COA); // Use clearing parameters if stale String accountNbr = stale ? clAcct : paymentAccountDetail.getAccountNbr(); String finObjectCode = stale ? obCode : paymentAccountDetail.getFinObjectCode(); String finCoaCd = stale ? coaCode : paymentAccountDetail.getFinChartCode(); Boolean relieveLiabilities = paymentGroup.getBatch().getCustomerProfile().getRelieveLiabilities(); if ((relieveLiabilities != null) && (relieveLiabilities.booleanValue()) && paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode() != null) { OffsetDefinition offsetDefinition = SpringContext.getBean(OffsetDefinitionService.class) .getByPrimaryId(glPendingTransaction.getUniversityFiscalYear(), glPendingTransaction.getChartOfAccountsCode(), paymentAccountDetail.getPaymentDetail().getFinancialDocumentTypeCode(), glPendingTransaction.getFinancialBalanceTypeCode()); glPendingTransaction.setAccountNumber(accountNbr); glPendingTransaction.setChartOfAccountsCode(finCoaCd); glPendingTransaction.setFinancialObjectCode( offsetDefinition != null ? offsetDefinition.getFinancialObjectCode() : finObjectCode); glPendingTransaction.setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode()); } else { glPendingTransaction.setAccountNumber(accountNbr); glPendingTransaction.setChartOfAccountsCode(finCoaCd); glPendingTransaction.setFinancialObjectCode(finObjectCode); glPendingTransaction.setFinancialSubObjectCode(paymentAccountDetail.getFinSubObjectCode()); } glPendingTransaction.setProjectCd(paymentAccountDetail.getProjectCode()); if (paymentAccountDetail.getAccountNetAmount().bigDecimalValue().signum() >= 0) { glPendingTransaction.setDebitCrdtCd(KFSConstants.GL_CREDIT_CODE); } else { glPendingTransaction.setDebitCrdtCd(KFSConstants.GL_DEBIT_CODE); } glPendingTransaction.setAmount(paymentAccountDetail.getAccountNetAmount().abs()); String trnDesc; String payeeName = paymentGroup.getPayeeName(); trnDesc = payeeName.length() > 40 ? payeeName.substring(0, 40) : StringUtils.rightPad(payeeName, 40); String poNbr = paymentAccountDetail.getPaymentDetail().getPurchaseOrderNbr(); if (StringUtils.isNotBlank(poNbr)) { trnDesc += " " + (poNbr.length() > 9 ? poNbr.substring(0, 9) : StringUtils.rightPad(poNbr, 9)); } String invoiceNbr = paymentAccountDetail.getPaymentDetail().getInvoiceNbr(); if (StringUtils.isNotBlank(invoiceNbr)) { trnDesc += " " + (invoiceNbr.length() > 14 ? invoiceNbr.substring(0, 14) : StringUtils.rightPad(invoiceNbr, 14)); } if (trnDesc.length() > 40) { trnDesc = trnDesc.substring(0, 40); } glPendingTransaction.setDescription(trnDesc); glPendingTransaction.setOrgDocNbr(paymentAccountDetail.getPaymentDetail().getOrganizationDocNbr()); glPendingTransaction.setOrgReferenceId(paymentAccountDetail.getOrgReferenceId()); glPendingTransaction.setFdocRefNbr(paymentAccountDetail.getPaymentDetail().getCustPaymentDocNbr()); // update the offset account if necessary SpringContext.getBean(FlexibleOffsetAccountService.class).updateOffset(glPendingTransaction); this.businessObjectService.save(glPendingTransaction); sequenceHelper.increment(); } }
From source file:de.weltraumschaf.registermachine.App.java
private void printOpCodes() { final StringBuilder buffer = new StringBuilder(); buffer.append("mnemonic args byte").append(NL).append("--------------------").append(NL); final String fmt = "%s0x%s%n"; for (final OpCode op : OpCode.values()) { final StringBuilder mnemonic = new StringBuilder(); mnemonic.append(StringUtils.rightPad(op.name().toLowerCase(LOCALE), MNEMONIC_PAD)).append(' '); char c = 'A'; for (int i = 0; i < op.getArgCount().getCount(); ++i) { mnemonic.append(c).append(' '); ++c;// w ww. ja v a 2s . c o m } buffer.append(String.format(fmt, StringUtils.rightPad(mnemonic.toString(), OPCODE_PAD), op.toHex())); } getIoStreams().print(buffer.toString()); }
From source file:msi.gama.util.GAML.java
public static String getDocumentationOn2(final String query) { final String keyword = StringUtils.removeEnd(StringUtils.removeStart(query.trim(), "#"), ":"); final THashMap<String, String> results = new THashMap<>(); // Statements final SymbolProto p = DescriptionFactory.getStatementProto(keyword); if (p != null) { results.put("Statement", p.getDocumentation()); }/* w w w.java2 s. c om*/ DescriptionFactory.visitStatementProtos((name, proto) -> { if (proto.getFacet(keyword) != null) { results.put("Facet of statement " + name, proto.getFacet(keyword).getDocumentation()); } }); final Set<String> types = new HashSet<>(); final String[] facetDoc = { "" }; DescriptionFactory.visitVarProtos((name, proto) -> { if (proto.getFacet(keyword) != null && types.size() < 4) { if (!Types.get(name).isAgentType() || name.equals(IKeyword.AGENT)) { types.add(name); } facetDoc[0] = proto.getFacet(keyword).getDocumentation(); } }); if (!types.isEmpty()) { results.put("Facet of attribute declarations with types " + types + (types.size() == 4 ? " ..." : ""), facetDoc[0]); } // Operators final THashMap<Signature, OperatorProto> ops = IExpressionCompiler.OPERATORS.get(keyword); if (ops != null) { ops.forEachEntry((sig, proto) -> { results.put("Operator on " + sig.toString(), proto.getDocumentation()); return true; }); } // Built-in skills final SkillDescription sd = GamaSkillRegistry.INSTANCE.get(keyword); if (sd != null) { results.put("Skill", sd.getDocumentation()); } GamaSkillRegistry.INSTANCE.visitSkills(desc -> { final SkillDescription sd1 = (SkillDescription) desc; final VariableDescription var = sd1.getAttribute(keyword); if (var != null) { results.put("Attribute of skill " + desc.getName(), var.getDocumentation()); } final ActionDescription action = sd1.getAction(keyword); if (action != null) { results.put("Primitive of skill " + desc.getName(), action.getDocumentation().isEmpty() ? "" : ":" + action.getDocumentation()); } return true; }); // Types final IType<?> t = Types.builtInTypes.containsType(keyword) ? Types.get(keyword) : null; if (t != null) { String tt = t.getDocumentation(); if (tt == null) { tt = "type " + keyword; } results.put("Type", tt); } // Built-in species for (final TypeDescription td : Types.getBuiltInSpecies()) { if (td.getName().equals(keyword)) { results.put("Built-in species", ((SpeciesDescription) td).getDocumentationWithoutMeta()); } final IDescription var = td.getOwnAttribute(keyword); if (var != null) { results.put("Attribute of built-in species " + td.getName(), var.getDocumentation()); } final ActionDescription action = td.getOwnAction(keyword); if (action != null) { results.put("Primitive of built-in species " + td.getName(), action.getDocumentation().isEmpty() ? "" : ":" + action.getDocumentation()); } } // Constants final UnitConstantExpression exp = IUnits.UNITS_EXPR.get(keyword); if (exp != null) { results.put("Constant", exp.getDocumentation()); } if (results.isEmpty()) { return "No result found"; } final StringBuilder sb = new StringBuilder(); final int max = results.keySet().stream().mapToInt(each -> each.length()).max().getAsInt(); final String separator = StringUtils.repeat("", max + 6).concat(Strings.LN); results.forEachEntry((sig, doc) -> { sb.append("").append(separator).append("|| "); sb.append(StringUtils.rightPad(sig, max)); sb.append(" ||").append(Strings.LN).append(separator); sb.append(toText(doc)).append(Strings.LN); return true; }); return sb.toString(); // }
From source file:com.bstek.dorado.web.loader.DoradoLoader.java
public synchronized void preload(ServletContext servletContext, boolean processOriginContextConfigLocation) throws Exception { if (preloaded) { throw new IllegalStateException("Dorado base configurations already loaded."); }// ww w .ja va2 s .co m preloaded = true; // ? ConsoleUtils.outputLoadingInfo("Initializing " + DoradoAbout.getProductTitle() + " engine..."); ConsoleUtils.outputLoadingInfo("[Vendor: " + DoradoAbout.getVendor() + "]"); ConfigureStore configureStore = Configure.getStore(); doradoHome = System.getenv("DORADO_HOME"); // ?DoradoHome String intParam; intParam = servletContext.getInitParameter("doradoHome"); if (intParam != null) { doradoHome = intParam; } if (doradoHome == null) { doradoHome = DEFAULT_DORADO_HOME; } configureStore.set(HOME_PROPERTY, doradoHome); ConsoleUtils.outputLoadingInfo("[Home: " + StringUtils.defaultString(doradoHome, "<not assigned>") + "]"); // ResourceLoader ResourceLoader resourceLoader = new ServletContextResourceLoader(servletContext) { @Override public Resource getResource(String resourceLocation) { if (resourceLocation != null && resourceLocation.startsWith(HOME_LOCATION_PREFIX)) { resourceLocation = ResourceUtils.concatPath(doradoHome, resourceLocation.substring(HOME_LOCATION_PREFIX_LEN)); } return super.getResource(resourceLocation); } }; String runMode = null; if (StringUtils.isNotEmpty(doradoHome)) { String configureLocation = HOME_LOCATION_PREFIX + "configure.properties"; loadConfigureProperties(configureStore, resourceLoader, configureLocation, false); } runMode = configureStore.getString("core.runMode"); if (StringUtils.isNotEmpty(runMode)) { loadConfigureProperties(configureStore, resourceLoader, CORE_PROPERTIES_LOCATION_PREFIX + "configure-" + runMode + ".properties", true); if (StringUtils.isNotEmpty(doradoHome)) { loadConfigureProperties(configureStore, resourceLoader, HOME_LOCATION_PREFIX + "configure-" + runMode + ".properties", true); } } ConsoleUtils.outputConfigureItem("core.runMode"); ConsoleUtils.outputConfigureItem("core.addonLoadMode"); File tempDir; String tempDirPath = configureStore.getString("core.tempDir"); if (StringUtils.isNotBlank(tempDirPath)) { tempDir = new File(tempDirPath); } else { tempDir = new File(WebUtils.getTempDir(servletContext), ".dorado"); } boolean supportsTempFile = configureStore.getBoolean("core.supportsTempFile"); TempFileUtils.setSupportsTempFile(supportsTempFile); if (supportsTempFile) { if ((tempDir.exists() && tempDir.isDirectory()) || tempDir.mkdir()) { TempFileUtils.setTempDir(tempDir); } ConsoleUtils.outputLoadingInfo("[TempDir: " + TempFileUtils.getTempDir().getPath() + "]"); } else { ConsoleUtils.outputLoadingInfo("Temp file is forbidden."); } // File storeDir; String storeDirSettring = configureStore.getString("core.storeDir"); if (StringUtils.isNotEmpty(storeDirSettring)) { storeDir = new File(storeDirSettring); File testFile = new File(storeDir, ".test"); if (!testFile.mkdirs()) { throw new IllegalStateException( "Store directory [" + storeDir.getAbsolutePath() + "] is not writable in actually."); } testFile.delete(); } else { storeDir = new File(tempDir, "dorado-store"); configureStore.set("core.storeDir", storeDir.getAbsolutePath()); } ConsoleUtils.outputConfigureItem("core.storeDir"); // gothrough packages String addonLoadMode = Configure.getString("core.addonLoadMode"); String[] enabledAddons = StringUtils.split(Configure.getString("core.enabledAddons"), ",; \n\r"); String[] disabledAddon = StringUtils.split(Configure.getString("core.disabledAddon"), ",; \n\r"); Collection<PackageInfo> packageInfos = PackageManager.getPackageInfoMap().values(); int addonNumber = 0; for (PackageInfo packageInfo : packageInfos) { String packageName = packageInfo.getName(); if (packageName.equals("dorado-core")) { continue; } if (addonNumber > 9999) { packageInfo.setEnabled(false); } else if (StringUtils.isEmpty(addonLoadMode) || "positive".equals(addonLoadMode)) { packageInfo.setEnabled(!ArrayUtils.contains(disabledAddon, packageName)); } else { // addonLoadMode == negative packageInfo.setEnabled(ArrayUtils.contains(enabledAddons, packageName)); } if (packageInfo.isEnabled()) { addonNumber++; } } // print packages int i = 0; for (PackageInfo packageInfo : packageInfos) { ConsoleUtils.outputLoadingInfo( StringUtils.rightPad(String.valueOf(++i) + '.', 4) + "Package [" + packageInfo.getName() + " - " + StringUtils.defaultIfBlank(packageInfo.getVersion(), "<Unknown Version>") + "] found." + ((packageInfo.isEnabled() ? "" : " #DISABLED# "))); } // load packages for (PackageInfo packageInfo : packageInfos) { if (!packageInfo.isEnabled()) { pushLocations(contextLocations, packageInfo.getComponentLocations()); continue; } PackageListener packageListener = packageInfo.getListener(); if (packageListener != null) { packageListener.beforeLoadPackage(packageInfo, resourceLoader); } PackageConfigurer packageConfigurer = packageInfo.getConfigurer(); if (StringUtils.isNotEmpty(packageInfo.getPropertiesLocations())) { for (String location : org.springframework.util.StringUtils.tokenizeToStringArray( packageInfo.getPropertiesLocations(), ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS)) { loadConfigureProperties(configureStore, resourceLoader, location, false); } } String[] locations; if (packageConfigurer != null) { locations = packageConfigurer.getPropertiesConfigLocations(resourceLoader); if (locations != null) { for (String location : locations) { loadConfigureProperties(configureStore, resourceLoader, location, false); } } } // ?Spring? pushLocations(contextLocations, packageInfo.getContextLocations()); if (packageConfigurer != null) { locations = packageConfigurer.getContextConfigLocations(resourceLoader); if (locations != null) { for (String location : locations) { pushLocation(contextLocations, location); } } } pushLocations(servletContextLocations, packageInfo.getServletContextLocations()); if (packageConfigurer != null) { locations = packageConfigurer.getServletContextConfigLocations(resourceLoader); if (locations != null) { for (String location : locations) { pushLocation(servletContextLocations, location); } } } packageInfo.setLoaded(true); } // ?dorado-homepropertiesaddon if (StringUtils.isNotEmpty(doradoHome)) { String configureLocation = HOME_LOCATION_PREFIX + "configure.properties"; loadConfigureProperties(configureStore, resourceLoader, configureLocation, true); if (StringUtils.isNotEmpty(runMode)) { loadConfigureProperties(configureStore, resourceLoader, CORE_PROPERTIES_LOCATION_PREFIX + "configure-" + runMode + ".properties", true); loadConfigureProperties(configureStore, resourceLoader, HOME_LOCATION_PREFIX + "configure-" + runMode + ".properties", true); } } Resource resource; // context if (processOriginContextConfigLocation) { intParam = servletContext.getInitParameter(CONTEXT_CONFIG_LOCATION); if (intParam != null) { pushLocations(contextLocations, intParam); } } resource = resourceLoader.getResource(HOME_CONTEXT_XML); if (resource.exists()) { pushLocations(contextLocations, HOME_CONTEXT_XML); } if (StringUtils.isNotEmpty(runMode)) { String extHomeContext = HOME_CONTEXT_PREFIX + '-' + runMode + CONTEXT_FILE_EXT; resource = resourceLoader.getResource(extHomeContext); if (resource.exists()) { pushLocations(contextLocations, extHomeContext); } } // servlet-context intParam = servletContext.getInitParameter(SERVLET_CONTEXT_CONFIG_LOCATION); if (intParam != null) { pushLocations(servletContextLocations, intParam); } resource = resourceLoader.getResource(HOME_SERVLET_CONTEXT_XML); if (resource.exists()) { pushLocations(servletContextLocations, HOME_SERVLET_CONTEXT_XML); } if (StringUtils.isNotEmpty(runMode)) { String extHomeContext = HOME_SERVLET_CONTEXT_PREFIX + '-' + runMode + CONTEXT_FILE_EXT; resource = resourceLoader.getResource(extHomeContext); if (resource.exists()) { pushLocations(servletContextLocations, extHomeContext); } } ConsoleUtils.outputConfigureItem(RESOURCE_LOADER_PROPERTY); ConsoleUtils.outputConfigureItem(BYTE_CODE_PROVIDER_PROPERTY); String contextLocationsFromProperties = configureStore.getString(CONTEXT_CONFIG_PROPERTY); if (contextLocationsFromProperties != null) { pushLocations(contextLocations, contextLocationsFromProperties); } configureStore.set(CONTEXT_CONFIG_PROPERTY, StringUtils.join(getRealResourcesPath(contextLocations), ';')); ConsoleUtils.outputConfigureItem(CONTEXT_CONFIG_PROPERTY); String serlvetContextLocationsFromProperties = configureStore.getString(SERVLET_CONTEXT_CONFIG_PROPERTY); if (serlvetContextLocationsFromProperties != null) { pushLocations(servletContextLocations, serlvetContextLocationsFromProperties); } configureStore.set(SERVLET_CONTEXT_CONFIG_PROPERTY, StringUtils.join(getRealResourcesPath(servletContextLocations), ';')); ConsoleUtils.outputConfigureItem(SERVLET_CONTEXT_CONFIG_PROPERTY); // ?WebContext DoradoContext context = DoradoContext.init(servletContext, false); Context.setFailSafeContext(context); }
From source file:gda.device.scannable.scannablegroup.ScannableGroup.java
@Override public String toFormattedString() { //TODO this method does not provide correct indentation level for a scannable group inside another scannable group //TODO the regex parser is unreliable as described by FIXME below // IT would be better to create format message by delegate to individual members directly, rather than re-parsing output again. //TODO this works if the toFormattedString method of the members conforms to a standard. But I don't think there is one! //Rather use getPosition and format here. String membersOutput = getName() + " ::\n"; for (Scannable member : groupMembers) { membersOutput += member.toFormattedString() + "\n"; }// w w w . ja va2 s .co m String[] originalInputNames = getInputNames(); String[] namesToSplitOn = getInputNames(); String[] names = getGroupMemberNames(); String[] extras = getExtraNames(); // FIXME regex-based splitting of membersOutput is broken if one group member name is a substring of another - e.g. "col_y" and "col_yaw" if (originalInputNames.length + extras.length == 0) { return membersOutput; } if (extras.length > 0) { namesToSplitOn = (String[]) ArrayUtils.addAll(namesToSplitOn, extras); } // find the longest name, to help with formatting the output int longestName = 0; for (String objName : namesToSplitOn) { if (objName.length() > longestName) { longestName = objName.length(); } } namesToSplitOn = (String[]) ArrayUtils.add(namesToSplitOn, getName()); namesToSplitOn = (String[]) ArrayUtils.addAll(namesToSplitOn, names); String regex = ""; for (String name : namesToSplitOn) { regex += name + " +|"; } regex = regex.substring(0, regex.length() - 1); String[] values = membersOutput.split(regex); String returnString = getName() + "::\n"; int nextNameIndex = 0; for (int i = 0; i < values.length; i++) { String value = values[i].trim(); if (value.startsWith(":")) { value = value.substring(1).trim(); } if (StringUtils.containsOnly(value, ":()") || value.isEmpty()) { continue; } returnString += " " + StringUtils.rightPad(namesToSplitOn[nextNameIndex], longestName) + ": " + value + "\n"; nextNameIndex++; } returnString.trim(); returnString = returnString.substring(0, returnString.length() - 1); return returnString; }
From source file:de.codesourcery.eve.skills.ui.components.impl.planning.CostStatementComponent.java
protected void putOnClipboard() { // create text final SpreadSheetTableModel model = (SpreadSheetTableModel) this.table.getModel(); int maxColumnCount = 1; final Map<Integer, Integer> maxColumnWidth = new HashMap<Integer, Integer>(); for (TableRow r : model.getRows()) { if (r.getCellCount() > maxColumnCount) { maxColumnCount = r.getCellCount(); }//from w w w . j a v a2 s . c om for (int i = 0; i < r.getCellCount(); i++) { Integer maxWidth = maxColumnWidth.get(i); if (maxWidth == null) { maxWidth = new Integer(0); maxColumnWidth.put(i, maxWidth); } final ITableCell cell = r.getCell(i); if (cell.getValue() != null) { final int len = toString(cell).length(); if (len > maxWidth.intValue()) { maxWidth = new Integer(len); maxColumnWidth.put(i, maxWidth); } } } } final StringBuffer text = new StringBuffer(); for (TableRow r : model.getRows()) { for (int i = 0; i < r.getCellCount(); i++) { final int width = maxColumnWidth.get(i); final ITableCell cell = r.getCell(i); if (i == 0) { text.append(StringUtils.rightPad(toString(cell), width)).append(" | "); } else { text.append(StringUtils.leftPad(toString(cell), width)).append(" | "); } } text.append("\n"); } // put on clipboard final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(new PlainTextTransferable(text.toString()), null); }