List of usage examples for org.apache.commons.lang StringUtils substringAfterLast
public static String substringAfterLast(String str, String separator)
Gets the substring after the last occurrence of a separator.
From source file:com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.SelectStageListener.java
public void processChanged(List<Long> processIds) { super.processChanged(processIds); // add by ljh at 2012-09-13,zookeeper ConnectionLoss for (Long processId : processIds) { if (!replyProcessIds.contains(processId)) { logger.warn("process is not in order, please check processId:{}", processId); addReply(processId);// w ww . java 2s . c om } } try { String path = StagePathUtils.getProcessRoot(getPipelineId()); // ? int size = ArbitrateConfigUtils.getParallelism(getPipelineId()) - processIds.size(); if (size > 0) {// PermitMonitor permit = ArbitrateFactory.getInstance(getPipelineId(), PermitMonitor.class); if (permit.isPermit() == false) { // ????? return; } String mainStemPath = StagePathUtils.getMainStem(getPipelineId()); byte[] bytes = zookeeper.readData(mainStemPath, true); if (bytes == null) { return; } MainStemEventData eventData = JsonUtils.unmarshalFromByte(bytes, MainStemEventData.class); if (eventData.getNid().equals(ArbitrateConfigUtils.getCurrentNid()) == false) { return;// ?mainStem,??? } // ?select???????????? // DistributedLock lock = new DistributedLock(PathUtils.getSelectLock(getPipelineId())); // try { // lock.lock(); // //process // } finally { // lock.unlock(); // } synchronized (this) { // ???, dobble-check List<String> currentProcesses = zookeeper.getChildren(path); size = ArbitrateConfigUtils.getParallelism(getPipelineId()) - currentProcesses.size(); if (size > 0) {// ProcessNodeEventData nodeData = new ProcessNodeEventData(); nodeData.setStatus(ProcessNodeEventData.Status.UNUSED);// nodeData.setNid(ArbitrateConfigUtils.getCurrentNid()); byte[] nodeBytes = JsonUtils.marshalToByte(nodeData); String processPath = zookeeper.create(path + "/", nodeBytes, CreateMode.PERSISTENT_SEQUENTIAL); // ? String processNode = StringUtils.substringAfterLast(processPath, "/"); Long processId = StagePathUtils.getProcessId(processNode);// ?process addReply(processId); } } } } catch (ZkException e) { recovery(getPipelineId());// ?recovery??ConnectionLosscreate? logger.error("SelectStageListener", e); } }
From source file:de.tudarmstadt.ukp.dkpro.core.io.conll.Conll2012Writer.java
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { PrintWriter out = null;/* w w w . ja v a 2 s .c o m*/ try { out = new PrintWriter(new OutputStreamWriter(getOutputStream(aJCas, filenameSuffix), encoding)); String documentId = DocumentMetaData.get(aJCas).getDocumentId(); int partNumber = 0; if (documentId.contains("#")) { partNumber = Integer.parseInt(StringUtils.substringAfterLast(documentId, "#")); documentId = StringUtils.substringBeforeLast(documentId, "#"); } out.printf("#begin document (%s); part %03d%n", documentId, partNumber); convert(aJCas, out); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } finally { closeQuietly(out); } }
From source file:com.alibaba.otter.shared.arbitrate.impl.setl.rpc.monitor.SelectProcessListener.java
public void processChanged(List<Long> processIds) { super.processChanged(processIds); // add by ljh at 2012-09-13,zookeeper ConnectionLoss for (Long processId : processIds) { if (!replyProcessIds.contains(processId)) { logger.warn("process is not in order, please check processId:{}", processId); addReply(processId);/* w w w . j a v a 2s . com*/ } } try { String path = StagePathUtils.getProcessRoot(getPipelineId()); // ? int size = ArbitrateConfigUtils.getParallelism(getPipelineId()) - processIds.size(); if (size > 0) {// PermitMonitor permit = ArbitrateFactory.getInstance(getPipelineId(), PermitMonitor.class); if (permit.isPermit() == false) { // ????? return; } String mainStemPath = StagePathUtils.getMainStem(getPipelineId()); byte[] bytes = zookeeper.readData(mainStemPath, true); if (bytes == null) { return; } MainStemEventData eventData = JsonUtils.unmarshalFromByte(bytes, MainStemEventData.class); if (eventData.getNid().equals(ArbitrateConfigUtils.getCurrentNid()) == false) { return;// ?mainStem,??? } // ?select???????????? // DistributedLock lock = new DistributedLock(PathUtils.getSelectLock(getPipelineId())); // try { // lock.lock(); // //process // } finally { // lock.unlock(); // } synchronized (this) { // ???, dobble-check List<String> currentProcesses = zookeeper.getChildren(path); size = ArbitrateConfigUtils.getParallelism(getPipelineId()) - currentProcesses.size(); if (size > 0) {// ProcessNodeEventData nodeData = new ProcessNodeEventData(); nodeData.setStatus(ProcessNodeEventData.Status.UNUSED);// nodeData.setMode(ArbitrateMode.RPC); nodeData.setNid(ArbitrateConfigUtils.getCurrentNid()); byte[] nodeBytes = JsonUtils.marshalToByte(nodeData); String processPath = zookeeper.create(path + "/", nodeBytes, CreateMode.PERSISTENT_SEQUENTIAL); // ? String processNode = StringUtils.substringAfterLast(processPath, "/"); Long processId = StagePathUtils.getProcessId(processNode);// ?process addReply(processId); } } } } catch (ZkException e) { recovery(getPipelineId());// ?recovery??ConnectionLosscreate? logger.error("add process error!", e); } }
From source file:com.echosource.ada.rules.AdaProfileExporter.java
private void appendModule(Writer writer, ActiveRule activeRule, boolean manyInstances) throws IOException { String moduleName = StringUtils.substringAfterLast(activeRule.getConfigKey(), "/"); writer.append("<module name=\""); StringEscapeUtils.escapeXml(writer, moduleName); writer.append("\">"); if (manyInstances) { appendModuleProperty(writer, "id", activeRule.getRuleKey()); }/* w w w. j a v a2 s . c om*/ appendModuleProperty(writer, "severity", AdaRulePriorityMapper.to(activeRule.getPriority())); appendRuleParameters(writer, activeRule); writer.append("</module>"); }
From source file:com.bstek.dorado.idesupport.RuleSetBuilder.java
protected void applyTemplateToRule(RuleTemplate ruleTemplate, Rule rule, RuleSet ruleSet) throws Exception { applyProperties(ruleTemplate, rule,/* w ww. j a va2 s . c om*/ "label,abstract,nodeName,type,category,robots,icon,labelProperty,autoGenerateId,clientTypes,reserve,deprecated,visible"); if (StringUtils.isEmpty(rule.getNodeName())) { if (StringUtils.isNotEmpty(rule.getType())) { String type = rule.getType(); rule.setNodeName(StringUtils.substringAfterLast(type, ".")); } else { rule.setNodeName(rule.getName()); } } if (StringUtils.isEmpty(rule.getLabel())) { rule.setLabel(rule.getNodeName()); } if (ruleTemplate.getSortFactor() > 0) { rule.setSortFactor(ruleTemplate.getSortFactor()); } Map<String, PropertyTemplate> primitiveProperties = ruleTemplate.getFinalPrimitiveProperties(); if (!primitiveProperties.isEmpty()) { for (PropertyTemplate propertyTemplate : primitiveProperties.values()) { Property property = new Property(); applyTemplateToProperty(propertyTemplate, property, ruleSet); rule.addPrimitiveProperty(property); } } Map<String, PropertyTemplate> properties = ruleTemplate.getFinalProperties(); if (!properties.isEmpty()) { for (PropertyTemplate propertyTemplate : properties.values()) { Property property = new Property(); applyTemplateToProperty(propertyTemplate, property, ruleSet); rule.addProperty(property); } } Map<String, ClientEvent> clientEvents = ruleTemplate.getFinalClientEvents(); if (!clientEvents.isEmpty()) { rule.addClientEvents(clientEvents.values()); } Collection<ChildTemplate> children = ruleTemplate.getFinalChildren().values(); if (!children.isEmpty()) { for (ChildTemplate childTemplate : children) { addChildrenByChildTemplate(rule, childTemplate, ruleSet); } } }
From source file:eionet.cr.api.feeds.amp.AmpFeedWriter.java
@Override public void readRow(BindingSet bindingSet) throws ResultSetReaderException { rowCount++;/*from www . java2 s. c o m*/ try { if (rowCount == 1) { // write RDF header outputStream.write("<?xml version=\"1.0\"?>".getBytes()); outputStream.write(("\n<rdf:RDF" + getHeaderAttributes() + ">").getBytes()); outputStream.flush(); } Value subjectValue = bindingSet.getValue("s"); String subjUri = subjectValue.stringValue(); if (currSubjUri == null || !currSubjUri.equals(subjUri)) { // new subject, so close previous one, unless it's the first time if (rowCount > 1) { // close the subject currSubjBuf.append("\n\t</rdf:Description>"); outputStream.write(currSubjBuf.toString().getBytes()); outputStream.flush(); } // start new subject currSubjBuf = new StringBuilder("\n\t<rdf:Description rdf:about=\""); currSubjBuf.append(StringEscapeUtils.escapeXml(subjUri)).append("\">"); // set current subject to the new one currSubjUri = subjUri; writtenSubjectsCount++; } Value predicateValue = bindingSet.getValue("p"); String predUri = predicateValue.stringValue(); // if new predicate, clear the set of already written objects if (currPredUri == null || !currPredUri.equals(predUri)) { currPredWrittenObjects = new HashSet<String>(); currPredUri = predUri; } Value objectValueObject = bindingSet.getValue("o"); boolean isLitObject = objectValueObject instanceof Literal; // skip literal values of rdf:type if (predUri.equals(Predicates.RDF_TYPE) && isLitObject) { return; } String objValue = objectValueObject.stringValue(); boolean objAlreadyWritten = currPredWrittenObjects.contains(objValue); // skip if object value is blank, or object has already been written if (StringUtils.isBlank(objValue) || objAlreadyWritten) { return; } // get namespace URI for this predicate String predNsUri = NamespaceUtil.extractNamespace(predUri); if (StringUtils.isBlank(predNsUri)) { throw new CRRuntimeException("Could not extract namespace URL from " + predUri); } // include only predicates from supplied namespaces if (namespaces.containsKey(predNsUri)) { // extract predicate's local name String predLocalName = StringUtils.substringAfterLast(predUri, predNsUri); if (StringUtils.isBlank(predLocalName)) { throw new CRRuntimeException("Could not extract local name from " + predUri); } // start predicate tag currSubjBuf.append("\n\t\t<").append(namespaces.get(predNsUri)).append(":").append(predLocalName); // prepare escaped-for-XML object value String objValueEscaped = StringEscapeUtils.escapeXml(objValue); // write object value, depending on whether it is literal or not // (and close the predicate tag too!) if (!isLitObject && URLUtil.isURL(objValue)) { currSubjBuf.append(" rdf:resource=\"").append(objValueEscaped).append("\"/>"); } else { currSubjBuf.append(">").append(objValueEscaped).append("</").append(namespaces.get(predNsUri)) .append(":").append(predLocalName).append(">"); } writtenTriplesCount++; currPredWrittenObjects.add(objValue); } } catch (IOException e) { throw new ExportException(e.toString(), e); } }
From source file:net.bpelunit.framework.control.ws.WebServiceHandler.java
/** * Find the partner name in the incoming request URI. Is supposed to be the * last segment of the path URI./*from ww w . j a v a 2s .c o m*/ * * @param path * @return */ private static String getPartnerName(String path) { String stringToTest = path; // Remove trailing slash, if any. stringToTest = StringUtils.removeEnd(stringToTest, "/"); // Get last part of the URL. stringToTest = StringUtils.substringAfterLast(stringToTest, "/"); return stringToTest; }
From source file:gobblin.aws.AWSJobConfigurationManager.java
private void fetchJobConf() throws IOException, ConfigurationException { // Refresh job config pull details from config fetchJobConfSettings();/*from www.j a v a 2 s . c om*/ // TODO: Eventually when config store supports job files as well // .. we can replace this logic with config store if (this.jobConfS3Uri.isPresent() && this.jobConfDirPath.isPresent()) { // Download the zip file final String zipFile = appendSlash(this.jobConfDirPath.get()) + StringUtils.substringAfterLast(this.jobConfS3Uri.get(), File.separator); LOGGER.debug("Downloading to zip: " + zipFile + " from uri: " + this.jobConfS3Uri.get()); FileUtils.copyURLToFile(new URL(this.jobConfS3Uri.get()), new File(zipFile)); final String extractedPullFilesPath = appendSlash(this.jobConfDirPath.get()) + "files"; // Extract the zip file LOGGER.debug("Extracting to directory: " + extractedPullFilesPath + " from zip: " + zipFile); unzipArchive(zipFile, new File(extractedPullFilesPath)); // Load all new job configurations // TODO: Currently new and updated jobs are handled, we should un-schedule deleted jobs as well final File jobConfigDir = new File(extractedPullFilesPath); if (jobConfigDir.exists()) { LOGGER.info("Loading job configurations from " + jobConfigDir); final Properties properties = new Properties(); properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, jobConfigDir.getAbsolutePath()); final List<Properties> jobConfigs = SchedulerUtils.loadGenericJobConfigs(properties); LOGGER.info("Loaded " + jobConfigs.size() + " job configuration(s)"); for (Properties config : jobConfigs) { LOGGER.debug("Config value: " + config); // If new config or existing config got updated, then post new job config arrival event final String jobConfigPathIdentifier = config .getProperty(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY); if (!jobConfFiles.containsKey(jobConfigPathIdentifier)) { jobConfFiles.put(jobConfigPathIdentifier, config); postNewJobConfigArrival(config.getProperty(ConfigurationKeys.JOB_NAME_KEY), config); LOGGER.info("New config arrived for job: " + jobConfigPathIdentifier); } else if (!config.equals(jobConfFiles.get(jobConfigPathIdentifier))) { jobConfFiles.put(jobConfigPathIdentifier, config); postNewJobConfigArrival(config.getProperty(ConfigurationKeys.JOB_NAME_KEY), config); LOGGER.info("Config updated for job: " + jobConfigPathIdentifier); } else { LOGGER.info("Config not changed for job: " + jobConfigPathIdentifier); } } } else { LOGGER.warn("Job configuration directory " + jobConfigDir + " not found"); } } }
From source file:eionet.cr.api.feeds.SubjectsRDFWriter.java
/** * * @param subjects/*from w ww. j a v a 2 s .c o m*/ * @param out * @throws IOException */ public void write(List<SubjectDTO> subjects, OutputStream out) throws IOException { // if no subjects, write empty rdf:RDF tag if (subjects == null || subjects.isEmpty()) { out.write("<rdf:RDF/>".getBytes()); return; } // start rdf:RDF element out.write(("<rdf:RDF" + getAttributes() + ">").getBytes()); // loop over subjects for (SubjectDTO subject : subjects) { // initialize subject processor if not initialized yet if (subjectProcessor != null) { subjectProcessor.process(subject); } // continuing has only point if subject has at least one predicate if (subject.getPredicateCount() > 0) { String subjectUri = subject.getUri(); if (StringUtils.isBlank(subjectUri)) { LOGGER.error("Subject URI must not be blank (subject hash = " + subject.getUriHash() + ")"); continue; } // start rdf:Description tag StringBuffer buf = new StringBuffer("\n\t<rdf:Description rdf:about=\""); buf.append(StringEscapeUtils.escapeXml(subjectUri)).append("\">"); // loop over this subject's predicates for (Entry<String, Collection<ObjectDTO>> entry : subject.getPredicates().entrySet()) { String predicate = entry.getKey(); Collection<ObjectDTO> objects = entry.getValue(); // continue only if predicate has at least one object if (objects != null && !objects.isEmpty()) { // get namespace URI for this predicate String nsUrl = extractNamespace(predicate); if (nsUrl == null || nsUrl.trim().length() == 0) { throw new CRRuntimeException("Could not extract namespace URL from " + predicate); } // include only predicates from supplied namespaces if (namespaces.containsKey(nsUrl)) { // extract predicate's local name String localName = StringUtils.substringAfterLast(predicate, nsUrl); if (localName == null || localName.trim().length() == 0) { throw new CRRuntimeException("Could not extract local name from " + predicate); } // hash-set for remembering already written object values HashSet<String> alreadyWritten = new HashSet<String>(); // loop over this predicate's objects for (ObjectDTO object : entry.getValue()) { // skip literal values of rdf:type if (object.isLiteral() && predicate.equals(Predicates.RDF_TYPE)) { continue; } String objectValue = object.getValue(); boolean isDerivedObject = object.getDerivSourceHash() != 0; // include only non-blank and non-derived objects // that have not been written yet if (!StringUtils.isBlank(objectValue) && !alreadyWritten.contains(objectValue) && (includeDerivedValues || !isDerivedObject)) { // start predicate tag buf.append("\n\t\t<").append(namespaces.get(nsUrl)).append(":") .append(localName); // prepare escaped-for-XML object value String escapedValue = StringEscapeUtils.escapeXml(objectValue); // write object value, depending on whether it is literal or not // (close the predicate tag too) if (!object.isLiteral() && URLUtil.isURL(objectValue)) { buf.append(" rdf:resource=\"").append(escapedValue).append("\"/>"); } else { buf.append(">").append(escapedValue).append("</") .append(namespaces.get(nsUrl)).append(":").append(localName) .append(">"); } alreadyWritten.add(objectValue); } } } } } // close rdf:Description tag buf.append("\n\t</rdf:Description>"); out.write(buf.toString().getBytes()); } } // close rdf:RDF tag out.write("</rdf:RDF>\n".getBytes()); }
From source file:com.huateng.ebank.framework.web.TransFilter.java
private boolean expiredSystem(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String uriStr = StringUtils.substringAfterLast(req.getServletPath(), "/"); if (StringUtils.indexOf(loginRef, uriStr) == -1) { resp.setHeader("Pragma", "No-cache"); resp.setHeader("Cache-Control", "no-cache,no-store,max-age=0"); resp.setDateHeader("Expires", 1); RequestDispatcher rd = (req).getRequestDispatcher(expiredPageName); rd.forward(req, resp);/*from w ww . ja v a 2s .c o m*/ return true; } return false; }