Example usage for java.util LinkedHashMap get

List of usage examples for java.util LinkedHashMap get

Introduction

In this page you can find the example usage for java.util LinkedHashMap get.

Prototype

public V get(Object key) 

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:com.pari.nm.utils.db.InventoryDBHelper.java

public static void insertPixAclIntoDB(LinkedHashMap lmap, int device_id) {
    Connection c = null;/*from ww  w.ja v  a  2 s. c  o m*/
    PreparedStatement ps = null;

    try {
        try {
            DBHelper.executeUpdate("delete from device_acl_table where device_id=" + device_id);
        } catch (Exception ee) {
            logger.warn("Error while deleting from device_acl_table", device_id, ee);
        }

        c = DBHelper.getConnection();
        c.setAutoCommit(false);

        Iterator it = lmap.keySet().iterator();
        // ps = c.prepareStatement(DBHelperConstants.INSERT_PIX_ACL_DATA);
        ps = c.prepareStatement(DBHelperConstants.INSERT_ACL_DATA);

        // System.out.println("Inside insertPixAclIntoDB\t" +
        // lmap.toString());
        while (it.hasNext()) {
            String aclId = (String) it.next();
            ArrayList alist = (ArrayList) lmap.get(aclId);
            Iterator itr = alist.iterator();
            while (itr.hasNext()) {
                PixAccessListElement pelem = (PixAccessListElement) itr.next();
                // device_id, aclId, aceData, aclData, matches
                ps.setInt(1, device_id);
                ps.setString(2, aclId);
                ps.setString(3, pelem.getAceData());
                ps.setString(4, pelem.getAclData());
                ps.setString(5, pelem.getMatches());
                try {
                    ps.executeUpdate();
                } catch (Exception e) {
                    logger.warn(
                            "Exception while inserting pix aclid\t" + aclId + "\t for \t" + pelem.getAclData());
                }
            }
        }
    } catch (Exception e) {
        logger.warn("Exception while inserting Pix ACLS into DB.", e);
    } finally {
        try {
            ps.close();
        } catch (Exception ee) {
        }

        try {
            c.commit();
        } catch (Exception e1) {
        }

        try {
            c.setAutoCommit(true);
        } catch (Exception ee) {
        }
        DBHelper.releaseConnection(c);
    }
}

From source file:geogebra.kernel.Kernel.java

public boolean handleCoords(GeoElement geo, LinkedHashMap<String, String> attrs) {

    if (!(geo instanceof GeoVec3D)) {
        Application.debug("wrong element type for <coords>: " + geo.getClass());
        return false;
    }//from   w w  w .  java  2 s .c  om
    GeoVec3D v = (GeoVec3D) geo;

    try {
        double x = Double.parseDouble((String) attrs.get("x"));
        double y = Double.parseDouble((String) attrs.get("y"));
        double z = Double.parseDouble((String) attrs.get("z"));
        v.setCoords(x, y, z);
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:ch.elexis.core.ui.views.FallDetailBlatt2.java

/**
 * disposes of required and optional fields on the bottom of the page.<br>
 * re-reads the contents for this case for the upper part<br>
 * recreates the required and optional fields on the bottom of the page (call to
 * setExtendedFields)//from   w w  w  . j a  v  a2 s  . c  o  m
 * 
 * @param f
 *            caseID
 */
@SuppressWarnings("unchecked")
public void setFall(final IFall f) {
    if (actFall != null) {
        save();
    }
    // *** dispose of currently displayed fields
    actFall = f;
    for (Control c : lReqs) {
        c.dispose();
    }
    lReqs.clear();
    keepEditable.clear();

    // *** fill billing systems into combo, set current system
    cAbrechnung.setItems(Abrechnungstypen);
    if (f == null) {
        form.setText(Messages.FallDetailBlatt2_NoCaseSelected); //$NON-NLS-1$
        tBezeichnung.setText("");
        tBezeichnung.setMessage(Messages.FallDetailBlatt2_29);
        cReason.select(0);
        return;
    }

    String billingSystem = f.getAbrechnungsSystem();
    // auto select accident if uvg is selected
    if ("UVG".equals(billingSystem)) {
        int idx = ArrayUtils.indexOf(Reasons, FallConstants.TYPE_ACCIDENT);
        if (idx > -1) {
            f.setGrund(Reasons[idx]);
        }
    }

    form.setText(f.getLabel());

    // *** set Fallbezeichnung
    tBezeichnung.setText(f.getBezeichnung());

    // *** set Grund (Krankheit/Unfall/...)
    String grund = f.getGrund();
    int ix = cReason.indexOf(grund);
    if (ix == -1) {
        ix = 0;
    }
    cReason.select(ix);

    cAbrechnung.setText(billingSystem);

    // *** set startDate/EndDate
    TimeTool tt = new TimeTool();
    if (tt.set(f.getBeginnDatum()) == true) {
        dpVon.setDate(tt.getTime());
    } else {
        dpVon.setDate(null);
    }
    if (tt.set(f.getEndDatum()) == true) {
        dpBis.setDate(tt.getTime());
    } else {
        dpBis.setDate(null);
    }

    // *** set copy for patient
    btnCopyForPatient.setSelection(f.getCopyForPatient());

    // *** set Garant
    tGarant.setBackground(null);
    tGarant.setToolTipText(null);
    Kontakt garant = f.getGarant();
    String garantLabel = garant.getLabel();
    if (garant.isDeleted()) {
        tGarant.setBackground(UiDesk.getColor(UiDesk.COL_RED));
        garantLabel = "*** " + garantLabel;
        tGarant.setToolTipText(Messages.Contact_is_marked_deleted);
    }
    tGarant.setText(garantLabel);

    // *** set cost bearer (if enabled for billing system)
    boolean costBearerDisabled = BillingSystem.isCostBearerDisabled(billingSystem);
    tCostBearer.setVisible(!costBearerDisabled);
    hlCostBearer.setVisible(!costBearerDisabled);

    tCostBearer.setBackground(null);
    tCostBearer.setToolTipText(null);
    if (!costBearerDisabled) {
        Kontakt costBearer = f.getCostBearer();
        String label = (costBearer != null) ? costBearer.getLabel() : f.getPatient().getLabel();
        if (costBearer != null && costBearer.isDeleted()) {
            tCostBearer.setBackground(UiDesk.getColor(UiDesk.COL_RED));
            label = "*** " + label;
            tCostBearer.setToolTipText(Messages.Contact_is_marked_deleted);
        }
        tCostBearer.setText(label);
    } else {
        tCostBearer.setText(StringConstants.EMPTY);
    }

    // *** adding required fields defined in prefs
    String reqs = BillingSystem.getRequirementsBySystem(billingSystem);
    if ((reqs != null) && (reqs.length() > 0)) {
        // *** do not display a title bar since this is already displayed
        // above Rechnungsempfnger!
        setExtendedFields(f, reqs, StringTool.leer, false, false, false);
    }
    // *** adding optional fields defined in prefs
    String optionals = f.getOptionals();
    if ((optionals != null) && (optionals.length() > 0)) {
        setExtendedFields(f, optionals, Messages.FallDetailBlatt2_optionalData, false, false, true); //$NON-NLS-1$
    }

    // ****** show any other fields from extinfo - ONLY FOR ADMINS, NOT
    // INTENDED FOR NORMAL USERS !!!
    // first part fields with definition, second part without definition

    // *** display all unused field having a display specification
    String[] reqsArray = BillingSystem.getRequirementsBySystem(billingSystem).split(DEFINITIONSDELIMITER);
    for (int reqI = 0; reqI < reqsArray.length; reqI++) {
        reqsArray[reqI] = reqsArray[reqI].split(ARGUMENTSSDELIMITER)[0];
    }
    String[] optsArray = f.getOptionals().split(DEFINITIONSDELIMITER);
    for (int reqI = 0; reqI < optsArray.length; reqI++) {
        optsArray[reqI] = optsArray[reqI].split(ARGUMENTSSDELIMITER)[0];
    }
    // *** read field definitions for unused fields (previously required or
    // optional)
    List<String> unused = new ArrayList<String>();
    LinkedHashMap<String, String> unusedHash = new LinkedHashMap<String, String>();
    String strUnused = f.getUnused();
    if ((strUnused != null) && (!strUnused.isEmpty())) {
        String[] allUnused = strUnused.split(DEFINITIONSDELIMITER); //$NON-NLS-1$
        Arrays.sort(allUnused, String.CASE_INSENSITIVE_ORDER); // *** sort
        // alphabetically
        for (String unusedPart : allUnused) {
            int posColon = unusedPart.indexOf(ARGUMENTSSDELIMITER);
            String key = unusedPart.substring(0, posColon);
            // *** do not show if already displayed in required or optional
            // fields
            boolean alreadyDisplayed = false;
            for (int reqI = 0; reqI < reqsArray.length; reqI++) {
                if (key.equalsIgnoreCase(reqsArray[reqI])) {
                    alreadyDisplayed = true;
                }
            }
            for (int reqI = 0; reqI < optsArray.length; reqI++) {
                if (key.equalsIgnoreCase(optsArray[reqI])) {
                    alreadyDisplayed = true;
                }
            }
            if (!alreadyDisplayed) {
                String value = unusedPart.substring(posColon + 1);
                unusedHash.put(key, value);
                unused.add(unusedPart);
            }
        }
    }

    Map<String, String> httmp = getSelectedFall().getMap(PersistentObject.FLD_EXTINFO);

    HashMap<String, String> ht = new HashMap<String, String>(httmp);

    String[] unusedHashStringArray = {};
    if (unusedHash.size() > 0) {
        String unusedHashString = unusedHash.toString();
        unusedHashString = unusedHashString.substring(1);
        unusedHashString = unusedHashString.substring(0, unusedHashString.length() - 1);
        unusedHashStringArray = unusedHashString.split(", "); //$NON-NLS-1$
    }
    String otherFieldsList_2 = StringTool.leer;
    String delim = StringTool.leer;
    for (int uhi = 0; uhi < unusedHashStringArray.length; uhi++) {
        String unusedItem = unusedHashStringArray[uhi];
        String[] itemParts = unusedItem.split("="); //$NON-NLS-1$
        String controlName = itemParts[0];
        String[] controlDefParts = itemParts[1].split(ARGUMENTSSDELIMITER);
        String controlType = controlDefParts[0];

        String[] itemList = { StringTool.leer };
        if (controlType.equalsIgnoreCase("X")) { //$NON-NLS-1$
            if (controlDefParts.length > 1) {
                itemList = controlDefParts[1].split(ITEMDELIMITER);
            }
        }
        boolean isAdded = false;
        // *** special handling if multiple items
        for (int ili = 0; ili < itemList.length; ili++) {
            String item = itemList[ili];
            if (!item.isEmpty()) {
                item = "_" + item; //$NON-NLS-1$
            }
            String combControlName = controlName + item;
            if (ht.containsKey(combControlName)) {
                ht.remove(combControlName);
                String values = StringTool.leer;
                if (controlDefParts.length > 1) {
                    values = controlDefParts[1];
                }
                if (!isAdded) {
                    otherFieldsList_2 = otherFieldsList_2 + delim + controlName + ARGUMENTSSDELIMITER
                            + controlType + ARGUMENTSSDELIMITER + values;
                }
                delim = DEFINITIONSDELIMITER;
                isAdded = true;
            }
        }
    }
    // *** only for admins!
    if (otherFieldsList_2.length() > 0) {
        if (CoreHub.acl.request(AccessControlDefaults.CASE_MODIFY_SPECIALS) == true) {
            setExtendedFields(f, otherFieldsList_2, Messages.FallDetailBlatt2_unusedFieldsWithDefinition, true,
                    true, false); //$NON-NLS-1$
        }
    }

    // *** collect all other fields that are not yet shown anywhere else,
    // display as text
    String otherFieldsList = otherFieldsList_2;
    otherFieldsList = StringTool.leer;
    Set<String> keySet = ht.keySet();
    Object[] arr = keySet.toArray();
    for (int i = 0; i < arr.length; i++) {
        String subkey = (String) arr[i];
        String abrSystem = getSelectedFall().getAbrechnungsSystem();
        String key = Preferences.LEISTUNGSCODES_CFG_KEY + "/" + abrSystem; //$NON-NLS-1$
        String bed = CoreHub.globalCfg.get(key + "/bedingungen", StringTool.leer); //$NON-NLS-1$
        boolean isAlreadyShown = false;
        if (subkey.equalsIgnoreCase(FallConstants.FLD_EXTINFO_BILLING))
            isAlreadyShown = true;
        // if (subkey.equalsIgnoreCase("payment")) isAlreadyShown = true;
        // if (subkey.equalsIgnoreCase("Fallnummer")) isAlreadyShown = true;
        // if (subkey.equalsIgnoreCase("Gesetz")) isAlreadyShown = true;
        String[] bedArr = bed.split(DEFINITIONSDELIMITER);
        if (!bed.isEmpty()) {
            for (int ii = 0; ii < bedArr.length; ii++) {
                String fldParts = bedArr[ii];
                String[] flds = fldParts.split(ARGUMENTSSDELIMITER);
                String fld = flds[0];
                if ((flds[1].equalsIgnoreCase("X")) && ((flds.length > 2)) //$NON-NLS-1$
                        && (!flds[2].isEmpty())) {
                    String checkBoxes = flds[2];
                    String[] checkBoxArray = checkBoxes.split(ITEMDELIMITER);
                    for (int cb_i = 0; cb_i < checkBoxArray.length; cb_i++) {
                        if ((fld + "_" + checkBoxArray[cb_i]).equalsIgnoreCase(subkey)) { //$NON-NLS-1$
                            isAlreadyShown = true;
                            break;
                        }
                    }
                } else {
                    if (fld.equalsIgnoreCase(subkey)) {
                        isAlreadyShown = true;
                        break;
                    }
                }
            }
        }
        String opt = CoreHub.globalCfg.get(key + "/fakultativ", StringTool.leer); //$NON-NLS-1$
        if (!isAlreadyShown) {
            String[] optArr = opt.split(DEFINITIONSDELIMITER);
            if (!opt.isEmpty()) {
                for (int ii = 0; ii < optArr.length; ii++) {
                    String fld = optArr[ii].split(ARGUMENTSSDELIMITER)[0];
                    if (fld.equalsIgnoreCase(subkey)) {
                        isAlreadyShown = true;
                        break;
                    }
                }
            }
        }
        if (!isAlreadyShown) {
            if (unusedHash.containsKey(subkey)) {
                // *** try to find def
                String theVal = (String) unusedHash.get(subkey);
                String[] vals = theVal.split(ARGUMENTSSDELIMITER);
                otherFieldsList = otherFieldsList + delim + subkey + ARGUMENTSSDELIMITER + vals[0];
                if (vals.length > 1) {
                    otherFieldsList = otherFieldsList + ARGUMENTSSDELIMITER + vals[1];
                }
            } else {
                // *** if no spec found, then show as text
                otherFieldsList = otherFieldsList + delim + subkey + ":T"; //$NON-NLS-1$
            }
            delim = DEFINITIONSDELIMITER;
        }
    }

    if (otherFieldsList.length() > 0) {
        // *** want to sort alphabetically here
        String[] tmpArr = otherFieldsList.split(DEFINITIONSDELIMITER);
        Arrays.sort(tmpArr, String.CASE_INSENSITIVE_ORDER);
        otherFieldsList = StringTool.leer;
        String tmpDel = StringTool.leer;
        for (int i = 0; i < tmpArr.length; i++) {
            otherFieldsList = otherFieldsList + tmpDel + tmpArr[i];
            tmpDel = DEFINITIONSDELIMITER;
        }
        // *** only for admins!
        if (CoreHub.acl.request(AccessControlDefaults.CASE_MODIFY_SPECIALS) == true) {
            setExtendedFields(f, otherFieldsList, Messages.FallDetailBlatt2_unusedFieldsWithoutDefinition, true,
                    true, false); //$NON-NLS-1$
        }
    }

    if (lockUpdate) {
        setUnlocked(CoreHub.getLocalLockService().isLockedLocal(actFall));
    }
}

From source file:com.primeleaf.krystal.web.view.console.ViewDocumentView.java

@SuppressWarnings("unchecked")
private void printDocument() throws Exception {
    Document document = (Document) request.getAttribute("DOCUMENT");
    DocumentRevision documentRevision = (DocumentRevision) request.getAttribute("DOCUMENTREVISION");
    DocumentClass documentClass = (DocumentClass) request.getAttribute("DOCUMENTCLASS");

    LinkedHashMap<String, String> documentIndexes = (LinkedHashMap<String, String>) request
            .getAttribute("DOCUMENTINDEXES");
    boolean isHeadRevision = document.getRevisionId().equalsIgnoreCase(documentRevision.getRevisionId());

    ACL acl = (ACL) request.getAttribute("ACL");

    if (view.trim().length() <= 0) {//do not show document id and revision id for attachment or quick view
        printBreadCrumbs();/*from  ww w . j  av  a2 s  . c om*/
    }

    out.println("<h3><i class=\"fa fa-folder-open\"></i> "
            + StringEscapeUtils.escapeHtml4(documentClass.getClassName()));
    out.println("<small>");
    out.println(
            "<span class=\"label label-success tip\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Document ID\">"
                    + documentRevision.getDocumentId() + "</span>&nbsp;");
    out.println(
            "<span class=\"label label-default tip\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Revision ID\">"
                    + documentRevision.getRevisionId() + "</span>&nbsp;");
    out.println(
            "<span class=\"label label-success tip\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"File Size\">"
                    + StringHelper.formatSizeText(documentRevision.getLength()) + "</span></small></h3>");

    String lastModified = "";
    if (document.getModified() == null) {
        lastModified = document.getCreated();
    } else {
        lastModified = document.getModified().toString();
    }
    out.println("Last Modified By &nbsp;" + StringEscapeUtils.escapeHtml4(document.getModifiedBy()));
    out.println("&nbsp;");
    out.println("On &nbsp;" + StringHelper.formatDate(lastModified));
    out.println(" (" + StringHelper.getFriendlyDateTime(lastModified) + ")");

    out.println("<hr/>");

    if (request.getAttribute(HTTPConstants.REQUEST_ERROR) != null) {
        printErrorDismissable((String) request.getAttribute(HTTPConstants.REQUEST_ERROR));
    }
    if (request.getAttribute(HTTPConstants.REQUEST_MESSAGE) != null) {
        printSuccessDismissable((String) request.getAttribute(HTTPConstants.REQUEST_MESSAGE));
    }

    out.println("<ul class=\"nav nav-tabs\" id=\"documenTabs\">");
    out.println("<li class=\"active\"><a href=\"#document\" data-toggle=\"tab\"><img src=\"/images/"
            + StringHelper.getIconFileNameForExtension(document.getExtension())
            + ".gif\" >&nbsp;Document</a></li>");
    out.println(
            "<li><a href=\"#documentNotes\" data-toggle=\"tab\" class=\"internal\"  datatarget=\"#resultNotes\" data-src=\"/console/documentnotes?documentid="
                    + document.getDocumentId() + "&revisionid=" + documentRevision.getRevisionId()
                    + "\"><i class=\"fa fa-comments-o\"></i> Notes</a></li>");
    out.println(
            "<li><a href=\"#accessHistory\" data-toggle=\"tab\" class=\"internal\"  datatarget=\"#resultAccessHistory\" data-src=\"/console/accesshistory?documentid="
                    + document.getDocumentId() + "&revisionid=" + documentRevision.getRevisionId()
                    + "\"><i class=\"fa fa-clock-o\"></i> Access History</a></li>");
    out.println("</ul>");
    out.println("<div class=\"tab-content\">");
    out.println("<div class=\"tab-pane in active\" id=\"document\"><br/>");
    out.println("<div class=\"row\">");
    out.println("<div class=\"col-sm-9\">");
    //viewer applet starts here
    try {

        out.println("<div class=\"well well-sm\" id=\"viewer\">");
        out.println("<iframe src = \"/js/ViewerJS/?type=pdf#/console/mobiledocumentviewer?documentid="
                + documentRevision.getDocumentId() + "&revisionid=" + documentRevision.getRevisionId()
                + "\" width='100%' height='800'></iframe>");
        out.println("</div>");//visible-xs

        if (acl.canEmail()) {
            out.println("<div class=\"panel panel-default\">");
            out.println("<div class=\"panel-heading\"><i class=\"fa fa-envelope-o\"></i> Share Document</div>");
            out.println("<div class=\"panel-body\">");
            out.println(
                    "<form action=\"/console/sharedocument\" method=\"post\" id=\"frmShareDocument\" form-type=\"ajax\" datatarget=\"#resultShareDocument\">");
            out.println("<div id=\"resultShareDocument\"></div>");
            out.println("<p>Fields marked with <span style='color:red'>*</span> are mandatory</p>");

            out.println("<div class=\"form-group\">");
            out.println("<label for=\"txtEmail\">Email ID <span style='color:red'>*</span></label>");
            out.println(
                    "<input type=\"text\" id=\"txtEmail\" name=\"txtEmail\" class=\"required form-control multiemail\" maxlength=\"500\" title=\"Please use a comma to separate multiple email addresses\"/>");
            out.println("</div>");

            out.println("<div class=\"form-group\">");
            out.println("<label for=\"txtComments\">Comments <span style='color:red'>*</span></label>");
            out.println(
                    "<textarea class=\"form-control required\" rows=\"4\" name=\"txtComments\"  id=\"txtComments\"  placeholder=\"Put your comments here\"></textarea>");
            out.println("</div>");
            out.println("<input type=\"hidden\"  name=\"documentid\"     value=\"" + document.getDocumentId()
                    + "\" />");
            out.println("<input type=\"hidden\"  name=\"revisionid\"     value=\""
                    + documentRevision.getRevisionId() + "\" />");
            out.println(
                    "<input type=\"submit\"  name=\"btnSubmit\"    id=\"btnShare\"    value=\"Share Document\"    class=\"btn btn-sm btn-default\"  data-loading-text=\"Sharing Document...\"/>");
            out.println("</form>");
            out.println("</div>");//panel-body
            out.println("</div>");//panel
        }

        out.println("</div>");//col-sm-9

        out.println("<div class=\"col-sm-3\">");
        String expiryOn = "";
        if (document.getExpiry() == null) {
            expiryOn = "";
        } else {
            expiryOn = document.getExpiry().toString();
            expiryOn = StringHelper.formatDate(expiryOn, ServerConstants.FORMAT_SHORT_DATE);
        }
        String lastAccessed = "";
        if (document.getLastAccessed() == null) {
            lastAccessed = document.getCreated();
        } else {
            lastAccessed = document.getLastAccessed().toString();
        }

        if (acl.canWrite() && document.getStatus().equalsIgnoreCase(Hit.STATUS_AVAILABLE) && isHeadRevision) {
            out.println("<div class=\"panel panel-default\">");
            out.println("<div class=\"panel-heading\"><i class=\"fa fa-list\"></i> Edit Indexes</div>");
            out.println("<div class=\"panel-body\">");
            out.println(
                    "<form action=\"/console/editdocumentindexes\" method=\"post\" id=\"frmEditIndexes\" accept-charset=\"utf-8\"  form-type=\"ajax\" datatarget=\"#resultIndexes\">");
            out.println("<div id=\"resultIndexes\"></div>");
            out.println("<p>Fields marked with <span style='color:red'>*</span> are mandatory</p>");
            for (IndexDefinition indexDefinition : documentClass.getIndexDefinitions()) {
                String required = "";
                out.println("<div class=\"form-group\">");
                out.println("<label for=\"" + indexDefinition.getIndexColumnName() + "\"> "
                        + StringEscapeUtils.escapeHtml4(indexDefinition.getIndexDisplayName()));
                if (indexDefinition.isMandatory()) {
                    required = "required";
                    out.println(" <span style='color:red'>*</span>");
                }
                out.println("</label>");

                String value = (String) documentIndexes.get(indexDefinition.getIndexDisplayName());
                value = StringEscapeUtils.escapeHtml4(value);

                if (indexDefinition.getIndexType().equals(IndexDefinition.INDEXTYPE_DATE)) {
                    out.println("<div class=\"input-group\">");
                    out.println("<input type=\"text\" class=\"shortdate isdate form-control " + required
                            + "\" name=\"" + indexDefinition.getIndexColumnName() + "\" id=\""
                            + indexDefinition.getIndexColumnName() + "\" value=\"" + value + "\" maxlength=\""
                            + indexDefinition.getIndexMaxLength() + "\"  cid=\"" + documentClass.getClassId()
                            + "\">");
                    out.println("<span class=\"input-group-addon\"><i class=\"fa fa-calendar\"></i></span>");
                    out.println("</div>");
                } else if (indexDefinition.getIndexType().equals(IndexDefinition.INDEXTYPE_NUMBER)) {
                    out.println("<input type=\"text\" class=\"number  form-control " + required
                            + " autocomplete\"    id=\"" + indexDefinition.getIndexColumnName() + "\" name=\""
                            + indexDefinition.getIndexColumnName() + "\" value=\"" + value + "\" maxlength=\""
                            + indexDefinition.getIndexMaxLength() + "\"   cid=\"" + documentClass.getClassId()
                            + "\">");
                } else {
                    out.println("<input type=\"text\" class=\"autocomplete form-control " + required
                            + " \" id=\"" + indexDefinition.getIndexColumnName() + "\"  name=\""
                            + indexDefinition.getIndexColumnName() + "\" value=\"" + value + "\" maxlength=\""
                            + indexDefinition.getIndexMaxLength() + "\"  cid=\"" + documentClass.getClassId()
                            + "\">");
                }
                out.println("</div>");
            }

            out.println("<hr/>");
            out.println("<div class=\"form-group\">");
            out.println("<label for=\"txtExpiryDate\"> Expiry On</label>");
            out.println("<div class=\"input-group\">");
            out.println(
                    "<input type=\"text\" class=\"shortdate isdate form-control\" name=\"txtExpiryDate\" id=\"txtExpiryDate\" maxlength=\"12\" value=\""
                            + expiryOn + "\"/>");
            out.println("<span class=\"input-group-addon\"><i class=\"fa fa-calendar\"></i></span>");
            out.println("</div>");
            out.println("</div>");

            out.println("<input type=\"hidden\" name=\"revisionid\" value=\"" + documentRevision.getRevisionId()
                    + "\">");
            out.println("<input type=\"hidden\"  name=\"documentid\"  value=\"" + document.getDocumentId()
                    + "\"/>");
            out.println(
                    "<input type=\"submit\"  name=\"btnSubmit\"  value=\"Submit\" class=\"btn btn-sm btn-default\">");

            out.println("</form>");
            out.println("</div>");//panel-body
            out.println("</div>");//panel

        } else {
            out.println("<div class=\"panel panel-default\">");
            out.println(
                    "<div class=\"panel-heading\"><i class=\"fa fa-check-square-o\"></i> Document Indexes</div>");
            out.println("<div class=\"panel-body\">");
            out.println("<div class=\"table-responsive\">");
            out.println("<table class=\"table table-hover\">");
            if (!documentIndexes.keySet().isEmpty()) {
                out.println("<thead>");
                out.println("<tr>");
                out.println("<th>Index Field</th>");
                out.println("<th>Index Value</th>");
                out.println("</tr>");
                out.println("</thead>");

                out.println("<tbody>");
                for (String indexName : documentIndexes.keySet()) {
                    String indexValue = (String) documentIndexes.get(indexName);
                    out.println("<tr>");
                    out.println("<td>" + StringEscapeUtils.escapeHtml4(indexName) + "</td>");
                    out.println("<td>" + StringEscapeUtils.escapeHtml4(indexValue) + "</td>");
                    out.println("</tr>");
                }
            }
            out.println("<tr class=\"text-success\">");
            out.println("<td >Expiry On</td>");
            out.println("<td>" + expiryOn + "</td>");
            out.println("</tr>");

            out.println("</tbody>");
            out.println("</table>");
            out.println("</div>");//table-responsive
            out.println("</div>");//panel-body
            out.println("</div>");//panel
        }

        out.println("<div class=\"panel panel-default\">");
        out.println("<div class=\"panel-heading\"><i class=\"fa fa-file\"></i> Document Properties</div>");
        out.println("<div class=\"table-responsive\">");
        out.println("<table class=\"table table-hover\">");
        out.println("<thead><tr><th>Property</th><th>Value</th></tr></thead>");
        out.println("<tbody><tr><td>Created By</td><td> " + document.getCreatedBy() + "</td></tr>");
        out.println("<tr><td>Created On</td><td>" + StringHelper.getFriendlyDateTime(document.getCreated())
                + "</td></tr>");
        out.println("<tr><td>Last Accessed On</td><td>" + StringHelper.getFriendlyDateTime(lastAccessed)
                + "</td></tr>");
        out.println("<tr><td>Access Count</td><td>" + document.getAccessCount() + "</td></tr>");
        out.println("</tbody></table>");//
        out.println("</div>");//table-responsive
        out.println("</div>");//panel

        out.println("<div class=\"panel panel-default\">");
        out.println("<div class=\"panel-heading\"><i class=\"fa fa-bookmark\"></i> Bookmark Document</div>");
        out.println("<div class=\"panel-body\">");
        out.println(
                "<form action=\"/console/newbookmark\" method=\"post\" id=\"frmNewBookmark\"  form-type=\"ajax\" datatarget=\"#resultBookmark\" accept-charset=\"utf-8\">");
        out.println("<div id=\"resultBookmark\"></div>");
        out.println("<p>Fields marked with <span style='color:red'>*</span> are mandatory</p>");
        out.println("<div class=\"form-group\">");
        out.println("<label for=\"txtBookmarkName\">Bookmark Name<span style='color:red'>*</span></label>");
        out.println(
                "<input type=\"text\" id=\"txtBookmarkName\" name=\"txtBookmarkName\" class=\"required form-control\" maxlength=\"50\" title=\"Please enter Bookmark Name\"/>");
        out.println("</div>");
        out.println("<input type=\"hidden\"  name=\"documentid\"     value=\"" + document.getDocumentId()
                + "\" />");
        out.println("<input type=\"hidden\"  name=\"revisionid\"     value=\""
                + documentRevision.getRevisionId() + "\" />");
        out.println("<input type=\"submit\"  name=\"btnSubmit\"     value=\"" + "Save"
                + "\"    class=\"btn btn-sm btn-default\"/>");
        out.println("</form>");
        out.println("</div>");//panel-body
        out.println("</div>");//panel

        if (view.trim().length() <= 0) {
            out.println("<div class=\"well well-sm\">");
            if (acl.canDownload()) {
                out.println("<a href=\"/console/downloaddocument?documentid=" + document.getDocumentId()
                        + "&revisionid=" + documentRevision.getRevisionId()
                        + "\" class=\"btn btn-default btn-block \" title=\"Download Document\" ><i class=\"fa fa-download\"></i> Download Document</a>");
            }
            if (documentClass.isRevisionControlEnabled()) {
                if (document.getStatus().equalsIgnoreCase(Hit.STATUS_AVAILABLE) && isHeadRevision) {
                    if (acl.canCheckout()) {
                        out.println("<a href=\"/console/checkoutdocument?documentid=" + document.getDocumentId()
                                + "\" class=\"btn btn-default btn-block \" title=\"Check Out Document\" ><i class=\"fa fa-lock\"></i> Check Out Document</a>");
                    }
                }
                if (document.getStatus().equalsIgnoreCase(Hit.STATUS_LOCKED)) {
                    out.println("<a href=\"/console/cancelcheckout?documentid=" + document.getDocumentId()
                            + "\" class=\"btn  btn-default btn-block confirm\" title=\"Are you sure, you want to cancel checkout of this document?\" ><i class=\"fa fa-unlock-alt\"></i> Cancel Checkout</a>");
                    if (acl.canCheckin()) {
                        out.println("<a href=\"/console/checkindocument?documentid=" + document.getDocumentId()
                                + "\" class=\"btn  btn-default btn-block \" title=\"Check In\" ><i class=\"fa fa-arrow-right\"></i> Check In</a>");
                    }
                }
                out.println("<a href=\"/console/revisionhistory?documentid=" + document.getDocumentId()
                        + "\" data-toggle=\"modal\" data-target=\"#revisionHistoryModal\" class=\"btn  btn-default btn-block \" title=\"Revision History\"><i class=\"fa fa-clock-o\"></i> Revision History</a>");
            }
            if (acl.canDelete() && document.getStatus().equalsIgnoreCase(Hit.STATUS_AVAILABLE)
                    && isHeadRevision) {
                out.println("<a href=\"/console/deletedocument?documentid=" + document.getDocumentId()
                        + "\" class=\"btn btn-danger btn-block confirm\" title=\"Are you sure, you want to mark this document as deleted?\" ><i class=\"fa fa-trash-o\"></i> Delete Document</a>");
            }
            out.println("</div>");//well well-sm
        }
        out.println("</div>");//col-sm-3
        out.println("</div>");//row
        out.println("</div>");//tab-pane active #document

        out.println("<div class=\"tab-pane fade\" id=\"attachment\">");
        out.println(
                "<iframe frameborder=\"0\" border=\"0\" width=\"0\" height=\"0\" name=\"attachmentFrame\" id=\"attachmentFrame\" src=\"\" style=\"border:0px;\"></iframe>");

        out.println("<div class=\"row\">");
        out.println("<div class=\"col-sm-9\">");
        out.println("<div id=\"resultAttachments\"></div>");
        out.println("</div>");//col-sm-9

        out.println("<div class=\"col-sm-3\">");
        out.println("<div class=\"panel panel-default\">");
        out.println("<div class=\"panel-heading\"><i class=\"fa fa-paperclip\"></i> Add Attachment</div>");
        out.println("<div class=\"panel-body\">");
        out.println(
                "<form action=\"/console/attachments\" method=\"post\" id=\"frmAttachments\" name=\"frmAttachments\" enctype=\"multipart/form-data\" target=\"attachmentFrame\" accept-charset=\"utf-8\" class=\"internal\">");
        out.println("<p>Fields marked with <span style='color:red'>*</span> are mandatory</p>");

        out.println("<div class=\"form-group\">");
        out.println("<label for=\"fileDocument\">Select Document <span style='color:red'>*</span></label>");
        out.println(
                "<input type=\"file\" name=\"fileDocument\" class=\"required\" title=\"Please select document\">");
        out.println("</div>");

        out.println("<div class=\"form-group\">");
        out.println("<label for=\"TITLE\">Attachment Title <span class=\"text-success\">*</span></label>");
        out.println(
                "<input type=\"text\" name=\"TITLE\" id=\"TITLE\" class=\"form-control required\" title=\"Please enter attachment title\" placeholder=\"Attachment Title\"/>");
        out.println("</div>");

        out.println("<div class=\"form-group\">");
        out.println("<label for=\"KEYWORDS\">Attachment Keywords </label>");
        out.println(
                "<textarea name=\"KEYWORDS\" id=\"KEYWORDS\" rows=\"5\" class=\"form-control\" placeholder=\"Attachment Keywords\"></textarea>");
        out.println("</div>");

        out.println("<div class=\"form-group\" id=\"pbContainer\" style=\"display:none;\">");
        out.println("<div class=\"progress progress-striped active\" id=\"progressbarMain\">");
        out.println(
                "<div class=\"progress-bar progress-bar-success\" id=\"progressbar\" role=\"progressbar\" aria-valuenow=\"0\" aria-valuemin=\"0\" aria-valuemax=\"100\" style=\"width: 0%\">");
        out.println("<span class=\"sr-only\">0% Complete</span>");
        out.println("</div>");
        out.println("</div>");
        out.println(
                "<div id=\"progressMessage\" class=\"alert alert-success alert-dismissable\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button></div>");
        out.println("</div>");

        out.println("<input type=\"hidden\" name=\"DOCID\" value=\"" + document.getDocumentId() + "\">");
        out.println("<input type=\"hidden\" name=\"REVISIONID\" value=\"" + documentRevision.getRevisionId()
                + "\">");
        out.println(
                "<input type=\"submit\"  name=\"btnSubmit\"  value=\"Submit\" class=\"btn btn-sm btn-default\">");
        out.println("</form>");
        out.println("</div>");//col-sm-3
        out.println("</div>");//row
        out.println("</div>");//panel-body
        out.println("</div>");//panel
        out.println("</div>");//tab-pane active #attachment

        out.println("<div class=\"tab-pane fade\" id=\"documentNotes\"><br/>");
        out.println("<div class=\"row\">");
        out.println("<div class=\"col-sm-9\">");
        out.println("<div id=\"resultNotes\"></div>");//notes will be loaded here
        out.println("</div>");//col-sm-9
        out.println("<div class=\"col-sm-3\">");
        out.println("<div class=\"panel panel-default\">");
        out.println(
                "<div class=\"panel-heading\"><i class=\"fa fa-comment-o fa-lg\"></i> Add Note / Comments</div>");
        out.println("<div class=\"panel-body\">");
        out.println(
                "<form action=\"/console/documentnotes\" id=\"frmNotes\" method=\"post\"  form-type=\"ajax\" datatarget=\"#resultNotes\">");
        out.println("<p>Fields marked with <span style='color:red'>*</span> are mandatory</p>");
        out.println("<div class=\"form-group\">");
        out.println("<label for=\"txtNote\">Note / Comments <span class=\"text-success\">*</span></label>");
        out.println(
                "<textarea name=\"txtNote\" id=\"txtNote\" rows=\"5\" class=\"form-control required alphaNumericSpace\" title=\"Please enter note\" placeholder=\"Note / Comments\"></textarea>");
        out.println("</div>");

        out.println("<div class=\"form-group\">");
        out.println("<div class=\"btn-group\" data-toggle=\"buttons\">");
        out.println("<label class=\"btn btn-sm btn-default active\">");
        out.println(
                "<input type=\"radio\" id=\"radNoteType1\" name=\"radNoteType\" value=\"P\" checked>Public");
        out.println("</label>");
        out.println("<label class=\"btn btn-sm btn-default\">");
        out.println("<input type=\"radio\" id=\"radNoteType2\" name=\"radNoteType\"  value=\"U\">Private");
        out.println("</label>");
        out.println("</div>");
        out.println("</div>");

        out.println("<hr/>");
        out.println("<input type=\"hidden\" name=\"documentid\" value=\"" + document.getDocumentId() + "\">");
        out.println(
                "<input type=\"submit\"  name=\"btnSubmit\"  value=\"Submit\" class=\"btn btn-sm btn-default\">");

        out.println("</form>");
        out.println("</div>");//col-sm-3
        out.println("</div>");//row

        out.println("</div>");//panel-body
        out.println("</div>");//panel
        out.println("</div>");//tab-pane active #notes

        out.println("<div class=\"tab-pane fade\" id=\"accessHistory\"><br/>");
        out.println("<div class=\"row\">");
        out.println("<div class=\"col-sm-9\">");
        out.println("<div id=\"resultAccessHistory\"></div>");//access history will be loaded here
        out.println("</div>");//col-sm-9
        out.println("<div class=\"col-sm-3\">");
        out.println("<div class=\"panel panel-default\">");
        out.println(
                "<div class=\"panel-heading\"><i class=\"fa fa-filter fa-lg\"></i> Filter Access History</div>");
        out.println("<div class=\"panel-body\">");
        out.println(
                "<form action=\"/console/accesshistory\" id=\"frmAccessHistory\" method=\"post\" form-type=\"ajax\" datatarget=\"#resultAccessHistory\">");
        out.println("<div class=\"form-group\">");
        out.println("<label for=\"fromDate\">From</label>");
        out.println("<div class=\"input-group\">");
        out.println(
                "<input type=\"text\"  id=\"fromDate\" name=\"fromDate\" class=\"form-control shortdate isDate\">");
        out.println("<span class=\"input-group-addon\"><i class=\"fa fa-calendar\"></i></span>");
        out.println("</div>");
        out.println("</div>");

        out.println("<div class=\"form-group\">");
        out.println("<label for=\"toDate\">To</label>");
        out.println("<div class=\"input-group\">");
        out.println(
                "<input type=\"text\"  id=\"toDate\" name=\"toDate\" class=\" form-control shortdate isDate\">");
        out.println("<span class=\"input-group-addon\"><i class=\"fa fa-calendar\"></i></span>");
        out.println("</div>");
        out.println("</div>");

        out.println("<input type=\"hidden\" name=\"documentid\" value=\"" + document.getDocumentId() + "\">");
        out.println(
                "<input type=\"submit\"  name=\"btnSubmit\"  value=\"Show Access History\" class=\"btn btn-sm btn-default btn-block\">");

        out.println("</form>");
        out.println("</div>");//col-sm-3
        out.println("</div>");//row
        out.println("</div>");//panel-body
        out.println("</div>");//panel

        out.println("</div>");//tab-pane active #accessHistory

        printModal("revisionHistoryModal");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    out.println("</div>");//tab-content
}

From source file:kreidos.diamond.web.view.console.ViewDocumentView.java

@SuppressWarnings("unchecked")
private void printDocument() throws Exception {
    Document document = (Document) request.getAttribute("DOCUMENT");
    DocumentRevision documentRevision = (DocumentRevision) request.getAttribute("DOCUMENTREVISION");
    DocumentClass documentClass = (DocumentClass) request.getAttribute("DOCUMENTCLASS");

    LinkedHashMap<String, String> documentIndexes = (LinkedHashMap<String, String>) request
            .getAttribute("DOCUMENTINDEXES");
    boolean isHeadRevision = document.getRevisionId().equalsIgnoreCase(documentRevision.getRevisionId());

    ACL acl = (ACL) request.getAttribute("ACL");

    if (view.trim().length() <= 0) {//do not show document id and revision id for attachment or quick view
        printBreadCrumbs();/*from  ww w.j  a v a  2  s.c o  m*/
    }

    out.println("<h3><i class=\"fa fa-folder-open\"></i> "
            + StringEscapeUtils.escapeHtml4(documentClass.getClassName()));
    out.println("<small>");
    out.println(
            "<span class=\"label label-success tip\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Document ID\">"
                    + documentRevision.getDocumentId() + "</span>&nbsp;");
    out.println(
            "<span class=\"label label-default tip\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"Revision ID\">"
                    + documentRevision.getRevisionId() + "</span>&nbsp;");
    out.println(
            "<span class=\"label label-success tip\" data-toggle=\"tooltip\" data-placement=\"bottom\" title=\"File Size\">"
                    + StringHelper.formatSizeText(documentRevision.getLength()) + "</span></small></h3>");

    String lastModified = "";
    if (document.getModified() == null) {
        lastModified = document.getCreated();
    } else {
        lastModified = document.getModified().toString();
    }
    out.println("Last Modified By &nbsp;" + StringEscapeUtils.escapeHtml4(document.getModifiedBy()));
    out.println("&nbsp;");
    out.println("On &nbsp;" + StringHelper.formatDate(lastModified));
    out.println(" (" + StringHelper.getFriendlyDateTime(lastModified) + ")");

    out.println("<hr/>");

    if (request.getAttribute(HTTPConstants.REQUEST_ERROR) != null) {
        printErrorDismissable((String) request.getAttribute(HTTPConstants.REQUEST_ERROR));
    }
    if (request.getAttribute(HTTPConstants.REQUEST_MESSAGE) != null) {
        printSuccessDismissable((String) request.getAttribute(HTTPConstants.REQUEST_MESSAGE));
    }

    out.println("<ul class=\"nav nav-tabs\" id=\"documenTabs\">");
    out.println("<li class=\"active\"><a href=\"#document\" data-toggle=\"tab\"><img src=\"/images/"
            + StringHelper.getIconFileNameForExtension(document.getExtension())
            + ".gif\" >&nbsp;Document</a></li>");
    out.println(
            "<li><a href=\"#documentNotes\" data-toggle=\"tab\" class=\"internal\"  datatarget=\"#resultNotes\" data-src=\"/console/documentnotes?documentid="
                    + document.getDocumentId() + "&revisionid=" + documentRevision.getRevisionId()
                    + "\"><i class=\"fa fa-comments-o\"></i> Notes</a></li>");
    out.println(
            "<li><a href=\"#accessHistory\" data-toggle=\"tab\" class=\"internal\"  datatarget=\"#resultAccessHistory\" data-src=\"/console/accesshistory?documentid="
                    + document.getDocumentId() + "&revisionid=" + documentRevision.getRevisionId()
                    + "\"><i class=\"fa fa-clock-o\"></i> Access History</a></li>");
    out.println("</ul>");
    out.println("<div class=\"tab-content\">");
    out.println("<div class=\"tab-pane in active\" id=\"document\"><br/>");
    out.println("<div class=\"row\">");
    out.println("<div class=\"col-sm-9\">");
    //viewer applet starts here
    try {

        out.println("<div class=\"well well-sm\" id=\"viewer\">");
        out.println("<iframe src = \"/js/ViewerJS/?type=pdf#/console/mobiledocumentviewer?documentid="
                + documentRevision.getDocumentId() + "&revisionid=" + documentRevision.getRevisionId()
                + "\" width='100%' height='800'></iframe>");
        out.println("</div>");//visible-xs

        if (acl.canEmail()) {
            out.println("<div class=\"panel panel-default\">");
            out.println("<div class=\"panel-heading\"><i class=\"fa fa-envelope-o\"></i> Share Document</div>");
            out.println("<div class=\"panel-body\">");
            out.println(
                    "<form action=\"/console/sharedocument\" method=\"post\" id=\"frmShareDocument\" form-type=\"ajax\" datatarget=\"#resultShareDocument\">");
            out.println("<div id=\"resultShareDocument\"></div>");
            out.println("<p>Fields marked with <span style='color:red'>*</span> are mandatory</p>");

            out.println("<div class=\"form-group\">");
            out.println("<label for=\"txtEmail\">Email ID <span style='color:red'>*</span></label>");
            out.println(
                    "<input type=\"text\" id=\"txtEmail\" name=\"txtEmail\" class=\"required form-control multiemail\" maxlength=\"500\" title=\"Please use a comma to separate multiple email addresses\"/>");
            out.println("</div>");

            out.println("<div class=\"form-group\">");
            out.println("<label for=\"txtComments\">Comments <span style='color:red'>*</span></label>");
            out.println(
                    "<textarea class=\"form-control required\" rows=\"4\" name=\"txtComments\"  id=\"txtComments\"  placeholder=\"Put your comments here\"></textarea>");
            out.println("</div>");
            out.println("<input type=\"hidden\"  name=\"documentid\"     value=\"" + document.getDocumentId()
                    + "\" />");
            out.println("<input type=\"hidden\"  name=\"revisionid\"     value=\""
                    + documentRevision.getRevisionId() + "\" />");
            out.println(
                    "<input type=\"submit\"  name=\"btnSubmit\"    id=\"btnShare\"    value=\"Share Document\"    class=\"btn btn-sm btn-default\"  data-loading-text=\"Sharing Document...\"/>");
            out.println("</form>");
            out.println("</div>");//panel-body
            out.println("</div>");//panel
        }

        out.println("</div>");//col-sm-9

        out.println("<div class=\"col-sm-3\">");
        String expiryOn = "";
        if (document.getExpiry() == null) {
            expiryOn = "";
        } else {
            expiryOn = document.getExpiry().toString();
            expiryOn = StringHelper.formatDate(expiryOn, ServerConstants.FORMAT_SHORT_DATE);
        }
        String lastAccessed = "";
        if (document.getLastAccessed() == null) {
            lastAccessed = document.getCreated();
        } else {
            lastAccessed = document.getLastAccessed().toString();
        }

        if (acl.canWrite() && document.getStatus().equalsIgnoreCase(Hit.STATUS_AVAILABLE) && isHeadRevision) {
            out.println("<div class=\"panel panel-default\">");
            out.println("<div class=\"panel-heading\"><i class=\"fa fa-list\"></i> Edit Indexes</div>");
            out.println("<div class=\"panel-body\">");
            out.println(
                    "<form action=\"/console/editdocumentindexes\" method=\"post\" id=\"frmEditIndexes\" accept-charset=\"utf-8\"  form-type=\"ajax\" datatarget=\"#resultIndexes\">");
            out.println("<div id=\"resultIndexes\"></div>");
            out.println("<p>Fields marked with <span style='color:red'>*</span> are mandatory</p>");
            for (IndexDefinition indexDefinition : documentClass.getIndexDefinitions()) {
                String required = "";
                out.println("<div class=\"form-group\">");
                out.println("<label for=\"" + indexDefinition.getIndexColumnName() + "\"> "
                        + StringEscapeUtils.escapeHtml4(indexDefinition.getIndexDisplayName()));
                if (indexDefinition.isMandatory()) {
                    required = "required";
                    out.println(" <span style='color:red'>*</span>");
                }
                out.println("</label>");

                String value = (String) documentIndexes.get(indexDefinition.getIndexDisplayName());
                value = StringEscapeUtils.escapeHtml4(value);

                if (indexDefinition.getIndexType().equals(IndexDefinition.INDEXTYPE_DATE)) {
                    out.println("<div class=\"input-group\">");
                    out.println("<input type=\"text\" class=\"shortdate isdate form-control " + required
                            + "\" name=\"" + indexDefinition.getIndexColumnName() + "\" id=\""
                            + indexDefinition.getIndexColumnName() + "\" value=\"" + value + "\" maxlength=\""
                            + indexDefinition.getIndexMaxLength() + "\"  cid=\"" + documentClass.getClassId()
                            + "\">");
                    out.println("<span class=\"input-group-addon\"><i class=\"fa fa-calendar\"></i></span>");
                    out.println("</div>");
                } else if (indexDefinition.getIndexType().equals(IndexDefinition.INDEXTYPE_NUMBER)) {
                    out.println("<input type=\"text\" class=\"number  form-control " + required
                            + " autocomplete\"    id=\"" + indexDefinition.getIndexColumnName() + "\" name=\""
                            + indexDefinition.getIndexColumnName() + "\" value=\"" + value + "\" maxlength=\""
                            + indexDefinition.getIndexMaxLength() + "\"   cid=\"" + documentClass.getClassId()
                            + "\">");
                } else {
                    out.println("<input type=\"text\" class=\"autocomplete form-control " + required
                            + " \" id=\"" + indexDefinition.getIndexColumnName() + "\"  name=\""
                            + indexDefinition.getIndexColumnName() + "\" value=\"" + value + "\" maxlength=\""
                            + indexDefinition.getIndexMaxLength() + "\"  cid=\"" + documentClass.getClassId()
                            + "\">");
                }
                out.println("</div>");
            }

            out.println("<hr/>");
            out.println("<div class=\"form-group\">");
            out.println("<label for=\"txtExpiryDate\"> Expiry On</label>");
            out.println("<div class=\"input-group\">");
            out.println(
                    "<input type=\"text\" class=\"shortdate isdate form-control\" name=\"txtExpiryDate\" id=\"txtExpiryDate\" maxlength=\"12\" value=\""
                            + expiryOn + "\"/>");
            out.println("<span class=\"input-group-addon\"><i class=\"fa fa-calendar\"></i></span>");
            out.println("</div>");
            out.println("</div>");

            out.println("<input type=\"hidden\" name=\"revisionid\" value=\"" + documentRevision.getRevisionId()
                    + "\">");
            out.println("<input type=\"hidden\"  name=\"documentid\"  value=\"" + document.getDocumentId()
                    + "\"/>");
            out.println(
                    "<input type=\"submit\"  name=\"btnSubmit\"  value=\"Submit\" class=\"btn btn-sm btn-default\">");

            out.println("</form>");
            out.println("</div>");//panel-body
            out.println("</div>");//panel

        } else {
            out.println("<div class=\"panel panel-default\">");
            out.println(
                    "<div class=\"panel-heading\"><i class=\"fa fa-check-square-o\"></i> Document Indexes</div>");
            out.println("<div class=\"panel-body\">");
            out.println("<div class=\"table-responsive\">");
            out.println("<table class=\"table table-hover\">");
            if (!documentIndexes.keySet().isEmpty()) {
                out.println("<thead>");
                out.println("<tr>");
                out.println("<th>Index Field</th>");
                out.println("<th>Index Value</th>");
                out.println("</tr>");
                out.println("</thead>");

                out.println("<tbody>");
                for (String indexName : documentIndexes.keySet()) {
                    String indexValue = (String) documentIndexes.get(indexName);
                    out.println("<tr>");
                    out.println("<td>" + StringEscapeUtils.escapeHtml4(indexName) + "</td>");
                    out.println("<td>" + StringEscapeUtils.escapeHtml4(indexValue) + "</td>");
                    out.println("</tr>");
                }
            }
            out.println("<tr class=\"text-success\">");
            out.println("<td >Expiry On</td>");
            out.println("<td>" + expiryOn + "</td>");
            out.println("</tr>");

            out.println("</tbody>");
            out.println("</table>");
            out.println("</div>");//table-responsive
            out.println("</div>");//panel-body
            out.println("</div>");//panel
        }

        out.println("<div class=\"panel panel-default\">");
        out.println("<div class=\"panel-heading\"><i class=\"fa fa-file\"></i> Document Properties</div>");
        out.println("<div class=\"table-responsive\">");
        out.println("<table class=\"table table-hover\">");
        out.println("<thead><tr><th>Property</th><th>Value</th></tr></thead>");
        out.println("<tbody>");
        if (document.getFilename() != null) //Show filename if present
            out.println("<tr><td>Filename</td><td> " + document.getFullFilename() + "</td></tr>");
        out.println("<tr><td>Created By</td><td> " + document.getCreatedBy() + "</td></tr>");
        out.println("<tr><td>Created On</td><td>" + StringHelper.getFriendlyDateTime(document.getCreated())
                + "</td></tr>");
        out.println("<tr><td>Last Accessed On</td><td>" + StringHelper.getFriendlyDateTime(lastAccessed)
                + "</td></tr>");
        out.println("<tr><td>Access Count</td><td>" + document.getAccessCount() + "</td></tr>");
        out.println("</tbody></table>");//
        out.println("</div>");//table-responsive
        out.println("</div>");//panel

        out.println("<div class=\"panel panel-default\">");
        out.println("<div class=\"panel-heading\"><i class=\"fa fa-bookmark\"></i> Bookmark Document</div>");
        out.println("<div class=\"panel-body\">");
        out.println(
                "<form action=\"/console/newbookmark\" method=\"post\" id=\"frmNewBookmark\"  form-type=\"ajax\" datatarget=\"#resultBookmark\" accept-charset=\"utf-8\">");
        out.println("<div id=\"resultBookmark\"></div>");
        out.println("<p>Fields marked with <span style='color:red'>*</span> are mandatory</p>");
        out.println("<div class=\"form-group\">");
        out.println("<label for=\"txtBookmarkName\">Bookmark Name<span style='color:red'>*</span></label>");
        out.println(
                "<input type=\"text\" id=\"txtBookmarkName\" name=\"txtBookmarkName\" class=\"required form-control\" maxlength=\"50\" title=\"Please enter Bookmark Name\"/>");
        out.println("</div>");
        out.println("<input type=\"hidden\"  name=\"documentid\"     value=\"" + document.getDocumentId()
                + "\" />");
        out.println("<input type=\"hidden\"  name=\"revisionid\"     value=\""
                + documentRevision.getRevisionId() + "\" />");
        out.println("<input type=\"submit\"  name=\"btnSubmit\"     value=\"" + "Save"
                + "\"    class=\"btn btn-sm btn-default\"/>");
        out.println("</form>");
        out.println("</div>");//panel-body
        out.println("</div>");//panel

        if (view.trim().length() <= 0) {
            out.println("<div class=\"well well-sm\">");
            if (acl.canDownload()) {
                out.println("<a href=\"/console/downloaddocument?documentid=" + document.getDocumentId()
                        + "&revisionid=" + documentRevision.getRevisionId()
                        + "\" class=\"btn btn-default btn-block \" title=\"Download Document\" ><i class=\"fa fa-download\"></i> Download Document</a>");
            }
            if (documentClass.isRevisionControlEnabled()) {
                if (document.getStatus().equalsIgnoreCase(Hit.STATUS_AVAILABLE) && isHeadRevision) {
                    if (acl.canCheckout()) {
                        out.println("<a href=\"/console/checkoutdocument?documentid=" + document.getDocumentId()
                                + "\" class=\"btn btn-default btn-block \" title=\"Check Out Document\" ><i class=\"fa fa-lock\"></i> Check Out Document</a>");
                    }
                }
                if (document.getStatus().equalsIgnoreCase(Hit.STATUS_LOCKED)) {
                    out.println("<a href=\"/console/cancelcheckout?documentid=" + document.getDocumentId()
                            + "\" class=\"btn  btn-default btn-block confirm\" title=\"Are you sure, you want to cancel checkout of this document?\" ><i class=\"fa fa-unlock-alt\"></i> Cancel Checkout</a>");
                    if (acl.canCheckin()) {
                        out.println("<a href=\"/console/checkindocument?documentid=" + document.getDocumentId()
                                + "\" class=\"btn  btn-default btn-block \" title=\"Check In\" ><i class=\"fa fa-arrow-right\"></i> Check In</a>");
                    }
                }
                out.println("<a href=\"/console/revisionhistory?documentid=" + document.getDocumentId()
                        + "\" data-toggle=\"modal\" data-target=\"#revisionHistoryModal\" class=\"btn  btn-default btn-block \" title=\"Revision History\"><i class=\"fa fa-clock-o\"></i> Revision History</a>");
            }
            if (acl.canDelete() && document.getStatus().equalsIgnoreCase(Hit.STATUS_AVAILABLE)
                    && isHeadRevision) {
                out.println("<a href=\"/console/deletedocument?documentid=" + document.getDocumentId()
                        + "\" class=\"btn btn-danger btn-block confirm\" title=\"Are you sure, you want to mark this document as deleted?\" ><i class=\"fa fa-trash-o\"></i> Delete Document</a>");
            }
            out.println("</div>");//well well-sm
        }
        out.println("</div>");//col-sm-3
        out.println("</div>");//row
        out.println("</div>");//tab-pane active #document

        out.println("<div class=\"tab-pane fade\" id=\"attachment\">");
        out.println(
                "<iframe frameborder=\"0\" border=\"0\" width=\"0\" height=\"0\" name=\"attachmentFrame\" id=\"attachmentFrame\" src=\"\" style=\"border:0px;\"></iframe>");

        out.println("<div class=\"row\">");
        out.println("<div class=\"col-sm-9\">");
        out.println("<div id=\"resultAttachments\"></div>");
        out.println("</div>");//col-sm-9

        out.println("<div class=\"col-sm-3\">");
        out.println("<div class=\"panel panel-default\">");
        out.println("<div class=\"panel-heading\"><i class=\"fa fa-paperclip\"></i> Add Attachment</div>");
        out.println("<div class=\"panel-body\">");
        out.println(
                "<form action=\"/console/attachments\" method=\"post\" id=\"frmAttachments\" name=\"frmAttachments\" enctype=\"multipart/form-data\" target=\"attachmentFrame\" accept-charset=\"utf-8\" class=\"internal\">");
        out.println("<p>Fields marked with <span style='color:red'>*</span> are mandatory</p>");

        out.println("<div class=\"form-group\">");
        out.println("<label for=\"fileDocument\">Select Document <span style='color:red'>*</span></label>");
        out.println(
                "<input type=\"file\" name=\"fileDocument\" class=\"required\" title=\"Please select document\">");
        out.println("</div>");

        out.println("<div class=\"form-group\">");
        out.println("<label for=\"TITLE\">Attachment Title <span class=\"text-success\">*</span></label>");
        out.println(
                "<input type=\"text\" name=\"TITLE\" id=\"TITLE\" class=\"form-control required\" title=\"Please enter attachment title\" placeholder=\"Attachment Title\"/>");
        out.println("</div>");

        out.println("<div class=\"form-group\">");
        out.println("<label for=\"KEYWORDS\">Attachment Keywords </label>");
        out.println(
                "<textarea name=\"KEYWORDS\" id=\"KEYWORDS\" rows=\"5\" class=\"form-control\" placeholder=\"Attachment Keywords\"></textarea>");
        out.println("</div>");

        out.println("<div class=\"form-group\" id=\"pbContainer\" style=\"display:none;\">");
        out.println("<div class=\"progress progress-striped active\" id=\"progressbarMain\">");
        out.println(
                "<div class=\"progress-bar progress-bar-success\" id=\"progressbar\" role=\"progressbar\" aria-valuenow=\"0\" aria-valuemin=\"0\" aria-valuemax=\"100\" style=\"width: 0%\">");
        out.println("<span class=\"sr-only\">0% Complete</span>");
        out.println("</div>");
        out.println("</div>");
        out.println(
                "<div id=\"progressMessage\" class=\"alert alert-success alert-dismissable\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button></div>");
        out.println("</div>");

        out.println("<input type=\"hidden\" name=\"DOCID\" value=\"" + document.getDocumentId() + "\">");
        out.println("<input type=\"hidden\" name=\"REVISIONID\" value=\"" + documentRevision.getRevisionId()
                + "\">");
        out.println(
                "<input type=\"submit\"  name=\"btnSubmit\"  value=\"Submit\" class=\"btn btn-sm btn-default\">");
        out.println("</form>");
        out.println("</div>");//col-sm-3
        out.println("</div>");//row
        out.println("</div>");//panel-body
        out.println("</div>");//panel
        out.println("</div>");//tab-pane active #attachment

        out.println("<div class=\"tab-pane fade\" id=\"documentNotes\"><br/>");
        out.println("<div class=\"row\">");
        out.println("<div class=\"col-sm-9\">");
        out.println("<div id=\"resultNotes\"></div>");//notes will be loaded here
        out.println("</div>");//col-sm-9
        out.println("<div class=\"col-sm-3\">");
        out.println("<div class=\"panel panel-default\">");
        out.println(
                "<div class=\"panel-heading\"><i class=\"fa fa-comment-o fa-lg\"></i> Add Note / Comments</div>");
        out.println("<div class=\"panel-body\">");
        out.println(
                "<form action=\"/console/documentnotes\" id=\"frmNotes\" method=\"post\"  form-type=\"ajax\" datatarget=\"#resultNotes\">");
        out.println("<p>Fields marked with <span style='color:red'>*</span> are mandatory</p>");
        out.println("<div class=\"form-group\">");
        out.println("<label for=\"txtNote\">Note / Comments <span class=\"text-success\">*</span></label>");
        out.println(
                "<textarea name=\"txtNote\" id=\"txtNote\" rows=\"5\" class=\"form-control required alphaNumericSpace\" title=\"Please enter note\" placeholder=\"Note / Comments\"></textarea>");
        out.println("</div>");

        out.println("<div class=\"form-group\">");
        out.println("<div class=\"btn-group\" data-toggle=\"buttons\">");
        out.println("<label class=\"btn btn-sm btn-default active\">");
        out.println(
                "<input type=\"radio\" id=\"radNoteType1\" name=\"radNoteType\" value=\"P\" checked>Public");
        out.println("</label>");
        out.println("<label class=\"btn btn-sm btn-default\">");
        out.println("<input type=\"radio\" id=\"radNoteType2\" name=\"radNoteType\"  value=\"U\">Private");
        out.println("</label>");
        out.println("</div>");
        out.println("</div>");

        out.println("<hr/>");
        out.println("<input type=\"hidden\" name=\"documentid\" value=\"" + document.getDocumentId() + "\">");
        out.println(
                "<input type=\"submit\"  name=\"btnSubmit\"  value=\"Submit\" class=\"btn btn-sm btn-default\">");

        out.println("</form>");
        out.println("</div>");//col-sm-3
        out.println("</div>");//row

        out.println("</div>");//panel-body
        out.println("</div>");//panel
        out.println("</div>");//tab-pane active #notes

        out.println("<div class=\"tab-pane fade\" id=\"accessHistory\"><br/>");
        out.println("<div class=\"row\">");
        out.println("<div class=\"col-sm-9\">");
        out.println("<div id=\"resultAccessHistory\"></div>");//access history will be loaded here
        out.println("</div>");//col-sm-9
        out.println("<div class=\"col-sm-3\">");
        out.println("<div class=\"panel panel-default\">");
        out.println(
                "<div class=\"panel-heading\"><i class=\"fa fa-filter fa-lg\"></i> Filter Access History</div>");
        out.println("<div class=\"panel-body\">");
        out.println(
                "<form action=\"/console/accesshistory\" id=\"frmAccessHistory\" method=\"post\" form-type=\"ajax\" datatarget=\"#resultAccessHistory\">");
        out.println("<div class=\"form-group\">");
        out.println("<label for=\"fromDate\">From</label>");
        out.println("<div class=\"input-group\">");
        out.println(
                "<input type=\"text\"  id=\"fromDate\" name=\"fromDate\" class=\"form-control shortdate isDate\">");
        out.println("<span class=\"input-group-addon\"><i class=\"fa fa-calendar\"></i></span>");
        out.println("</div>");
        out.println("</div>");

        out.println("<div class=\"form-group\">");
        out.println("<label for=\"toDate\">To</label>");
        out.println("<div class=\"input-group\">");
        out.println(
                "<input type=\"text\"  id=\"toDate\" name=\"toDate\" class=\" form-control shortdate isDate\">");
        out.println("<span class=\"input-group-addon\"><i class=\"fa fa-calendar\"></i></span>");
        out.println("</div>");
        out.println("</div>");

        out.println("<input type=\"hidden\" name=\"documentid\" value=\"" + document.getDocumentId() + "\">");
        out.println(
                "<input type=\"submit\"  name=\"btnSubmit\"  value=\"Show Access History\" class=\"btn btn-sm btn-default btn-block\">");

        out.println("</form>");
        out.println("</div>");//col-sm-3
        out.println("</div>");//row
        out.println("</div>");//panel-body
        out.println("</div>");//panel

        out.println("</div>");//tab-pane active #accessHistory

        printModal("revisionHistoryModal");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    out.println("</div>");//tab-content
}

From source file:com.disney.opa.dao.impl.ProductDaoImpl.java

private Product[] getChildProducts(int parentID, int languageID, int castAsTemplateID, int onlyRangeChildrens)
        throws PADataAccessException {
    if (log.isDebugEnabled()) {
        log.debug("Method getChildProducts(" + parentID + ", " + languageID + ", " + castAsTemplateID + ", "
                + onlyRangeChildrens + ") ... begin");
    }/*  w  w w . j av  a2s. c o m*/

    int childTemplateID = 0;
    Product[] array = null;
    String onlyRangeChildrensString = null;
    if (onlyRangeChildrens != JDBCUtil.IGNORED) {
        onlyRangeChildrensString = String.valueOf(onlyRangeChildrens);
    }
    // Step 1: Get all child headers
    /*
    ProductHeaderProcessor headerProcessor = new ProductHeaderProcessor();
    JDBCUtil.query(SP_GET_CHILD_PRODUCTS,
     new Object[] {String.valueOf(parentID), onlyRangeChildrensString},
     headerProcessor);
    List list = headerProcessor.getList();
    */
    String sql = JDBCUtil.query(SP_GET_CHILD_PRODUCTS,
            new Object[] { String.valueOf(parentID), onlyRangeChildrensString });

    MapSqlParameterSource parmSource = new MapSqlParameterSource();
    List<ProductHeader> list = namedJdbcTemplate.query(sql, parmSource, rowMappers.productHeaderRowMapper);

    ProductHeader[] headers = null;
    if (list != null && list.size() > 0) {
        headers = new ProductHeader[list.size()];
        list.toArray(headers);
    }

    if (headers != null && headers.length > 0) {
        LinkedHashMap map = new LinkedHashMap();

        for (int i = 0; i < headers.length; i++) {
            //Step 2: Load Attribute Set for each child template id (updated for FHB 2011 - not all child products have the same template)              
            childTemplateID = headers[i].getProductTemplateID();
            if (castAsTemplateID != JDBCUtil.IGNORED) {
                childTemplateID = castAsTemplateID;
            }
            int childProductStatusID = headers[i].getProductStatusID();
            boolean populateAvailableOptions = false;
            /*
            String sqlWithParameters = (populateAvailableOptions) ? SP_FIRSTSTEP_WITH_OPTION : SP_FIRSTSTEP_WITHOUT_OPTION;
            SetResultSetProcessor processor = new SetResultSetProcessor(populateAvailableOptions);
            JDBCUtil.query(sqlWithParameters,
                new Object[]{
             String.valueOf(childTemplateID),
             String.valueOf(childProductStatusID),
             String.valueOf(languageID)},
                processor);
            AttributeDefinitionSet set = processor.getPAAttributeDefinitionSet();
            */
            String sqlWithParameters = (populateAvailableOptions) ? SP_FIRSTSTEP_WITH_OPTION
                    : SP_FIRSTSTEP_WITHOUT_OPTION;
            String sqlChild = JDBCUtil.query(sqlWithParameters, new Object[] { String.valueOf(childTemplateID),
                    String.valueOf(childProductStatusID), String.valueOf(languageID) });
            MapSqlParameterSource parmSourceChild = new MapSqlParameterSource();
            List<AttributeDefinitionSet> listChildren = namedJdbcTemplate.query(sqlChild, parmSourceChild,
                    rowMappers.processResultSetRowMapper);
            AttributeDefinitionSet set = null;
            if (listChildren != null && listChildren.size() > 0) {
                set = listChildren.get(0);
            }

            //Step 3: Build products with headers, no attribute value yet
            ProductHeader header = headers[i];

            Product product = new Product();
            product.setID(header.getProductID());
            product.setAssociateUserID(header.getAssociateID());
            product.setTechnicalLeadUserID(header.getTechnicalLeadID());
            product.setProductStatusID(header.getProductStatusID());
            product.setCreatorID(header.getCreatorID());
            product.setLicenseeCompanyID(header.getLicenseeCompanyID());
            product.setLicenseeUserID(header.getLicenseeID());
            product.setProductTemplateID(header.getProductTemplateID());
            product.setLastUpdateDate(header.getUpdateDate());
            product.setActive(header.isActive());
            product.setParentID(header.getParentID());

            product.setAttributeDefinitionSet(set);
            AttributeDefinition[] definitions = set.getAllAttributeDefinitions();
            if (definitions != null && definitions.length > 0) {
                for (int j = 0; j < definitions.length; j++) {
                    product.initAttribute(definitions[j]);
                }
            }

            map.put(new Integer(product.getID()), product);
        }

        // Step 4: Populate attribute values for each product
        // TODO setup all the child attributes
        String processedTemplateIds = "";
        for (int i = 0; i < headers.length; i++) {
            String templateId = String.valueOf(headers[i].getProductTemplateID());
            if (processedTemplateIds.indexOf(templateId) < 0) {

                /*
                ChildrenProductAttributeProcessor attributeValuesProcessor =
                   new ChildrenProductAttributeProcessor(map);
                JDBCUtil.query(SP_GET_CHILD_PRODUCTS_ATTRIBUTES,
                    new Object[]{
                String.valueOf(languageID),
                String.valueOf(parentID),
                String.valueOf(headers[i].getProductTemplateID())},
                    attributeValuesProcessor);
                */

                sql = JDBCUtil.query(SP_GET_CHILD_PRODUCTS_ATTRIBUTES,
                        new Object[] { String.valueOf(languageID), String.valueOf(parentID),
                                String.valueOf(headers[i].getProductTemplateID()) });

                parmSource = new MapSqlParameterSource();
                List<Attribute> AttributeList = namedJdbcTemplate.query(sql, parmSource,
                        rowMappers.attributeResultSetExtractor);
                Product currentProduct = (Product) map.get(Integer.valueOf(headers[i].getProductID()));
                for (Attribute a : AttributeList) {
                    for (Attribute productAttribute : currentProduct.getAllAttributes()) {
                        if (a.getAttributeId() == productAttribute.getAttributeId()) {
                            if (null != a.getValues()) {
                                productAttribute.set(a.getValues());
                            } else {
                                productAttribute.add(a.getValue());
                            }
                            productAttribute.setDirty(false);
                        }
                    }
                }
                processedTemplateIds += templateId + ";";
            }
        }

        array = new Product[list.size()];
        map.values().toArray(array);

        // Set dirty flag to false for each attribute
        // so future update will check if an attribute is dirty to determine if an update is necessary.
        for (int i = 0; i < array.length; i++) {
            if (array[i] != null) {
                Attribute[] attributes = array[i].getAllAttributes();
                if (attributes != null && attributes.length > 0) {
                    for (int j = 0; j < attributes.length; j++) {
                        Attribute a = (Attribute) attributes[j];
                        a.setDirty(false);
                    }
                }
            }
        }
    }

    if (log.isDebugEnabled()) {
        log.debug("Method getChildProducts(" + parentID + ", " + languageID + ", " + castAsTemplateID + ", "
                + onlyRangeChildrens + ") ... end");
    }

    return array;
}

From source file:com.intellectualcrafters.plot.database.SQLManager.java

/**
 * @return//from   w w w .  j ava  2s. c o  m
 */
@Override
public LinkedHashMap<String, HashMap<PlotId, Plot>> getPlots() {
    final LinkedHashMap<String, HashMap<PlotId, Plot>> newplots = new LinkedHashMap<String, HashMap<PlotId, Plot>>();
    try {
        final DatabaseMetaData data = connection.getMetaData();
        ResultSet rs = data.getColumns(null, null, prefix + "plot", "plot_id");
        final boolean execute = rs.next();
        if (execute) {
            final Statement statement = connection.createStatement();
            statement.addBatch("ALTER IGNORE TABLE `" + prefix + "plot` ADD `plot_id_x` int(11) DEFAULT 0");
            statement.addBatch("ALTER IGNORE TABLE `" + prefix + "plot` ADD `plot_id_z` int(11) DEFAULT 0");
            statement.addBatch("UPDATE `" + prefix + "plot` SET\n" + "    `plot_id_x` = IF("
                    + "        LOCATE(';', `plot_id`) > 0,"
                    + "        SUBSTRING(`plot_id`, 1, LOCATE(';', `plot_id`) - 1)," + "        `plot_id`"
                    + "    )," + "    `plot_id_z` = IF(" + "        LOCATE(';', `plot_id`) > 0,"
                    + "        SUBSTRING(`plot_id`, LOCATE(';', `plot_id`) + 1)," + "        NULL" + "    )");
            statement.addBatch("ALTER TABLE `" + prefix + "plot` DROP `plot_id`");
            statement.addBatch(
                    "ALTER IGNORE TABLE `" + prefix + "plot_settings` ADD `flags` VARCHAR(512) DEFAULT NULL");
            statement.executeBatch();
            statement.close();
        }
        rs = data.getColumns(null, null, prefix + "plot_settings", "merged");
        if (!rs.next()) {
            final Statement statement = connection.createStatement();
            statement.addBatch("ALTER TABLE `" + prefix + "plot_settings` ADD `merged` int(11) DEFAULT NULL");
            statement.executeBatch();
            statement.close();
        }
    } catch (final Exception e) {
        e.printStackTrace();
    }
    final HashMap<Integer, Plot> plots = new HashMap<Integer, Plot>();

    Statement stmt = null;
    try {

        Set<String> worlds = new HashSet<String>();
        if (PlotMain.config.contains("worlds")) {
            worlds = PlotMain.config.getConfigurationSection("worlds").getKeys(false);
        }

        final HashMap<String, UUID> uuids = new HashMap<String, UUID>();
        final HashMap<String, Integer> noExist = new HashMap<String, Integer>();

        /*
         * Getting plots
         */
        stmt = connection.createStatement();
        ResultSet r = stmt.executeQuery(
                "SELECT `id`, `plot_id_x`, `plot_id_z`, `owner`, `world` FROM `" + prefix + "plot`");
        PlotId plot_id;
        int id;
        Plot p;
        String o;
        UUID user;
        while (r.next()) {
            plot_id = new PlotId(r.getInt("plot_id_x"), r.getInt("plot_id_z"));
            id = r.getInt("id");
            final String worldname = r.getString("world");
            if (!worlds.contains(worldname)) {
                if (noExist.containsKey(worldname)) {
                    noExist.put(worldname, noExist.get(worldname) + 1);
                } else {
                    noExist.put(worldname, 1);
                }
            }
            o = r.getString("owner");
            user = uuids.get(o);
            if (user == null) {
                user = UUID.fromString(o);
                uuids.put(o, user);
            }
            p = new Plot(plot_id, user, Biome.FOREST, new ArrayList<UUID>(), new ArrayList<UUID>(),
                    new ArrayList<UUID>(), "", PlotHomePosition.DEFAULT, null, worldname,
                    new boolean[] { false, false, false, false });
            plots.put(id, p);
        }
        //            stmt.close();

        /*
         * Getting helpers
         */
        //            stmt = connection.createStatement();
        r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + prefix + "plot_helpers`");
        while (r.next()) {
            id = r.getInt("plot_plot_id");
            o = r.getString("user_uuid");
            user = uuids.get(o);
            if (user == null) {
                user = UUID.fromString(o);
                uuids.put(o, user);
            }
            final Plot plot = plots.get(id);
            if (plot != null) {
                plot.addHelper(user);
            } else {
                PlotMain.sendConsoleSenderMessage("&cPLOT " + id
                        + " in plot_helpers does not exist. Please create the plot or remove this entry.");
            }
        }
        //            stmt.close();

        /*
         * Getting trusted
         */
        //            stmt = connection.createStatement();
        r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + prefix + "plot_trusted`");
        while (r.next()) {
            id = r.getInt("plot_plot_id");
            o = r.getString("user_uuid");
            user = uuids.get(o);
            if (user == null) {
                user = UUID.fromString(o);
                uuids.put(o, user);
            }
            final Plot plot = plots.get(id);
            if (plot != null) {
                plot.addTrusted(user);
            } else {
                PlotMain.sendConsoleSenderMessage("&cPLOT " + id
                        + " in plot_trusted does not exist. Please create the plot or remove this entry.");
            }
        }
        //            stmt.close();

        /*
         * Getting denied
         */
        //            stmt = connection.createStatement();
        r = stmt.executeQuery("SELECT `user_uuid`, `plot_plot_id` FROM `" + prefix + "plot_denied`");
        while (r.next()) {
            id = r.getInt("plot_plot_id");
            o = r.getString("user_uuid");
            user = uuids.get(o);
            if (user == null) {
                user = UUID.fromString(o);
                uuids.put(o, user);
            }
            final Plot plot = plots.get(id);
            if (plot != null) {
                plot.addDenied(user);
            } else {
                PlotMain.sendConsoleSenderMessage("&cPLOT " + id
                        + " in plot_denied does not exist. Please create the plot or remove this entry.");
            }
        }
        //            stmt.close();

        //            stmt = connection.createStatement();
        r = stmt.executeQuery("SELECT * FROM `" + prefix + "plot_settings`");
        while (r.next()) {
            id = r.getInt("plot_plot_id");
            final Plot plot = plots.get(id);
            if (plot != null) {

                final String b = r.getString("biome");
                Biome biome = null;
                if (b != null) {
                    for (final Biome mybiome : Biome.values()) {
                        if (mybiome.toString().equalsIgnoreCase(b)) {
                            biome = mybiome;
                            break;
                        }
                    }
                }

                final String alias = r.getString("alias");
                if (alias != null) {
                    plot.settings.setAlias(alias);
                }

                final String pos = r.getString("position");
                if (pos != null) {
                    for (final PlotHomePosition plotHomePosition : PlotHomePosition.values()) {
                        if (plotHomePosition.isMatching(pos)) {
                            if (plotHomePosition != PlotHomePosition.DEFAULT) {
                                plot.settings.setPosition(plotHomePosition);
                            }
                            break;
                        }
                    }
                }
                final Integer m = r.getInt("merged");
                if (m != null) {
                    final boolean[] merged = new boolean[4];
                    for (int i = 0; i < 4; i++) {
                        merged[3 - i] = ((m) & (1 << i)) != 0;
                    }
                    plot.settings.setMerged(merged);
                } else {
                    plot.settings.setMerged(new boolean[] { false, false, false, false });
                }

                String[] flags_string;
                final String myflags = r.getString("flags");
                if (myflags == null) {
                    flags_string = new String[] {};
                } else {
                    flags_string = myflags.split(",");
                }
                final ArrayList<Flag> flags = new ArrayList<Flag>();
                boolean exception = false;
                for (final String element : flags_string) {
                    if (element.contains(":")) {
                        final String[] split = element.split(":");
                        try {
                            flags.add(new Flag(FlagManager.getFlag(split[0], true),
                                    split[1].replaceAll("\u00AF", ":").replaceAll("", ",")));
                        } catch (final Exception e) {
                            exception = true;
                        }
                    } else {
                        flags.add(new Flag(FlagManager.getFlag(element, true), ""));
                    }
                }
                if (exception) {
                    PlotMain.sendConsoleSenderMessage(
                            "&cPlot " + id + " had an invalid flag. A fix has been attempted.");
                    setFlags(id, flags.toArray(new Flag[0]));
                }
                plot.settings.setFlags(flags.toArray(new Flag[0]));
            } else {
                PlotMain.sendConsoleSenderMessage("&cPLOT " + id
                        + " in plot_settings does not exist. Please create the plot or remove this entry.");
            }
        }
        stmt.close();
        for (final Plot plot : plots.values()) {
            final String world = plot.world;
            if (!newplots.containsKey(world)) {
                newplots.put(world, new HashMap<PlotId, Plot>());
            }
            newplots.get(world).put(plot.id, plot);
        }
        boolean invalidPlot = false;
        for (final String worldname : noExist.keySet()) {
            invalidPlot = true;
            PlotMain.sendConsoleSenderMessage("&c[WARNING] Found " + noExist.get(worldname)
                    + " plots in DB for non existant world; '" + worldname + "'.");
        }
        if (invalidPlot) {
            PlotMain.sendConsoleSenderMessage(
                    "&c[WARNING] - Please create the world/s or remove the plots using the purge command");
        }
    } catch (final SQLException e) {
        Logger.add(LogLevel.WARNING, "Failed to load plots.");
        e.printStackTrace();
    }
    return newplots;
}