List of usage examples for org.apache.commons.lang SystemUtils LINE_SEPARATOR
String LINE_SEPARATOR
To view the source code for org.apache.commons.lang SystemUtils LINE_SEPARATOR.
Click Source Link
The line.separator
System Property.
From source file:de.tudarmstadt.ukp.csniper.webapp.evaluation.MlPipeline.java
/** * Mind this method may return less results than parses were passed to it, e.g. because a * cached parse may be empty or "ERROR" in which case no result for it is generated! *///from www.jav a 2 s .c o m public static List<EvaluationResult> classifyPreParsed(File aModelDir, List<CachedParse> aParses, String aType, String aUser) throws IOException, UIMAException { TKSVMlightSequenceClassifierBuilder builder = new TKSVMlightSequenceClassifierBuilder(); TKSVMlightSequenceClassifier classifier = builder.loadClassifierFromTrainingDirectory(aModelDir); File cFile = File.createTempFile("tkclassify", ".txt"); List<EvaluationItem> items = new ArrayList<EvaluationItem>(); BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(cFile)); for (CachedParse parse : aParses) { if (parse.getPennTree().isEmpty() || "ERROR".equals(parse.getPennTree())) { continue; } String coveredText; try { coveredText = PennTreeUtils.toText(parse.getPennTree()); } catch (EmptyStackException e) { LOG.error("Invalid Penn Tree: [" + parse.getPennTree() + "]", e); continue; } // Prepare evaluation item to return EvaluationItem item = new EvaluationItem(); item.setType(aType); item.setBeginOffset(parse.getBeginOffset()); item.setEndOffset(parse.getEndOffset()); item.setDocumentId(parse.getDocumentId()); item.setCollectionId(parse.getCollectionId()); item.setCoveredText(coveredText); items.add(item); // write tree to file Feature tree = new Feature("TK_tree", StringUtils.normalizeSpace(parse.getPennTree())); TreeFeatureVector tfv = classifier.getFeaturesEncoder().encodeAll(Arrays.asList(tree)); bw.write("0"); bw.write(TKSVMlightDataWriter.createString(tfv)); bw.write(SystemUtils.LINE_SEPARATOR); } } catch (IOException e) { throw new AnalysisEngineProcessException(e); } finally { IOUtils.closeQuietly(bw); } // classify all List<Double> predictions = classifier.tkSvmLightPredict2(cFile); if (predictions.size() != items.size()) { // TODO throw different exception instead throw new IOException("there are [" + predictions.size() + "] predictions, but [" + items.size() + "] were expected."); } List<EvaluationResult> results = new ArrayList<EvaluationResult>(); for (EvaluationItem item : items) { results.add(new EvaluationResult(item, aUser, "")); } for (int i = 0; i < results.size(); i++) { Mark m = (predictions.get(i) > THRESHOLD) ? Mark.PRED_CORRECT : Mark.PRED_WRONG; results.get(i).setResult(m.getTitle()); } return results; }
From source file:fr.ign.cogit.geoxygene.datatools.ojb.GeOxygeneBrokerHelper.java
public static String buildMessageString(Object obj, Object value, Field field) { String eol = SystemUtils.LINE_SEPARATOR; StringBuffer buf = new StringBuffer(); buf.append(eol + "object class[ " //$NON-NLS-1$ + (obj != null ? obj.getClass().getName() : null)).append(eol + "target field: " //$NON-NLS-1$ + (field != null ? field.getName() : null)) .append(eol + "target field type: " //$NON-NLS-1$ + (field != null ? field.getType() : null)) .append(eol + "object value class: " //$NON-NLS-1$ + (value != null ? value.getClass().getName() : null)) .append(eol + "object value: " //$NON-NLS-1$ + (value != null ? value : null)) .append("]"); //$NON-NLS-1$ return buf.toString(); }
From source file:junk.gui.HazardDataSetCalcCondorApp.java
/** * Returns the metadata associated with this calculation * * @returns the String containing the values selected for different parameters *///from ww w . java2s . c om public String getParametersInfo() { String lf = SystemUtils.LINE_SEPARATOR; String metadata = "IMR Param List:" + lf + "---------------" + lf + this.imrGuiBean.getVisibleParametersCloned().getParameterListMetadataString() + lf + lf + "Region Param List: " + lf + "----------------" + lf + sitesGuiBean.getVisibleParametersCloned().getParameterListMetadataString() + lf + lf + "IMT Param List: " + lf + "---------------" + lf + imtGuiBean.getVisibleParametersCloned().getParameterListMetadataString() + lf + lf + "Forecast Param List: " + lf + "--------------------" + lf + erfGuiBean.getERFParameterList().getParameterListMetadataString() + lf + lf + "TimeSpan Param List: " + lf + "--------------------" + lf + erfGuiBean.getSelectedERFTimespanGuiBean().getParameterListMetadataString() + lf + lf + "Miscellaneous Metadata:" + lf + "--------------------" + lf + "Maximum Site Source Distance = " + maxDistance + lf + lf + "X Values = "; //getting the X values used to generate the metadata. ListIterator it = function.getXValuesIterator(); String xVals = ""; while (it.hasNext()) xVals += (Double) it.next() + " , "; xVals = xVals.substring(0, xVals.lastIndexOf(",")); //adding the X Vals used to the Metadata. metadata += xVals; return metadata; }
From source file:nl.nn.adapterframework.configuration.Configuration.java
public String VersionInfo() { StringBuilder sb = new StringBuilder(); sb.append(getInstanceInfo() + SystemUtils.LINE_SEPARATOR); sb.append(nl.nn.adapterframework.util.XmlUtils.getVersionInfo()); return sb.toString(); }
From source file:nl.nn.adapterframework.configuration.ConfigurationDigester.java
public void digestConfiguration(ClassLoader classLoader, Configuration configuration, String configurationFile, boolean configLogAppend) throws ConfigurationException { Digester digester = null;/*w w w . java 2 s . c o m*/ try { digester = getDigester(configuration); URL digesterRulesURL = ClassUtils.getResourceURL(this, getDigesterRules()); if (digesterRulesURL == null) { throw new ConfigurationException("Digester rules file not found: " + getDigesterRules()); } URL configurationFileURL = ClassUtils.getResourceURL(classLoader, configurationFile); if (configurationFileURL == null) { throw new ConfigurationException("Configuration file not found: " + configurationFile); } configuration.setDigesterRulesURL(digesterRulesURL); configuration.setConfigurationURL(configurationFileURL); fillConfigWarnDefaultValueExceptions(configuration); String lineSeparator = SystemUtils.LINE_SEPARATOR; if (null == lineSeparator) lineSeparator = "\n"; String original = Misc.resourceToString(configurationFileURL, lineSeparator, false); original = XmlUtils.identityTransform(classLoader, original); configuration.setOriginalConfiguration(original); List<String> propsToHide = new ArrayList<String>(); String propertiesHideString = AppConstants.getInstance(Thread.currentThread().getContextClassLoader()) .getString("properties.hide", null); if (propertiesHideString != null) { propsToHide.addAll(Arrays.asList(propertiesHideString.split("[,\\s]+"))); } String loaded = StringResolver.substVars(original, AppConstants.getInstance(Thread.currentThread().getContextClassLoader())); String loadedHide = StringResolver.substVars(original, AppConstants.getInstance(Thread.currentThread().getContextClassLoader()), null, propsToHide); loaded = ConfigurationUtils.getActivatedConfiguration(configuration, loaded); loadedHide = ConfigurationUtils.getActivatedConfiguration(configuration, loadedHide); if (ConfigurationUtils.stubConfiguration()) { loaded = ConfigurationUtils.getStubbedConfiguration(configuration, loaded); loadedHide = ConfigurationUtils.getStubbedConfiguration(configuration, loadedHide); } configuration.setLoadedConfiguration(loadedHide); saveConfig(loadedHide, configLogAppend); digester.parse(new StringReader(loaded)); } catch (Throwable t) { // wrap exception to be sure it gets rendered via the IbisException-renderer String currentElementName = null; if (digester != null) { currentElementName = digester.getCurrentElementName(); } ConfigurationException e = new ConfigurationException( "error during unmarshalling configuration from file [" + configurationFile + "] with digester-rules-file [" + getDigesterRules() + "] in element [" + currentElementName + "]" + (StringUtils.isEmpty(lastResolvedEntity) ? "" : " last resolved entity [" + lastResolvedEntity + "]"), t); throw e; } if (MonitorManager.getInstance().isEnabled()) { MonitorManager.getInstance().configure(configuration); } }
From source file:nl.nn.adapterframework.configuration.ConfigurationDigester.java
private void fillConfigWarnDefaultValueExceptions(Configuration configuration) throws Exception { URL xsltSource = ClassUtils.getResourceURL(this, attributesGetter_xslt); if (xsltSource == null) { throw new ConfigurationException("cannot find resource [" + attributesGetter_xslt + "]"); }//from ww w .j a v a2 s .co m Transformer transformer = XmlUtils.createTransformer(xsltSource); String lineSeparator = SystemUtils.LINE_SEPARATOR; if (null == lineSeparator) lineSeparator = "\n"; String configString = Misc.resourceToString(configuration.getConfigurationURL(), lineSeparator, false); configString = XmlUtils.identityTransform(configuration.getClassLoader(), configString); String attributes = XmlUtils.transformXml(transformer, configString); Element attributesElement = XmlUtils.buildElement(attributes); Collection attributeElements = XmlUtils.getChildTags(attributesElement, "attribute"); Iterator iter = attributeElements.iterator(); while (iter.hasNext()) { Element attributeElement = (Element) iter.next(); Element valueElement = XmlUtils.getFirstChildTag(attributeElement, "value"); String value = XmlUtils.getStringValue(valueElement); if (value.startsWith("${") && value.endsWith("}")) { Element keyElement = XmlUtils.getFirstChildTag(attributeElement, "key"); String key = XmlUtils.getStringValue(keyElement); Element elementElement = XmlUtils.getFirstChildTag(attributeElement, "element"); String element = XmlUtils.getStringValue(elementElement); Element nameElement = XmlUtils.getFirstChildTag(attributeElement, "name"); String name = XmlUtils.getStringValue(nameElement); String mergedKey = element + "/" + (name == null ? "" : name) + "/" + key; configWarnings.addDefaultValueExceptions(mergedKey); } } }
From source file:nl.nn.adapterframework.errormessageformatters.FixedErrorMessage.java
public String format(String message, Throwable t, INamedObject location, String originalMessage, String messageId, long receivedTime) { String stringToReturn = getReturnString(); if (stringToReturn == null) { stringToReturn = ""; }//from w w w. j ava 2s . co m if (StringUtils.isNotEmpty(getFileName())) { try { stringToReturn += Misc.resourceToString(ClassUtils.getResourceURL(classLoader, getFileName()), SystemUtils.LINE_SEPARATOR); } catch (Throwable e) { log.error("got exception loading error message file [" + getFileName() + "]", e); } } if (StringUtils.isEmpty(stringToReturn)) { stringToReturn = super.format(message, t, location, originalMessage, messageId, receivedTime); } if (StringUtils.isNotEmpty(getReplaceFrom())) { stringToReturn = Misc.replace(stringToReturn, getReplaceFrom(), getReplaceTo()); } if (StringUtils.isNotEmpty(styleSheetName)) { URL xsltSource = ClassUtils.getResourceURL(classLoader, styleSheetName); if (xsltSource != null) { try { String xsltResult = null; Transformer transformer = XmlUtils.createTransformer(xsltSource); xsltResult = XmlUtils.transformXml(transformer, stringToReturn); stringToReturn = xsltResult; } catch (Throwable e) { log.error("got error transforming resource [" + xsltSource.toString() + "] from [" + styleSheetName + "]", e); } } } return stringToReturn; }
From source file:nl.nn.adapterframework.pipes.FixedResult.java
/** * checks for correct configuration, and translates the fileName to * a file, to check existence. /*from w ww. j a va2s . c om*/ * If a fileName or fileNameSessionKey was specified, the contents of the file is put in the * <code>returnString</code>, so that the <code>returnString</code> * may always be returned. * @throws ConfigurationException */ public void configure() throws ConfigurationException { super.configure(); appConstants = AppConstants.getInstance(classLoader); if (StringUtils.isNotEmpty(getFileName()) && !isLookupAtRuntime()) { URL resource = null; try { resource = ClassUtils.getResourceURL(classLoader, getFileName()); } catch (Throwable e) { throw new ConfigurationException( getLogPrefix(null) + "got exception searching for [" + getFileName() + "]", e); } if (resource == null) { throw new ConfigurationException( getLogPrefix(null) + "cannot find resource [" + getFileName() + "]"); } try { returnString = Misc.resourceToString(resource, SystemUtils.LINE_SEPARATOR); } catch (Throwable e) { throw new ConfigurationException( getLogPrefix(null) + "got exception loading [" + getFileName() + "]", e); } } if ((StringUtils.isEmpty(fileName)) && (StringUtils.isEmpty(fileNameSessionKey)) && returnString == null) { // allow an empty returnString to be specified throw new ConfigurationException( getLogPrefix(null) + "has neither fileName nor fileNameSessionKey nor returnString specified"); } if (StringUtils.isNotEmpty(replaceFrom)) { returnString = replace(returnString, replaceFrom, replaceTo); } }
From source file:nl.nn.adapterframework.pipes.FixedResult.java
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException { String result = returnString; if ((StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) || StringUtils.isNotEmpty(getFileNameSessionKey())) { String fileName = null;/*from w w w. ja v a 2 s. co m*/ if (StringUtils.isNotEmpty(getFileNameSessionKey())) { fileName = (String) session.get(fileNameSessionKey); } if (fileName == null) { if (StringUtils.isNotEmpty(getFileName()) && isLookupAtRuntime()) { fileName = getFileName(); } } URL resource = null; try { resource = ClassUtils.getResourceURL(classLoader, fileName); } catch (Throwable e) { throw new PipeRunException(this, getLogPrefix(session) + "got exception searching for [" + fileName + "]", e); } if (resource == null) { PipeForward fileNotFoundForward = findForward(FILE_NOT_FOUND_FORWARD); if (fileNotFoundForward != null) { return new PipeRunResult(fileNotFoundForward, input); } else { throw new PipeRunException(this, getLogPrefix(session) + "cannot find resource [" + fileName + "]"); } } try { result = Misc.resourceToString(resource, SystemUtils.LINE_SEPARATOR); } catch (Throwable e) { throw new PipeRunException(this, getLogPrefix(session) + "got exception loading [" + fileName + "]", e); } } if (getParameterList() != null) { ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session); ParameterValueList pvl; try { pvl = prc.getValues(getParameterList()); } catch (ParameterException e) { throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e); } for (int i = 0; i < pvl.size(); i++) { ParameterValue pv = pvl.getParameterValue(i); String replaceFrom; if (isReplaceFixedParams()) { replaceFrom = pv.getDefinition().getName(); } else { replaceFrom = "${" + pv.getDefinition().getName() + "}"; } result = replace(result, replaceFrom, pv.asStringValue("")); } } if (getSubstituteVars()) { result = StringResolver.substVars(returnString, session, appConstants); } if (StringUtils.isNotEmpty(styleSheetName)) { URL xsltSource = ClassUtils.getResourceURL(classLoader, styleSheetName); if (xsltSource != null) { try { String xsltResult = null; Transformer transformer = XmlUtils.createTransformer(xsltSource); xsltResult = XmlUtils.transformXml(transformer, result); result = xsltResult; } catch (IOException e) { throw new PipeRunException(this, getLogPrefix(session) + "cannot retrieve [" + styleSheetName + "], resource [" + xsltSource.toString() + "]", e); } catch (TransformerConfigurationException te) { throw new PipeRunException(this, getLogPrefix(session) + "got error creating transformer from file [" + styleSheetName + "]", te); } catch (TransformerException te) { throw new PipeRunException(this, getLogPrefix(session) + "got error transforming resource [" + xsltSource.toString() + "] from [" + styleSheetName + "]", te); } catch (DomBuilderException te) { throw new PipeRunException(this, getLogPrefix(session) + "caught DomBuilderException", te); } } } log.debug(getLogPrefix(session) + " returning fixed result [" + result + "]"); return new PipeRunResult(getForward(), result); }
From source file:nl.nn.adapterframework.pipes.MessageSendingPipe.java
/** * Checks whether a sender is defined for this pipe. *///from ww w.j a v a 2 s .c o m public void configure() throws ConfigurationException { super.configure(); if (StringUtils.isNotEmpty(getStubFileName())) { URL stubUrl; try { stubUrl = ClassUtils.getResourceURL(classLoader, getStubFileName()); } catch (Throwable e) { throw new ConfigurationException(getLogPrefix(null) + "got exception finding resource for stubfile [" + getStubFileName() + "]", e); } if (stubUrl == null) { throw new ConfigurationException( getLogPrefix(null) + "could not find resource for stubfile [" + getStubFileName() + "]"); } try { returnString = Misc.resourceToString(stubUrl, SystemUtils.LINE_SEPARATOR); } catch (Throwable e) { throw new ConfigurationException(getLogPrefix(null) + "got exception loading stubfile [" + getStubFileName() + "] from resource [" + stubUrl.toExternalForm() + "]", e); } } else { propagateName(); if (getSender() == null) { throw new ConfigurationException(getLogPrefix(null) + "no sender defined "); } try { if (getSender() instanceof PipeAware) { ((PipeAware) getSender()).setPipe(this); } getSender().configure(); } catch (ConfigurationException e) { throw new ConfigurationException(getLogPrefix(null) + "while configuring sender", e); } if (getSender() instanceof HasPhysicalDestination) { log.info(getLogPrefix(null) + "has sender on " + ((HasPhysicalDestination) getSender()).getPhysicalDestinationName()); } if (getListener() != null) { if (getSender().isSynchronous()) { throw new ConfigurationException( getLogPrefix(null) + "cannot have listener with synchronous sender"); } try { getListener().configure(); } catch (ConfigurationException e) { throw new ConfigurationException(getLogPrefix(null) + "while configuring listener", e); } if (getListener() instanceof HasPhysicalDestination) { log.info(getLogPrefix(null) + "has listener on " + ((HasPhysicalDestination) getListener()).getPhysicalDestinationName()); } } if (!(getLinkMethod().equalsIgnoreCase("MESSAGEID")) && (!(getLinkMethod().equalsIgnoreCase("CORRELATIONID")))) { throw new ConfigurationException(getLogPrefix(null) + "Invalid argument for property LinkMethod [" + getLinkMethod() + "]. it should be either MESSAGEID or CORRELATIONID"); } if (!(getHideMethod().equalsIgnoreCase("all")) && (!(getHideMethod().equalsIgnoreCase("firstHalf")))) { throw new ConfigurationException(getLogPrefix(null) + "invalid value for hideMethod [" + getHideMethod() + "], must be 'all' or 'firstHalf'"); } if (isCheckXmlWellFormed() || StringUtils.isNotEmpty(getCheckRootTag())) { if (findForward(ILLEGALRESULTFORWARD) == null) throw new ConfigurationException( getLogPrefix(null) + "has no forward with name [illegalResult]"); } if (!ConfigurationUtils.stubConfiguration()) { if (StringUtils.isNotEmpty(getTimeOutOnResult())) { throw new ConfigurationException( getLogPrefix(null) + "timeOutOnResult only allowed in stub mode"); } if (StringUtils.isNotEmpty(getExceptionOnResult())) { throw new ConfigurationException( getLogPrefix(null) + "exceptionOnResult only allowed in stub mode"); } } if (getMaxRetries() > 0) { ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance(); if (getRetryMinInterval() < MIN_RETRY_INTERVAL) { String msg = "retryMinInterval [" + getRetryMinInterval() + "] should be greater than or equal to [" + MIN_RETRY_INTERVAL + "], assuming the lower limit"; configWarnings.add(log, msg); setRetryMinInterval(MIN_RETRY_INTERVAL); } if (getRetryMaxInterval() > MAX_RETRY_INTERVAL) { String msg = "retryMaxInterval [" + getRetryMaxInterval() + "] should be less than or equal to [" + MAX_RETRY_INTERVAL + "], assuming the upper limit"; configWarnings.add(log, msg); setRetryMaxInterval(MAX_RETRY_INTERVAL); } if (getRetryMaxInterval() < getRetryMinInterval()) { String msg = "retryMaxInterval [" + getRetryMaxInterval() + "] should be greater than or equal to [" + getRetryMinInterval() + "], assuming the lower limit"; configWarnings.add(log, msg); setRetryMaxInterval(getRetryMinInterval()); } } } ITransactionalStorage messageLog = getMessageLog(); if (checkMessageLog) { if (!getSender().isSynchronous() && getListener() == null && !(getSender() instanceof nl.nn.adapterframework.senders.IbisLocalSender)) { if (messageLog == null) { ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance(); String msg = "asynchronous sender [" + getSender().getName() + "] without sibling listener has no messageLog. Integrity check not possible"; configWarnings.add(log, msg); } } } if (messageLog != null) { messageLog.configure(); if (messageLog instanceof HasPhysicalDestination) { String msg = getLogPrefix(null) + "has messageLog in " + ((HasPhysicalDestination) messageLog).getPhysicalDestinationName(); log.info(msg); if (getAdapter() != null) getAdapter().getMessageKeeper().add(msg); } if (StringUtils.isNotEmpty(getAuditTrailXPath())) { auditTrailTp = TransformerPool.configureTransformer(getLogPrefix(null), classLoader, getAuditTrailNamespaceDefs(), getAuditTrailXPath(), null, "text", false, null); } if (StringUtils.isNotEmpty(getCorrelationIDXPath()) || StringUtils.isNotEmpty(getCorrelationIDStyleSheet())) { correlationIDTp = TransformerPool.configureTransformer(getLogPrefix(null), classLoader, getCorrelationIDNamespaceDefs(), getCorrelationIDXPath(), getCorrelationIDStyleSheet(), "text", false, null); } if (StringUtils.isNotEmpty(getLabelXPath()) || StringUtils.isNotEmpty(getLabelStyleSheet())) { labelTp = TransformerPool.configureTransformer(getLogPrefix(null), classLoader, getLabelNamespaceDefs(), getLabelXPath(), getLabelStyleSheet(), "text", false, null); } } if (StringUtils.isNotEmpty(getRetryXPath())) { retryTp = TransformerPool.configureTransformer(getLogPrefix(null), classLoader, getRetryNamespaceDefs(), getRetryXPath(), null, "text", false, null); } if (getInputValidator() != null) { PipeForward pf = new PipeForward(); pf.setName("success"); getInputValidator().registerForward(pf); } if (getOutputValidator() != null) { PipeForward pf = new PipeForward(); pf.setName("success"); getOutputValidator().registerForward(pf); } if (getInputWrapper() != null) { PipeForward pf = new PipeForward(); pf.setName("success"); getInputWrapper().registerForward(pf); if (getInputWrapper() instanceof EsbSoapWrapperPipe) { EsbSoapWrapperPipe eswPipe = (EsbSoapWrapperPipe) getInputWrapper(); ISender sender = getSender(); eswPipe.retrievePhysicalDestinationFromSender(sender); } } if (getOutputWrapper() != null) { PipeForward pf = new PipeForward(); pf.setName("success"); getOutputWrapper().registerForward(pf); } registerEvent(PIPE_TIMEOUT_MONITOR_EVENT); registerEvent(PIPE_CLEAR_TIMEOUT_MONITOR_EVENT); registerEvent(PIPE_EXCEPTION_MONITOR_EVENT); }