Package org.apache.manifoldcf.agents.interfaces

Examples of org.apache.manifoldcf.agents.interfaces.RepositoryDocument


        Document document = (Document) cmisObject;
        long fileLength = document.getContentStreamLength();
        InputStream is = null;
       
        try {
          RepositoryDocument rd = new RepositoryDocument();
          Date createdDate = document.getCreationDate().getTime();
          Date modifiedDate = document.getLastModificationDate().getTime();
         
          rd.setFileName(document.getContentStreamFileName());
          rd.setMimeType(document.getContentStreamMimeType());
          rd.setCreatedDate(createdDate);
          rd.setModifiedDate(modifiedDate);
         
          //binary
          if(fileLength>0 && document.getContentStream()!=null){
            is = document.getContentStream().getStream();
            rd.setBinary(is, fileLength);
          }

          //properties
          List<Property<?>> properties = document.getProperties();
          String id = StringUtils.EMPTY;
          for (Property<?> property : properties) {
            String propertyId = property.getId();
            if (propertyId.endsWith(Constants.PARAM_OBJECT_ID))
              id = (String) property.getValue();

            if (property.getValue() !=null
                || property.getValues() != null) {
              PropertyType propertyType = property.getType();

              switch (propertyType) {

              case STRING:
              case ID:
              case URI:
              case HTML:
                if(property.isMultiValued()){
                  List<String> htmlPropertyValues = (List<String>) property.getValues();
                  for (String htmlPropertyValue : htmlPropertyValues) {
                    rd.addField(propertyId, htmlPropertyValue);
                  }
                } else {
                  String stringValue = (String) property.getValue();
                  if(StringUtils.isNotEmpty(stringValue)){
                    rd.addField(propertyId, stringValue);
                  }
                }
                break;
    
              case BOOLEAN:
                if(property.isMultiValued()){
                  List<Boolean> booleanPropertyValues = (List<Boolean>) property.getValues();
                  for (Boolean booleanPropertyValue : booleanPropertyValues) {
                    rd.addField(propertyId, booleanPropertyValue.toString());
                  }
                } else {
                  Boolean booleanValue = (Boolean) property.getValue();
                  if(booleanValue!=null){
                    rd.addField(propertyId, booleanValue.toString());
                  }
                }
                break;

              case INTEGER:
                if(property.isMultiValued()){
                  List<BigInteger> integerPropertyValues = (List<BigInteger>) property.getValues();
                  for (BigInteger integerPropertyValue : integerPropertyValues) {
                    rd.addField(propertyId, integerPropertyValue.toString());
                  }
                } else {
                  BigInteger integerValue = (BigInteger) property.getValue();
                  if(integerValue!=null){
                    rd.addField(propertyId, integerValue.toString());
                  }
                }
                break;

              case DECIMAL:
                if(property.isMultiValued()){
                  List<BigDecimal> decimalPropertyValues = (List<BigDecimal>) property.getValues();
                  for (BigDecimal decimalPropertyValue : decimalPropertyValues) {
                    rd.addField(propertyId, decimalPropertyValue.toString());
                  }
                } else {
                  BigDecimal decimalValue = (BigDecimal) property.getValue();
                  if(decimalValue!=null){
                    rd.addField(propertyId, decimalValue.toString());
                  }
                }
                break;

              case DATETIME:
                if(property.isMultiValued()){
                  List<GregorianCalendar> datePropertyValues = (List<GregorianCalendar>) property.getValues();
                  for (GregorianCalendar datePropertyValue : datePropertyValues) {
                    rd.addField(propertyId,
                        ISO8601_DATE_FORMATTER.format(datePropertyValue.getTime()));
                  }
                } else {
                  GregorianCalendar dateValue = (GregorianCalendar) property.getValue();
                  if(dateValue!=null){
                    rd.addField(propertyId, ISO8601_DATE_FORMATTER.format(dateValue.getTime()));
                  }
                }
                break;

              default:
View Full Code Here


              if (index < version.length() && version.charAt(index++) == '+') {
                index = unpack(denyAclBuffer,version,index,'+');
              }

              //otherwise process
              RepositoryDocument rd = new RepositoryDocument();

              // Turn into acls and add into description
              String[] aclArray = new String[acls.size()];
              for (int j = 0; j < aclArray.length; j++) {
                aclArray[j] = (String)acls.get(j);
              }
              rd.setSecurityACL(RepositoryDocument.SECURITY_TYPE_DOCUMENT,aclArray);
              if (denyAclBuffer.length() > 0) {
                String[] denyAclArray = new String[]{denyAclBuffer.toString()};
                rd.setSecurityDenyACL(RepositoryDocument.SECURITY_TYPE_DOCUMENT,denyAclArray);
              }

              // Now do standard stuff
              String mimeType = googleFile.getMimeType();
              DateTime createdDate = googleFile.getCreatedDate();
              DateTime modifiedDate = googleFile.getModifiedDate();
              String extension = googleFile.getFileExtension();
              String title = googleFile.getTitle();
             
              if (mimeType != null)
                rd.setMimeType(mimeType);
              if (createdDate != null)
                rd.setCreatedDate(new Date(createdDate.getValue()));
              if (modifiedDate != null)
                rd.setModifiedDate(new Date(modifiedDate.getValue()));
              if (extension != null)
              {
                if (title == null)
                  title = "";
                rd.setFileName(title + "." + extension);
              }

              // Get general document metadata
              for (Entry<String, Object> entry : googleFile.entrySet()) {
                rd.addField(entry.getKey(), entry.getValue().toString());
              }

              // Fire up the document reading thread
              DocumentReadingThread t = new DocumentReadingThread(documentURI);
              try {
                t.start();
                boolean wasInterrupted = false;
                try {
                  InputStream is = t.getSafeInputStream();
                  try {
                    // Can only index while background thread is running!
                    rd.setBinary(is, fileLength);
                    activities.ingestDocumentWithException(nodeId, version, documentURI, rd);
                  } finally {
                    is.close();
                  }
                } catch (ManifoldCFException e) {
View Full Code Here

          SearchMessagesThread smt = new SearchMessagesThread(session, folder, messageIDTerm);
          smt.start();
          Message[] message = smt.finishUp();

          for (Message msg : message) {
            RepositoryDocument rd = new RepositoryDocument();
            Date setDate = msg.getSentDate();
            rd.setFileName(msg.getFileName());
            is = msg.getInputStream();
            rd.setBinary(is, msg.getSize());
            String subject = StringUtils.EMPTY;
            for (String metadata : requiredMetadata) {
              if (metadata.toLowerCase().equals(EmailConfig.EMAIL_TO)) {
                Address[] to = msg.getRecipients(Message.RecipientType.TO);
                String[] toStr = new String[to.length];
                int j = 0;
                for (Address address : to) {
                  toStr[j] = address.toString();
                }
                rd.addField(EmailConfig.EMAIL_TO, toStr);
              } else if (metadata.toLowerCase().equals(EmailConfig.EMAIL_FROM)) {
                Address[] from = msg.getFrom();
                String[] fromStr = new String[from.length];
                int j = 0;
                for (Address address : from) {
                  fromStr[j] = address.toString();
                }
                rd.addField(EmailConfig.EMAIL_TO, fromStr);

              } else if (metadata.toLowerCase().equals(EmailConfig.EMAIL_SUBJECT)) {
                subject = msg.getSubject();
                rd.addField(EmailConfig.EMAIL_SUBJECT, subject);
              } else if (metadata.toLowerCase().equals(EmailConfig.EMAIL_BODY)) {
                Multipart mp = (Multipart) msg.getContent();
                for (int k = 0, n = mp.getCount(); k < n; k++) {
                  Part part = mp.getBodyPart(k);
                  String disposition = part.getDisposition();
                  if ((disposition == null)) {
                    MimeBodyPart mbp = (MimeBodyPart) part;
                    if (mbp.isMimeType(EmailConfig.MIMETYPE_TEXT_PLAIN)) {
                      rd.addField(EmailConfig.EMAIL_BODY, mbp.getContent().toString());
                    } else if (mbp.isMimeType(EmailConfig.MIMETYPE_HTML)) {
                      rd.addField(EmailConfig.EMAIL_BODY, mbp.getContent().toString()); //handle html accordingly. Returns content with html tags
                    }
                  }
                }
              } else if (metadata.toLowerCase().equals(EmailConfig.EMAIL_DATE)) {
                Date sentDate = msg.getSentDate();
                rd.addField(EmailConfig.EMAIL_DATE, sentDate.toString());
              } else if (metadata.toLowerCase().equals(EmailConfig.EMAIL_ATTACHMENT_ENCODING)) {
                Multipart mp = (Multipart) msg.getContent();
                if (mp != null) {
                  String[] encoding = new String[mp.getCount()];
                  for (int k = 0, n = mp.getCount(); k < n; k++) {
                    Part part = mp.getBodyPart(k);
                    String disposition = part.getDisposition();
                    if ((disposition != null) &&
                        ((disposition.equals(Part.ATTACHMENT) ||
                            (disposition.equals(Part.INLINE))))) {
                      encoding[k] = part.getFileName().split("\\?")[1];

                    }
                  }
                  rd.addField(EmailConfig.ENCODING_FIELD, encoding);
                }
              } else if (metadata.toLowerCase().equals(EmailConfig.EMAIL_ATTACHMENT_MIMETYPE)) {
                Multipart mp = (Multipart) msg.getContent();
                String[] MIMEType = new String[mp.getCount()];
                for (int k = 0, n = mp.getCount(); k < n; k++) {
                  Part part = mp.getBodyPart(k);
                  String disposition = part.getDisposition();
                  if ((disposition != null) &&
                      ((disposition.equals(Part.ATTACHMENT) ||
                          (disposition.equals(Part.INLINE))))) {
                    MIMEType[k] = part.getContentType();

                  }
                }
                rd.addField(EmailConfig.MIMETYPE_FIELD, MIMEType);
              }
            }
            String documentURI = makeDocumentURI(urlTemplate, folderName, id);
            activities.ingestDocumentWithException(id, version, documentURI, rd);
View Full Code Here

TOP

Related Classes of org.apache.manifoldcf.agents.interfaces.RepositoryDocument

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.