Pages

Saturday 10 November 2018

Converting InputStream to String


    private String convertToString(InputStream inputStreamObj)
            throws IOException {
        if (inputStreamObj != null) {
            Writer writer = new StringWriter();
            char[] buffer = new char[1024];
            try {
                Reader reader = new BufferedReader(new InputStreamReader(
                        inputStreamObj, "UTF-8"));
                int n;
                while ((n = reader.read(buffer)) != -1) {
                    writer.write(buffer, 0, n);
                }
            } finally {
                inputStreamObj.close();
            }
            return writer.toString();
        } else {
            return "";
        }
    }

Keyboard shortcuts in CRXDE Lite

Ctrl-G - Go to path/Search
Ctrl-Shift-R - Reload selected node
Ctrl-O - Open selected file
Ctrl-N - Create a node
Ctrl-Alt-N - Create a node
Ctrl-Shift-N - Create a file
Ctrl-M - Move a node
Ctrl-Shift-C - Copy node to clipboard
Ctrl-Shift-V - Paste node from clipboard
Shift-Del - Delete node ( When focus is on Repository Tree)
Shift-Del - Delete property (When focus is on Property Editor)


CQ Developer Tricks

Here are a list of tricks that are useful for Developers.


Remove #cf/
Don’t want to see/wait for the content-finder while refreshing pages, just remove #cf/ in your url.
 
?debug=layout
Shows you all details of the components used on your page
 
?debugConsole=true
Runs Firebug Lite inside your browser
 
?wcmmode=(edit|preview|design|disabled)
This parameter sets your WcmMode in the specified mode, makes testing for a particular WcmMode easier .
 
?debugClientLibs=true
Writes out all Clientlib categories as separate files (check your HTML-source).
 
CTRL+SHIFT+U
In combination with ?debugClientLibs=true will show you timing information of your page
 
http://server/libs/cq/ui/content/dumplibs.html
Shows you all information around the clientlibs used in your CQ5-environment.

Saturday 22 October 2016

Appending or Concatenating Strings

Appending two strings

${'{0} {1}' @ format=[properties.property1,properties.property2]}

In other way

${[properties.property1,properties.property1] @ join=' '}
 

  This shows that we are appending two strings with a single white space. You can use any other elements/characters.

Appending .html to the URL in Sightly

<a href="${properties.path ? '{0}.{1}' : 'Default Path'  @ format=[properties.path,'html']}" class="link">${properties.title || 'Default Title'}</a>

Or

<a href="${currentPage.path @ extension = 'html'}">${currentPage.title}</a>

AEM Node to JSON Converter Logic Ignoring Unnecessary Properties

            final Node node = resource.adaptTo(Node.class);
            /* Node properties to exclude from the JSON object. */
            @SuppressWarnings("serial")
            final Set<String> propertiesToIgnore = new HashSet<String>() {{
                add("jcr:created");
                add("jcr:createdBy");
                add("jcr:lastModified");
                add("jcr:lastModifiedBy");
                add("jcr:versionHistory");
                add("jcr:predecessors");
                add("jcr:baseVersion");
                add("jcr:uuid");
                add("sling:resourceType");
                add("jcr:primaryType");
            }};
           
            StringWriter stringWriter = new StringWriter();
            JsonItemWriter jsonWriter = new JsonItemWriter(propertiesToIgnore);
            JSONObject jsonObject = null;

            try {
                jsonWriter.dump(node, stringWriter, 0);
                jsonObject = new JSONObject(stringWriter.toString());
                return jsonObject;
            } catch (RepositoryException e) {
                LOG.info("Repository exception :: {} ", e);
            } catch (JSONException e) {
                LOG.info("JSON exception :: {} ", e);
                e.printStackTrace();
            } catch (Exception e) {
                LOG.info("Exception :: {} ", e);
            }

Converting InputStream to String

    private String convertToString(InputStream inputStreamObj)             throws IOException {         if (inputStreamObj != null) {     ...