Ejemplo n.º 1
0
  private boolean processFieldDeref(
      Element fieldEl, String valueExpr, DerefValue deref, String derefPart)
      throws IndexerConfException, InterruptedException, RepositoryException {
    boolean lastFollowIsRecord;
    FieldType followField = getFieldType(derefPart, fieldEl);

    String type = followField.getValueType().getBaseName();
    if (type.equals("LIST")) {
      type = followField.getValueType().getNestedValueType().getBaseName();
    }

    if (type.equals("RECORD")) {
      deref.addRecordFieldFollow(followField);
      lastFollowIsRecord = true;
    } else if (type.equals("LINK")) {
      deref.addLinkFieldFollow(followField);
      lastFollowIsRecord = false;
    } else {
      throw new IndexerConfException(
          "Dereferencing is not possible on field of type "
              + followField.getValueType().getName()
              + ". Field: '"
              + derefPart
              + "', deref expression '"
              + valueExpr
              + "' at "
              + LocationAttributes.getLocation(fieldEl));
    }
    return lastFollowIsRecord;
  }
Ejemplo n.º 2
0
  private void processLessDimensionedVariantsDeref(
      Element fieldEl, String valueExpr, DerefValue deref, String derefPart)
      throws IndexerConfException {
    // The variant dimensions are specified in a syntax like "-var1,-var2,-var3"
    boolean validConfig = true;
    Set<String> dimensions = new HashSet<String>();
    for (String op : COMMA_SPLITTER.split(derefPart)) {
      if (op.length() > 1 && op.startsWith("-")) {
        String dimension = op.substring(1);
        dimensions.add(dimension);
      } else {
        validConfig = false;
        break;
      }
    }
    if (dimensions.size() == 0) validConfig = false;

    if (!validConfig) {
      throw new IndexerConfException(
          "Invalid specification of variants to follow: '"
              + derefPart
              + "', deref expression: '"
              + valueExpr
              + "' "
              + "at "
              + LocationAttributes.getLocation(fieldEl));
    }

    deref.addVariantFollow(dimensions);
  }
Ejemplo n.º 3
0
  private void processMoreDimensionedVariantsDeref(
      Element fieldEl, String valueExpr, DerefValue deref, String derefPart)
      throws IndexerConfException {
    // The variant dimension is specified in a syntax like "+var1=boo,+var2"
    boolean validConfig = true;
    Map<String, String> dimensions = new HashMap<String, String>();
    for (String op : COMMA_SPLITTER.split(derefPart)) {
      if (op.length() > 1 && op.startsWith("+")) {
        final Iterator<String> keyAndValue = EQUAL_SIGN_SPLITTER.split(op).iterator();
        if (keyAndValue.hasNext()) {
          final String key = keyAndValue.next().substring(1); // ignore leading '+'
          if (keyAndValue.hasNext()) {
            // there is an equal sign -> key and value
            final String value = keyAndValue.next();
            dimensions.put(key, value);
          } else {
            // no equal sign -> only key without value
            dimensions.put(key, null);
          }
        } else {
          // nothing at all?
          validConfig = false;
          break;
        }
      } else {
        validConfig = false;
        break;
      }
    }
    if (dimensions.size() == 0) validConfig = false;

    if (!validConfig) {
      throw new IndexerConfException(
          "Invalid specification of variants to follow: '"
              + derefPart
              + "', deref expression: '"
              + valueExpr
              + "' "
              + "at "
              + LocationAttributes.getLocation(fieldEl));
    }

    deref.addForwardVariantFollow(dimensions);
  }
Ejemplo n.º 4
0
  private Value buildDerefValue(
      Element fieldEl, String valueExpr, boolean extractContent, String formatter)
      throws IndexerConfException, InterruptedException, RepositoryException {

    final String[] derefParts = parseDerefParts(fieldEl, valueExpr);
    final FieldType fieldType = constructDerefFieldType(fieldEl, valueExpr, derefParts);

    final DerefValue deref = new DerefValue(fieldType, extractContent, formatter);

    //
    // Run over all children except the last
    //
    boolean lastFollowIsRecord = false;
    for (int i = 0; i < derefParts.length - 1; i++) {
      String derefPart = derefParts[i];

      // A deref expression can navigate through 5 kinds of 'links':
      //  - a link stored in a link field (detected based on presence of a colon)
      //  - a nested record
      //  - a link to the master variant (if it's the literal string 'master')
      //  - a link to a less-dimensioned variant
      //  - a link to a more-dimensioned variant

      if (derefPart.contains(":")) { // It's a field name
        lastFollowIsRecord = processFieldDeref(fieldEl, valueExpr, deref, derefPart);
      } else if (derefPart.equals("master")) { // Link to master variant
        if (lastFollowIsRecord) {
          throw new IndexerConfException(
              "In dereferencing, master cannot follow on record-type field."
                  + " Deref expression: '"
                  + valueExpr
                  + "' at "
                  + LocationAttributes.getLocation(fieldEl));
        }
        lastFollowIsRecord = false;

        deref.addMasterFollow();
      } else if (derefPart.trim().startsWith("-")) { // Link to less dimensioned variant
        if (lastFollowIsRecord) {
          throw new IndexerConfException(
              "In dereferencing, variant cannot follow on record-type field."
                  + " Deref expression: '"
                  + valueExpr
                  + "' at "
                  + LocationAttributes.getLocation(fieldEl));
        }
        lastFollowIsRecord = false;

        processLessDimensionedVariantsDeref(fieldEl, valueExpr, deref, derefPart);
      } else if (derefPart.trim().startsWith("+")) { // Link to more dimensioned variant
        if (lastFollowIsRecord) {
          throw new IndexerConfException(
              "In dereferencing, variant cannot follow on record-type field."
                  + " Deref expression: '"
                  + valueExpr
                  + "' at "
                  + LocationAttributes.getLocation(fieldEl));
        }
        lastFollowIsRecord = false;

        processMoreDimensionedVariantsDeref(fieldEl, valueExpr, deref, derefPart);
      }
    }

    deref.init(typeManager);
    return deref;
  }