public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException {

    final String value = req.getParameter(P_VALUE);
    NodeRef nodeRef = null;
    if (null != value && NodeRef.isNodeRef(value)) {
      nodeRef = new NodeRef(value);
    }

    final String engine = req.getParameter(P_ENGINE);

    String mimetype = req.getParameter(P_MIMETYPE);
    mimetype = null == mimetype ? D_MIMETYPE : mimetype;

    final ByteArrayOutputStream output = new ByteArrayOutputStream();

    if (req.getServerPath().contains("/new")) {

      final String reference = referenceProviderService.getNewReference(engine, null);
      generateBarcode(reference, output, mimetype);

    } else {

      String barcodeValue = value;

      if (null != nodeRef) {
        barcodeValue = referenceProviderService.getExistingReference(nodeRef);
      }

      if (null != value && !value.isEmpty()) {
        generateBarcode(barcodeValue, output, mimetype);
      } else {
        logger.debug(String.format("No barcode generated for value '%s'", value));
      }
    }

    res.setContentType(mimetype);
    // res.setContentEncoding(reader.getEncoding());
    res.setHeader("Content-Length", Long.toString(output.size()));

    // get the content and stream directly to the response output stream
    // assuming the repository is capable of streaming in chunks, this should allow large files
    // to be streamed directly to the browser response stream.
    try {
      res.getOutputStream().write(output.toByteArray());
    } catch (SocketException e1) {
      // the client cut the connection - our mission was accomplished apart from a little error
      // message
      if (logger.isInfoEnabled()) logger.info("Client aborted stream read.");
    } catch (ContentIOException e2) {
      if (logger.isInfoEnabled()) logger.info("Client aborted stream read.");
    }
  }
  /*
   * Extract favourite nodes of the given type from the comma-separated list in "nodes".
   */
  private Map<PersonFavouriteKey, PersonFavourite> extractFavouriteNodes(
      String userName, Type type, String nodes) {
    PrefKeys prefKeys = getPrefKeys(type);
    Map<PersonFavouriteKey, PersonFavourite> favouriteNodes =
        new HashMap<PersonFavouriteKey, PersonFavourite>();

    StringTokenizer st = new StringTokenizer(nodes, ",");
    while (st.hasMoreTokens()) {
      String nodeRefStr = st.nextToken();
      nodeRefStr = nodeRefStr.trim();
      if (!NodeRef.isNodeRef((String) nodeRefStr)) {
        continue;
      }

      NodeRef nodeRef = new NodeRef((String) nodeRefStr);

      if (!nodeService.exists(nodeRef)) {
        continue;
      }

      if (permissionService.hasPermission(nodeRef, PermissionService.READ_PROPERTIES)
          == AccessStatus.DENIED) {
        continue;
      }

      // get createdAt for this favourited node
      // use ISO8601
      StringBuilder builder = new StringBuilder(prefKeys.getAlfrescoPrefKey());
      builder.append(nodeRef.toString());
      builder.append(".createdAt");
      String prefKey = builder.toString();
      String createdAtStr = (String) preferenceService.getPreference(userName, prefKey);
      Date createdAt = (createdAtStr != null ? ISO8601DateFormat.parse(createdAtStr) : null);

      String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);

      PersonFavourite personFavourite =
          new PersonFavourite(userName, nodeRef, type, name, createdAt);
      PersonFavouriteKey key = personFavourite.getKey();
      favouriteNodes.put(key, personFavourite);
    }

    return favouriteNodes;
  }
  @Override
  protected void processAssociationPersist(
      NodeRef nodeRef,
      Map<QName, AssociationDefinition> assocDefs,
      Map<QName, ChildAssociationDefinition> childAssocDefs,
      FieldData fieldData,
      List<org.alfresco.repo.forms.processor.node.AbstractAssocCommand> assocCommands) {
    if (getLogger().isDebugEnabled())
      getLogger().debug("Processing field " + fieldData + " for association persistence");

    String fieldName = fieldData.getName();
    Matcher m =
        this.associationNamePattern.matcher(
            fieldName.replaceAll(DOT_CHARACTER_REPLACEMENT, DOT_CHARACTER));
    if (m.matches()) {
      String qNamePrefix = m.group(1);
      String localName = m.group(2);
      String assocSuffix = m.group(3);

      QName fullQName = QName.createQName(qNamePrefix, localName, namespaceService);

      // ensure that the association being persisted is defined in the model
      AssociationDefinition assocDef = assocDefs.get(fullQName);

      // TODO: if the association is not defined on the node, check for the association
      // in all models, however, the source of an association can be critical so we
      // can't just look up the association in the model regardless. We need to
      // either check the source class of the node and the assoc def match or we
      // check that the association was defined as part of an aspect (where by it's
      // nature can have any source type)

      // SIDE : since forms and model are generated by SIDE we make the assertion that fields are
      // valid, so no advanced validation are done
      if (assocDef == null) {
        if (getLogger().isWarnEnabled()) {
          getLogger()
              .debug(
                  "Field '"
                      + fieldName
                      + "' as an association definition can not be found in the current model");
        }
        assocDef = this.dictionaryService.getAssociation(fullQName);

        if (assocDef == null) {
          if (getLogger().isWarnEnabled()) {
            getLogger()
                .warn(
                    "Ignoring field '"
                        + fieldName
                        + "' as an association definition can not be found in ANY models ");
          }
          return;
        } else {
          if (getLogger().isDebugEnabled()) {
            getLogger()
                .debug(
                    "Field '"
                        + fieldName
                        + "' Found as an association definition in another model : "
                        + assocDef.getModel().getName());
          }
        }
      }

      String value = (String) fieldData.getValue();
      String[] nodeRefs = value.split(",");

      // Each element in this array will be a new target node in association
      // with the current node.
      for (String nextTargetNode : nodeRefs) {
        if (nextTargetNode.length() > 0) {
          if (NodeRef.isNodeRef(nextTargetNode)) {
            if (assocSuffix.equals(ASSOC_DATA_ADDED_SUFFIX)) {
              if (assocDef.isChild()) {
                assocCommands.add(
                    new AddChildAssocCommand(nodeRef, new NodeRef(nextTargetNode), fullQName));
              } else {
                assocCommands.add(
                    new AddAssocCommand(nodeRef, new NodeRef(nextTargetNode), fullQName));
              }
            } else if (assocSuffix.equals(ASSOC_DATA_REMOVED_SUFFIX)) {
              if (assocDef.isChild()) {
                assocCommands.add(
                    new RemoveChildAssocCommand(nodeRef, new NodeRef(nextTargetNode), fullQName));
              } else {
                assocCommands.add(
                    new RemoveAssocCommand(nodeRef, new NodeRef(nextTargetNode), fullQName));
              }
            } else {
              if (getLogger().isWarnEnabled()) {
                StringBuilder msg = new StringBuilder();
                msg.append("Ignoring 'fieldName ")
                    .append(fieldName)
                    .append("' as it does not have one of the expected suffixes (")
                    .append(ASSOC_DATA_ADDED_SUFFIX)
                    .append(" or ")
                    .append(ASSOC_DATA_REMOVED_SUFFIX)
                    .append(")");
                getLogger().warn(msg.toString());
              }
            }
          } else {
            if (getLogger().isWarnEnabled()) {
              StringBuilder msg = new StringBuilder();
              msg.append("targetNode ")
                  .append(nextTargetNode)
                  .append(" is not a valid NodeRef and has been ignored.");
              getLogger().warn(msg.toString());
            }
          }
        }
      }
    } else if (getLogger().isWarnEnabled()) {
      getLogger().warn("Ignoring unrecognised field '" + fieldName + "'");
    }
  }