Example usage for org.w3c.dom Node getNextSibling

List of usage examples for org.w3c.dom Node getNextSibling

Introduction

In this page you can find the example usage for org.w3c.dom Node getNextSibling.

Prototype

public Node getNextSibling();

Source Link

Document

The node immediately following this node.

Usage

From source file:com.enonic.vertical.adminweb.MenuHandlerServlet.java

private void moveMenuItemDown(HttpServletRequest request, HttpServletResponse response, HttpSession session,
        ExtendedMap formItems) throws VerticalAdminException {

    String menuXML = (String) session.getAttribute("menuxml");
    Document doc = XMLTool.domparse(menuXML);

    String xpath = "/model/menuitems-to-list//menuitem[@key = '" + formItems.getString("key") + "']";
    Element movingMenuItemElement = (Element) XMLTool.selectNode(doc, xpath);

    Element parentElement = (Element) movingMenuItemElement.getParentNode();
    Node nextSiblingElement = movingMenuItemElement.getNextSibling();

    movingMenuItemElement = (Element) parentElement.removeChild(movingMenuItemElement);
    doc.importNode(movingMenuItemElement, true);

    if (nextSiblingElement != null) {
        // spool forward...
        for (nextSiblingElement = nextSiblingElement.getNextSibling(); (nextSiblingElement != null
                && nextSiblingElement
                        .getNodeType() != Node.ELEMENT_NODE); nextSiblingElement = nextSiblingElement
                                .getNextSibling()) {

        }/*  w ww  .j av  a  2s.  co m*/

        if (nextSiblingElement != null) {
            parentElement.insertBefore(movingMenuItemElement, nextSiblingElement);
        } else {
            parentElement.appendChild(movingMenuItemElement);
        }
    } else {
        // This is the bottom element, move it to the top
        parentElement.insertBefore(movingMenuItemElement, parentElement.getFirstChild());
    }

    session.setAttribute("menuxml", XMLTool.documentToString(doc));

    MultiValueMap queryParams = new MultiValueMap();
    queryParams.put("page", formItems.get("page"));
    queryParams.put("op", "browse");
    queryParams.put("keepxml", "yes");
    queryParams.put("highlight", formItems.get("key"));
    queryParams.put("menukey", formItems.get("menukey"));
    queryParams.put("parentmi", formItems.get("parentmi"));
    queryParams.put("subop", "shiftmenuitems");

    queryParams.put("move_menuitem", formItems.getString("move_menuitem", ""));
    queryParams.put("move_from_parent", formItems.getString("move_from_parent", ""));
    queryParams.put("move_to_parent", formItems.getString("move_to_parent", ""));

    redirectClientToAdminPath("adminpage", queryParams, request, response);
}

From source file:org.gvnix.service.roo.addon.addon.ws.WSConfigServiceImpl.java

/**
 * {@inheritDoc}//from w  w w.j  ava  2 s  .com
 */
public void addToJava2wsPlugin(JavaType serviceClass, String serviceName, String addressName,
        String fullyQualifiedTypeName) {

    // Get pom
    String pomPath = getPomFilePath();
    Validate.isTrue(pomPath != null, "Cxf configuration file not found, export again the service.");
    MutableFile pomMutableFile = getFileManager().updateFile(pomPath);
    Document pom = getInputDocument(pomMutableFile.getInputStream());
    Element root = pom.getDocumentElement();

    // Gets java2ws plugin element
    Element jaxWsPlugin = XmlUtils.findFirstElement(
            "/project/build/plugins/plugin[groupId='org.apache.cxf' and artifactId='cxf-java2ws-plugin']",
            root);

    // Install it if it's missing
    if (jaxWsPlugin == null) {

        logger.log(Level.INFO, "Jax-Ws plugin is not defined in the pom.xml. Installing in project.");
        // Installs jax2ws plugin.
        addPlugin();
    }

    // Checks if already exists the execution.
    Element serviceExecution = XmlUtils
            .findFirstElement("/project/build/plugins/plugin/executions/execution/configuration[className='"
                    .concat(serviceClass.getFullyQualifiedTypeName()).concat("']"), root);

    if (serviceExecution != null) {
        logger.log(Level.FINE, "A previous Wsdl generation with CXF plugin for '".concat(serviceName)
                .concat("' service has been found."));
        return;
    }

    // Checks if name of java class has been changed comparing current
    // service class and name declared in annotation
    boolean classNameChanged = false;
    if (!serviceClass.getFullyQualifiedTypeName().contentEquals(fullyQualifiedTypeName)) {
        classNameChanged = true;
    }

    // if class has been changed (package or name) update execution
    if (classNameChanged) {
        serviceExecution = XmlUtils
                .findFirstElement("/project/build/plugins/plugin/executions/execution/configuration[className='"
                        .concat(fullyQualifiedTypeName).concat("']"), root);

        // Update with serviceClass.getFullyQualifiedTypeName().
        if (serviceExecution != null && serviceExecution.hasChildNodes()) {

            Node updateServiceExecution;
            updateServiceExecution = (serviceExecution.getFirstChild() != null)
                    ? serviceExecution.getFirstChild().getNextSibling()
                    : null;

            // Find node which contains old class name
            while (updateServiceExecution != null) {

                if (updateServiceExecution.getNodeName().contentEquals("className")) {
                    // Update node content with new value
                    updateServiceExecution.setTextContent(serviceClass.getFullyQualifiedTypeName());

                    // write pom
                    XmlUtils.writeXml(pomMutableFile.getOutputStream(), pom);
                    logger.log(Level.INFO,
                            "Wsdl generation with CXF plugin for '" + serviceName
                                    + " service, updated className attribute for '"
                                    + serviceClass.getFullyQualifiedTypeName() + "'.");
                    // That's all
                    return;
                }

                // Check next node.
                updateServiceExecution = updateServiceExecution.getNextSibling();

            }
        }
    }

    // Prepare Execution configuration
    String executionID = "${project.basedir}/src/test/resources/generated/wsdl/".concat(addressName)
            .concat(".wsdl");
    serviceExecution = createJava2wsExecutionElement(pom, serviceClass, addressName, executionID);

    // Checks if already exists the execution.

    // XXX ??? this is hard difficult because previously it's already
    // checked
    // using class name
    Element oldExecution = XmlUtils.findFirstElement(
            "/project/build/plugins/plugin/executions/execution[id='" + executionID + "']", root);

    if (oldExecution != null) {
        logger.log(Level.FINE, "Wsdl generation with CXF plugin for '" + serviceName
                + " service, has been configured before.");
        return;
    }

    // Checks if already exists the executions to update or create.
    Element oldExecutions = DomUtils.findFirstElementByName(EXECUTIONS, jaxWsPlugin);

    Element newExecutions;

    // To Update execution definitions It must be replaced in pom.xml to
    // maintain the format.
    if (oldExecutions != null) {
        newExecutions = oldExecutions;
        newExecutions.appendChild(serviceExecution);
        oldExecutions.getParentNode().replaceChild(oldExecutions, newExecutions);
    } else {
        newExecutions = pom.createElement(EXECUTIONS);
        newExecutions.appendChild(serviceExecution);

        jaxWsPlugin.appendChild(newExecutions);
    }

    XmlUtils.writeXml(pomMutableFile.getOutputStream(), pom);
}

From source file:com.globalsight.everest.tda.TdaHelper.java

private void domNodeVisitor(Node p_node, ArrayList matchList, long tmProfileThreshold) {
    HashMap TDAResults = new HashMap();
    LeverageTDAResult tdaResult = null;/*from   w ww.java 2  s  .  c om*/

    if (matchList.size() > 0) {
        tdaResult = (LeverageTDAResult) matchList.get(matchList.size() - 1);
    }

    while (true) {
        if (p_node == null) {
            return;
        }

        switch (p_node.getNodeType()) {
        case Node.DOCUMENT_NODE:
            domNodeVisitor(p_node.getFirstChild(), matchList, tmProfileThreshold);
            return;
        case Node.ELEMENT_NODE:
            String nodeName = p_node.getNodeName().toLowerCase();

            if (nodeName.equals("alt-trans")) {
                String tuid = "-1";

                NamedNodeMap parentAttrs = p_node.getParentNode().getAttributes();

                for (int i = 0; i < parentAttrs.getLength(); ++i) {
                    Node att = parentAttrs.item(i);
                    String attname = att.getNodeName();
                    String value = att.getNodeValue();

                    if (attname.equals("id")) {
                        tuid = value;
                    }
                }

                NamedNodeMap attrs = p_node.getAttributes();
                boolean fromTDA = false;
                String percentValue = "";

                for (int i = 0; i < attrs.getLength(); ++i) {
                    Node att = attrs.item(i);
                    String attname = att.getNodeName();
                    String value = att.getNodeValue();

                    if (attname.equals("tda:provider")) {
                        fromTDA = true;
                    }

                    if (attname.equals("match-quality")) {
                        percentValue = value;
                    }

                }

                if (fromTDA) {
                    if (PecentToInt(percentValue) > tmProfileThreshold
                            || PecentToInt(percentValue) == tmProfileThreshold) {
                        tdaResult = new LeverageTDAResult();
                        tdaResult.setTuid(Long.parseLong(tuid));
                        tdaResult.setMatchPercent(percentValue);
                        matchList.add(tdaResult);
                    } else {
                        p_node = p_node.getNextSibling();
                        break;
                    }
                }
            }

            domNodeVisitor(p_node.getFirstChild(), matchList, tmProfileThreshold);
            p_node = p_node.getNextSibling();
            break;
        case Node.TEXT_NODE:
            nodeName = p_node.getNodeName().toLowerCase();

            if (p_node.getParentNode() != null && p_node.getParentNode().getParentNode() != null) {
                String parentNodeName = p_node.getParentNode().getNodeName().toLowerCase();
                String grandNodeName = p_node.getParentNode().getParentNode().getNodeName().toLowerCase();

                if (grandNodeName.equals("alt-trans") && parentNodeName.equals("target")) {
                    if (tdaResult != null) {
                        tdaResult.setResultText(p_node.getNodeValue());
                    }
                } else if (grandNodeName.equals("alt-trans") && parentNodeName.equals("source")) {
                    if (tdaResult != null) {
                        tdaResult.setSourceText(p_node.getNodeValue());
                    }
                }
            }

            p_node = p_node.getNextSibling();
            break;
        }
    }
}

From source file:de.escidoc.core.test.EscidocTestBase.java

/**
 * Adds the provided new node after the element selected by the xPath in the given node.
 * /*  www  .  j  a  v a  2s.c o  m*/
 * @param node
 *            The node.
 * @param xPath
 *            The xPath.
 * @param newNode
 *            The new node.
 * @return The resulting node after the substitution.
 * @throws Exception
 *             If anything fails.
 */
public static Node addAfter(final Node node, final String xPath, final Node newNode) throws Exception {

    Node result = node;
    Node before = selectSingleNode(result, xPath);
    assertNotNull("No node for xpath [" + xPath + "] found", before);
    Node parent = before.getParentNode();
    parent.insertBefore(newNode, before.getNextSibling());
    return result;
}

From source file:de.escidoc.core.test.EscidocTestBase.java

/**
 * Gets the root element of the provided document.
 * //from w w w  .  ja v a  2s  . co m
 * @param doc
 *            The document to get the root element from.
 * @return Returns the first child of the document htat is an element node.
 * @throws Exception
 *             If anything fails.
 */
public static Element getRootElement(final Document doc) throws Exception {

    Node node = doc.getFirstChild();
    while (node != null) {
        if (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
            return (Element) node;
        }
        node = node.getNextSibling();
    }
    return null;
}

From source file:DOMProcessor.java

/** Converts the given DOM node into XML. Recursively converts
  * any child nodes. This version allows the XML version, encoding and stand-alone
  * status to be set.//from w w w.j  av a2 s.c  om
  * @param node DOM Node to display.
  * @param version XML version, or null if default ('1.0') is to be used.
  * @param encoding XML encoding, or null if encoding is not to be specified.
  * @param standalone XML stand-alone status or null if not to be specified.
  */
private void outputNodeAsXML(Node node, String version, String encoding, Boolean standalone) {
    // Store node name, type and value.
    String name = node.getNodeName(), value = makeFriendly(node.getNodeValue());
    int type = node.getNodeType();

    // Ignore empty nodes (e.g. blank lines etc.)
    if ((value != null) && (value.trim().equals(""))) {
        return;
    }

    switch (type) {
    case Node.DOCUMENT_NODE: // Start of document.
    {
        if (version == null) {
            out.print("<?xml version=\"1.0\" ");
        } else {
            out.print("<?xml version=\"" + version + "\" ");
        }

        if (encoding != null) {
            out.print("encoding=\"" + encoding + "\" ");
        }

        if (standalone != null) {
            if (standalone.booleanValue()) {
                out.print("standalone=\"yes\" ");
            } else {
                out.print("standalone=\"no\" ");
            }
        }

        out.println("?>");

        // Output the document's child nodes.
        NodeList children = node.getChildNodes();

        for (int i = 0; i < children.getLength(); i++) {
            outputNodeAsXML(children.item(i));
        }
        break;
    }

    case Node.ELEMENT_NODE: // Document element with attributes.
    {
        // Output opening element tag.
        indent++;
        indent();
        out.print("<" + name);

        // Output any attributes the element might have.
        NamedNodeMap attributes = node.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
            Node attribute = attributes.item(i);
            out.print(" " + attribute.getNodeName() + "=\"" + attribute.getNodeValue() + "\"");
        }
        out.print(">");

        // Output any child nodes that exist.                    
        NodeList children = node.getChildNodes();

        for (int i = 0; i < children.getLength(); i++) {
            outputNodeAsXML(children.item(i));
        }

        break;
    }

    case Node.CDATA_SECTION_NODE: // Display text.
    case Node.TEXT_NODE: {
        out.print(value);
        break;
    }

    case Node.COMMENT_NODE: // Comment node.
    {
        indent++;
        indent();
        out.print("<!--" + value + "-->");
        indent--;
        break;
    }

    case Node.ENTITY_REFERENCE_NODE: // Entity reference nodes.
    {
        indent++;
        indent();
        out.print("&" + name + ";");
        indent--;
        break;
    }

    case Node.PROCESSING_INSTRUCTION_NODE: // Processing instruction.
    {
        indent++;
        indent();
        out.print("<?" + name);
        if ((value != null) && (value.length() > 0)) {
            out.print(" " + value);
        }
        out.println("?>");
        indent--;
        break;
    }
    }

    // Finally output closing tags for each element.
    if (type == Node.ELEMENT_NODE) {
        out.print("</" + node.getNodeName() + ">");
        indent--;
        if (node.getNextSibling() == null) {
            indent(); // Only throw new line if this is the last sibling.
        }
    }
}

From source file:de.mpg.mpdl.inge.transformation.transformations.commonPublicationFormats.Bibtex.java

/**
 * @param bibtex//www  . j ava 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();
            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:com.portfolio.rest.RestServicePortfolio.java

@Path("/nodes/node/{node-id}/rights")
@POST/*  w ww. j  av a  2  s.  c o m*/
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes(MediaType.APPLICATION_XML)
public String postNodeRights(String xmlNode, @CookieParam("user") String user,
        @CookieParam("credential") String token, @QueryParam("group") int groupId,
        @PathParam("node-id") String nodeUuid, @Context ServletConfig sc,
        @Context HttpServletRequest httpServletRequest, @HeaderParam("Accept") String accept,
        @QueryParam("user") Integer userId) {
    UserInfo ui = checkCredential(httpServletRequest, user, token, null);

    try {
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        Document doc = documentBuilder.parse(new ByteArrayInputStream(xmlNode.getBytes("UTF-8")));

        XPath xPath = XPathFactory.newInstance().newXPath();
        String xpathRole = "//role";
        XPathExpression findRole = xPath.compile(xpathRole);
        NodeList roles = (NodeList) findRole.evaluate(doc, XPathConstants.NODESET);

        /// For all roles we have to change
        for (int i = 0; i < roles.getLength(); ++i) {
            Node rolenode = roles.item(i);
            String rolename = rolenode.getAttributes().getNamedItem("name").getNodeValue();
            Node right = rolenode.getFirstChild();

            //
            if ("user".equals(rolename)) {
                /// username as role
            }

            if ("#text".equals(right.getNodeName()))
                right = right.getNextSibling();

            if ("right".equals(right.getNodeName())) // Changing node rights
            {
                NamedNodeMap rights = right.getAttributes();

                NodeRight noderight = new NodeRight(null, null, null, null, null, null);

                String val = rights.getNamedItem("RD").getNodeValue();
                if (val != null)
                    noderight.read = "Y".equals(val) ? true : false;
                val = rights.getNamedItem("WR").getNodeValue();
                if (val != null)
                    noderight.write = "Y".equals(val) ? true : false;
                val = rights.getNamedItem("DL").getNodeValue();
                if (val != null)
                    noderight.delete = "Y".equals(val) ? true : false;
                val = rights.getNamedItem("SB").getNodeValue();
                if (val != null)
                    noderight.submit = "Y".equals(val) ? true : false;

                // change right
                dataProvider.postRights(ui.userId, nodeUuid, rolename, noderight);
            } else if ("action".equals(right.getNodeName())) // Using an action on node
            {
                // reset right
                dataProvider.postMacroOnNode(ui.userId, nodeUuid, "reset");
            }
        }

        //         returnValue = dataProvider.postRRGCreate(ui.userId, xmlNode);
        logRestRequest(httpServletRequest, xmlNode, "Change rights", Status.OK.getStatusCode());
    } catch (RestWebApplicationException ex) {
        throw new RestWebApplicationException(Status.FORBIDDEN, ex.getResponse().getEntity().toString());
    } catch (NullPointerException ex) {
        logRestRequest(httpServletRequest, null, null, Status.NOT_FOUND.getStatusCode());

        throw new RestWebApplicationException(Status.NOT_FOUND, "Node " + nodeUuid + " not found");
    } catch (Exception ex) {
        ex.printStackTrace();
        logRestRequest(httpServletRequest, null, ex.getMessage() + "\n\n" + javaUtils.getCompleteStackTrace(ex),
                Status.INTERNAL_SERVER_ERROR.getStatusCode());

        throw new RestWebApplicationException(Status.INTERNAL_SERVER_ERROR, ex.getMessage());
    } finally {
        dataProvider.disconnect();
    }

    return "";
}

From source file:de.mpg.escidoc.services.transformation.transformations.commonPublicationFormats.Bibtex.java

/**
 * @param bibtex//from w  w  w . j  a  va2s .  com
 * @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);
    }
}