List of usage examples for java.util.regex Matcher quoteReplacement
public static String quoteReplacement(String s)
From source file:com.krawler.spring.crm.dashboard.CrmDashboardController.java
private void getLeads(Map<String, List<AuditTrailDetail>> auditTrailDetailMap, List<String> recordIds) { String itemname;//from www. j a va2s .c o m try { List<CrmLead> leads = getCrmleadDAO().getLeads(recordIds); if (leads != null) { for (CrmLead lead : leads) { List<AuditTrailDetail> list = auditTrailDetailMap.get(lead.getLeadid()); for (AuditTrailDetail auditDetail : list) { itemname = lead.getLastname(); if (!lead.getIsarchive() && lead.getDeleteflag() != 1) { auditDetail.detail = auditDetail.detail.replaceAll(Matcher.quoteReplacement(itemname), "<a href=# onclick=\"addLeadTab('" + lead.getLeadid() + "')\">" + Matcher.quoteReplacement(itemname) + "</a>"); } } } } } catch (Exception ex) { logger.warn(ex.getMessage(), ex); } }
From source file:org.apache.ambari.server.upgrade.UpgradeCatalog220.java
protected String updateHiveEnvContentHDP23(String hiveEnvContent) { if (hiveEnvContent == null) { return null; }// ww w .j a va 2 s. com String oldHeapSizeRegex = "# The heap size of the jvm stared by hive shell script can be controlled via:\\s*\\n"; String newHeapSizeRegex = "# The heap size of the jvm stared by hive shell script can be controlled via:\n" + "\n" + "if [ \"$SERVICE\" = \"metastore\" ]; then\n" + " export HADOOP_HEAPSIZE={{hive_metastore_heapsize}} # Setting for HiveMetastore\n" + "else\n" + " export HADOOP_HEAPSIZE={{hive_heapsize}} # Setting for HiveServer2 and Client\n" + "fi\n" + "\n" + "export HADOOP_CLIENT_OPTS=\"$HADOOP_CLIENT_OPTS -Xmx${HADOOP_HEAPSIZE}m\"\n" + "\n"; return hiveEnvContent.replaceFirst(oldHeapSizeRegex, Matcher.quoteReplacement(newHeapSizeRegex)); }
From source file:com.krawler.spring.crm.dashboard.CrmDashboardController.java
private void getAccounts(Map<String, List<AuditTrailDetail>> auditTrailDetailMap, List<String> recordIds) { String itemname;/* w w w . j a v a 2s.c om*/ try { List<CrmAccount> accounts = getAccountDAO().getAccounts(recordIds); if (accounts != null) { for (CrmAccount account : accounts) { List<AuditTrailDetail> list = auditTrailDetailMap.get(account.getAccountid()); for (AuditTrailDetail auditDetail : list) { itemname = account.getAccountname(); if (!account.getIsarchive() && account.getDeleteflag() != 1) { auditDetail.detail = auditDetail.detail.replaceAll(Matcher.quoteReplacement(itemname), "<a href=# onclick=\"addAccountTab('" + account.getAccountid() + "')\">" + Matcher.quoteReplacement(itemname) + "</a>"); } } } } } catch (Exception ex) { logger.warn(ex.getMessage(), ex); } }
From source file:com.krawler.spring.crm.dashboard.CrmDashboardController.java
private void getContacts(Map<String, List<AuditTrailDetail>> auditTrailDetailMap, List<String> recordIds) { String itemname;/*from w ww .j a v a 2 s .c o m*/ try { List<CrmContact> contacts = getContactDAO().getContacts(recordIds); if (contacts != null) { for (CrmContact contact : contacts) { List<AuditTrailDetail> list = auditTrailDetailMap.get(contact.getContactid()); for (AuditTrailDetail auditDetail : list) { itemname = contact.getFirstname() + " " + contact.getLastname(); if (!contact.getIsarchive() && contact.getDeleteflag() != 1) { auditDetail.detail = auditDetail.detail.replaceAll(Matcher.quoteReplacement(itemname), "<a href=# onclick=\"addContactTab('" + contact.getContactid() + "')\">" + Matcher.quoteReplacement(itemname) + "</a>"); } } } } } catch (Exception ex) { logger.warn(ex.getMessage(), ex); } }
From source file:edu.harvard.iq.dataverse.ingest.tabulardata.impl.plugins.dta.DTAFileReader.java
private void decodeData(BufferedInputStream stream) throws IOException { dbgLog.fine("\n***** decodeData(): start *****"); if (stream == null) { throw new IllegalArgumentException("stream == null!"); }//from w w w . j av a 2 s . c o m //int nvar = (Integer)smd.getFileInformation().get("varQnty"); int nvar = dataTable.getVarQuantity().intValue(); //int nobs = (Integer)smd.getFileInformation().get("caseQnty"); int nobs = dataTable.getCaseQuantity().intValue(); if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("data dimensions[observations x variables] = (" + nobs + "x" + nvar + ")"); } if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("bytes per row=" + bytes_per_row + " bytes"); } if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("variableTypes=" + Arrays.deepToString(variableTypes)); } if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("StringLengthTable=" + StringLengthTable); } // create a File object to save the tab-delimited data file FileOutputStream fileOutTab = null; PrintWriter pwout = null; File tabDelimitedDataFile = File.createTempFile("tempTabfile.", ".tab"); // save the temp tab-delimited file in the return ingest object: ingesteddata.setTabDelimitedFile(tabDelimitedDataFile); fileOutTab = new FileOutputStream(tabDelimitedDataFile); pwout = new PrintWriter(new OutputStreamWriter(fileOutTab, "utf8"), true); /* Should we lose this dateFormat thing in 4.0? * the UNF should be calculatable on the app side solely from the data * stored in the tab file and the type information stored the dataVariable * object. * furthermore, the very idea of storing a format entry not just for * every variable, but for every value/observation is a bit strange. * TODO: review and confirm that, in the 3.* implementation, every * entry in dateFormat[nvar][*] is indeed the same - except for the * missing value entries. -- L.A. 4.0 (OK, I got rid of the dateFormat; instead I kinda sorta assume that the format is the same for every value in a column, save for the missing values... like this: dataTable.getDataVariables().get(columnCounter).setFormatSchemaName(ddt.format); BUT, this needs to be reviewed/confirmed etc! */ //String[][] dateFormat = new String[nvar][nobs]; for (int i = 0; i < nobs; i++) { byte[] dataRowBytes = new byte[bytes_per_row]; Object[] dataRow = new Object[nvar]; int nbytes = stream.read(dataRowBytes, 0, bytes_per_row); if (nbytes == 0) { String errorMessage = "reading data: no data were read at(" + i + "th row)"; throw new IOException(errorMessage); } // decoding each row int byte_offset = 0; for (int columnCounter = 0; columnCounter < variableTypes.length; columnCounter++) { Integer varType = variableTypeMap.get(variableTypes[columnCounter]); // 4.0 Check if this is a time/date variable: boolean isDateTimeDatum = false; String formatCategory = dataTable.getDataVariables().get(columnCounter).getFormatCategory(); if (formatCategory != null && (formatCategory.equals("time") || formatCategory.equals("date"))) { isDateTimeDatum = true; } String variableFormat = dateVariableFormats[columnCounter]; switch (varType != null ? varType : 256) { case -5: // Byte case // note: 1 byte signed byte byte_datum = dataRowBytes[byte_offset]; if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column byte =" + byte_datum); } if (byte_datum >= BYTE_MISSING_VALUE) { if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column byte MV=" + byte_datum); } dataRow[columnCounter] = MissingValueForTabDelimitedFile; } else { dataRow[columnCounter] = byte_datum; } byte_offset++; break; case -4: // Stata-int (=java's short: 2byte) case // note: 2-byte signed int, not java's int ByteBuffer int_buffer = ByteBuffer.wrap(dataRowBytes, byte_offset, 2); if (isLittleEndian) { int_buffer.order(ByteOrder.LITTLE_ENDIAN); } short short_datum = int_buffer.getShort(); if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column stata int =" + short_datum); } if (short_datum >= INT_MISSIG_VALUE) { if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column stata long missing value=" + short_datum); } dataRow[columnCounter] = MissingValueForTabDelimitedFile; } else { if (isDateTimeDatum) { DecodedDateTime ddt = decodeDateTimeData("short", variableFormat, Short.toString(short_datum)); if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row , decodedDateTime " + ddt.decodedDateTime + ", format=" + ddt.format); } dataRow[columnCounter] = ddt.decodedDateTime; //dateFormat[columnCounter][i] = ddt.format; dataTable.getDataVariables().get(columnCounter).setFormat(ddt.format); } else { dataRow[columnCounter] = short_datum; } } byte_offset += 2; break; case -3: // stata-Long (= java's int: 4 byte) case // note: 4-byte singed, not java's long //dbgLog.fine("DATreader: stata long"); ByteBuffer long_buffer = ByteBuffer.wrap(dataRowBytes, byte_offset, 4); if (isLittleEndian) { long_buffer.order(ByteOrder.LITTLE_ENDIAN); } int int_datum = long_buffer.getInt(); if (dbgLog.isLoggable(Level.FINE)) { //dbgLog.fine(i + "-th row " + columnCounter // + "=th column stata long =" + int_datum); } if (int_datum >= LONG_MISSING_VALUE) { if (dbgLog.isLoggable(Level.FINE)) { //dbgLog.fine(i + "-th row " + columnCounter // + "=th column stata long missing value=" + int_datum); } dataRow[columnCounter] = MissingValueForTabDelimitedFile; } else { if (isDateTimeDatum) { DecodedDateTime ddt = decodeDateTimeData("int", variableFormat, Integer.toString(int_datum)); if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row , decodedDateTime " + ddt.decodedDateTime + ", format=" + ddt.format); } dataRow[columnCounter] = ddt.decodedDateTime; dataTable.getDataVariables().get(columnCounter).setFormat(ddt.format); } else { dataRow[columnCounter] = int_datum; } } byte_offset += 4; break; case -2: // float case // note: 4-byte ByteBuffer float_buffer = ByteBuffer.wrap(dataRowBytes, byte_offset, 4); if (isLittleEndian) { float_buffer.order(ByteOrder.LITTLE_ENDIAN); } float float_datum = float_buffer.getFloat(); if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column float =" + float_datum); } if (FLOAT_MISSING_VALUE_SET.contains(float_datum)) { if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column float missing value=" + float_datum); } dataRow[columnCounter] = MissingValueForTabDelimitedFile; } else { if (isDateTimeDatum) { DecodedDateTime ddt = decodeDateTimeData("float", variableFormat, doubleNumberFormatter.format(float_datum)); if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row , decodedDateTime " + ddt.decodedDateTime + ", format=" + ddt.format); } dataRow[columnCounter] = ddt.decodedDateTime; dataTable.getDataVariables().get(columnCounter).setFormat(ddt.format); } else { dataRow[columnCounter] = float_datum; // This may be temporary - but for now (as in, while I'm testing // 4.0 ingest against 3.* ingest, I need to be able to tell if a // floating point value was a single, or double float in the // original STATA file: -- L.A. Jul. 2014 dataTable.getDataVariables().get(columnCounter).setFormat("float"); } } byte_offset += 4; break; case -1: // double case // note: 8-byte ByteBuffer double_buffer = ByteBuffer.wrap(dataRowBytes, byte_offset, 8); if (isLittleEndian) { double_buffer.order(ByteOrder.LITTLE_ENDIAN); } double double_datum = double_buffer.getDouble(); if (DOUBLE_MISSING_VALUE_SET.contains(double_datum)) { if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column double missing value=" + double_datum); } dataRow[columnCounter] = MissingValueForTabDelimitedFile; } else { if (isDateTimeDatum) { DecodedDateTime ddt = decodeDateTimeData("double", variableFormat, doubleNumberFormatter.format(double_datum)); if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row , decodedDateTime " + ddt.decodedDateTime + ", format=" + ddt.format); } dataRow[columnCounter] = ddt.decodedDateTime; dataTable.getDataVariables().get(columnCounter).setFormat(ddt.format); } else { dataRow[columnCounter] = doubleNumberFormatter.format(double_datum); } } byte_offset += 8; break; case 0: // String case int strVarLength = StringLengthTable.get(columnCounter); String raw_datum = new String( Arrays.copyOfRange(dataRowBytes, byte_offset, (byte_offset + strVarLength)), "ISO-8859-1"); // TODO: // is it the right thing to do, to default to "ISO-8859-1"? // (it may be; since there's no mechanism for specifying // alternative encodings in Stata, this may be their default; // it just needs to be verified. -- L.A. Jul. 2014) String string_datum = getNullStrippedString(raw_datum); if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column string =" + string_datum); } if (string_datum.isEmpty()) { if (dbgLog.isLoggable(Level.FINER)) { dbgLog.finer(i + "-th row " + columnCounter + "=th column string missing value=" + string_datum); } // TODO: /* Is this really a missing value case? * Or is it an honest empty string? * Is there such a thing as a missing value for a String in Stata? * -- L.A. 4.0 */ dataRow[columnCounter] = MissingValueForTabDelimitedFile; } else { /* * Some special characters, like new lines and tabs need to * be escaped - otherwise they will break our TAB file * structure! * But before we escape anything, all the back slashes * already in the string need to be escaped themselves. */ String escapedString = string_datum.replace("\\", "\\\\"); // escape quotes: escapedString = escapedString.replaceAll("\"", Matcher.quoteReplacement("\\\"")); // escape tabs and new lines: escapedString = escapedString.replaceAll("\t", Matcher.quoteReplacement("\\t")); escapedString = escapedString.replaceAll("\n", Matcher.quoteReplacement("\\n")); escapedString = escapedString.replaceAll("\r", Matcher.quoteReplacement("\\r")); // the escaped version of the string is stored in the tab file // enclosed in double-quotes; this is in order to be able // to differentiate between an empty string (tab-delimited empty string in // double quotes) and a missing value (tab-delimited empty string). // Although the question still remains - is it even possible // to store an empty string, that's not a missing value, in Stata? // - see the comment in the missing value case above. -- L.A. 4.0 dataRow[columnCounter] = "\"" + escapedString + "\""; } byte_offset += strVarLength; break; default: dbgLog.fine("unknown variable type found"); String errorMessage = "unknow variable Type found at data section"; throw new InvalidObjectException(errorMessage); } // switch } // for-columnCounter // Dump the row of data to the tab-delimited file we are producing: pwout.println(StringUtils.join(dataRow, "\t")); if (dbgLog.isLoggable(Level.FINE)) { //dbgLog.fine(i + "-th row's data={" + StringUtils.join(dataRow, ",") + "};"); } } // for- i (row) pwout.close(); if (dbgLog.isLoggable(Level.FINE)) { dbgLog.fine("variableTypes:\n" + Arrays.deepToString(variableTypes)); } dbgLog.fine("DTA Ingest: decodeData(): end."); }
From source file:com.krawler.spring.crm.dashboard.CrmDashboardController.java
private void getOpportunities(Map<String, List<AuditTrailDetail>> auditTrailDetailMap, List<String> recordIds) { String itemname;/*from ww w. j a v a2 s. c o m*/ try { List<CrmOpportunity> opportunities = getOpportunityDAO().getOpportunities(recordIds); if (opportunities != null) { for (CrmOpportunity opportunity : opportunities) { List<AuditTrailDetail> list = auditTrailDetailMap.get(opportunity.getOppid()); for (AuditTrailDetail auditDetail : list) { itemname = opportunity.getOppname(); if (!opportunity.getIsarchive() && opportunity.getDeleteflag() != 1) { auditDetail.detail = auditDetail.detail.replaceAll(Matcher.quoteReplacement(itemname), "<a href=# onclick=\"addOpportunityTab('" + opportunity.getOppid() + "')\">" + Matcher.quoteReplacement(itemname) + "</a>"); } } } } } catch (Exception ex) { logger.warn(ex.getMessage(), ex); } }
From source file:com.krawler.spring.crm.dashboard.CrmDashboardController.java
private void getCases(Map<String, List<AuditTrailDetail>> auditTrailDetailMap, List<String> recordIds) { String itemname;//from w w w . ja v a2s . co m try { List<CrmCase> cases = getCaseDAO().getCases(recordIds); if (cases != null) { for (CrmCase caseObj : cases) { List<AuditTrailDetail> list = auditTrailDetailMap.get(caseObj.getCaseid()); for (AuditTrailDetail auditDetail : list) { itemname = caseObj.getSubject(); if (!caseObj.getIsarchive() && caseObj.getDeleteflag() != 1) { auditDetail.detail = auditDetail.detail.replaceAll(Matcher.quoteReplacement(itemname), "<a href=# onclick=\"addCaseTab('" + caseObj.getCaseid() + "')\">" + Matcher.quoteReplacement(itemname) + "</a>"); } } } } } catch (Exception ex) { logger.warn(ex.getMessage(), ex); } }
From source file:org.LexGrid.LexBIG.gui.ValueSetDefinitionDetails.java
private boolean isDateValid(String dateStr) { String format = "M/d/yyyy"; String reFormat = Pattern.compile("d+|M+").matcher(Matcher.quoteReplacement(format)) .replaceAll("\\\\d{1,2}"); reFormat = Pattern.compile("y+").matcher(reFormat).replaceAll("\\\\d{4}"); if (Pattern.compile(reFormat).matcher(dateStr).matches()) { // date string matches format structure, // - now test it can be converted to a valid date SimpleDateFormat sdf = (SimpleDateFormat) DateFormat.getDateInstance(); sdf.setLenient(false);/*from ww w .j a va 2 s .c o m*/ sdf.applyPattern(format); try { sdf.parse(dateStr); return true; } catch (ParseException e) { return false; } } return false; }
From source file:com.krawler.spring.crm.dashboard.CrmDashboardController.java
private void getActivities(Map<String, List<AuditTrailDetail>> auditTrailDetailMap, List<String> recordIds) { String itemname;//from ww w. j a v a2s .co m try { List<CrmActivityMaster> activities = getActivityDAO().getActivities(recordIds); if (activities != null) { for (CrmActivityMaster activity : activities) { List<AuditTrailDetail> list = auditTrailDetailMap.get(activity.getActivityid()); for (AuditTrailDetail auditDetail : list) { itemname = activity.getFlag(); if (!activity.getIsarchive() && activity.getDeleteflag() != 1) { auditDetail.detail = auditDetail.detail.replaceAll(Matcher.quoteReplacement(itemname), "<a href=# onclick=\"addModuleActivityMasterTab('" + auditDetail.getRecId() + "'," + activity.getMapwith() + ")\">" + Matcher.quoteReplacement(itemname) + "</a>"); } } } } } catch (Exception ex) { logger.warn(ex.getMessage(), ex); } }
From source file:xc.mst.services.normalization.NormalizationService.java
/** * Edits OCLC 035 records with common incorrect formats to take the format * (OCoLC)%CONTROL_NUMBER%./* ww w . j a v a 2 s . c o m*/ * * Current list of patterns we will process: * * 035 $b ocm $a <control_number> * 035 $b ocn $a <control_number> * 035 $b ocl $a <control_number> * 035 $b on $a <control_number> * * 035 $9 ocm<control_number> * 035 $9 ocn<control_number> * 035 $9 ocl<control_number> * 035 $9 on<control_number> * * 035 $a (OCoLC)ocm<control_number> * 035 $a (OCoLC)ocn<control_number> * 035 $a (OCoLC)ocl<control_number> * 035 $a (OCoLC)on<control_number> * 035 $a ocm<control_number> * 035 $a ocn<control_number> * 035 $a ocl<control_number> * 035 $a on<control_number> * 035 $a (OCLC)ocm<control_number> * 035 $a (OCLC)ocn<control_number> * 035 $a (OCLC)ocl<control_number> * 035 $a (OCLC)on<control_number> * 035 $a (OCLC)<control_number> * 035 $a (OCoCL)ocm<control_number> * 035 $a (OCoCL)ocn<control_number> * 035 $a (OCoCL)ocl<control_number> * 035 $a (OCoCL)on<control_number> * 035 $a (OCoCL)<control_number> * * * @param marcXml * The original MARCXML record * @return The MARCXML record after performing this normalization step. */ @SuppressWarnings("unchecked") private MarcXmlManager fix035(MarcXmlManager marcXml) { if (LOG.isDebugEnabled()) LOG.debug("Entering fix035 normalization step."); boolean fix035_0s = enabledSteps.getProperty(CONFIG_ENABLED_035_LEADING_ZERO, "0").equals("1"); // Get the original list of 035 elements. We know that any 035 we // supplied had the correct format, so all incorrect 035 records must // be contained in this list ArrayList<Element> field035Elements = marcXml.getOriginal035Fields(); LOG.debug("*** field035Elements size=" + field035Elements.size()); // Loop over the 035 elements for (Element field035 : field035Elements) { // The $a and $b subfields of Element aSubfield = null; Element bSubfield = null; Element subfield9 = null; // Get the control fields List<Element> subfields = field035.getChildren("subfield", marcNamespace); //StringBuilder err_sb = new StringBuilder(""); // Iterate over the subfields to find the $a and $b subfields for (Element subfield : subfields) { // Initialize the aSubfield if we found the $a if (subfield.getAttribute("code").getValue().equals("a")) { aSubfield = subfield; } // Initialize the bSubfield if we found the $b else if (subfield.getAttribute("code").getValue().equals("b")) { //err_sb.append("subfield b"); bSubfield = subfield; } // Initialize the subfield9 if we found the $9 else if (subfield.getAttribute("code").getValue().equals("9")) { //err_sb.append("subfield 9"); subfield9 = subfield; } } // end loop over 035 subfields boolean modified = false; // First, process those b/a patterns: /* * 035 $b ocm $a <control_number> * 035 $b ocn $a <control_number> * 035 $b ocl $a <control_number> * 035 $b on $a <control_number> */ if (aSubfield != null && bSubfield != null && substitute035_a_b != null) { for (int i = 0; i < substitute035_a_b.size(); i++) { final String matchPrefix = substitute035_a_b.get(i).get("MatchPrefix"); if (matchPrefix != null) { final String replaceWith = substitute035_a_b.get(i).get("ReplaceWith"); if (bSubfield.getText().equals(matchPrefix)) { String controlNumber = aSubfield.getText().trim(); // Set $a to (OCoLC)%CONTROL_NUMBER% aSubfield.setText(replaceWith + controlNumber); modified = true; break; } } } } // Now, the sub-9-only patterns: /* * 035 $9 ocm<control_number> * 035 $9 ocn<control_number> * 035 $9 ocl<control_number> * 035 $9 on<control_number> */ else if (subfield9 != null && substitute035_9 != null) { for (int i = 0; i < substitute035_9.size(); i++) { final Pattern matchPrefix = (Pattern) substitute035_9.get(i).get("MatchPrefix"); if (matchPrefix != null) { Matcher matcher = matchPrefix.matcher(subfield9.getText()); if (matcher.find()) { matches.clear(); int numMatches = matcher.groupCount(); for (int j = 1; j <= MAX_035_REGEX_MATCHES && j <= numMatches; j++) { matches.add(j - 1, matcher.group(j)); } final String replaceWith = (String) substitute035_9.get(i).get("ReplaceWith"); Matcher action = variablePattern.matcher(replaceWith); StringBuffer sb = new StringBuffer(replaceWith.length()); int j = 0; while (action.find()) { String text = matches.get(j++); action.appendReplacement(sb, Matcher.quoteReplacement(text)); } action.appendTail(sb); // Add an $a subfield if there wasn't one if (aSubfield == null) { aSubfield = new Element("subfield", marcNamespace); aSubfield.setAttribute("code", "a"); field035.addContent("\t").addContent(aSubfield).addContent("\n"); } // Set $a to (OCoLC)%CONTROL_NUMBER% aSubfield.setText(sb.toString()); modified = true; break; } } } } // Finally, the sub-a-only patterns: /* * 035 $a (OCoLC)ocm<control_number> * 035 $a (OCoLC)ocn<control_number> * 035 $a (OCoLC)ocl<control_number> * 035 $a (OCoLC)on<control_number> * 035 $a ocm<control_number> * 035 $a ocn<control_number> * 035 $a ocl<control_number> * 035 $a on<control_number> * 035 $a (OCLC)ocm<control_number> * 035 $a (OCLC)ocn<control_number> * 035 $a (OCLC)ocl<control_number> * 035 $a (OCLC)on<control_number> * 035 $a (OCLC)<control_number> * 035 $a (OCoCL)ocm<control_number> * 035 $a (OCoCL)ocn<control_number> * 035 $a (OCoCL)ocl<control_number> * 035 $a (OCoCL)on<control_number> * 035 $a (OCoCL)<control_number> * */ else if (aSubfield != null && substitute035_a != null) { for (int i = 0; i < substitute035_a.size(); i++) { final Pattern matchPrefix = (Pattern) substitute035_a.get(i).get("MatchPrefix"); if (matchPrefix != null) { Matcher matcher = matchPrefix.matcher(aSubfield.getText()); if (matcher.find()) { matches.clear(); int numMatches = matcher.groupCount(); for (int j = 1; j <= MAX_035_REGEX_MATCHES && j <= numMatches; j++) { matches.add(j - 1, matcher.group(j)); } final String replaceWith = (String) substitute035_a.get(i).get("ReplaceWith"); Matcher action = variablePattern.matcher(replaceWith); StringBuffer sb = new StringBuffer(replaceWith.length()); int j = 0; while (action.find()) { String text = matches.get(j++); action.appendReplacement(sb, Matcher.quoteReplacement(text)); } action.appendTail(sb); // Set $a to (OCoLC)%CONTROL_NUMBER% aSubfield.setText(sb.toString()); modified = true; break; } } } } // Allow admin to supply a prefix for 035$a's lacking one if (aSubfield != null && !modified && valid_035a_format_pattern != null) { final Matcher matcher = valid_035a_format_pattern.matcher(aSubfield.getText()); // if it doesn't match, it's invalid if (!matcher.find()) { // Set $a to (OCoLC)%CONTROL_NUMBER% aSubfield.setText("(" + default_035a_org_code + ")" + aSubfield.getText()); modified = true; } } // If the $a has more than one prefix, only use the first one if (modified && aSubfield != null) { String aSubfieldText = aSubfield.getText(); if (aSubfieldText.contains("(") && aSubfieldText.contains(")")) aSubfield.setText(aSubfieldText.substring(0, aSubfieldText.indexOf(')') + 1) + aSubfieldText.substring(aSubfieldText.lastIndexOf(')') + 1)); } // remove preceeding 0s if (aSubfield != null && fix035_0s) { // Get value of $a String value = aSubfield.getText(); // Remove leading zeros in value. Ex. Change (OCoLC)000214052 to (OCoLC)214052 int indexOfBracket = value.indexOf(")"); if (indexOfBracket >= 0) { StringBuffer newValue = new StringBuffer(value.length()); int currInx = indexOfBracket + 1; newValue.append(value.substring(0, currInx)); // ignore any white space after closing parenthesis and before numeric while (String.valueOf(value.charAt(currInx)).matches("\\s")) currInx++; // now, ignore any leading zeroes while (value.charAt(currInx) == '0') currInx++; // finally, keep the rest newValue.append(value.substring(currInx)); // Set the new value back in subfield $a aSubfield.setText(newValue.toString()); } } // Remove unnecessary sub-b and sub-9 if (modified && bSubfield != null) { field035.removeContent(bSubfield); } if (modified && subfield9 != null) { field035.removeContent(subfield9); } } // end loop over 035 elements return marcXml; }