Package com.google.enterprise.connector.spi

Examples of com.google.enterprise.connector.spi.Value


   */
  public void setLastModifiedDate(String propertyName, Timestamp propertyValue) {
    if (propertyValue != null) {
      Calendar cal = Calendar.getInstance();
      cal.setTimeInMillis(propertyValue.getTime());
      Value value = Value.getDateValue(cal);
      properties.put(propertyName, ImmutableList.of(value));
      try {
        jsonObject.put(propertyName, value.toString());
      } catch (JSONException e) {
        LOG.warning("Exception for " + propertyName + " with value "
            + propertyValue + "\n" + e.toString());
      }
    }
View Full Code Here


    {
      MockRepositoryProperty testProp = pl.getProperty("xyzzy");
      MockJcrProperty testJCRProp = new MockJcrProperty(testProp);
      Property p = new JcrProperty(testJCRProp);
      Value v = p.nextValue();
      Assert.assertEquals("skeedle", v.toString());
    }

    {
      MockRepositoryProperty testProp = pl.getProperty("baz");
      MockJcrProperty testJCRProp = new MockJcrProperty(testProp);
      Property p = new JcrProperty(testJCRProp);
      Value v = p.nextValue();
      Assert.assertEquals("42", v.toString());
    }

    {
      MockRepositoryProperty testProp = pl.getProperty("abc");
      MockJcrProperty testJCRProp = new MockJcrProperty(testProp);
      Property p = new JcrProperty(testJCRProp);
      int counter = 0;
      Value v = null;
      while ((v = p.nextValue()) != null) {
        String res = v.toString();
        switch (counter) {
        case 0:
          Assert.assertEquals("2", res);
          break;
        case 1:
          Assert.assertEquals("3", res);
          break;
        case 2:
          Assert.assertEquals("5", res);
          break;
        case 3:
          Assert.assertEquals("7", res);
          break;
        case 4:
          Assert.assertEquals("11", res);
          break;
        }
        counter++;
      }
      Assert.assertEquals(5, counter);
    }

    {
      // TODO: date test
    }

    {
      MockRepositoryProperty testProp = pl.getProperty("ghi");
      MockJcrProperty testJCRProp = new MockJcrProperty(testProp);
      Property p = new JcrProperty(testJCRProp);
      Value v = p.nextValue();
      Assert.assertNull(v);
    }

  }
View Full Code Here

    }
  }

  private void validateProperty(Document document, String name,
      String expectedValue) throws RepositoryException {
    Value v = document.findProperty(name).nextValue();
    if (v instanceof BinaryValue) {
      // Note this won't work for streams that originate as binary files or
      // documents since the call to streamToString() will mangle the
      // characters.  For this test case, all these originate as plain text.
      assertEquals(expectedValue,
          StringUtils.streamToString(((BinaryValue) v).getInputStream()));
    } else {
      assertEquals(expectedValue, v.toString());
    }
  }
View Full Code Here

    int counter = 0;
    System.out.println();
    for (String name : document.getPropertyNames()) {
      Property property = document.findProperty(name);
      assertNotNull(property);
      Value value = property.nextValue();
      assertNotNull(value);
      System.out.print(name);
      System.out.print("(");
      String type = value.getClass().getName();
      System.out.print(type);
      System.out.print(") ");
      String valueString = value.toString();
      System.out.print(valueString);
      System.out.println();
      counter++;
    }
    return counter;
View Full Code Here

    return new JcrDocument(node);
  }

  private void assertContainsScope(String scopeId, JcrProperty aclProp)
      throws RepositoryException {
    Value v = null;
    while ((v = aclProp.nextValue()) != null) {
      String aclScopeId = v.toString();
      if (scopeId.equals(aclScopeId)) {
        return;
      }
    }
    fail("aclProp does not contain scope (" + scopeId + ")");
View Full Code Here

    fail("aclProp does not contain scope (" + scopeId + ")");
  }

  private void assertContainsRole(String role, JcrProperty rolesProp)
      throws RepositoryException {
    Value v = null;
    // Don't assume any default roles.
    while ((v = rolesProp.nextValue()) != null) {
      String aclRole = v.toString();
      if (role.equals(aclRole)) {
        return;
      }
    }
    fail("rolesProp does not contain role=" + role);
View Full Code Here

   */
  private static Property processAclProperty(Document document,
      String aclPropName, String aclRolePrefix) throws RepositoryException {
    LinkedList<Value> acl = new LinkedList<Value>();
    Property scopeProp = document.findProperty(aclPropName);
    Value scopeVal;
    while ((scopeVal = scopeProp.nextValue()) != null) {
      Principal principal = (scopeVal instanceof PrincipalValue)
          ? ((PrincipalValue) scopeVal).getPrincipal()
          : new Principal(scopeVal.toString().trim());
      String aclScope = principal.getName();
      if (Strings.isNullOrEmpty(aclScope)) {
        continue;
      }
      Property scopeRoleProp = document.findProperty(aclRolePrefix + aclScope);
      if (scopeRoleProp != null) {
        // Add ACL Entry (scope=role pair) to the list.
        Value roleVal;
        while ((roleVal = scopeRoleProp.nextValue()) != null) {
          String role = roleVal.toString().trim();
          if (role.length() > 0) {
            acl.add(Value.getPrincipalValue(new Principal(
                principal.getPrincipalType(),
                principal.getNamespace(), aclScope + '=' + role,
                principal.getCaseSensitivityType())));
View Full Code Here

  private void processProperty(String name, Property property)
      throws RepositoryException {
    InputStream contentStream = null;
    InputStream encodedContentStream = null;
    try {
      Value v = property.nextValue();
      // if we have a contentfile property, we want to stream the InputStream
      // to demonstrate that we don't blow up memory
      if (v instanceof BinaryValue) {
        contentStream = ((BinaryValue) v).getInputStream();
        if (null != contentStream) {
          encodedContentStream = new Base64FilterInputStream(contentStream);
        }
        int totalBytesRead = 0;
        if (null != encodedContentStream) {
          int bytesRead = 0;
          byte[] b = new byte[16384];
          try {
            while (-1 != (bytesRead = encodedContentStream.read(b))) {
              totalBytesRead += bytesRead;
            }
          } catch (IOException e) {
            throw new RepositoryDocumentException(
                "Error reading content stream.", e);
          }
        }
        printStream.println("Total bytes read in base64 encoded file: "
            + totalBytesRead);
      }
      do {
        printStream.println("<" + name + ">");
        printStream.println(v.toString());
        printStream.println("</" + name + ">");
      } while ((v = property.nextValue()) != null);
    } finally {
      if (null != encodedContentStream) {
        try { encodedContentStream.close(); } catch (IOException e) {}
View Full Code Here

    Document input = ConnectorTestUtils.createSimpleDocument(props);

    Document output = createFilter(input,
        CaseSensitivityType.EVERYTHING_CASE_INSENSITIVE, null, false);
    Property prop = output.findProperty(SpiConstants.PROPNAME_ACLUSERS);
    Value value = prop.nextValue();

    Principal newPrincipal = ((PrincipalValue) value).getPrincipal();
    assertEquals(principal.getName(), newPrincipal.getName());
    assertEquals(CaseSensitivityType.EVERYTHING_CASE_INSENSITIVE,
        newPrincipal.getCaseSensitivityType());
View Full Code Here

    Document input = ConnectorTestUtils.createSimpleDocument(props);

    Document output = createFilter(input,
        CaseSensitivityType.EVERYTHING_CASE_SENSITIVE, null, false);
    Property prop = output.findProperty(SpiConstants.PROPNAME_ACLUSERS);
    Value value = prop.nextValue();

    Principal newPrincipal = ((PrincipalValue) value).getPrincipal();
    assertEquals(principal.getName(), newPrincipal.getName());
    assertTrue(newPrincipal.getCaseSensitivityType().equals(
        CaseSensitivityType.EVERYTHING_CASE_SENSITIVE));
View Full Code Here

TOP

Related Classes of com.google.enterprise.connector.spi.Value

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.