Package com.dotmarketing.portlets.structure.business

Examples of com.dotmarketing.portlets.structure.business.FieldAPI


    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols();
    otherSymbols.setDecimalSeparator('.');
   
    DecimalFormat numFormatter = new DecimalFormat("0000000000000000000.000000000000000000", otherSymbols);
   
      FieldAPI fAPI=APILocator.getFieldAPI();
      List<Field> fields = new ArrayList<Field>(FieldsCache.getFieldsByStructureInode(con.getStructureInode()));

      Structure st=con.getStructure();
        for (Field f : fields) {
            if (f.getFieldType().equals(Field.FieldType.BINARY.toString())
                    || f.getFieldContentlet() != null && f.getFieldContentlet().startsWith("system_field")) {
                continue;
            }
            if(!f.isIndexed()){
              continue;
            }
            try {
                if(fAPI.isElementConstant(f)){
                    m.put(st.getVelocityVarName() + "." + f.getVelocityVarName(), (f.getValues() == null ? "":f.getValues().toString()));
                    continue;
                }

                Object valueObj = con.get(f.getVelocityVarName());
View Full Code Here


      Field field=(Field) fieldsIt.next();
     
      String contField=field.getFieldContentlet();
      String contFieldValue=null;
      Object contFieldValueObject=null;
      FieldAPI fdAPI=APILocator.getFieldAPI();
      String velPath=(!EDIT_MODE) ? "live/" : "working/";
      if(fdAPI.isElementConstant(field)){
        if(field.getVelocityVarName().equals("widgetPreexecute")){
          continue;
        }
        if(field.getVelocityVarName().equals("widgetCode")) {
          widgetCode="#set($_dummy=$!dotcms_content_" + content.getIdentifier() + ".put(\"" + field.getVelocityVarName() + "\", $velutil.mergeTemplate(\"" + velPath + content.getInode() + "_" + field.getInode()  + "." + Config.getStringProperty("VELOCITY_FIELD_EXTENSION") + "\")))";
          continue;
        }else{
            String fv=field.getValues()!=null ? field.getValues() : "";
          if(fv.contains("$") || fv.contains("#")){
            sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("\", $velutil.mergeTemplate(\"").append(velPath).append(content.getInode()).append("_").append(field.getInode()).append(".").append(Config.getStringProperty("VELOCITY_FIELD_EXTENSION")).append("\")))");
          }else{
            sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("\", \"").append(UtilMethods.espaceForVelocity(field.getValues()).trim()).append("\"))");
          }
          continue;
        }

      }
      if (UtilMethods.isSet(contField)) {
        try {
          contFieldValueObject=conAPI.getFieldValue(content, field);
          contFieldValue=contFieldValueObject == null ? "" : contFieldValueObject.toString();
        } catch (Exception e) {
          Logger.error(ContentletMapServices.class, "writeContentletToFile: " + e.getMessage());
        }
        if (!field.getFieldType().equals(Field.FieldType.DATE_TIME.toString()) && !field.getFieldType().equals(Field.FieldType.DATE.toString())
            && !field.getFieldType().equals(Field.FieldType.TIME.toString())) {
          if (fdAPI.isNumeric(field)) {
            sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("\", ").append(contFieldValue).append("))");
          } else {
            if(contFieldValue.contains("$") || contFieldValue.contains("#")){
              sb.append("#set($_dummy=$!dotcms_content_").append(content.getIdentifier()).append(".put(\"").append(field.getVelocityVarName()).append("\", $velutil.mergeTemplate(\"").append(velPath).append(content.getInode()).append("_").append(field.getInode()).append(".").append(Config.getStringProperty("VELOCITY_FIELD_EXTENSION")).append("\")))");
            }else{
View Full Code Here

    if(!UtilMethods.isSet(field)){
      Logger.warn(FieldServices.class,"Field not found.  Unable to load velocity code");
      return new ByteArrayInputStream("".toString().getBytes());
    }
    ContentletAPI conAPI = APILocator.getContentletAPI();
    FieldAPI fAPI = APILocator.getFieldAPI();
    Contentlet content = conAPI.find(contentInode, APILocator.getUserAPI().getSystemUser(), true);
    if(!UtilMethods.isSet(content)){
      Logger.warn(FieldServices.class,"Content not found.  Unable to load velocity code");
      return new ByteArrayInputStream("".toString().getBytes());
    }
    Object contFieldValueObject = conAPI.getFieldValue(content, field);
    String contFieldValue = "";
   
    if(fAPI.isElementConstant(field)){
      contFieldValue = field.getValues() == null ? "" : field.getValues();
    }else{
      contFieldValue = contFieldValueObject == null ? "" : contFieldValueObject.toString();
    }
   
View Full Code Here

  }

  public static InputStream buildVelocity(Contentlet content, Identifier identifier, boolean EDIT_MODE) throws DotDataException, DotSecurityException {
    InputStream result;
    ContentletAPI conAPI= APILocator.getContentletAPI();
    FieldAPI fAPI= APILocator.getFieldAPI();
    User systemUser= APILocator.getUserAPI().getSystemUser();


    // let's write this puppy out to our file
    StringBuilder sb= new StringBuilder();

    // CONTENTLET CONTROLS BEGIN
    sb.append("#if($EDIT_MODE)");
    sb.append("#set( $EDIT_CONTENT_PERMISSION=$EDIT_CONTENT_PERMISSION" ).append( identifier.getInode() ).append( ")");
    sb.append("#end");

    sb.append("#set($CONTENT_INODE='" ).append( content.getInode() ).append( "' )");
    sb.append("#set($IDENTIFIER_INODE='" ).append( identifier.getInode() ).append( "' )");

    // set all properties from the contentlet
    sb.append("#set($ContentInode='" ).append( content.getInode() ).append( "' )");
    sb.append("#set($ContentIdentifier='" ).append( identifier.getInode() ).append( "' )");
    sb.append("#set($ContentletTitle=\"" ).append( UtilMethods.espaceForVelocity(conAPI.getName(content, APILocator.getUserAPI().getSystemUser(), true)) ).append( "\" )");
    String modDateStr= UtilMethods.dateToHTMLDate((Date) content.getModDate(), "yyyy-MM-dd H:mm:ss");
    sb.append("#set($ContentLastModDate= $date.toDate(\"yyyy-MM-dd H:mm:ss\", \"" ).append( modDateStr ).append( "\"))");
    sb.append("#set($ContentLastModUserId= \"" ).append( content.getModUser() ).append( "\")");
    if (content.getOwner() != null)
      sb.append("#set($ContentOwnerId= \"" ).append( content.getOwner() ).append( "\")");

    // Structure fields

    Structure structure= content.getStructure();

    List<Field> fields= FieldsCache.getFieldsByStructureInode(structure.getInode());
    Iterator<Field> fieldsIt= fields.iterator();

    String widgetCode= "";

    while (fieldsIt.hasNext()) {
      Field field= (Field) fieldsIt.next();
      String contField= field.getFieldContentlet();
      String contFieldValue= null;
      Object contFieldValueObject= null;
      String velPath= (!EDIT_MODE) ? "live/" : "working/";
      if(fAPI.isElementConstant(field)){
          if(field.getVelocityVarName().equals("widgetPreexecute")){
          continue;
        }
        if(field.getVelocityVarName().equals("widgetCode")){
          widgetCode= "#set($" + field.getVelocityVarName() + "=$velutil.mergeTemplate(\"" + velPath +  content.getInode() + "_" + field.getInode() + "." + Config.getStringProperty("VELOCITY_FIELD_EXTENSION") + "\"))";
View Full Code Here

    WebContext ctx = WebContextFactory.get();
    HttpServletRequest req = ctx.getHttpServletRequest();
    UserWebAPI userWebAPI = WebAPILocator.getUserWebAPI();
    User user = userWebAPI.getLoggedInUser(req);
    boolean respectFrontendRoles = userWebAPI.isLoggedToFrontend(req);
    FieldAPI fieldAPI = APILocator.getFieldAPI();
   
    List<Map<String, Object>> resultList = new LinkedList<Map<String,Object>>();
    List<FieldVariable> fieldVars = fieldAPI.getFieldVariablesForField(fieldId, user, respectFrontendRoles);
    for(FieldVariable variable : fieldVars) {
      Map<String, Object> variableMap = variable.getMap();
      User variableLastModifier = userWebAPI.loadUserById(variable.getLastModifierId(), userWebAPI.getSystemUser(), false);
      String lastModifierFullName = "Unknown";
      if(variableLastModifier != null)
View Full Code Here

 
    if (RegEX.contains(key, "[^A-Za-z0-9]")) {
      return LanguageUtil.get(user, "message.fieldvariables.exist.error.regex");
    }
 
    FieldAPI fieldAPI = APILocator.getFieldAPI();
 
    List<FieldVariable> variables = fieldAPI.getFieldVariablesForField(fieldId, user, false);
 
    FieldVariable fieldVariable = null;
    for (FieldVariable next : variables) {
      if (next.getKey().equals(key) && !next.getId().equals(id)) {
        return LanguageUtil.get(user, "message.fieldvariables.exist.error.key");
      }
      if(UtilMethods.isSet(id) && next.getId().equals(id)) {
        fieldVariable = next;
        continue;
      }
    }
   
    if(fieldVariable == null) {
      fieldVariable = new FieldVariable();
    }
 
    fieldVariable.setId(id);
    fieldVariable.setFieldId(fieldId);
    fieldVariable.setName(name);
    fieldVariable.setKey(key);
    fieldVariable.setValue(value);
    fieldVariable.setLastModifierId(user.getUserId());
    fieldVariable.setLastModDate(new Date());
    try {
      fieldAPI.saveFieldVariable(fieldVariable, user, respectFrontendRoles);
    } catch (DotSecurityException e) {
      return LanguageUtil.get(user, "message.fieldvariables.permission.error.save");
    }
   
    return null;
View Full Code Here

    HttpServletRequest req = ctx.getHttpServletRequest();
    UserWebAPI userWebAPI = WebAPILocator.getUserWebAPI();
    User user = userWebAPI.getLoggedInUser(req);
    boolean respectFrontendRoles = userWebAPI.isLoggedToFrontend(req);

    FieldAPI fieldAPI = APILocator.getFieldAPI();
    FieldVariable fieldVar = fieldAPI.findFieldVariable(fieldVarId, user, respectFrontendRoles);
    fieldAPI.deleteFieldVariable(fieldVar, user, respectFrontendRoles);
   
    return LanguageUtil.get(user, "message.fieldvariables.deleted");
  }
View Full Code Here

  }
 
  public void execute(JobExecutionContext ctx) throws JobExecutionException {

    ContentletAPI conAPI = APILocator.getContentletAPI();
    FieldAPI fieldAPI = APILocator.getFieldAPI();
    PermissionAPI perAPI = APILocator.getPermissionAPI();
    try {
 
        List<Structure> allStructures = StructureFactory.getStructures();   
        for(Structure structure:allStructures){
         
          boolean isCongigured = false;
          String host = "";
          String username = "";
          String password = "";
          int port = 0;
          boolean isSSL = true;
   
          try{
            host = Config.getStringProperty("pop."+structure.getVelocityVarName()+".host");
            username = Config.getStringProperty("pop."+structure.getVelocityVarName()+".login");
            password = Config.getStringProperty("pop."+structure.getVelocityVarName()+".password");
            port = Config.getIntProperty("pop."+structure.getVelocityVarName()+".port");
            isSSL  = Config.getBooleanProperty("pop."+structure.getVelocityVarName()+".ssl");
          }catch (Exception e) {
           
          }
   
          if(UtilMethods.isSet(host)
              && UtilMethods.isSet(port)
              && UtilMethods.isSet(isSSL)
              && UtilMethods.isSet(username)
              && UtilMethods.isSet(password)){
            isCongigured = true;
          }
   
          if(isCongigured){
           
            String messageIdFieldVarNm = "";
            String subjectFieldVarNm = "";
            String bodyFieldVarNm = "";
            String fromFieldVarNm = "";
            String toFieldVarNm = "";
            String ccFieldVarNm = "";
            String bccFieldVarNm = "";
            String dateFieldVarNm = "";
            String referencesFieldVarNm = "";
            String inReplyToFieldVarNm = "";
            String attachment1FieldVarNm = "";
            String attachment2FieldVarNm = "";
            String attachment3FieldVarNm = "";
            String attachment4FieldVarNm = "";
            String attachment5FieldVarNm = "";
            String attachment6FieldVarNm = "";
            String attachment7FieldVarNm = "";
            String attachment8FieldVarNm = "";
            String attachment9FieldVarNm = "";
            String attachment10FieldVarNm = "";
           
            try{
              messageIdFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".messageId");
              subjectFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".subject");
              bodyFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".body");
              fromFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".from");
              toFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".to");
              ccFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".cc");
              bccFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".bcc");
              dateFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".date");
              referencesFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".references");
              inReplyToFieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".inReplyTo");
              attachment1FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment1");
              attachment2FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment2");
              attachment3FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment3");
              attachment4FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment4");
              attachment5FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment5");
              attachment6FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment6");
              attachment7FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment7");
              attachment8FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment8");
              attachment9FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment9");
              attachment10FieldVarNm = Config.getStringProperty("pop."+structure.getVelocityVarName()+".attachment10");
            }catch (Exception e) {
             
            }
   
            List<Field> fields = FieldsCache.getFieldsByStructureVariableName(structure.getVelocityVarName());
   
            ContentletRelationships contRel;
            ArrayList<Category> cats;
            User systemUser = null;
            try {
              systemUser = APILocator.getUserAPI().getSystemUser();
            } catch (DotDataException e) {
              Logger.error(this, e.getMessage());
            }
   
            try {
              List<Map<String,Object>> emails = EmailUtils.getEmails(host, port, isSSL, username, password);
   
              for(Map<String,Object> email:emails){
                Contentlet contentlet = new Contentlet();
                contentlet.setStructureInode(structure.getInode());
   
                for (Field field : fields){
                  if(fieldAPI.isElementConstant(field)){
                    continue;
                  }
                  Object value = null;
                  // using the standard headers/names from javax.mail.* to retrieve the email headers and field's values below
                  if(UtilMethods.isSet(messageIdFieldVarNm) && field.getVelocityVarName().equals(messageIdFieldVarNm)){
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.structure.business.FieldAPI

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.