List of usage examples for java.util.regex Matcher appendTail
public StringBuilder appendTail(StringBuilder sb)
From source file:info.magnolia.module.admininterface.SaveHandlerImpl.java
/** * Update the links in a string returned by a rich text editor. If there are links to temporary files created due * the fckeditor upload mechanism those filese are written to the node. * @param node node saving to. used to save the files and fileinfod to * @param name the name of the field. used to make a subnode for the files * @param valueStr the value containing the links * @return the cleaned value/*from w w w. j a v a2 s .c o m*/ * @throws AccessDeniedException * @throws RepositoryException * @throws PathNotFoundException */ private String updateLinks(Content node, String name, String valueStr) throws AccessDeniedException, RepositoryException, PathNotFoundException { // process the images and uploaded files HierarchyManager hm = MgnlContext.getHierarchyManager(this.getRepository()); Pattern imagePattern = Pattern.compile("(<(a|img)[^>]+(href|src)[ ]*=[ ]*\")([^\"]*)(\"[^>]*>)"); Pattern uuidPattern = Pattern.compile(MgnlContext.getContextPath() + "/tmp/fckeditor/([^/]*)/[^\"]*"); Content filesNode = ContentUtil.getOrCreateContent(node, name + "_files", ItemType.CONTENTNODE); String pageName = StringUtils.substringAfterLast(this.getPath(), "/"); // adapt img urls Matcher srcMatcher = imagePattern.matcher(valueStr); StringBuffer res = new StringBuffer(); while (srcMatcher.find()) { String src = srcMatcher.group(4); // the editor creates relative links after moving an absolute path: ../../../ replace them src = StringUtils.replace(src, "../../../", MgnlContext.getContextPath() + "/"); String link = src; // process the tmporary uploaded files Matcher uuidMatcher = uuidPattern.matcher(src); if (uuidMatcher.find()) { String uuid = uuidMatcher.group(1); Document doc = FCKEditorTmpFiles.getDocument(uuid); String fileNodeName = Path.getUniqueLabel(hm, filesNode.getHandle(), "file"); SaveHandlerImpl.saveDocument(filesNode, doc, fileNodeName, "", ""); String subpath = StringUtils.removeStart(filesNode.getHandle(), this.getPath() + "/"); link = pageName + "/" + subpath + "/" + fileNodeName + "/" + doc.getFileNameWithExtension(); doc.delete(); try { FileUtils.deleteDirectory(new java.io.File(Path.getTempDirectory() + "/fckeditor/" + uuid)); } catch (IOException e) { log.error("can't delete tmp file [" + Path.getTempDirectory() + "/fckeditor/" + uuid + "]"); } } // make internal links relative else if (src.startsWith(MgnlContext.getContextPath())) { link = pageName + StringUtils.removeStart(src, MgnlContext.getContextPath() + this.getPath()); } // internal uuid links have a leading $ link = StringUtils.replace(link, "$", "\\$"); srcMatcher.appendReplacement(res, "$1" + link + "$5"); //$NON-NLS-1$ } srcMatcher.appendTail(res); valueStr = res.toString(); return valueStr; }
From source file:org.nuclos.client.wizard.steps.NuclosEntityAttributeCommonPropertiesStep.java
@Override public void prepare() { super.prepare(); cbMandatory.setEnabled(true);/* w w w . j a v a 2 s. co m*/ fillCalcFunctionBox(); if (!this.parentWizardModel.isStateModel()) { cbxAttributeGroup.setEnabled(false); } else { fillAttributeGroupBox(); } if (getModel().getAttribute().getDatatyp().getJavaType().equals("java.lang.Integer")) { final NumericFormatDocument nfd = new NumericFormatDocument(); nfd.addDocumentListener(new DefaultValueDocumentListener()); tfDefaultValue.setDocument(nfd); final NumericFormatDocument nfdMandatory = new NumericFormatDocument(); nfdMandatory.addDocumentListener(new MandatoryValueDocumentListener()); tfMandatory.setDocument(nfdMandatory); } else if (getModel().getAttribute().getDatatyp().getJavaType().equals("java.lang.Double")) { final DoubleFormatDocument dfd = new DoubleFormatDocument(); dfd.addDocumentListener(new DefaultValueDocumentListener()); tfDefaultValue.setDocument(dfd); final DoubleFormatDocument dfdMandatory = new DoubleFormatDocument(); dfdMandatory.addDocumentListener(new MandatoryValueDocumentListener()); tfMandatory.setDocument(dfdMandatory); } if (getModel().isEditMode()) { tfLabel.setText(getModel().getAttribute().getInternalName()); cbxCalcFunction.setSelectedItem(getModel().getAttribute().getCalcFunction()); cbxAttributeGroup.setSelectedItem(getModel().getAttribute().getAttributeGroup()); cbDistinct.setSelected(getModel().getAttribute().isDistinct()); ItemListener ilArray[] = cbMandatory.getItemListeners(); for (ItemListener il : ilArray) { cbMandatory.removeItemListener(il); } cbMandatory.setSelected(getModel().getAttribute().isMandatory()); for (ItemListener il : ilArray) { cbMandatory.addItemListener(il); } cbLogBook.setSelected(getModel().getAttribute().isLogBook()); cbIndexed.setSelected(getModel().getAttribute().isIndexed()); if (getModel().getAttribute().getDatatyp().getJavaType().equals("java.util.Date")) { String str = getModel().getAttribute().getDefaultValue(); if (RelativeDate.today().toString().equals(str)) { dateDefaultValue.setDate(new Date(System.currentTimeMillis())); dateDefaultValue.getJTextField().setText("Heute"); } else if ("Heute".equalsIgnoreCase(str)) { dateDefaultValue.setDate(new Date(System.currentTimeMillis())); dateDefaultValue.getJTextField().setText("Heute"); } else { SimpleDateFormat result = new SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY); result.setLenient(false); try { dateDefaultValue.setDate(result.parse(str)); } catch (Exception e) { // set no day LOG.warn("prepare failed: " + e, e); } } } else if (getModel().getAttribute().getDatatyp().getJavaType().equals("java.lang.Boolean")) { String value = getModel().getAttribute().getDefaultValue(); if (value != null && value.equalsIgnoreCase("ja")) { cbDefaultValue.setSelected(true); } else { cbDefaultValue.setSelected(false); } } else { tfDefaultValue.setText(getModel().getAttribute().getDefaultValue()); } if (getModel().getAttribute().getDbName() != null) { String sModifiedDBName = new String(getModel().getAttribute().getDbName()); tfDBFieldName.setText(sModifiedDBName.replaceFirst("^STRVALUE_", "").replaceFirst("^INTID_", "")); if (getModel().getAttribute().getMetaVO() != null && getModel().getAttribute().getField() != null) { tfDBFieldNameComplete.setText("STRVALUE_" + getModel().getAttribute().getDbName()); } else if (getModel().getAttribute().getMetaVO() != null && getModel().getAttribute().getField() == null) { tfDBFieldNameComplete.setText("INTID_" + getModel().getAttribute().getDbName()); } } } else { if (!blnLabelModified) tfLabel.setText(getModel().getName().toLowerCase()); if (getModel().getAttributeCount() == 0 && !blnDefaultSelected) { cbDistinct.setSelected(true); cbMandatory.setSelected(true); blnDefaultSelected = true; } cbDistinct.setEnabled(!this.parentWizardModel.hasRows()); cbIndexed.setSelected(getModel().isRefernzTyp()); if (cbxAttributeGroup.getModel().getSize() > 1) { if (this.parentWizardModel.isStateModel()) cbxAttributeGroup.setSelectedIndex(1); } if (getModel().getAttribute().getDbName() != null) { String sModifiedDBName = new String(getModel().getAttribute().getDbName()); tfDBFieldName.setText(sModifiedDBName.replaceFirst("^STRVALUE_", "").replaceFirst("^INTID_", "")); if (getModel().getAttribute().getMetaVO() != null && getModel().getAttribute().getField() != null) { tfDBFieldNameComplete.setText("STRVALUE_" + getModel().getAttribute().getDbName()); } else if (getModel().getAttribute().getMetaVO() != null && getModel().getAttribute().getField() == null) { tfDBFieldNameComplete.setText("INTID_" + getModel().getAttribute().getDbName()); } } } Object objMandatoryValue = getModel().getAttribute().getMandatoryValue(); if (getModel().isRefernzTyp() || getModel().isLookupTyp()) { ItemListener listener[] = cbxDefaultValue.getItemListeners(); for (ItemListener il : listener) { cbxDefaultValue.removeItemListener(il); } ItemListener listenerMandatory[] = cbxDefaultValue.getItemListeners(); for (ItemListener il : listenerMandatory) { cbxMandatory.removeItemListener(il); } boolean isValueList = getModel().getAttribute().isValueListProvider(); cbxDefaultValue.setVisible(!isValueList); lovDefaultValue.setVisible(isValueList); tfDefaultValue.setVisible(false); dateDefaultValue.setVisible(false); cbDefaultValue.setVisible(false); cbxMandatory.setVisible(!isValueList && this.parentWizardModel.isEditMode()); lovMandatory.setVisible(isValueList && this.parentWizardModel.isEditMode()); tfMandatory.setVisible(false); dateMandatory.setVisible(false); cbMandatoryValue.setVisible(false); List<DefaultValue> defaultModel = new ArrayList<DefaultValue>(); List<DefaultValue> mandatoryModel = new ArrayList<DefaultValue>(); DefaultValue mandatoryValue = null; final String sEntity = !getModel().isLookupTyp() ? getModel().getAttribute().getMetaVO().getEntity() : getModel().getAttribute().getLookupMetaVO().getEntity(); if (!isValueList) { Collection<MasterDataVO> colVO = MasterDataDelegate.getInstance().getMasterData(sEntity); for (MasterDataVO vo : colVO) { String sField = getModel().getAttribute().getField(); if (sField == null) break; Pattern referencedEntityPattern = Pattern.compile("[$][{][\\w\\[\\]]+[}]"); Matcher referencedEntityMatcher = referencedEntityPattern.matcher(sField); StringBuffer sb = new StringBuffer(); while (referencedEntityMatcher.find()) { Object value = referencedEntityMatcher.group().substring(2, referencedEntityMatcher.group().length() - 1); String sName = value.toString(); Object fieldValue = vo.getField(sName); if (fieldValue != null) referencedEntityMatcher.appendReplacement(sb, fieldValue.toString()); else referencedEntityMatcher.appendReplacement(sb, ""); } // complete the transfer to the StringBuffer referencedEntityMatcher.appendTail(sb); sField = sb.toString(); DefaultValue dv = new DefaultValue(vo.getIntId(), sField); defaultModel.add(dv); mandatoryModel.add(dv); if (dv.getId().equals(objMandatoryValue)) { mandatoryValue = dv; } } Collections.sort(defaultModel); Collections.sort(mandatoryModel); defaultModel.add(0, new DefaultValue(null, null)); mandatoryModel.add(0, new DefaultValue(null, null)); cbxDefaultValue.setModel(new ListComboBoxModel<DefaultValue>(defaultModel)); cbxDefaultValue.setSelectedItem(getModel().getAttribute().getIdDefaultValue()); cbxMandatory.setModel(new ListComboBoxModel<DefaultValue>(mandatoryModel)); if (mandatoryValue != null) { cbxMandatory.setSelectedItem(mandatoryValue); } for (ItemListener il : listener) { cbxDefaultValue.addItemListener(il); } for (ItemListener il : listenerMandatory) { cbxMandatory.addItemListener(il); } } else { final EntityFieldMetaDataVO efMetaDataVO = new EntityFieldMetaDataVO(); efMetaDataVO.setField(sEntity); efMetaDataVO.setDataType(String.class.getName()); efMetaDataVO.setForeignEntity(sEntity); efMetaDataVO.setForeignEntityField(getModel().getAttribute().getField()); lovDefaultValue.setModel(getModel()); lovDefaultValue.setEfMetaDataVO(efMetaDataVO); lovDefaultValue.setSelectedListener(new ListOfValues.SelectedListener() { @Override public void actionPerformed(CollectableValueIdField itemSelected) { if (itemSelected == null) { getModel().getAttribute().setIdDefaultValue(new DefaultValue(null, null)); } else { getModel().getAttribute().setIdDefaultValue( new DefaultValue(IdUtils.unsafeToId(itemSelected.getValueId()), (String) itemSelected.getValue())); } } }); lovMandatory.setModel(getModel()); lovMandatory.setEfMetaDataVO(efMetaDataVO); lovMandatory.setSelectedListener(new ListOfValues.SelectedListener() { @Override public void actionPerformed(CollectableValueIdField itemSelected) { if (itemSelected == null) { getModel().getAttribute().setMandatoryValue(new DefaultValue(null, null).getId()); } else { getModel().getAttribute().setMandatoryValue( new DefaultValue(IdUtils.unsafeToId(itemSelected.getValueId()), (String) itemSelected.getValue()).getId()); } } }); } } else if (getModel().getAttribute().getDatatyp().getJavaType().equals("java.util.Date")) { dateDefaultValue.setVisible(true); cbxDefaultValue.setVisible(false); lovDefaultValue.setVisible(false); tfDefaultValue.setVisible(false); cbDefaultValue.setVisible(false); cbxMandatory.setVisible(false); lovMandatory.setVisible(false); tfMandatory.setVisible(false); dateMandatory.setVisible(this.parentWizardModel.isEditMode()); if (objMandatoryValue != null && objMandatoryValue instanceof Date) { dateMandatory.setDate((Date) objMandatoryValue); } cbMandatoryValue.setVisible(false); } else if (getModel().getAttribute().getDatatyp().getJavaType().equals("java.lang.Boolean")) { cbxDefaultValue.setVisible(false); lovDefaultValue.setVisible(false); tfDefaultValue.setVisible(false); dateDefaultValue.setVisible(false); cbDefaultValue.setVisible(true); cbxMandatory.setVisible(false); lovMandatory.setVisible(false); tfMandatory.setVisible(false); dateMandatory.setVisible(false); cbMandatoryValue.setVisible(this.parentWizardModel.isEditMode()); if (objMandatoryValue != null && objMandatoryValue instanceof Boolean) { cbMandatoryValue.setSelected((Boolean) objMandatoryValue); } } else if (getModel().getAttribute().isValueList()) { ItemListener listener[] = cbxDefaultValue.getItemListeners(); for (ItemListener il : listener) { cbxDefaultValue.removeItemListener(il); } cbxCalcFunction.setEnabled(false); cbxDefaultValue.setVisible(true); lovDefaultValue.setVisible(false); tfDefaultValue.setVisible(false); dateDefaultValue.setVisible(false); cbDefaultValue.setVisible(false); cbxDefaultValue.removeAllItems(); cbxDefaultValue.addItem(new DefaultValue(null, null)); cbxMandatory.addItem(new DefaultValue(null, null)); for (ValueList valueList : getModel().getAttribute().getValueList()) { cbxDefaultValue.addItem(new DefaultValue( valueList.getId() != null ? valueList.getId().intValue() : null, valueList.getLabel())); } cbxDefaultValue.setSelectedItem(getModel().getAttribute().getDefaultValue()); for (ItemListener il : listener) { cbxDefaultValue.addItemListener(il); } listener = cbxMandatory.getItemListeners(); for (ItemListener il : listener) { cbxMandatory.removeItemListener(il); } for (ValueList valueList : getModel().getAttribute().getValueList()) { DefaultValue dv = new DefaultValue(valueList.getId() != null ? valueList.getId().intValue() : null, valueList.getLabel()); cbxMandatory.addItem(dv); if (dv.getId() != null && dv.getId().equals(objMandatoryValue)) { cbxMandatory.setSelectedItem(dv); } } for (ItemListener il : listener) { cbxMandatory.addItemListener(il); } cbMandatory.setEnabled(getModel().getAttribute().getId() != null); cbxMandatory.setVisible(true); lovMandatory.setVisible(parentWizardModel.isEditMode() && getModel().getAttribute().getId() != null); tfMandatory.setVisible(false); dateMandatory.setVisible(false); cbMandatoryValue.setVisible(false); } else if (getModel().getAttribute().isImage() || getModel().getAttribute().isPasswordField() || getModel().getAttribute().isFileType()) { cbMandatory.setEnabled(false); cbxMandatory.setVisible(false); lovMandatory.setVisible(false); tfMandatory.setVisible(false); dateMandatory.setVisible(false); cbMandatoryValue.setVisible(false); } else { cbxDefaultValue.setVisible(false); lovDefaultValue.setVisible(false); tfDefaultValue.setVisible(true); dateDefaultValue.setVisible(false); cbDefaultValue.setVisible(false); cbxMandatory.setVisible(false); lovMandatory.setVisible(false); tfMandatory.setVisible(this.parentWizardModel.isEditMode()); if (objMandatoryValue != null) { tfMandatory.setText(objMandatoryValue.toString()); } dateMandatory.setVisible(false); cbMandatoryValue.setVisible(false); } Attribute attr = NuclosEntityAttributeCommonPropertiesStep.this.getModel().getAttribute(); if (NuclosEntityAttributeCommonPropertiesStep.this.parentWizardModel.hasRows() && attr.getId() != null) { boolean blnAllowed = StringUtils.isEmpty(attr.getInternalName()) ? false : MetaDataDelegate.getInstance().isChangeDatabaseColumnToUniqueAllowed( NuclosEntityAttributeCommonPropertiesStep.this.parentWizardModel.getEntityName(), attr.getInternalName()); if (!blnAllowed && !attr.isDistinct()) { cbDistinct.setSelected(false); cbDistinct.setEnabled(false); cbDistinct.setToolTipText(SpringLocaleDelegate.getInstance().getMessage( "wizard.step.entitysqllayout.6", "Das Feld {0} kann nicht auf ein eindeutiges Feld umgestellt werden.", attr.getLabel())); } } if (parentWizardModel.isVirtual()) { cbDistinct.setSelected(false); cbDistinct.setEnabled(false); tfMandatory.setEnabled(false); dateMandatory.setEnabled(false); cbMandatory.setEnabled(false); cbxMandatory.setEnabled(false); cbMandatoryValue.setEnabled(false); cbxCalcFunction.setEnabled(false); tfDBFieldName.setEnabled(false); cbIndexed.setEnabled(false); tfDefaultValue.setEnabled(false); dateDefaultValue.setEnabled(false); cbxDefaultValue.setEnabled(false); cbDefaultValue.setEnabled(false); cbLogBook.setEnabled(false); } }
From source file:org.etudes.util.XrefHelper.java
/** * Replace any full URL references that include the server DNS, port, etc, with a root-relative one (i.e. starting with "/access" or "/library" or whatever) * /*w ww . java 2 s . c om*/ * @param data * the html data. * @return The shortened data. */ public static String shortenFullUrls(String data) { if (data == null) return data; Pattern p = getPattern(); Matcher m = p.matcher(data); StringBuffer sb = new StringBuffer(); // for the relative access check: matches ..\..\access\ etc with any number of leading "../" Pattern relAccessPattern = Pattern.compile("^(../)+(access/.*)"); // to fix our messed up URLs with this pattern: // /access/content/private/meleteDocs/3349d4ca-38f3-4744-00c6-26715545e441/module_339214362/../../../../access/meleteDocs/content/private/meleteDocs/3349d4ca-38f3-4744-00c6-26715545e441/uploads/applelogohistory.jpg Pattern messUpFixPattern = Pattern.compile("^/access/content/.*(../)+(access/.*)"); // process each "harvested" string (avoiding like strings that are not in src= or href= patterns) while (m.find()) { if (m.groupCount() == 3) { String ref = m.group(2); String terminator = m.group(3); String origRef = ref; // if this is an access to our own server, shorten it to root relative (i.e. starting with "/access") int pos = internallyHostedUrl(ref); if (pos != -1) { ref = ref.substring(pos); m.appendReplacement(sb, Matcher.quoteReplacement(m.group(1) + "=\"" + ref + terminator)); } // if this is a relative access URL, fix it else { Matcher relAccessMatcher = relAccessPattern.matcher(ref); if (relAccessMatcher.matches()) { ref = "/" + relAccessMatcher.group(2); m.appendReplacement(sb, Matcher.quoteReplacement(m.group(1) + "=\"" + ref + terminator)); } // fix a botched attempt a xref fixing that got tripped up with ../../../../access relative references else { Matcher messUpFixer = messUpFixPattern.matcher(ref); if (messUpFixer.matches()) { ref = "/" + messUpFixer.group(2); m.appendReplacement(sb, Matcher.quoteReplacement(m.group(1) + "=\"" + ref + terminator)); M_log.warn("shortenFullUrls: fixing ref: " + origRef + " : to : " + ref); } } } } } m.appendTail(sb); return sb.toString(); }
From source file:org.forgerock.openidm.repo.orientdb.impl.query.TokenHandler.java
/** * Replaces a query string with tokens of format ${token-name} with the values from the * passed in map, where the token-name must be the key in the map * /*from w ww . j av a2 s . c o m*/ * @param queryString the query with tokens * @param params the parameters to replace the tokens. Values can be String or List. * @return the query with all tokens replace with their found values * @throws BadRequestException if token in the query is not in the passed parameters */ String replaceTokensWithValues(String queryString, Map<String, String> params) throws BadRequestException { java.util.regex.Matcher matcher = tokenPattern.matcher(queryString); StringBuffer buffer = new StringBuffer(); while (matcher.find()) { String fullTokenKey = matcher.group(1); String tokenKey = fullTokenKey; String tokenPrefix = null; String[] tokenKeyParts = tokenKey.split(":", 2); // if prefix found if (tokenKeyParts.length == 2) { tokenPrefix = tokenKeyParts[0]; tokenKey = tokenKeyParts[1]; } if (!params.containsKey(tokenKey)) { // fail with an exception if token not found throw new BadRequestException("Missing entry in params passed to query for token " + tokenKey); } else { Object replacement = params.get(tokenKey); if (PREFIX_LIST.equals(tokenPrefix)) { // escape quotes, quote each element, and split on , replacement = Arrays.asList( ("'" + replacement.toString().replaceAll("'", "\\\\'").replaceAll(",", "','") + "'") .split(",")); } if (replacement instanceof List) { StringBuffer commaSeparated = new StringBuffer(); boolean first = true; for (Object entry : ((List) replacement)) { if (!first) { commaSeparated.append(","); } else { first = false; } commaSeparated.append(entry.toString()); } replacement = commaSeparated.toString(); } if (replacement == null) { replacement = ""; } // Optional control of representation via prefix if (tokenPrefix != null) { if (tokenPrefix.equals(PREFIX_UNQUOTED)) { // Leave replacement unquoted } else if (tokenPrefix.equals(PREFIX_DOTNOTATION)) { // Convert Json Pointer to OrientDB dot notation replacement = JSON_POINTER_TO_DOT_NOTATION.apply(replacement.toString()); } } else { // Default is single quoted string replacement (escaping single quotes in replacement) replacement = "'" + replacement.toString().replaceAll("'", "\\\\'") + "'"; } matcher.appendReplacement(buffer, ""); buffer.append(replacement); } } matcher.appendTail(buffer); return buffer.toString(); }
From source file:com.ibm.jaggr.service.impl.AggregatorImpl.java
@Override public String substituteProps(String str, SubstitutionTransformer transformer) { if (str == null) { return null; }//from w w w. j a v a 2 s . c o m StringBuffer buf = new StringBuffer(); Matcher matcher = pattern.matcher(str); while (matcher.find()) { String propName = matcher.group(1); String propValue = null; if (getBundleContext() != null) { propValue = getBundleContext().getProperty(propName); } else { propValue = System.getProperty(propName); } if (propValue == null && variableResolverServiceTracker != null) { ServiceReference[] refs = variableResolverServiceTracker.getServiceReferences(); if (refs != null) { for (ServiceReference sr : refs) { IVariableResolver resolver = (IVariableResolver) getBundleContext().getService(sr); try { propValue = resolver.resolve(propName); if (propValue != null) { break; } } finally { getBundleContext().ungetService(sr); } } } } if (propValue != null) { if (transformer != null) { propValue = transformer.transform(propName, propValue); } matcher.appendReplacement(buf, propValue.replace("\\", "\\\\") //$NON-NLS-1$ //$NON-NLS-2$ .replace("$", "\\$") //$NON-NLS-1$ //$NON-NLS-2$ ); } else { matcher.appendReplacement(buf, "\\${" + propName + "}"); //$NON-NLS-1$ //$NON-NLS-2$ } } matcher.appendTail(buf); return buf.toString(); }
From source file:org.intermine.bio.dataconversion.FlyBaseProcessor.java
/** * Return a map from feature_id to seqlen * @throws SQLException if somethign goes wrong *//*from www .j a va 2s.co m*/ // private Map<Integer, Integer> makeCDNALengthMap(Connection connection) // throws SQLException { // Map<Integer, Integer> retMap = new HashMap(); // // ResultSet res = getCDNALengthResultSet(connection); // while (res.next()) { // Integer featureId = new Integer(res.getInt("feature_id")); // Integer seqlen = new Integer(res.getInt("seqlen")); // retMap.put(featureId, seqlen); // } // return retMap; // } private Item makePhenotypeAnnotation(String alleleItemIdentifier, String value, Item dataSetItem, List<String> publicationsItemIdList) throws ObjectStoreException { Item phenotypeAnnotation = getChadoDBConverter().createItem("PhenotypeAnnotation"); phenotypeAnnotation.addToCollection("dataSets", dataSetItem); Pattern p = Pattern.compile(FLYBASE_PROP_ATTRIBUTE_PATTERN); Matcher m = p.matcher(value); StringBuffer sb = new StringBuffer(); List<String> dbAnatomyTermIdentifiers = new ArrayList<String>(); List<String> dbDevelopmentTermIdentifiers = new ArrayList<String>(); List<String> dbCVTermIdentifiers = new ArrayList<String>(); while (m.find()) { String field = m.group(1); int colonPos = field.indexOf(':'); if (colonPos == -1) { m.appendReplacement(sb, field); } else { String identifier = field.substring(0, colonPos); if (identifier.startsWith(FLYBASE_ANATOMY_TERM_PREFIX)) { dbAnatomyTermIdentifiers.add(addCVTermColon(identifier)); } else { if (identifier.startsWith("FBdv")) { dbDevelopmentTermIdentifiers.add(addCVTermColon(identifier)); } else { if (identifier.startsWith("FBcv")) { dbCVTermIdentifiers.add(addCVTermColon(identifier)); } } } String text = field.substring(colonPos + 1); m.appendReplacement(sb, text); } } m.appendTail(sb); /* * ignore with for now because the with text is wrong in chado - see ticket #889 List<String> withAlleleIdentifiers = findWithAllele(value); if (withAlleleIdentifiers.size() > 0) { phenotypeAnnotation.setCollection("with", withAlleleIdentifiers); } */ String valueNoRefs = sb.toString(); String valueNoUps = valueNoRefs.replaceAll("<up>", "[").replaceAll("</up>", "]"); phenotypeAnnotation.setAttribute("description", valueNoUps); phenotypeAnnotation.setReference("allele", alleleItemIdentifier); if (publicationsItemIdList != null && publicationsItemIdList.size() > 0) { ReferenceList pubReferenceList = new ReferenceList("publications", publicationsItemIdList); phenotypeAnnotation.addCollection(pubReferenceList); } if (dbAnatomyTermIdentifiers.size() == 1) { String anatomyIdentifier = dbAnatomyTermIdentifiers.get(0); String anatomyTermItemId = makeAnatomyTerm(anatomyIdentifier); phenotypeAnnotation.setReference("anatomyTerm", anatomyTermItemId); } else { if (dbAnatomyTermIdentifiers.size() > 1) { throw new RuntimeException("more than one anatomy term: " + dbAnatomyTermIdentifiers); } } if (dbDevelopmentTermIdentifiers.size() == 1) { String developmentTermIdentifier = dbDevelopmentTermIdentifiers.get(0); String developmentTermItemId = makeDevelopmentTerm(developmentTermIdentifier); phenotypeAnnotation.setReference("developmentTerm", developmentTermItemId); } else { if (dbAnatomyTermIdentifiers.size() > 1) { throw new RuntimeException("more than one anatomy term: " + dbAnatomyTermIdentifiers); } } if (dbCVTermIdentifiers.size() > 0) { for (String cvTermIdentifier : dbCVTermIdentifiers) { String cvTermItemId = makeCVTerm(cvTermIdentifier); phenotypeAnnotation.addToCollection("cvTerms", cvTermItemId); } } return phenotypeAnnotation; }
From source file:de.mpg.mpdl.inge.transformation.transformations.commonPublicationFormats.Bibtex.java
/** * @param bibtex/*from ww w. j a va 2s . c om*/ * @return eSciDoc-publication item XML representation of this BibTeX entry * @throws RuntimeException */ public String getBibtex(String bibtex) throws RuntimeException { // Remove Math '$' from the whole BibTex-String Pattern mathPattern = Pattern.compile("(?sm)\\$(\\\\.*?)(?<!\\\\)\\$"); Matcher mathMatcher = mathPattern.matcher(bibtex); StringBuffer sb = new StringBuffer(); while (mathMatcher.find()) { mathMatcher.appendReplacement(sb, "$1"); } mathMatcher.appendTail(sb); bibtex = sb.toString(); BibtexParser parser = new BibtexParser(true); BibtexFile file = new BibtexFile(); try { parser.parse(file, new StringReader(bibtex)); } catch (Exception e) { this.logger.error("Error parsing BibTex record."); throw new RuntimeException(e); } PubItemVO itemVO = new PubItemVO(); MdsPublicationVO mds = new MdsPublicationVO(); itemVO.setMetadata(mds); List entries = file.getEntries(); boolean entryFound = false; if (entries == null || entries.size() == 0) { this.logger.warn("No entry found in BibTex record."); throw new RuntimeException(); } for (Object object : entries) { if (object instanceof BibtexEntry) { if (entryFound) { this.logger.error("Multiple entries in BibTex record."); throw new RuntimeException(); } entryFound = true; BibtexEntry entry = (BibtexEntry) object; // genre BibTexUtil.Genre bibGenre; try { bibGenre = BibTexUtil.Genre.valueOf(entry.getEntryType()); } catch (IllegalArgumentException iae) { bibGenre = BibTexUtil.Genre.misc; this.logger.warn("Unrecognized genre: " + entry.getEntryType()); } MdsPublicationVO.Genre itemGenre = BibTexUtil.getGenreMapping().get(bibGenre); mds.setGenre(itemGenre); SourceVO sourceVO = new SourceVO(); SourceVO secondSourceVO = new SourceVO(); Map fields = entry.getFields(); // Mapping of BibTeX Standard Entries // title if (fields.get("title") != null) { if (fields.get("chapter") != null) { mds.setTitle(BibTexUtil.stripBraces( BibTexUtil.bibtexDecode(fields.get("chapter").toString()), false) + " - " + BibTexUtil.stripBraces(BibTexUtil.bibtexDecode(fields.get("title").toString()), false)); } else { mds.setTitle(BibTexUtil.stripBraces(BibTexUtil.bibtexDecode(fields.get("title").toString()), false)); } } // booktitle if (fields.get("booktitle") != null) { if (bibGenre == BibTexUtil.Genre.book) { mds.setTitle(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("booktitle").toString()), false)); } else if (bibGenre == BibTexUtil.Genre.conference || bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.incollection || bibGenre == BibTexUtil.Genre.inproceedings) { sourceVO.setTitle(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("booktitle").toString()), false)); if (bibGenre == BibTexUtil.Genre.conference || bibGenre == BibTexUtil.Genre.inproceedings) { sourceVO.setGenre(Genre.PROCEEDINGS); } else if (bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.incollection) { sourceVO.setGenre(Genre.BOOK); } } } // fjournal, journal if (fields.get("fjournal") != null) { if (bibGenre == BibTexUtil.Genre.article || bibGenre == BibTexUtil.Genre.misc || bibGenre == BibTexUtil.Genre.unpublished) { sourceVO.setTitle(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("fjournal").toString()), false)); sourceVO.setGenre(SourceVO.Genre.JOURNAL); if (fields.get("journal") != null) { sourceVO.getAlternativeTitles().add(new AlternativeTitleVO(BibTexUtil.stripBraces( BibTexUtil.bibtexDecode(fields.get("journal").toString()), false))); } } } else if (fields.get("journal") != null) { if (bibGenre == BibTexUtil.Genre.article || bibGenre == BibTexUtil.Genre.misc || bibGenre == BibTexUtil.Genre.unpublished || bibGenre == BibTexUtil.Genre.inproceedings) { sourceVO.setTitle(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("journal").toString()), false)); sourceVO.setGenre(SourceVO.Genre.JOURNAL); } } // number if (fields.get("number") != null && bibGenre != BibTexUtil.Genre.techreport) { sourceVO.setIssue(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("number").toString()), false)); } else if (fields.get("number") != null && bibGenre == BibTexUtil.Genre.techreport) { { mds.getIdentifiers().add(new IdentifierVO(IdentifierVO.IdType.REPORT_NR, BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("number").toString()), false))); } } // pages if (fields.get("pages") != null) { if (bibGenre == BibTexUtil.Genre.book || bibGenre == BibTexUtil.Genre.proceedings) { mds.setTotalNumberOfPages(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("pages").toString()), false)); } else { BibTexUtil.fillSourcePages(BibTexUtil.stripBraces( BibTexUtil.bibtexDecode(fields.get("pages").toString()), false), sourceVO); if (bibGenre == BibTexUtil.Genre.inproceedings && (fields.get("booktitle") == null || fields.get("booktitle").toString() == "") && (fields.get("event_name") != null && fields.get("event_name").toString() != "")) { sourceVO.setTitle(BibTexUtil.stripBraces(fields.get("event_name").toString(), false)); sourceVO.setGenre(Genre.PROCEEDINGS); } } } // Publishing info PublishingInfoVO publishingInfoVO = new PublishingInfoVO(); mds.setPublishingInfo(publishingInfoVO); // address if (fields.get("address") != null) { if (!(bibGenre == BibTexUtil.Genre.article || bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.inproceedings || bibGenre == BibTexUtil.Genre.conference || bibGenre == BibTexUtil.Genre.incollection) && (sourceVO.getTitle() == null || sourceVO.getTitle() == null)) { publishingInfoVO.setPlace(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("address").toString()), false)); } else { if (sourceVO.getPublishingInfo() == null) { PublishingInfoVO sourcePublishingInfoVO = new PublishingInfoVO(); sourceVO.setPublishingInfo(sourcePublishingInfoVO); } sourceVO.getPublishingInfo().setPlace(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("address").toString()), false)); } } // edition if (fields.get("edition") != null) { publishingInfoVO.setEdition(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("edition").toString()), false)); } // publisher if (!(bibGenre == BibTexUtil.Genre.article || bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.inproceedings || bibGenre == BibTexUtil.Genre.conference || bibGenre == BibTexUtil.Genre.incollection) && (sourceVO.getTitle() == null || sourceVO.getTitle() == null)) { if (fields.get("publisher") != null) { publishingInfoVO.setPublisher(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("publisher").toString()), false)); } else if (fields.get("school") != null && (bibGenre == BibTexUtil.Genre.mastersthesis || bibGenre == BibTexUtil.Genre.phdthesis || bibGenre == BibTexUtil.Genre.techreport)) { publishingInfoVO.setPublisher(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("school").toString()), false)); } else if (fields.get("institution") != null) { publishingInfoVO.setPublisher(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("institution").toString()), false)); } else if (fields.get("publisher") == null && fields.get("school") == null && fields.get("institution") == null && fields.get("address") != null) { publishingInfoVO.setPublisher("ANY PUBLISHER"); } } else { if (sourceVO.getPublishingInfo() == null) { PublishingInfoVO sourcePublishingInfoVO = new PublishingInfoVO(); sourceVO.setPublishingInfo(sourcePublishingInfoVO); } if (fields.get("publisher") != null) { sourceVO.getPublishingInfo().setPublisher(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("publisher").toString()), false)); } else if (fields.get("school") != null && (bibGenre == BibTexUtil.Genre.mastersthesis || bibGenre == BibTexUtil.Genre.phdthesis || bibGenre == BibTexUtil.Genre.techreport)) { sourceVO.getPublishingInfo().setPublisher(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("school").toString()), false)); } else if (fields.get("institution") != null) { sourceVO.getPublishingInfo().setPublisher(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("institution").toString()), false)); } else if (fields.get("publisher") == null && fields.get("school") == null && fields.get("institution") == null && fields.get("address") != null) { sourceVO.getPublishingInfo().setPublisher("ANY PUBLISHER"); } } // series if (fields.get("series") != null) { if (bibGenre == BibTexUtil.Genre.book || bibGenre == BibTexUtil.Genre.misc || bibGenre == BibTexUtil.Genre.techreport) { sourceVO.setTitle(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("series").toString()), false)); sourceVO.setGenre(SourceVO.Genre.SERIES); } else if (bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.incollection || bibGenre == BibTexUtil.Genre.inproceedings || bibGenre == BibTexUtil.Genre.conference) { secondSourceVO.setTitle(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("series").toString()), false)); secondSourceVO.setGenre(SourceVO.Genre.SERIES); } } // type --> degree if (fields.get("type") != null && bibGenre == BibTexUtil.Genre.mastersthesis) { if (fields.get("type").toString().toLowerCase().contains("master") || fields.get("type").toString().toLowerCase().contains("m.a.") || fields.get("type").toString().toLowerCase().contains("m.s.") || fields.get("type").toString().toLowerCase().contains("m.sc.")) { mds.setDegree(MdsPublicationVO.DegreeType.MASTER); } else if (fields.get("type").toString().toLowerCase().contains("bachelor")) { mds.setDegree(MdsPublicationVO.DegreeType.BACHELOR); } else if (fields.get("type").toString().toLowerCase().contains("magister")) { mds.setDegree(MdsPublicationVO.DegreeType.MAGISTER); } else if (fields.get("type").toString().toLowerCase().contains("diplom")) // covers also // the english // version // (diploma) { mds.setDegree(MdsPublicationVO.DegreeType.DIPLOMA); } else if (fields.get("type").toString().toLowerCase().contains("statsexamen") || fields.get("type").toString().toLowerCase().contains("state examination")) { mds.setDegree(MdsPublicationVO.DegreeType.DIPLOMA); } } else if (fields.get("type") != null && bibGenre == BibTexUtil.Genre.phdthesis) { if (fields.get("type").toString().toLowerCase().contains("phd") || fields.get("type").toString().toLowerCase().contains("dissertation") || fields.get("type").toString().toLowerCase().contains("doktor") || fields.get("type").toString().toLowerCase().contains("doctor")) { mds.setDegree(MdsPublicationVO.DegreeType.PHD); } else if (fields.get("type").toString().toLowerCase().contains("habilitation")) { mds.setDegree(MdsPublicationVO.DegreeType.HABILITATION); } } // volume if (fields.get("volume") != null) { if (bibGenre == BibTexUtil.Genre.article || bibGenre == BibTexUtil.Genre.book) { sourceVO.setVolume(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("volume").toString()), false)); } else if (bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.inproceedings || bibGenre == BibTexUtil.Genre.incollection || bibGenre == BibTexUtil.Genre.conference) { if (sourceVO.getSources() != null && !sourceVO.getSources().isEmpty()) { sourceVO.getSources().get(0).setVolume(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("volume").toString()), false)); } else { sourceVO.setVolume(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("volume").toString()), false)); } } } // event infos if (bibGenre != null && (bibGenre.equals(BibTexUtil.Genre.inproceedings) || bibGenre.equals(BibTexUtil.Genre.proceedings) || bibGenre.equals(BibTexUtil.Genre.conference) || bibGenre.equals(BibTexUtil.Genre.poster) || bibGenre.equals(BibTexUtil.Genre.talk))) { EventVO event = new EventVO(); boolean eventNotEmpty = false; // event location if (fields.get("location") != null) { event.setPlace(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("location").toString()), false)); eventNotEmpty = true; } // event place else if (fields.get("event_place") != null) { event.setPlace(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("event_place").toString()), false)); eventNotEmpty = true; } // event name/title if (fields.get("event_name") != null) { event.setTitle(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("event_name").toString()), false)); eventNotEmpty = true; } // event will be set only it's not empty if (eventNotEmpty == true) { if (event.getTitle() == null) { event.setTitle(""); } mds.setEvent(event); } } // year, month String dateString = null; if (fields.get("year") != null) { dateString = BibTexUtil.stripBraces(BibTexUtil.bibtexDecode(fields.get("year").toString()), false); if (fields.get("month") != null) { String month = BibTexUtil.parseMonth(fields.get("month").toString()); dateString += "-" + month; } if (bibGenre == BibTexUtil.Genre.unpublished) { mds.setDateCreated(dateString); } else { mds.setDatePublishedInPrint(dateString); } } String affiliation = null; String affiliationAddress = null; // affiliation if (fields.get("affiliation") != null) { affiliation = BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("affiliation").toString()), false); } // affiliationaddress if (fields.get("affiliationaddress") != null) { affiliationAddress = BibTexUtil.stripBraces( BibTexUtil.bibtexDecode(fields.get("affiliationaddress").toString()), false); } // author boolean noConeAuthorFound = true; if (fields.get("author") != null) { if (fields.get("author") instanceof BibtexPersonList) { BibtexPersonList authors = (BibtexPersonList) fields.get("author"); for (Object author : authors.getList()) { if (author instanceof BibtexPerson) { addCreator(mds, (BibtexPerson) author, CreatorVO.CreatorRole.AUTHOR, affiliation, affiliationAddress); } else { this.logger.warn("Entry in BibtexPersonList not a BibtexPerson: [" + author + "] in [" + author + "]"); } } } else if (fields.get("author") instanceof BibtexPerson) { BibtexPerson author = (BibtexPerson) fields.get("author"); addCreator(mds, (BibtexPerson) author, CreatorVO.CreatorRole.AUTHOR, affiliation, affiliationAddress); } else if (fields.get("author") instanceof BibtexString) { AuthorDecoder decoder; try { String authorString = BibTexUtil.bibtexDecode(fields.get("author").toString(), false); List<CreatorVO> teams = new ArrayList<CreatorVO>(); if (authorString.contains("Team")) { // set pattern for finding Teams (leaded or followed by [and|,|;|{|}|^|$]) Pattern pattern = Pattern.compile( "(?<=(and|,|;|\\{|^))([\\w|\\s]*?Team[\\w|\\s]*?)(?=(and|,|;|\\}|$))", Pattern.DOTALL); Matcher matcher = pattern.matcher(authorString); String matchedGroup; while (matcher.find()) { matchedGroup = matcher.group(); // remove matchedGroup (and prefix/suffix) from authorString if (authorString.startsWith(matchedGroup)) { authorString = authorString.replaceAll(matchedGroup + "(and|,|;|\\})", ""); } else { authorString = authorString.replaceAll("(and|,|;|\\{)" + matchedGroup, ""); } // set matchedGroup as Organisation Author OrganizationVO team = new OrganizationVO(); team.setName(matchedGroup.trim()); CreatorVO creatorVO = new CreatorVO(team, CreatorVO.CreatorRole.AUTHOR); teams.add(creatorVO); } } decoder = new AuthorDecoder(authorString, false); if (decoder.getBestFormat() != null) { List<Author> authors = decoder.getAuthorListList().get(0); for (Author author : authors) { PersonVO personVO = new PersonVO(); personVO.setFamilyName(author.getSurname()); if (author.getGivenName() != null) { personVO.setGivenName(author.getGivenName()); } else { personVO.setGivenName(author.getInitial()); } /* * Case for MPI-KYB (Biological Cybernetics) with CoNE identifier in brackets and * affiliations to adopt from CoNE for each author (also in brackets) */ if (configuration != null && "true".equals(configuration.get("CoNE")) && ("identifier and affiliation in brackets" .equals(configuration.get("CurlyBracketsForCoNEAuthors"))) && (author.getTags().get("identifier") != null)) { String query = author.getTags().get("identifier"); int affiliationsCount = Integer .parseInt(author.getTags().get("affiliationsCount")); if (affiliationsCount > 0 || configuration.get("OrganizationalUnit") != null) { for (int ouCount = 0; ouCount < (affiliationsCount > 0 ? affiliationsCount : 1); ouCount++) // 1 // is // for // the // case // configuration.get("OrganizationalUnit") // != // null { String organizationalUnit = (author.getTags().get( "affiliation" + new Integer(ouCount).toString()) != null ? author.getTags() .get("affiliation" + new Integer(ouCount).toString()) : (configuration.get("OrganizationalUnit") != null ? configuration.get("OrganizationalUnit") : "")); Node coneEntries = null; if (query.equals(author.getTags().get("identifier"))) { coneEntries = Util.queryConeExactWithIdentifier("persons", query, organizationalUnit); // for MPIKYB due to OUs which do not occur in CoNE if (coneEntries.getFirstChild().getFirstChild() == null) { logger.error("No Person with Identifier (" + author.getTags().get("identifier") + ") and OU (" + organizationalUnit + ") found in CoNE for Publication \"" + fields.get("title") + "\""); } } else { coneEntries = Util.queryConeExact("persons", query, organizationalUnit); } Node coneNode = coneEntries.getFirstChild().getFirstChild(); if (coneNode != null) { Node currentNode = coneNode.getFirstChild(); boolean first = true; while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE && first) { first = false; noConeAuthorFound = false; Node coneEntry = currentNode; String coneId = coneEntry.getAttributes() .getNamedItem("rdf:about").getNodeValue(); personVO.setIdentifier( new IdentifierVO(IdType.CONE, coneId)); for (int i = 0; i < coneEntry.getChildNodes() .getLength(); i++) { Node posNode = coneEntry.getChildNodes().item(i); if ("escidoc:position" .equals(posNode.getNodeName())) { String from = null; String until = null; String name = null; String id = null; Node node = posNode.getFirstChild() .getFirstChild(); while (node != null) { if ("eprints:affiliatedInstitution" .equals(node.getNodeName())) { name = node.getFirstChild() .getNodeValue(); } else if ("escidoc:start-date" .equals(node.getNodeName())) { from = node.getFirstChild() .getNodeValue(); } else if ("escidoc:end-date" .equals(node.getNodeName())) { until = node.getFirstChild() .getNodeValue(); } else if ("dc:identifier" .equals(node.getNodeName())) { id = node.getFirstChild() .getNodeValue(); } node = node.getNextSibling(); } if (smaller(from, dateString) && smaller(dateString, until)) { OrganizationVO org = new OrganizationVO(); org.setName(name); org.setIdentifier(id); personVO.getOrganizations().add(org); } } } } else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { throw new RuntimeException( "Ambigous CoNE entries for " + query); } currentNode = currentNode.getNextSibling(); } } else { throw new RuntimeException("Missing CoNE entry for " + query); } } } } /* * Case for MPI-Microstructure Physics with affiliation identifier in brackets and * affiliations to adopt from CoNE for each author (also in brackets) */ else if (configuration != null && "true".equals(configuration.get("CoNE")) && ("affiliation id in brackets" .equals(configuration.get("CurlyBracketsForCoNEAuthors"))) && (author.getTags().get("identifier") != null)) { String identifier = author.getTags().get("identifier"); String query = personVO.getFamilyName() + ", " + personVO.getGivenName(); if (!("extern".equals(identifier))) { Node coneEntries = null; coneEntries = Util.queryConeExact("persons", query, (configuration.get("OrganizationalUnit") != null ? configuration.get("OrganizationalUnit") : "")); Node coneNode = coneEntries.getFirstChild().getFirstChild(); if (coneNode != null) { Node currentNode = coneNode.getFirstChild(); boolean first = true; while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE && first) { first = false; noConeAuthorFound = false; Node coneEntry = currentNode; String coneId = coneEntry.getAttributes() .getNamedItem("rdf:about").getNodeValue(); personVO.setIdentifier( new IdentifierVO(IdType.CONE, coneId)); if (identifier != null && !("".equals(identifier))) { try { String ouSubTitle = identifier.substring(0, identifier.indexOf(",")); Document document = Util.queryFramework( "/oum/organizational-units?query=" + URLEncoder.encode("\"/title\"=\"" + ouSubTitle + "\"", "UTF-8")); NodeList ouList = document.getElementsByTagNameNS( "http://www.escidoc.de/schemas/organizationalunit/0.8", "organizational-unit"); Element ou = (Element) ouList.item(0); String href = ou.getAttribute("xlink:href"); String ouId = href .substring(href.lastIndexOf("/") + 1); OrganizationVO org = new OrganizationVO(); org.setName(identifier); org.setIdentifier(ouId); personVO.getOrganizations().add(org); } catch (Exception e) { logger.error("Error getting OUs", e); throw new RuntimeException( "Error getting Organizational Unit for " + identifier); } } } else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { throw new RuntimeException( "Ambigous CoNE entries for " + query); } currentNode = currentNode.getNextSibling(); } } else { throw new RuntimeException("Missing CoNE entry for " + query); } } } else if (configuration != null && "true".equals(configuration.get("CoNE")) && ("empty brackets" .equals(configuration.get("CurlyBracketsForCoNEAuthors")) && (author.getTags().get("brackets") != null))) { String query = personVO.getFamilyName() + ", " + personVO.getGivenName(); Node coneEntries = Util.queryConeExact("persons", query, (configuration.get("OrganizationalUnit") != null ? configuration.get("OrganizationalUnit") : "")); Node coneNode = coneEntries.getFirstChild().getFirstChild(); if (coneNode != null) { Node currentNode = coneNode.getFirstChild(); boolean first = true; while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE && first) { first = false; noConeAuthorFound = false; Node coneEntry = currentNode; String coneId = coneEntry.getAttributes() .getNamedItem("rdf:about").getNodeValue(); personVO.setIdentifier(new IdentifierVO(IdType.CONE, coneId)); for (int i = 0; i < coneEntry.getChildNodes() .getLength(); i++) { Node posNode = coneEntry.getChildNodes().item(i); if ("escidoc:position".equals(posNode.getNodeName())) { String from = null; String until = null; String name = null; String id = null; Node node = posNode.getFirstChild().getFirstChild(); while (node != null) { if ("eprints:affiliatedInstitution" .equals(node.getNodeName())) { name = node.getFirstChild().getNodeValue(); } else if ("escidoc:start-date" .equals(node.getNodeName())) { from = node.getFirstChild().getNodeValue(); } else if ("escidoc:end-date" .equals(node.getNodeName())) { until = node.getFirstChild().getNodeValue(); } else if ("dc:identifier" .equals(node.getNodeName())) { id = node.getFirstChild().getNodeValue(); } node = node.getNextSibling(); } if (smaller(from, dateString) && smaller(dateString, until)) { OrganizationVO org = new OrganizationVO(); org.setName(name); org.setIdentifier(id); personVO.getOrganizations().add(org); } } } } else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { throw new RuntimeException( "Ambigous CoNE entries for " + query); } currentNode = currentNode.getNextSibling(); } } else { throw new RuntimeException("Missing CoNE entry for " + query); } } else if (configuration != null && "true".equals(configuration.get("CoNE")) && ("no".equals(configuration.get("CurlyBracketsForCoNEAuthors")))) { String query = personVO.getFamilyName() + ", " + personVO.getGivenName(); Node coneEntries = Util.queryConeExact("persons", query, (configuration.get("OrganizationalUnit") != null ? configuration.get("OrganizationalUnit") : "")); Node coneNode = coneEntries.getFirstChild().getFirstChild(); if (coneNode != null) { Node currentNode = coneNode.getFirstChild(); boolean first = true; while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE && first) { first = false; noConeAuthorFound = false; Node coneEntry = currentNode; String coneId = coneEntry.getAttributes() .getNamedItem("rdf:about").getNodeValue(); personVO.setIdentifier(new IdentifierVO(IdType.CONE, coneId)); for (int i = 0; i < coneEntry.getChildNodes() .getLength(); i++) { Node posNode = coneEntry.getChildNodes().item(i); if ("escidoc:position".equals(posNode.getNodeName())) { String from = null; String until = null; String name = null; String id = null; Node node = posNode.getFirstChild().getFirstChild(); while (node != null) { if ("eprints:affiliatedInstitution" .equals(node.getNodeName())) { name = node.getFirstChild().getNodeValue(); } else if ("escidoc:start-date" .equals(node.getNodeName())) { from = node.getFirstChild().getNodeValue(); } else if ("escidoc:end-date" .equals(node.getNodeName())) { until = node.getFirstChild().getNodeValue(); } else if ("dc:identifier" .equals(node.getNodeName())) { id = node.getFirstChild().getNodeValue(); } node = node.getNextSibling(); } if (smaller(from, dateString) && smaller(dateString, until)) { OrganizationVO org = new OrganizationVO(); org.setName(name); org.setIdentifier(id); personVO.getOrganizations().add(org); } } } } else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { throw new RuntimeException( "Ambigous CoNE entries for " + query); } currentNode = currentNode.getNextSibling(); } } } if (affiliation != null) { OrganizationVO organization = new OrganizationVO(); organization.setIdentifier(PropertyReader .getProperty("escidoc.pubman.external.organisation.id")); organization.setName(affiliation); organization.setAddress(affiliationAddress); personVO.getOrganizations().add(organization); } CreatorVO creatorVO = new CreatorVO(personVO, CreatorVO.CreatorRole.AUTHOR); mds.getCreators().add(creatorVO); } } if (!teams.isEmpty()) { mds.getCreators().addAll(teams); } } catch (Exception e) { this.logger.error("An error occured while getting field 'author'.", e); throw new RuntimeException(e); } } } // editor boolean noConeEditorFound = false; if (fields.get("editor") != null) { this.logger.debug("fields.get(\"editor\"): " + fields.get("editor").getClass()); if (fields.get("editor") instanceof BibtexPersonList) { BibtexPersonList editors = (BibtexPersonList) fields.get("editor"); for (Object editor : editors.getList()) { if (editor instanceof BibtexPerson) { addCreator(mds, (BibtexPerson) editor, CreatorVO.CreatorRole.EDITOR, affiliation, affiliationAddress); } else { this.logger.warn("Entry in BibtexPersonList not a BibtexPerson: [" + editor + "] in [" + editors + "]"); } } } else if (fields.get("editor") instanceof BibtexPerson) { BibtexPerson editor = (BibtexPerson) fields.get("editor"); addCreator(mds, (BibtexPerson) editor, CreatorVO.CreatorRole.EDITOR, affiliation, affiliationAddress); } else if (fields.get("editor") instanceof BibtexString) { AuthorDecoder decoder; try { String editorString = BibTexUtil.bibtexDecode(fields.get("editor").toString(), false); List<CreatorVO> teams = new ArrayList<CreatorVO>(); if (editorString.contains("Team")) { // set pattern for finding Teams (leaded or followed by [and|,|;|{|}|^|$]) Pattern pattern = Pattern.compile( "(?<=(and|,|;|\\{|^))([\\w|\\s]*?Team[\\w|\\s]*?)(?=(and|,|;|\\}|$))", Pattern.DOTALL); Matcher matcher = pattern.matcher(editorString); String matchedGroup; while (matcher.find()) { matchedGroup = matcher.group(); // remove matchedGroup (and prefix/suffix) from authorString if (editorString.startsWith(matchedGroup)) { editorString = editorString.replaceAll(matchedGroup + "(and|,|;|\\})", ""); } else { editorString = editorString.replaceAll("(and|,|;|\\{)" + matchedGroup, ""); } // set matchedGroup as Organisation Author OrganizationVO team = new OrganizationVO(); team.setName(matchedGroup.trim()); CreatorVO creatorVO = new CreatorVO(team, CreatorVO.CreatorRole.EDITOR); teams.add(creatorVO); } } decoder = new AuthorDecoder(editorString, false); if (decoder.getBestFormat() != null) { List<Author> editors = decoder.getAuthorListList().get(0); for (Author editor : editors) { PersonVO personVO = new PersonVO(); personVO.setFamilyName(editor.getSurname()); if (editor.getGivenName() != null) { personVO.setGivenName(editor.getGivenName()); } else { personVO.setGivenName(editor.getInitial()); } /* * Case for MPI-KYB (Biological Cybernetics) with CoNE identifier in brackets and * affiliations to adopt from CoNE for each author (also in brackets) */ if (configuration != null && "true".equals(configuration.get("CoNE")) && ("identifier and affiliation in brackets" .equals(configuration.get("CurlyBracketsForCoNEAuthors"))) && (editor.getTags().get("identifier") != null)) { String query = editor.getTags().get("identifier"); int affiliationsCount = Integer .parseInt(editor.getTags().get("affiliationsCount")); if (affiliationsCount > 0 || configuration.get("OrganizationalUnit") != null) { for (int ouCount = 0; ouCount < (affiliationsCount > 0 ? affiliationsCount : 1); ouCount++) // 1 // is // for // the // case // configuration.get("OrganizationalUnit") // != // null { String organizationalUnit = (editor.getTags().get( "affiliation" + new Integer(ouCount).toString()) != null ? editor.getTags() .get("affiliation" + new Integer(ouCount).toString()) : (configuration.get("OrganizationalUnit") != null ? configuration.get("OrganizationalUnit") : "")); Node coneEntries = null; if (query.equals(editor.getTags().get("identifier"))) { coneEntries = Util.queryConeExactWithIdentifier("persons", query, organizationalUnit); // for MPIKYB due to OUs which do not occur in CoNE if (coneEntries.getFirstChild().getFirstChild() == null) { logger.error("No Person with Identifier (" + editor.getTags().get("identifier") + ") and OU (" + organizationalUnit + ") found in CoNE for Publication \"" + fields.get("title") + "\""); } } else { coneEntries = Util.queryConeExact("persons", query, organizationalUnit); } Node coneNode = coneEntries.getFirstChild().getFirstChild(); if (coneNode != null) { Node currentNode = coneNode.getFirstChild(); boolean first = true; while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE && first) { first = false; noConeEditorFound = false; Node coneEntry = currentNode; String coneId = coneEntry.getAttributes() .getNamedItem("rdf:about").getNodeValue(); personVO.setIdentifier( new IdentifierVO(IdType.CONE, coneId)); for (int i = 0; i < coneEntry.getChildNodes() .getLength(); i++) { Node posNode = coneEntry.getChildNodes().item(i); if ("escidoc:position" .equals(posNode.getNodeName())) { String from = null; String until = null; String name = null; String id = null; Node node = posNode.getFirstChild() .getFirstChild(); while (node != null) { if ("eprints:affiliatedInstitution" .equals(node.getNodeName())) { name = node.getFirstChild() .getNodeValue(); } else if ("escidoc:start-date" .equals(node.getNodeName())) { from = node.getFirstChild() .getNodeValue(); } else if ("escidoc:end-date" .equals(node.getNodeName())) { until = node.getFirstChild() .getNodeValue(); } else if ("dc:identifier" .equals(node.getNodeName())) { id = node.getFirstChild() .getNodeValue(); } node = node.getNextSibling(); } if (smaller(from, dateString) && smaller(dateString, until)) { OrganizationVO org = new OrganizationVO(); org.setName(name); org.setIdentifier(id); personVO.getOrganizations().add(org); } } } } else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { throw new RuntimeException( "Ambigous CoNE entries for " + query); } currentNode = currentNode.getNextSibling(); } } else { throw new RuntimeException("Missing CoNE entry for " + query); } } } } /* * Case for MPI-Microstructure Physics with affiliation identifier in brackets and * affiliations to adopt from CoNE for each author (also in brackets) */ else if (configuration != null && "true".equals(configuration.get("CoNE")) && ("affiliation id in brackets" .equals(configuration.get("CurlyBracketsForCoNEAuthors"))) && (editor.getTags().get("identifier") != null)) { String identifier = editor.getTags().get("identifier"); String query = personVO.getFamilyName() + ", " + personVO.getGivenName(); if (!("extern".equals(identifier))) { Node coneEntries = null; coneEntries = Util.queryConeExact("persons", query, (configuration.get("OrganizationalUnit") != null ? configuration.get("OrganizationalUnit") : "")); Node coneNode = coneEntries.getFirstChild().getFirstChild(); if (coneNode != null) { Node currentNode = coneNode.getFirstChild(); boolean first = true; while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE && first) { first = false; noConeAuthorFound = false; Node coneEntry = currentNode; String coneId = coneEntry.getAttributes() .getNamedItem("rdf:about").getNodeValue(); personVO.setIdentifier( new IdentifierVO(IdType.CONE, coneId)); if (identifier != null && !("".equals(identifier))) { try { String ouSubTitle = identifier.substring(0, identifier.indexOf(",")); Document document = Util.queryFramework( "/oum/organizational-units?query=" + URLEncoder.encode("\"/title\"=\"" + ouSubTitle + "\"", "UTF-8")); NodeList ouList = document.getElementsByTagNameNS( "http://www.escidoc.de/schemas/organizationalunit/0.8", "organizational-unit"); Element ou = (Element) ouList.item(0); String href = ou.getAttribute("xlink:href"); String ouId = href .substring(href.lastIndexOf("/") + 1); OrganizationVO org = new OrganizationVO(); org.setName(identifier); org.setIdentifier(ouId); personVO.getOrganizations().add(org); } catch (Exception e) { logger.error("Error getting OUs", e); throw new RuntimeException( "Error getting Organizational Unit for " + identifier); } } } else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { throw new RuntimeException( "Ambigous CoNE entries for " + query); } currentNode = currentNode.getNextSibling(); } } else { throw new RuntimeException("Missing CoNE entry for " + query); } } } else if (configuration != null && "true".equals(configuration.get("CoNE")) && ("empty brackets" .equals(configuration.get("CurlyBracketsForCoNEAuthors")) && (editor.getTags().get("brackets") != null))) { String query = personVO.getFamilyName() + ", " + personVO.getGivenName(); Node coneEntries = Util.queryConeExact("persons", query, (configuration.get("OrganizationalUnit") != null ? configuration.get("OrganizationalUnit") : "")); Node coneNode = coneEntries.getFirstChild().getFirstChild(); if (coneNode != null) { Node currentNode = coneNode.getFirstChild(); boolean first = true; while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE && first) { first = false; noConeEditorFound = false; Node coneEntry = currentNode; String coneId = coneEntry.getAttributes() .getNamedItem("rdf:about").getNodeValue(); personVO.setIdentifier(new IdentifierVO(IdType.CONE, coneId)); for (int i = 0; i < coneEntry.getChildNodes() .getLength(); i++) { Node posNode = coneEntry.getChildNodes().item(i); if ("escidoc:position".equals(posNode.getNodeName())) { String from = null; String until = null; String name = null; String id = null; Node node = posNode.getFirstChild().getFirstChild(); while (node != null) { if ("eprints:affiliatedInstitution" .equals(node.getNodeName())) { name = node.getFirstChild().getNodeValue(); } else if ("escidoc:start-date" .equals(node.getNodeName())) { from = node.getFirstChild().getNodeValue(); } else if ("escidoc:end-date" .equals(node.getNodeName())) { until = node.getFirstChild().getNodeValue(); } else if ("dc:identifier" .equals(node.getNodeName())) { id = node.getFirstChild().getNodeValue(); } node = node.getNextSibling(); } if (smaller(from, dateString) && smaller(dateString, until)) { OrganizationVO org = new OrganizationVO(); org.setName(name); org.setIdentifier(id); personVO.getOrganizations().add(org); } } } } else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { throw new RuntimeException( "Ambigous CoNE entries for " + query); } currentNode = currentNode.getNextSibling(); } } else { throw new RuntimeException("Missing CoNE entry for " + query); } } else if (configuration != null && "true".equals(configuration.get("CoNE")) && ("no".equals(configuration.get("CurlyBracketsForCoNEAuthors")))) { String query = personVO.getFamilyName() + ", " + personVO.getGivenName(); Node coneEntries = Util.queryConeExact("persons", query, (configuration.get("OrganizationalUnit") != null ? configuration.get("OrganizationalUnit") : "")); Node coneNode = coneEntries.getFirstChild().getFirstChild(); if (coneNode != null) { Node currentNode = coneNode.getFirstChild(); boolean first = true; while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE && first) { first = false; noConeEditorFound = false; Node coneEntry = currentNode; String coneId = coneEntry.getAttributes() .getNamedItem("rdf:about").getNodeValue(); personVO.setIdentifier(new IdentifierVO(IdType.CONE, coneId)); for (int i = 0; i < coneEntry.getChildNodes() .getLength(); i++) { Node posNode = coneEntry.getChildNodes().item(i); if ("escidoc:position".equals(posNode.getNodeName())) { String from = null; String until = null; String name = null; String id = null; Node node = posNode.getFirstChild().getFirstChild(); while (node != null) { if ("eprints:affiliatedInstitution" .equals(node.getNodeName())) { name = node.getFirstChild().getNodeValue(); } else if ("escidoc:start-date" .equals(node.getNodeName())) { from = node.getFirstChild().getNodeValue(); } else if ("escidoc:end-date" .equals(node.getNodeName())) { until = node.getFirstChild().getNodeValue(); } else if ("dc:identifier" .equals(node.getNodeName())) { id = node.getFirstChild().getNodeValue(); } node = node.getNextSibling(); } if (smaller(from, dateString) && smaller(dateString, until)) { OrganizationVO org = new OrganizationVO(); org.setName(name); org.setIdentifier(id); personVO.getOrganizations().add(org); } } } } else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { throw new RuntimeException( "Ambigous CoNE entries for " + query); } currentNode = currentNode.getNextSibling(); } } } if (affiliation != null) { OrganizationVO organization = new OrganizationVO(); organization.setIdentifier(PropertyReader .getProperty("escidoc.pubman.external.organisation.id")); organization.setName(affiliation); organization.setAddress(affiliationAddress); personVO.getOrganizations().add(organization); } CreatorVO creatorVO = new CreatorVO(personVO, CreatorVO.CreatorRole.EDITOR); if ((bibGenre == BibTexUtil.Genre.article || bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.inproceedings || bibGenre == BibTexUtil.Genre.conference || bibGenre == BibTexUtil.Genre.incollection) && (sourceVO.getTitle() != null || sourceVO.getTitle() == null)) { sourceVO.getCreators().add(creatorVO); } else { mds.getCreators().add(creatorVO); } } } if (!teams.isEmpty()) { mds.getCreators().addAll(teams); } } catch (Exception e) { this.logger.error("An error occured while getting field 'editor'.", e); throw new RuntimeException(e); } } } // No CoNE Author or Editor Found if (noConeAuthorFound == true && noConeEditorFound == true && configuration != null && "true".equals(configuration.get("CoNE"))) { throw new RuntimeException("No CoNE-Author and no CoNE-Editor was found"); } // If no affiliation is given, set the first author to "external" boolean affiliationFound = false; for (CreatorVO creator : mds.getCreators()) { if (creator.getPerson() != null && creator.getPerson().getOrganizations() != null) { for (OrganizationVO organization : creator.getPerson().getOrganizations()) { if (organization.getIdentifier() != null) { affiliationFound = true; break; } } } } if (!affiliationFound && mds.getCreators().size() > 0) { OrganizationVO externalOrganization = new OrganizationVO(); externalOrganization.setName("External Organizations"); try { externalOrganization.setIdentifier( PropertyReader.getProperty("escidoc.pubman.external.organisation.id")); } catch (Exception e) { throw new RuntimeException("Property escidoc.pubman.external.organisation.id not found", e); } if (mds.getCreators().get(0).getPerson() != null) { mds.getCreators().get(0).getPerson().getOrganizations().add(externalOrganization); } } // Mapping of "common" (maybe relevant), non standard BibTeX Entries // abstract if (fields.get("abstract") != null) { mds.getAbstracts().add(new AbstractVO(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("abstract").toString()), false))); } // contents if (fields.get("contents") != null) { mds.setTableOfContents(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("contents").toString()), false)); } // isbn if (fields.get("isbn") != null) { if (bibGenre == BibTexUtil.Genre.inproceedings || bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.incollection || bibGenre == BibTexUtil.Genre.conference) { if (sourceVO != null) { sourceVO.getIdentifiers().add(new IdentifierVO(IdentifierVO.IdType.ISBN, BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("isbn").toString()), false))); } } else { mds.getIdentifiers().add(new IdentifierVO(IdentifierVO.IdType.ISBN, BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("isbn").toString()), false))); } } // issn if (fields.get("issn") != null) { if (bibGenre == BibTexUtil.Genre.inproceedings || bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.incollection || bibGenre == BibTexUtil.Genre.conference) { if (sourceVO.getSources() != null && !sourceVO.getSources().isEmpty()) { sourceVO.getSources().get(0).getIdentifiers() .add(new IdentifierVO(IdentifierVO.IdType.ISSN, BibTexUtil.stripBraces( BibTexUtil.bibtexDecode(fields.get("issn").toString()), false))); } } else if (bibGenre == BibTexUtil.Genre.article) { if (sourceVO != null) { sourceVO.getIdentifiers().add(new IdentifierVO(IdentifierVO.IdType.ISSN, BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("issn").toString()), false))); } } else { mds.getIdentifiers().add(new IdentifierVO(IdentifierVO.IdType.ISSN, BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("issn").toString()), false))); } } // keywords if (fields.get("keywords") != null) { mds.setFreeKeywords(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("keywords").toString()), false)); } // language /* * if (fields.get("language") != null) { * mds.getLanguages().add(BibTexUtil.stripBraces(BibTexUtil * .bibtexDecode(fields.get("language").toString ()), false)); } */ // subtitle if (fields.get("subtitle") != null) { mds.getAlternativeTitles().add(new AlternativeTitleVO(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("subtitle").toString()), false))); } // url is now mapped to locator if (fields.get("url") != null) { // mds.getIdentifiers().add( // new IdentifierVO( // IdentifierVO.IdType.URI, // BibTexUtil.stripBraces(BibTexUtil.bibtexDecode(fields.get("url").toString()), false))); FileVO locator = new FileVO(); locator.setContent( BibTexUtil.stripBraces(BibTexUtil.bibtexDecode(fields.get("url").toString()), false)); locator.setName("Link"); locator.setStorage(FileVO.Storage.EXTERNAL_URL); locator.setVisibility(FileVO.Visibility.PUBLIC); locator.setContentCategory( "http://purl.org/escidoc/metadata/ves/content-categories/any-fulltext"); MdsFileVO metadata = new MdsFileVO(); metadata.setContentCategory( "http://purl.org/escidoc/metadata/ves/content-categories/any-fulltext"); metadata.setTitle("Link"); locator.getMetadataSets().add(metadata); itemVO.getFiles().add(locator); } // web_url as URI-Identifier else if (fields.get("web_url") != null) { mds.getIdentifiers().add(new IdentifierVO(IdentifierVO.IdType.URI, BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("web_url").toString()), false))); } // Prevent the creation of an empty source if (sourceVO.getTitle() != null && sourceVO.getTitle() != null && sourceVO.getTitle() != "" && sourceVO.getGenre() != null) { mds.getSources().add(sourceVO); // Prevent the creation of an empty second if (sourceVO.getSources() != null && !sourceVO.getSources().isEmpty() && sourceVO.getSources().get(0) != null && sourceVO.getSources().get(0).getTitle() != null && sourceVO.getSources().get(0).getTitle() != null && sourceVO.getSources().get(0).getTitle() != "") { mds.getSources().add(sourceVO.getSources().get(0)); } } // Prevent the creation of an empty second source if (secondSourceVO.getTitle() != null && secondSourceVO.getTitle() != null && secondSourceVO.getTitle() != "" && secondSourceVO.getGenre() != null) { mds.getSources().add(secondSourceVO); // Prevent the creation of an empty second if (secondSourceVO.getSources() != null && !secondSourceVO.getSources().isEmpty() && secondSourceVO.getSources().get(0) != null && secondSourceVO.getSources().get(0).getTitle() != null && secondSourceVO.getSources().get(0).getTitle() != null && secondSourceVO.getSources().get(0).getTitle() != "") { mds.getSources().add(secondSourceVO.getSources().get(0)); } } // New mapping for MPIS // DOI if (fields.get("doi") != null) { mds.getIdentifiers().add(new IdentifierVO(IdentifierVO.IdType.DOI, BibTexUtil.stripBraces(BibTexUtil.bibtexDecode(fields.get("doi").toString()), false))); } // eid if (fields.get("eid") != null) { if (mds.getSources().size() == 1) { mds.getSources().get(0).setSequenceNumber(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("eid").toString()), false)); } } // rev if (fields.get("rev") != null) { if ("Peer".equals( BibTexUtil.stripBraces(BibTexUtil.bibtexDecode(fields.get("rev").toString()), false))) { mds.setReviewMethod(ReviewMethod.PEER); } else if ("No review".equals( BibTexUtil.stripBraces(BibTexUtil.bibtexDecode(fields.get("rev").toString()), false))) { mds.setReviewMethod(ReviewMethod.NO_REVIEW); } } // MPG-Affil if (fields.get("MPG-Affil") != null) { if ("Peer".equals(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("MPG-Affil").toString()), false))) { // TODO } } // MPIS Groups if (fields.get("group") != null) { String[] groups = BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("group").toString()), false).split(","); for (String group : groups) { group = group.trim(); if (!"".equals(group)) { if (groupSet == null) { try { groupSet = loadGroupSet(); } catch (Exception e) { throw new RuntimeException(e); } } if (!groupSet.contains(group)) { throw new RuntimeException("Group '" + group + "' not found."); } mds.getSubjects() .add(new SubjectVO(group, null, SubjectClassification.MPIS_GROUPS.toString())); } } } // MPIS Projects if (fields.get("project") != null) { String[] projects = BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("project").toString()), false) .split(","); for (String project : projects) { project = project.trim(); if (!"".equals(project)) { if (projectSet == null) { try { projectSet = loadProjectSet(); } catch (Exception e) { throw new RuntimeException(e); } } if (!projectSet.contains(project)) { throw new RuntimeException("Project '" + project + "' not found."); } mds.getSubjects().add( new SubjectVO(project, null, SubjectClassification.MPIS_PROJECTS.toString())); } } } // Cite Key mds.getIdentifiers().add(new IdentifierVO(IdType.BIBTEX_CITEKEY, entry.getEntryKey())); } else if (object instanceof BibtexToplevelComment) { this.logger.debug("Comment found: " + ((BibtexToplevelComment) object).getContent()); } } XmlTransforming xmlTransforming = new XmlTransformingBean(); try { if (entryFound) { return xmlTransforming.transformToItem(itemVO); } else { this.logger.warn("No entry found in BibTex record."); throw new RuntimeException(); } } catch (TechnicalException e) { this.logger.error("An error ocurred while transforming the item."); throw new RuntimeException(e); } }
From source file:fr.paris.lutece.plugins.extend.service.content.ExtendableContentPostProcessor.java
/** * {@inheritDoc}//w w w.j av a 2s .co m */ @Override public String process(HttpServletRequest request, String strContent) { String strHtmlContent = strContent; // Check if the process is carried out in client or server side boolean bClientSide = Boolean.valueOf(AppPropertiesService.getProperty(PROPERTY_CLIENT_SIDE, "false")); if (bClientSide) { // CLIENT SIDE int nPos = strHtmlContent.indexOf(END_BODY); if (nPos < 0) { AppLogService.error("ExtendableContentPostProcessor Service : no BODY end tag found"); return strHtmlContent; } Map<String, Object> model = new HashMap<String, Object>(); model.put(MARK_BASE_URL, AppPathService.getBaseUrl(request)); model.put(MARK_REGEX_PATTERN, _strRegexPattern); HtmlTemplate template = AppTemplateService.getTemplate(TEMPLATE_CONTENT_POST_PROCESSOR, request.getLocale(), model); StringBuilder sb = new StringBuilder(); sb.append(strHtmlContent.substring(0, nPos)); sb.append(template.getHtml()); sb.append(strHtmlContent.substring(nPos)); strHtmlContent = sb.toString(); } else { // SERVER SIDE /** * Replace all makers @Extender[<idResource>,<resourceType>,<extenderType>,<params>]@ to * the correct HTML content of the extender. * 1) First parse the content of the markers * 2) Get all information (idResource, resourceType, extenderType, params) * 3) Get the html content from the given information * 4) Replace the markers by the html content */ // 1) First parse the content of the markers Matcher match = _regexPattern.matcher(strHtmlContent); Matcher parameterMatch = null; StringBuffer strResultHTML = new StringBuffer(strHtmlContent.length()); while (match.find()) { String strMarker = match.group(); // 2) Get all information (idResource, resourceType, extenderType, params) ResourceExtenderDTO resourceExtender = _mapper.map(match.group(1)); boolean bParameteredId = StringUtils.equalsIgnoreCase(resourceExtender.getIdExtendableResource(), EXTEND_PARAMETERED_ID); if (bParameteredId) { if (parameterMatch == null) { parameterMatch = _extendedParameterRegexPattern.matcher(strHtmlContent); } else { parameterMatch.reset(); } while (parameterMatch.find()) { ResourceExtenderDTO realResourceExtender = _mapper.map(parameterMatch.group(1)); if (StringUtils.equals(realResourceExtender.getExtendableResourceType(), resourceExtender.getExtendableResourceType()) && StringUtils.equals(realResourceExtender.getExtenderType(), resourceExtender.getExtenderType())) { resourceExtender .setIdExtendableResource(realResourceExtender.getIdExtendableResource()); break; } } } String strHtml = StringUtils.EMPTY; if (!bParameteredId || !StringUtils.equalsIgnoreCase(resourceExtender.getIdExtendableResource(), EXTEND_PARAMETERED_ID)) { // 3) Get the html content from the given information if (!StringUtils.equals(resourceExtender.getExtendableResourceType(), Page.RESOURCE_TYPE) || (StringUtils.isBlank(request.getParameter(PARAM_PAGE)) && StringUtils.isBlank(request.getParameter(PARAM_PORTLET_ID)))) { strHtml = _extenderService.getContent(resourceExtender.getIdExtendableResource(), resourceExtender.getExtendableResourceType(), resourceExtender.getExtenderType(), resourceExtender.getParameters(), request); } } // 4) Replace the markers by the html content match.appendReplacement(strResultHTML, Matcher.quoteReplacement(strHtml)); } match.appendTail(strResultHTML); strHtmlContent = strResultHTML.toString(); } if (StringUtils.isNotBlank(_strExtenderParameterRegexPattern)) { strHtmlContent = _extendedParameterRegexPattern.matcher(strHtmlContent).replaceAll(""); } return strHtmlContent; }
From source file:de.mpg.escidoc.services.transformation.transformations.commonPublicationFormats.Bibtex.java
/** * @param bibtex/*from ww w. j a va 2 s .c om*/ * @return eSciDoc-publication item XML representation of this BibTeX entry * @throws RuntimeException */ public String getBibtex(String bibtex) throws RuntimeException { // Remove Math '$' from the whole BibTex-String Pattern mathPattern = Pattern.compile("(?sm)\\$(\\\\.*?)(?<!\\\\)\\$"); Matcher mathMatcher = mathPattern.matcher(bibtex); StringBuffer sb = new StringBuffer(); while (mathMatcher.find()) { mathMatcher.appendReplacement(sb, "$1"); } mathMatcher.appendTail(sb); bibtex = sb.toString(); BibtexParser parser = new BibtexParser(true); BibtexFile file = new BibtexFile(); try { parser.parse(file, new StringReader(bibtex)); } catch (Exception e) { this.logger.error("Error parsing BibTex record."); throw new RuntimeException(e); } PubItemVO itemVO = new PubItemVO(); MdsPublicationVO mds = new MdsPublicationVO(); itemVO.setMetadata(mds); List entries = file.getEntries(); boolean entryFound = false; if (entries == null || entries.size() == 0) { this.logger.warn("No entry found in BibTex record."); throw new RuntimeException(); } for (Object object : entries) { if (object instanceof BibtexEntry) { if (entryFound) { this.logger.error("Multiple entries in BibTex record."); throw new RuntimeException(); } entryFound = true; BibtexEntry entry = (BibtexEntry) object; // genre BibTexUtil.Genre bibGenre; try { bibGenre = BibTexUtil.Genre.valueOf(entry.getEntryType()); } catch (IllegalArgumentException iae) { bibGenre = BibTexUtil.Genre.misc; this.logger.warn("Unrecognized genre: " + entry.getEntryType()); } MdsPublicationVO.Genre itemGenre = BibTexUtil.getGenreMapping().get(bibGenre); mds.setGenre(itemGenre); SourceVO sourceVO = new SourceVO(new TextVO()); SourceVO secondSourceVO = new SourceVO(new TextVO()); Map fields = entry.getFields(); // Mapping of BibTeX Standard Entries // title if (fields.get("title") != null) { if (fields.get("chapter") != null) { mds.setTitle(new TextVO(BibTexUtil.stripBraces( BibTexUtil.bibtexDecode(fields.get("chapter").toString()), false) + " - " + BibTexUtil.stripBraces(BibTexUtil.bibtexDecode(fields.get("title").toString()), false))); } else { mds.setTitle(new TextVO(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("title").toString()), false))); } } // booktitle if (fields.get("booktitle") != null) { if (bibGenre == BibTexUtil.Genre.book) { mds.setTitle(new TextVO(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("booktitle").toString()), false))); } else if (bibGenre == BibTexUtil.Genre.conference || bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.incollection || bibGenre == BibTexUtil.Genre.inproceedings) { sourceVO.setTitle(new TextVO(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("booktitle").toString()), false))); if (bibGenre == BibTexUtil.Genre.conference || bibGenre == BibTexUtil.Genre.inproceedings) { sourceVO.setGenre(Genre.PROCEEDINGS); } else if (bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.incollection) { sourceVO.setGenre(Genre.BOOK); } } } // fjournal, journal if (fields.get("fjournal") != null) { if (bibGenre == BibTexUtil.Genre.article || bibGenre == BibTexUtil.Genre.misc || bibGenre == BibTexUtil.Genre.unpublished) { sourceVO.setTitle(new TextVO(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("fjournal").toString()), false))); sourceVO.setGenre(SourceVO.Genre.JOURNAL); if (fields.get("journal") != null) { sourceVO.getAlternativeTitles().add(new TextVO(BibTexUtil.stripBraces( BibTexUtil.bibtexDecode(fields.get("journal").toString()), false))); } } } else if (fields.get("journal") != null) { if (bibGenre == BibTexUtil.Genre.article || bibGenre == BibTexUtil.Genre.misc || bibGenre == BibTexUtil.Genre.unpublished || bibGenre == BibTexUtil.Genre.inproceedings) { sourceVO.setTitle(new TextVO(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("journal").toString()), false))); sourceVO.setGenre(SourceVO.Genre.JOURNAL); } } // number if (fields.get("number") != null && bibGenre != BibTexUtil.Genre.techreport) { sourceVO.setIssue(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("number").toString()), false)); } else if (fields.get("number") != null && bibGenre == BibTexUtil.Genre.techreport) { { mds.getIdentifiers().add(new IdentifierVO(IdentifierVO.IdType.REPORT_NR, BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("number").toString()), false))); } } // pages if (fields.get("pages") != null) { if (bibGenre == BibTexUtil.Genre.book || bibGenre == BibTexUtil.Genre.proceedings) { mds.setTotalNumberOfPages(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("pages").toString()), false)); } else { BibTexUtil.fillSourcePages(BibTexUtil.stripBraces( BibTexUtil.bibtexDecode(fields.get("pages").toString()), false), sourceVO); if (bibGenre == BibTexUtil.Genre.inproceedings && (fields.get("booktitle") == null || fields.get("booktitle").toString() == "") && (fields.get("event_name") != null && fields.get("event_name").toString() != "")) { sourceVO.setTitle( new TextVO(BibTexUtil.stripBraces(fields.get("event_name").toString(), false))); sourceVO.setGenre(Genre.PROCEEDINGS); } } } // Publishing info PublishingInfoVO publishingInfoVO = new PublishingInfoVO(); mds.setPublishingInfo(publishingInfoVO); // address if (fields.get("address") != null) { if (!(bibGenre == BibTexUtil.Genre.article || bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.inproceedings || bibGenre == BibTexUtil.Genre.conference || bibGenre == BibTexUtil.Genre.incollection) && (sourceVO.getTitle() == null || sourceVO.getTitle().getValue() == null)) { publishingInfoVO.setPlace(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("address").toString()), false)); } else { if (sourceVO.getPublishingInfo() == null) { PublishingInfoVO sourcePublishingInfoVO = new PublishingInfoVO(); sourceVO.setPublishingInfo(sourcePublishingInfoVO); } sourceVO.getPublishingInfo().setPlace(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("address").toString()), false)); } } // edition if (fields.get("edition") != null) { publishingInfoVO.setEdition(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("edition").toString()), false)); } // publisher if (!(bibGenre == BibTexUtil.Genre.article || bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.inproceedings || bibGenre == BibTexUtil.Genre.conference || bibGenre == BibTexUtil.Genre.incollection) && (sourceVO.getTitle() == null || sourceVO.getTitle().getValue() == null)) { if (fields.get("publisher") != null) { publishingInfoVO.setPublisher(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("publisher").toString()), false)); } else if (fields.get("school") != null && (bibGenre == BibTexUtil.Genre.mastersthesis || bibGenre == BibTexUtil.Genre.phdthesis || bibGenre == BibTexUtil.Genre.techreport)) { publishingInfoVO.setPublisher(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("school").toString()), false)); } else if (fields.get("institution") != null) { publishingInfoVO.setPublisher(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("institution").toString()), false)); } else if (fields.get("publisher") == null && fields.get("school") == null && fields.get("institution") == null && fields.get("address") != null) { publishingInfoVO.setPublisher("ANY PUBLISHER"); } } else { if (sourceVO.getPublishingInfo() == null) { PublishingInfoVO sourcePublishingInfoVO = new PublishingInfoVO(); sourceVO.setPublishingInfo(sourcePublishingInfoVO); } if (fields.get("publisher") != null) { sourceVO.getPublishingInfo().setPublisher(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("publisher").toString()), false)); } else if (fields.get("school") != null && (bibGenre == BibTexUtil.Genre.mastersthesis || bibGenre == BibTexUtil.Genre.phdthesis || bibGenre == BibTexUtil.Genre.techreport)) { sourceVO.getPublishingInfo().setPublisher(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("school").toString()), false)); } else if (fields.get("institution") != null) { sourceVO.getPublishingInfo().setPublisher(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("institution").toString()), false)); } else if (fields.get("publisher") == null && fields.get("school") == null && fields.get("institution") == null && fields.get("address") != null) { sourceVO.getPublishingInfo().setPublisher("ANY PUBLISHER"); } } // series if (fields.get("series") != null) { if (bibGenre == BibTexUtil.Genre.book || bibGenre == BibTexUtil.Genre.misc || bibGenre == BibTexUtil.Genre.techreport) { sourceVO.setTitle(new TextVO(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("series").toString()), false))); sourceVO.setGenre(SourceVO.Genre.SERIES); } else if (bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.incollection || bibGenre == BibTexUtil.Genre.inproceedings || bibGenre == BibTexUtil.Genre.conference) { secondSourceVO.setTitle(new TextVO(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("series").toString()), false))); secondSourceVO.setGenre(SourceVO.Genre.SERIES); } } // type --> degree if (fields.get("type") != null && bibGenre == BibTexUtil.Genre.mastersthesis) { if (fields.get("type").toString().toLowerCase().contains("master") || fields.get("type").toString().toLowerCase().contains("m.a.") || fields.get("type").toString().toLowerCase().contains("m.s.") || fields.get("type").toString().toLowerCase().contains("m.sc.")) { mds.setDegree(MdsPublicationVO.DegreeType.MASTER); } else if (fields.get("type").toString().toLowerCase().contains("bachelor")) { mds.setDegree(MdsPublicationVO.DegreeType.BACHELOR); } else if (fields.get("type").toString().toLowerCase().contains("magister")) { mds.setDegree(MdsPublicationVO.DegreeType.MAGISTER); } else if (fields.get("type").toString().toLowerCase().contains("diplom")) // covers also the english // version (diploma) { mds.setDegree(MdsPublicationVO.DegreeType.DIPLOMA); } else if (fields.get("type").toString().toLowerCase().contains("statsexamen") || fields.get("type").toString().toLowerCase().contains("state examination")) { mds.setDegree(MdsPublicationVO.DegreeType.DIPLOMA); } } else if (fields.get("type") != null && bibGenre == BibTexUtil.Genre.phdthesis) { if (fields.get("type").toString().toLowerCase().contains("phd") || fields.get("type").toString().toLowerCase().contains("dissertation") || fields.get("type").toString().toLowerCase().contains("doktor") || fields.get("type").toString().toLowerCase().contains("doctor")) { mds.setDegree(MdsPublicationVO.DegreeType.PHD); } else if (fields.get("type").toString().toLowerCase().contains("habilitation")) { mds.setDegree(MdsPublicationVO.DegreeType.HABILITATION); } } // volume if (fields.get("volume") != null) { if (bibGenre == BibTexUtil.Genre.article || bibGenre == BibTexUtil.Genre.book) { sourceVO.setVolume(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("volume").toString()), false)); } else if (bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.inproceedings || bibGenre == BibTexUtil.Genre.incollection || bibGenre == BibTexUtil.Genre.conference) { if (sourceVO.getSources() != null && !sourceVO.getSources().isEmpty()) { sourceVO.getSources().get(0).setVolume(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("volume").toString()), false)); } else { sourceVO.setVolume(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("volume").toString()), false)); } } } // event infos if (bibGenre != null && (bibGenre.equals(BibTexUtil.Genre.inproceedings) || bibGenre.equals(BibTexUtil.Genre.proceedings) || bibGenre.equals(BibTexUtil.Genre.conference) || bibGenre.equals(BibTexUtil.Genre.poster) || bibGenre.equals(BibTexUtil.Genre.talk))) { EventVO event = new EventVO(); boolean eventNotEmpty = false; // event location if (fields.get("location") != null) { event.setPlace(new TextVO(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("location").toString()), false))); eventNotEmpty = true; } // event place else if (fields.get("event_place") != null) { event.setPlace(new TextVO(BibTexUtil.stripBraces( BibTexUtil.bibtexDecode(fields.get("event_place").toString()), false))); eventNotEmpty = true; } // event name/title if (fields.get("event_name") != null) { event.setTitle(new TextVO(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("event_name").toString()), false))); eventNotEmpty = true; } // event will be set only it's not empty if (eventNotEmpty == true) { if (event.getTitle() == null) { event.setTitle(new TextVO()); } mds.setEvent(event); } } // year, month String dateString = null; if (fields.get("year") != null) { dateString = BibTexUtil.stripBraces(BibTexUtil.bibtexDecode(fields.get("year").toString()), false); if (fields.get("month") != null) { String month = BibTexUtil.parseMonth(fields.get("month").toString()); dateString += "-" + month; } if (bibGenre == BibTexUtil.Genre.unpublished) { mds.setDateCreated(dateString); } else { mds.setDatePublishedInPrint(dateString); } } String affiliation = null; String affiliationAddress = null; // affiliation if (fields.get("affiliation") != null) { affiliation = BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("affiliation").toString()), false); } // affiliationaddress if (fields.get("affiliationaddress") != null) { affiliationAddress = BibTexUtil.stripBraces( BibTexUtil.bibtexDecode(fields.get("affiliationaddress").toString()), false); } // author boolean noConeAuthorFound = true; if (fields.get("author") != null) { if (fields.get("author") instanceof BibtexPersonList) { BibtexPersonList authors = (BibtexPersonList) fields.get("author"); for (Object author : authors.getList()) { if (author instanceof BibtexPerson) { addCreator(mds, (BibtexPerson) author, CreatorVO.CreatorRole.AUTHOR, affiliation, affiliationAddress); } else { this.logger.warn("Entry in BibtexPersonList not a BibtexPerson: [" + author + "] in [" + author + "]"); } } } else if (fields.get("author") instanceof BibtexPerson) { BibtexPerson author = (BibtexPerson) fields.get("author"); addCreator(mds, (BibtexPerson) author, CreatorVO.CreatorRole.AUTHOR, affiliation, affiliationAddress); } else if (fields.get("author") instanceof BibtexString) { AuthorDecoder decoder; try { String authorString = BibTexUtil.bibtexDecode(fields.get("author").toString(), false); List<CreatorVO> teams = new ArrayList<CreatorVO>(); if (authorString.contains("Team")) { // set pattern for finding Teams (leaded or followed by [and|,|;|{|}|^|$]) Pattern pattern = Pattern.compile( "(?<=(and|,|;|\\{|^))([\\w|\\s]*?Team[\\w|\\s]*?)(?=(and|,|;|\\}|$))", Pattern.DOTALL); Matcher matcher = pattern.matcher(authorString); String matchedGroup; while (matcher.find()) { matchedGroup = matcher.group(); // remove matchedGroup (and prefix/suffix) from authorString if (authorString.startsWith(matchedGroup)) { authorString = authorString.replaceAll(matchedGroup + "(and|,|;|\\})", ""); } else { authorString = authorString.replaceAll("(and|,|;|\\{)" + matchedGroup, ""); } // set matchedGroup as Organisation Author OrganizationVO team = new OrganizationVO(); team.setName(new TextVO(matchedGroup.trim())); CreatorVO creatorVO = new CreatorVO(team, CreatorVO.CreatorRole.AUTHOR); teams.add(creatorVO); } } decoder = new AuthorDecoder(authorString, false); if (decoder.getBestFormat() != null) { List<Author> authors = decoder.getAuthorListList().get(0); for (Author author : authors) { PersonVO personVO = new PersonVO(); personVO.setFamilyName(author.getSurname()); if (author.getGivenName() != null) { personVO.setGivenName(author.getGivenName()); } else { personVO.setGivenName(author.getInitial()); } /* * Case for MPI-KYB (Biological Cybernetics) with CoNE identifier in brackets and * affiliations to adopt from CoNE for each author (also in brackets) */ if (configuration != null && "true".equals(configuration.get("CoNE")) && ("identifier and affiliation in brackets" .equals(configuration.get("CurlyBracketsForCoNEAuthors"))) && (author.getTags().get("identifier") != null)) { String query = author.getTags().get("identifier"); int affiliationsCount = Integer .parseInt(author.getTags().get("affiliationsCount")); if (affiliationsCount > 0 || configuration.get("OrganizationalUnit") != null) { for (int ouCount = 0; ouCount < (affiliationsCount > 0 ? affiliationsCount : 1); ouCount++) // 1 // is // for // the // case // configuration.get("OrganizationalUnit") // != // null { String organizationalUnit = (author.getTags().get( "affiliation" + new Integer(ouCount).toString()) != null ? author.getTags() .get("affiliation" + new Integer(ouCount).toString()) : (configuration.get("OrganizationalUnit") != null ? configuration.get("OrganizationalUnit") : "")); Node coneEntries = null; if (query.equals(author.getTags().get("identifier"))) { coneEntries = Util.queryConeExactWithIdentifier("persons", query, organizationalUnit); // for MPIKYB due to OUs which do not occur in CoNE if (coneEntries.getFirstChild().getFirstChild() == null) { logger.error("No Person with Identifier (" + author.getTags().get("identifier") + ") and OU (" + organizationalUnit + ") found in CoNE for Publication \"" + fields.get("title") + "\""); } } else { coneEntries = Util.queryConeExact("persons", query, organizationalUnit); } Node coneNode = coneEntries.getFirstChild().getFirstChild(); if (coneNode != null) { Node currentNode = coneNode.getFirstChild(); boolean first = true; while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE && first) { first = false; noConeAuthorFound = false; Node coneEntry = currentNode; String coneId = coneEntry.getAttributes() .getNamedItem("rdf:about").getNodeValue(); personVO.setIdentifier( new IdentifierVO(IdType.CONE, coneId)); for (int i = 0; i < coneEntry.getChildNodes() .getLength(); i++) { Node posNode = coneEntry.getChildNodes().item(i); if ("escidoc:position" .equals(posNode.getNodeName())) { String from = null; String until = null; String name = null; String id = null; Node node = posNode.getFirstChild() .getFirstChild(); while (node != null) { if ("eprints:affiliatedInstitution" .equals(node.getNodeName())) { name = node.getFirstChild() .getNodeValue(); } else if ("escidoc:start-date" .equals(node.getNodeName())) { from = node.getFirstChild() .getNodeValue(); } else if ("escidoc:end-date" .equals(node.getNodeName())) { until = node.getFirstChild() .getNodeValue(); } else if ("dc:identifier" .equals(node.getNodeName())) { id = node.getFirstChild() .getNodeValue(); } node = node.getNextSibling(); } if (smaller(from, dateString) && smaller(dateString, until)) { OrganizationVO org = new OrganizationVO(); org.setName(new TextVO(name)); org.setIdentifier(id); personVO.getOrganizations().add(org); } } } } else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { throw new RuntimeException( "Ambigous CoNE entries for " + query); } currentNode = currentNode.getNextSibling(); } } else { throw new RuntimeException("Missing CoNE entry for " + query); } } } } /* * Case for MPI-Microstructure Physics with affiliation identifier in brackets and * affiliations to adopt from CoNE for each author (also in brackets) */ else if (configuration != null && "true".equals(configuration.get("CoNE")) && ("affiliation id in brackets" .equals(configuration.get("CurlyBracketsForCoNEAuthors"))) && (author.getTags().get("identifier") != null)) { String identifier = author.getTags().get("identifier"); String query = personVO.getFamilyName() + ", " + personVO.getGivenName(); if (!("extern".equals(identifier))) { Node coneEntries = null; coneEntries = Util.queryConeExact("persons", query, (configuration.get("OrganizationalUnit") != null ? configuration.get("OrganizationalUnit") : "")); Node coneNode = coneEntries.getFirstChild().getFirstChild(); if (coneNode != null) { Node currentNode = coneNode.getFirstChild(); boolean first = true; while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE && first) { first = false; noConeAuthorFound = false; Node coneEntry = currentNode; String coneId = coneEntry.getAttributes() .getNamedItem("rdf:about").getNodeValue(); personVO.setIdentifier( new IdentifierVO(IdType.CONE, coneId)); if (identifier != null && !("".equals(identifier))) { try { String ouSubTitle = identifier.substring(0, identifier.indexOf(",")); Document document = Util.queryFramework( "/oum/organizational-units?query=" + URLEncoder.encode("\"/title\"=\"" + ouSubTitle + "\"", "UTF-8")); NodeList ouList = document.getElementsByTagNameNS( "http://www.escidoc.de/schemas/organizationalunit/0.8", "organizational-unit"); Element ou = (Element) ouList.item(0); String href = ou.getAttribute("xlink:href"); String ouId = href .substring(href.lastIndexOf("/") + 1); OrganizationVO org = new OrganizationVO(); org.setName(new TextVO(identifier)); org.setIdentifier(ouId); personVO.getOrganizations().add(org); } catch (Exception e) { logger.error("Error getting OUs", e); throw new RuntimeException( "Error getting Organizational Unit for " + identifier); } } } else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { throw new RuntimeException( "Ambigous CoNE entries for " + query); } currentNode = currentNode.getNextSibling(); } } else { throw new RuntimeException("Missing CoNE entry for " + query); } } } else if (configuration != null && "true".equals(configuration.get("CoNE")) && ("empty brackets" .equals(configuration.get("CurlyBracketsForCoNEAuthors")) && (author.getTags().get("brackets") != null))) { String query = personVO.getFamilyName() + ", " + personVO.getGivenName(); Node coneEntries = Util.queryConeExact("persons", query, (configuration.get("OrganizationalUnit") != null ? configuration.get("OrganizationalUnit") : "")); Node coneNode = coneEntries.getFirstChild().getFirstChild(); if (coneNode != null) { Node currentNode = coneNode.getFirstChild(); boolean first = true; while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE && first) { first = false; noConeAuthorFound = false; Node coneEntry = currentNode; String coneId = coneEntry.getAttributes() .getNamedItem("rdf:about").getNodeValue(); personVO.setIdentifier(new IdentifierVO(IdType.CONE, coneId)); for (int i = 0; i < coneEntry.getChildNodes() .getLength(); i++) { Node posNode = coneEntry.getChildNodes().item(i); if ("escidoc:position".equals(posNode.getNodeName())) { String from = null; String until = null; String name = null; String id = null; Node node = posNode.getFirstChild().getFirstChild(); while (node != null) { if ("eprints:affiliatedInstitution" .equals(node.getNodeName())) { name = node.getFirstChild().getNodeValue(); } else if ("escidoc:start-date" .equals(node.getNodeName())) { from = node.getFirstChild().getNodeValue(); } else if ("escidoc:end-date" .equals(node.getNodeName())) { until = node.getFirstChild().getNodeValue(); } else if ("dc:identifier" .equals(node.getNodeName())) { id = node.getFirstChild().getNodeValue(); } node = node.getNextSibling(); } if (smaller(from, dateString) && smaller(dateString, until)) { OrganizationVO org = new OrganizationVO(); org.setName(new TextVO(name)); org.setIdentifier(id); personVO.getOrganizations().add(org); } } } } else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { throw new RuntimeException( "Ambigous CoNE entries for " + query); } currentNode = currentNode.getNextSibling(); } } else { throw new RuntimeException("Missing CoNE entry for " + query); } } else if (configuration != null && "true".equals(configuration.get("CoNE")) && ("no".equals(configuration.get("CurlyBracketsForCoNEAuthors")))) { String query = personVO.getFamilyName() + ", " + personVO.getGivenName(); Node coneEntries = Util.queryConeExact("persons", query, (configuration.get("OrganizationalUnit") != null ? configuration.get("OrganizationalUnit") : "")); Node coneNode = coneEntries.getFirstChild().getFirstChild(); if (coneNode != null) { Node currentNode = coneNode.getFirstChild(); boolean first = true; while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE && first) { first = false; noConeAuthorFound = false; Node coneEntry = currentNode; String coneId = coneEntry.getAttributes() .getNamedItem("rdf:about").getNodeValue(); personVO.setIdentifier(new IdentifierVO(IdType.CONE, coneId)); for (int i = 0; i < coneEntry.getChildNodes() .getLength(); i++) { Node posNode = coneEntry.getChildNodes().item(i); if ("escidoc:position".equals(posNode.getNodeName())) { String from = null; String until = null; String name = null; String id = null; Node node = posNode.getFirstChild().getFirstChild(); while (node != null) { if ("eprints:affiliatedInstitution" .equals(node.getNodeName())) { name = node.getFirstChild().getNodeValue(); } else if ("escidoc:start-date" .equals(node.getNodeName())) { from = node.getFirstChild().getNodeValue(); } else if ("escidoc:end-date" .equals(node.getNodeName())) { until = node.getFirstChild().getNodeValue(); } else if ("dc:identifier" .equals(node.getNodeName())) { id = node.getFirstChild().getNodeValue(); } node = node.getNextSibling(); } if (smaller(from, dateString) && smaller(dateString, until)) { OrganizationVO org = new OrganizationVO(); org.setName(new TextVO(name)); org.setIdentifier(id); personVO.getOrganizations().add(org); } } } } else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { throw new RuntimeException( "Ambigous CoNE entries for " + query); } currentNode = currentNode.getNextSibling(); } } } /* * Case for MPI-RA (Radio Astronomy) with identifier and affiliation in brackets * This Case is using NO CoNE! */ if (configuration != null && "false".equals(configuration.get("CoNE")) && ("identifier and affiliation in brackets" .equals(configuration.get("CurlyBracketsForCoNEAuthors"))) && (author.getTags().get("identifier") != null)) { String identifier = author.getTags().get("identifier"); String authoAffiliation = author.getTags().get("affiliation0"); OrganizationVO org = new OrganizationVO(); org.setName(new TextVO(authoAffiliation)); org.setIdentifier(identifier); personVO.getOrganizations().add(org); } if (affiliation != null) { OrganizationVO organization = new OrganizationVO(); organization.setIdentifier(PropertyReader .getProperty("escidoc.pubman.external.organisation.id")); organization.setName(new TextVO(affiliation)); organization.setAddress(affiliationAddress); personVO.getOrganizations().add(organization); } CreatorVO creatorVO = new CreatorVO(personVO, CreatorVO.CreatorRole.AUTHOR); mds.getCreators().add(creatorVO); } } if (!teams.isEmpty()) { mds.getCreators().addAll(teams); } } catch (Exception e) { this.logger.error("An error occured while getting field 'author'.", e); throw new RuntimeException(e); } } } // editor boolean noConeEditorFound = false; if (fields.get("editor") != null) { this.logger.debug("fields.get(\"editor\"): " + fields.get("editor").getClass()); if (fields.get("editor") instanceof BibtexPersonList) { BibtexPersonList editors = (BibtexPersonList) fields.get("editor"); for (Object editor : editors.getList()) { if (editor instanceof BibtexPerson) { addCreator(mds, (BibtexPerson) editor, CreatorVO.CreatorRole.EDITOR, affiliation, affiliationAddress); } else { this.logger.warn("Entry in BibtexPersonList not a BibtexPerson: [" + editor + "] in [" + editors + "]"); } } } else if (fields.get("editor") instanceof BibtexPerson) { BibtexPerson editor = (BibtexPerson) fields.get("editor"); addCreator(mds, (BibtexPerson) editor, CreatorVO.CreatorRole.EDITOR, affiliation, affiliationAddress); } else if (fields.get("editor") instanceof BibtexString) { AuthorDecoder decoder; try { String editorString = BibTexUtil.bibtexDecode(fields.get("editor").toString(), false); List<CreatorVO> teams = new ArrayList<CreatorVO>(); if (editorString.contains("Team")) { // set pattern for finding Teams (leaded or followed by [and|,|;|{|}|^|$]) Pattern pattern = Pattern.compile( "(?<=(and|,|;|\\{|^))([\\w|\\s]*?Team[\\w|\\s]*?)(?=(and|,|;|\\}|$))", Pattern.DOTALL); Matcher matcher = pattern.matcher(editorString); String matchedGroup; while (matcher.find()) { matchedGroup = matcher.group(); // remove matchedGroup (and prefix/suffix) from authorString if (editorString.startsWith(matchedGroup)) { editorString = editorString.replaceAll(matchedGroup + "(and|,|;|\\})", ""); } else { editorString = editorString.replaceAll("(and|,|;|\\{)" + matchedGroup, ""); } // set matchedGroup as Organisation Author OrganizationVO team = new OrganizationVO(); team.setName(new TextVO(matchedGroup.trim())); CreatorVO creatorVO = new CreatorVO(team, CreatorVO.CreatorRole.EDITOR); teams.add(creatorVO); } } decoder = new AuthorDecoder(editorString, false); if (decoder.getBestFormat() != null) { List<Author> editors = decoder.getAuthorListList().get(0); for (Author editor : editors) { PersonVO personVO = new PersonVO(); personVO.setFamilyName(editor.getSurname()); if (editor.getGivenName() != null) { personVO.setGivenName(editor.getGivenName()); } else { personVO.setGivenName(editor.getInitial()); } /* * Case for MPI-KYB (Biological Cybernetics) with CoNE identifier in brackets and * affiliations to adopt from CoNE for each author (also in brackets) */ if (configuration != null && "true".equals(configuration.get("CoNE")) && ("identifier and affiliation in brackets" .equals(configuration.get("CurlyBracketsForCoNEAuthors"))) && (editor.getTags().get("identifier") != null)) { String query = editor.getTags().get("identifier"); int affiliationsCount = Integer .parseInt(editor.getTags().get("affiliationsCount")); if (affiliationsCount > 0 || configuration.get("OrganizationalUnit") != null) { for (int ouCount = 0; ouCount < (affiliationsCount > 0 ? affiliationsCount : 1); ouCount++) // 1 // is // for // the // case // configuration.get("OrganizationalUnit") // != // null { String organizationalUnit = (editor.getTags().get( "affiliation" + new Integer(ouCount).toString()) != null ? editor.getTags() .get("affiliation" + new Integer(ouCount).toString()) : (configuration.get("OrganizationalUnit") != null ? configuration.get("OrganizationalUnit") : "")); Node coneEntries = null; if (query.equals(editor.getTags().get("identifier"))) { coneEntries = Util.queryConeExactWithIdentifier("persons", query, organizationalUnit); // for MPIKYB due to OUs which do not occur in CoNE if (coneEntries.getFirstChild().getFirstChild() == null) { logger.error("No Person with Identifier (" + editor.getTags().get("identifier") + ") and OU (" + organizationalUnit + ") found in CoNE for Publication \"" + fields.get("title") + "\""); } } else { coneEntries = Util.queryConeExact("persons", query, organizationalUnit); } Node coneNode = coneEntries.getFirstChild().getFirstChild(); if (coneNode != null) { Node currentNode = coneNode.getFirstChild(); boolean first = true; while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE && first) { first = false; noConeEditorFound = false; Node coneEntry = currentNode; String coneId = coneEntry.getAttributes() .getNamedItem("rdf:about").getNodeValue(); personVO.setIdentifier( new IdentifierVO(IdType.CONE, coneId)); for (int i = 0; i < coneEntry.getChildNodes() .getLength(); i++) { Node posNode = coneEntry.getChildNodes().item(i); if ("escidoc:position" .equals(posNode.getNodeName())) { String from = null; String until = null; String name = null; String id = null; Node node = posNode.getFirstChild() .getFirstChild(); while (node != null) { if ("eprints:affiliatedInstitution" .equals(node.getNodeName())) { name = node.getFirstChild() .getNodeValue(); } else if ("escidoc:start-date" .equals(node.getNodeName())) { from = node.getFirstChild() .getNodeValue(); } else if ("escidoc:end-date" .equals(node.getNodeName())) { until = node.getFirstChild() .getNodeValue(); } else if ("dc:identifier" .equals(node.getNodeName())) { id = node.getFirstChild() .getNodeValue(); } node = node.getNextSibling(); } if (smaller(from, dateString) && smaller(dateString, until)) { OrganizationVO org = new OrganizationVO(); org.setName(new TextVO(name)); org.setIdentifier(id); personVO.getOrganizations().add(org); } } } } else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { throw new RuntimeException( "Ambigous CoNE entries for " + query); } currentNode = currentNode.getNextSibling(); } } else { throw new RuntimeException("Missing CoNE entry for " + query); } } } } /* * Case for MPI-Microstructure Physics with affiliation identifier in brackets and * affiliations to adopt from CoNE for each author (also in brackets) */ else if (configuration != null && "true".equals(configuration.get("CoNE")) && ("affiliation id in brackets" .equals(configuration.get("CurlyBracketsForCoNEAuthors"))) && (editor.getTags().get("identifier") != null)) { String identifier = editor.getTags().get("identifier"); String query = personVO.getFamilyName() + ", " + personVO.getGivenName(); if (!("extern".equals(identifier))) { Node coneEntries = null; coneEntries = Util.queryConeExact("persons", query, (configuration.get("OrganizationalUnit") != null ? configuration.get("OrganizationalUnit") : "")); Node coneNode = coneEntries.getFirstChild().getFirstChild(); if (coneNode != null) { Node currentNode = coneNode.getFirstChild(); boolean first = true; while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE && first) { first = false; noConeAuthorFound = false; Node coneEntry = currentNode; String coneId = coneEntry.getAttributes() .getNamedItem("rdf:about").getNodeValue(); personVO.setIdentifier( new IdentifierVO(IdType.CONE, coneId)); if (identifier != null && !("".equals(identifier))) { try { String ouSubTitle = identifier.substring(0, identifier.indexOf(",")); Document document = Util.queryFramework( "/oum/organizational-units?query=" + URLEncoder.encode("\"/title\"=\"" + ouSubTitle + "\"", "UTF-8")); NodeList ouList = document.getElementsByTagNameNS( "http://www.escidoc.de/schemas/organizationalunit/0.8", "organizational-unit"); Element ou = (Element) ouList.item(0); String href = ou.getAttribute("xlink:href"); String ouId = href .substring(href.lastIndexOf("/") + 1); OrganizationVO org = new OrganizationVO(); org.setName(new TextVO(identifier)); org.setIdentifier(ouId); personVO.getOrganizations().add(org); } catch (Exception e) { logger.error("Error getting OUs", e); throw new RuntimeException( "Error getting Organizational Unit for " + identifier); } } } else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { throw new RuntimeException( "Ambigous CoNE entries for " + query); } currentNode = currentNode.getNextSibling(); } } else { throw new RuntimeException("Missing CoNE entry for " + query); } } } else if (configuration != null && "true".equals(configuration.get("CoNE")) && ("empty brackets" .equals(configuration.get("CurlyBracketsForCoNEAuthors")) && (editor.getTags().get("brackets") != null))) { String query = personVO.getFamilyName() + ", " + personVO.getGivenName(); Node coneEntries = Util.queryConeExact("persons", query, (configuration.get("OrganizationalUnit") != null ? configuration.get("OrganizationalUnit") : "")); Node coneNode = coneEntries.getFirstChild().getFirstChild(); if (coneNode != null) { Node currentNode = coneNode.getFirstChild(); boolean first = true; while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE && first) { first = false; noConeEditorFound = false; Node coneEntry = currentNode; String coneId = coneEntry.getAttributes() .getNamedItem("rdf:about").getNodeValue(); personVO.setIdentifier(new IdentifierVO(IdType.CONE, coneId)); for (int i = 0; i < coneEntry.getChildNodes() .getLength(); i++) { Node posNode = coneEntry.getChildNodes().item(i); if ("escidoc:position".equals(posNode.getNodeName())) { String from = null; String until = null; String name = null; String id = null; Node node = posNode.getFirstChild().getFirstChild(); while (node != null) { if ("eprints:affiliatedInstitution" .equals(node.getNodeName())) { name = node.getFirstChild().getNodeValue(); } else if ("escidoc:start-date" .equals(node.getNodeName())) { from = node.getFirstChild().getNodeValue(); } else if ("escidoc:end-date" .equals(node.getNodeName())) { until = node.getFirstChild().getNodeValue(); } else if ("dc:identifier" .equals(node.getNodeName())) { id = node.getFirstChild().getNodeValue(); } node = node.getNextSibling(); } if (smaller(from, dateString) && smaller(dateString, until)) { OrganizationVO org = new OrganizationVO(); org.setName(new TextVO(name)); org.setIdentifier(id); personVO.getOrganizations().add(org); } } } } else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { throw new RuntimeException( "Ambigous CoNE entries for " + query); } currentNode = currentNode.getNextSibling(); } } else { throw new RuntimeException("Missing CoNE entry for " + query); } } else if (configuration != null && "true".equals(configuration.get("CoNE")) && ("no".equals(configuration.get("CurlyBracketsForCoNEAuthors")))) { String query = personVO.getFamilyName() + ", " + personVO.getGivenName(); Node coneEntries = Util.queryConeExact("persons", query, (configuration.get("OrganizationalUnit") != null ? configuration.get("OrganizationalUnit") : "")); Node coneNode = coneEntries.getFirstChild().getFirstChild(); if (coneNode != null) { Node currentNode = coneNode.getFirstChild(); boolean first = true; while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE && first) { first = false; noConeEditorFound = false; Node coneEntry = currentNode; String coneId = coneEntry.getAttributes() .getNamedItem("rdf:about").getNodeValue(); personVO.setIdentifier(new IdentifierVO(IdType.CONE, coneId)); for (int i = 0; i < coneEntry.getChildNodes() .getLength(); i++) { Node posNode = coneEntry.getChildNodes().item(i); if ("escidoc:position".equals(posNode.getNodeName())) { String from = null; String until = null; String name = null; String id = null; Node node = posNode.getFirstChild().getFirstChild(); while (node != null) { if ("eprints:affiliatedInstitution" .equals(node.getNodeName())) { name = node.getFirstChild().getNodeValue(); } else if ("escidoc:start-date" .equals(node.getNodeName())) { from = node.getFirstChild().getNodeValue(); } else if ("escidoc:end-date" .equals(node.getNodeName())) { until = node.getFirstChild().getNodeValue(); } else if ("dc:identifier" .equals(node.getNodeName())) { id = node.getFirstChild().getNodeValue(); } node = node.getNextSibling(); } if (smaller(from, dateString) && smaller(dateString, until)) { OrganizationVO org = new OrganizationVO(); org.setName(new TextVO(name)); org.setIdentifier(id); personVO.getOrganizations().add(org); } } } } else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { throw new RuntimeException( "Ambigous CoNE entries for " + query); } currentNode = currentNode.getNextSibling(); } } } /* * Case for MPI-RA (Radio Astronomy) with identifier and affiliation in brackets * This Case is using NO CoNE! */ if (configuration != null && "false".equals(configuration.get("CoNE")) && ("identifier and affiliation in brackets" .equals(configuration.get("CurlyBracketsForCoNEAuthors"))) && (editor.getTags().get("identifier") != null)) { String identifier = editor.getTags().get("identifier"); String authoAffiliation = editor.getTags().get("affiliation0"); OrganizationVO org = new OrganizationVO(); org.setName(new TextVO(authoAffiliation)); org.setIdentifier(identifier); personVO.getOrganizations().add(org); } if (affiliation != null) { OrganizationVO organization = new OrganizationVO(); organization.setIdentifier(PropertyReader .getProperty("escidoc.pubman.external.organisation.id")); organization.setName(new TextVO(affiliation)); organization.setAddress(affiliationAddress); personVO.getOrganizations().add(organization); } CreatorVO creatorVO = new CreatorVO(personVO, CreatorVO.CreatorRole.EDITOR); if ((bibGenre == BibTexUtil.Genre.article || bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.inproceedings || bibGenre == BibTexUtil.Genre.conference || bibGenre == BibTexUtil.Genre.incollection) && (sourceVO.getTitle() != null || sourceVO.getTitle().getValue() == null)) { sourceVO.getCreators().add(creatorVO); } else { mds.getCreators().add(creatorVO); } } } if (!teams.isEmpty()) { mds.getCreators().addAll(teams); } } catch (Exception e) { this.logger.error("An error occured while getting field 'editor'.", e); throw new RuntimeException(e); } } } // No CoNE Author or Editor Found if (noConeAuthorFound == true && noConeEditorFound == true && configuration != null && "true".equals(configuration.get("CoNE"))) { throw new RuntimeException("No CoNE-Author and no CoNE-Editor was found"); } // If no affiliation is given, set the first author to "external" boolean affiliationFound = false; for (CreatorVO creator : mds.getCreators()) { if (creator.getPerson() != null && creator.getPerson().getOrganizations() != null) { for (OrganizationVO organization : creator.getPerson().getOrganizations()) { if (organization.getIdentifier() != null) { affiliationFound = true; break; } } } } if (!affiliationFound && mds.getCreators().size() > 0) { OrganizationVO externalOrganization = new OrganizationVO(); externalOrganization.setName(new TextVO("External Organizations")); try { externalOrganization.setIdentifier( PropertyReader.getProperty("escidoc.pubman.external.organisation.id")); } catch (Exception e) { throw new RuntimeException("Property escidoc.pubman.external.organisation.id not found", e); } if (mds.getCreators().get(0).getPerson() != null) { mds.getCreators().get(0).getPerson().getOrganizations().add(externalOrganization); } } // Mapping of "common" (maybe relevant), non standard BibTeX Entries // abstract if (fields.get("abstract") != null) { mds.getAbstracts().add(new TextVO(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("abstract").toString()), false))); } // contents if (fields.get("contents") != null) { mds.setTableOfContents(new TextVO(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("contents").toString()), false))); } // isbn if (fields.get("isbn") != null) { if (bibGenre == BibTexUtil.Genre.inproceedings || bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.incollection || bibGenre == BibTexUtil.Genre.conference) { if (sourceVO != null) { sourceVO.getIdentifiers().add(new IdentifierVO(IdentifierVO.IdType.ISBN, BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("isbn").toString()), false))); } } else { mds.getIdentifiers().add(new IdentifierVO(IdentifierVO.IdType.ISBN, BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("isbn").toString()), false))); } } // issn if (fields.get("issn") != null) { if (bibGenre == BibTexUtil.Genre.inproceedings || bibGenre == BibTexUtil.Genre.inbook || bibGenre == BibTexUtil.Genre.incollection || bibGenre == BibTexUtil.Genre.conference) { if (sourceVO.getSources() != null && !sourceVO.getSources().isEmpty()) { sourceVO.getSources().get(0).getIdentifiers() .add(new IdentifierVO(IdentifierVO.IdType.ISSN, BibTexUtil.stripBraces( BibTexUtil.bibtexDecode(fields.get("issn").toString()), false))); } } else if (bibGenre == BibTexUtil.Genre.article) { if (sourceVO != null) { sourceVO.getIdentifiers().add(new IdentifierVO(IdentifierVO.IdType.ISSN, BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("issn").toString()), false))); } } else { mds.getIdentifiers().add(new IdentifierVO(IdentifierVO.IdType.ISSN, BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("issn").toString()), false))); } } // keywords if (fields.get("keywords") != null) { mds.setFreeKeywords(new TextVO(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("keywords").toString()), false))); } // language /* * if (fields.get("language") != null) { * mds.getLanguages().add(BibTexUtil.stripBraces(BibTexUtil.bibtexDecode(fields.get("language").toString * ()), false)); } */ // subtitle if (fields.get("subtitle") != null) { mds.getAlternativeTitles().add(new TextVO(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("subtitle").toString()), false))); } // url is now mapped to locator if (fields.get("url") != null) { // mds.getIdentifiers().add( // new IdentifierVO( // IdentifierVO.IdType.URI, // BibTexUtil.stripBraces(BibTexUtil.bibtexDecode(fields.get("url").toString()), false))); FileVO locator = new FileVO(); locator.setContent( BibTexUtil.stripBraces(BibTexUtil.bibtexDecode(fields.get("url").toString()), false)); locator.setName("Link"); locator.setStorage(FileVO.Storage.EXTERNAL_URL); locator.setVisibility(FileVO.Visibility.PUBLIC); locator.setContentCategory( "http://purl.org/escidoc/metadata/ves/content-categories/any-fulltext"); MdsFileVO metadata = new MdsFileVO(); metadata.setContentCategory( "http://purl.org/escidoc/metadata/ves/content-categories/any-fulltext"); metadata.setTitle(new TextVO("Link")); locator.getMetadataSets().add(metadata); itemVO.getFiles().add(locator); } // web_url as URI-Identifier else if (fields.get("web_url") != null) { mds.getIdentifiers().add(new IdentifierVO(IdentifierVO.IdType.URI, BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("web_url").toString()), false))); } // Prevent the creation of an empty source if (sourceVO.getTitle() != null && sourceVO.getTitle().getValue() != null && sourceVO.getTitle().getValue() != "" && sourceVO.getGenre() != null) { mds.getSources().add(sourceVO); // Prevent the creation of an empty second if (sourceVO.getSources() != null && !sourceVO.getSources().isEmpty() && sourceVO.getSources().get(0) != null && sourceVO.getSources().get(0).getTitle() != null && sourceVO.getSources().get(0).getTitle().getValue() != null && sourceVO.getSources().get(0).getTitle().getValue() != "") { mds.getSources().add(sourceVO.getSources().get(0)); } } // Prevent the creation of an empty second source if (secondSourceVO.getTitle() != null && secondSourceVO.getTitle().getValue() != null && secondSourceVO.getTitle().getValue() != "" && secondSourceVO.getGenre() != null) { mds.getSources().add(secondSourceVO); // Prevent the creation of an empty second if (secondSourceVO.getSources() != null && !secondSourceVO.getSources().isEmpty() && secondSourceVO.getSources().get(0) != null && secondSourceVO.getSources().get(0).getTitle() != null && secondSourceVO.getSources().get(0).getTitle().getValue() != null && secondSourceVO.getSources().get(0).getTitle().getValue() != "") { mds.getSources().add(secondSourceVO.getSources().get(0)); } } // New mapping for MPIS // DOI if (fields.get("doi") != null) { mds.getIdentifiers().add(new IdentifierVO(IdentifierVO.IdType.DOI, BibTexUtil.stripBraces(BibTexUtil.bibtexDecode(fields.get("doi").toString()), false))); } // eid if (fields.get("eid") != null) { if (mds.getSources().size() == 1) { mds.getSources().get(0).setSequenceNumber(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("eid").toString()), false)); } } // rev if (fields.get("rev") != null) { if ("Peer".equals( BibTexUtil.stripBraces(BibTexUtil.bibtexDecode(fields.get("rev").toString()), false))) { mds.setReviewMethod(ReviewMethod.PEER); } else if ("No review".equals( BibTexUtil.stripBraces(BibTexUtil.bibtexDecode(fields.get("rev").toString()), false))) { mds.setReviewMethod(ReviewMethod.NO_REVIEW); } } // MPG-Affil if (fields.get("MPG-Affil") != null) { if ("Peer".equals(BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("MPG-Affil").toString()), false))) { // TODO } } // MPIS Groups if (fields.get("group") != null) { String[] groups = BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("group").toString()), false).split(","); for (String group : groups) { group = group.trim(); if (!"".equals(group)) { if (groupSet == null) { try { groupSet = loadGroupSet(); } catch (Exception e) { throw new RuntimeException(e); } } if (!groupSet.contains(group)) { throw new RuntimeException("Group '" + group + "' not found."); } mds.getSubjects() .add(new TextVO(group, null, SubjectClassification.MPIS_GROUPS.toString())); } } } // MPIS Projects if (fields.get("project") != null) { String[] projects = BibTexUtil .stripBraces(BibTexUtil.bibtexDecode(fields.get("project").toString()), false) .split(","); for (String project : projects) { project = project.trim(); if (!"".equals(project)) { if (projectSet == null) { try { projectSet = loadProjectSet(); } catch (Exception e) { throw new RuntimeException(e); } } if (!projectSet.contains(project)) { throw new RuntimeException("Project '" + project + "' not found."); } mds.getSubjects() .add(new TextVO(project, null, SubjectClassification.MPIS_PROJECTS.toString())); } } } // Cite Key mds.getIdentifiers().add(new IdentifierVO(IdType.BIBTEX_CITEKEY, entry.getEntryKey())); } else if (object instanceof BibtexToplevelComment) { this.logger.debug("Comment found: " + ((BibtexToplevelComment) object).getContent()); } } XmlTransforming xmlTransforming = new XmlTransformingBean(); try { if (entryFound) { return xmlTransforming.transformToItem(itemVO); } else { this.logger.warn("No entry found in BibTex record."); throw new RuntimeException(); } } catch (TechnicalException e) { this.logger.error("An error ocurred while transforming the item."); throw new RuntimeException(e); } }
From source file:org.apache.synapse.mediators.transform.PayloadFactoryMediator.java
/** * Replaces the payload format with property values from messageContext. * * @param format/*ww w.j a va 2 s.c o m*/ * @param resultCTX * @param synCtx */ private void replaceCTX(String format, StringBuffer resultCTX, MessageContext synCtx) { Matcher ctxMatcher; if (mediaType != null && (mediaType.equals(JSON_TYPE) || mediaType.equals(TEXT_TYPE))) { ctxMatcher = ctxPattern.matcher(format); } else { ctxMatcher = ctxPattern.matcher("<pfPadding>" + format + "</pfPadding>"); } while (ctxMatcher.find()) { String ctxMatchSeq = ctxMatcher.group(); String expressionTxt = ctxMatchSeq.substring(5, ctxMatchSeq.length()); String replaceValue = synCtx.getProperty(expressionTxt).toString(); if (mediaType.equals(JSON_TYPE) && inferReplacementType(replaceValue).equals(XML_TYPE)) { // XML to JSON conversion here try { replaceValue = "<jsonObject>" + replaceValue + "</jsonObject>"; OMElement omXML = AXIOMUtil.stringToOM(replaceValue); replaceValue = JsonUtil.toJsonString(omXML).toString(); } catch (XMLStreamException e) { handleException( "Error parsing XML for JSON conversion, please check your property values return valid XML: ", synCtx); } catch (AxisFault e) { handleException("Error converting XML to JSON", synCtx); } } else if (mediaType.equals(XML_TYPE) && inferReplacementType(replaceValue).equals(JSON_TYPE)) { // JSON to XML conversion here try { OMElement omXML = JsonUtil.toXml(IOUtils.toInputStream(replaceValue), false); if (JsonUtil.isAJsonPayloadElement(omXML)) { // remove <jsonObject/> from result. Iterator children = omXML.getChildElements(); String childrenStr = ""; while (children.hasNext()) { childrenStr += (children.next()).toString().trim(); } replaceValue = childrenStr; } else { replaceValue = omXML.toString(); } } catch (AxisFault e) { handleException( "Error converting JSON to XML, please check your property values return valid JSON: ", synCtx); } } ctxMatcher.appendReplacement(resultCTX, replaceValue); } ctxMatcher.appendTail(resultCTX); }