<commit_before>/* Copyright 2006 The JA-SIG Collaborative.  All rights reserved.
*  See license distributed with this file and
*  available online at http://www.uportal.org/license.html
*/

package org.jasig.portal.layout.dlm.publisher;

import java.io.FileOutputStream;
import java.util.Enumeration;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;



import org.jasig.portal.PortalException;
import org.jasig.portal.StructureStylesheetUserPreferences;
import org.jasig.portal.UserProfile;
import org.jasig.portal.i18n.LocaleManager;
import org.jasig.portal.layout.IUserLayout;
import org.jasig.portal.layout.IUserLayoutManager;
import org.jasig.portal.layout.IUserLayoutStore;
import org.jasig.portal.layout.TransientUserLayoutManagerWrapper;
import org.jasig.portal.layout.UserLayoutManagerFactory;
import org.jasig.portal.layout.dlm.RDBMDistributedLayoutStore;
import org.jasig.portal.layout.node.IUserLayoutChannelDescription;
import org.jasig.portal.layout.node.IUserLayoutFolderDescription;
import org.jasig.portal.layout.node.IUserLayoutNodeDescription;
import org.jasig.portal.layout.node.UserLayoutFolderDescription;
import org.jasig.portal.security.IPerson;
import org.jasig.portal.security.PersonFactory;
import org.jasig.portal.utils.DocumentFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class DlmLayoutExporter {

    // Static Members.
    private static final Log log = LogFactory.getLog(DlmLayoutExporter.class);
    private static final int PROFILE_ID = 1;
    private static final int LAYOUT_ID = 1;
    private static final int STYLESHEET_ID = 4;
    private static final int THEME_ID = 3;

    public static void main(String[] args) {

        // PrintWriter out = new PrintWriter(System.out);
        log.info("DLM Layout Exporter Tool");
        log.info("");

        switch (args.length) {
            case 2:

                try {

                    // Set up the layout store...
                    IUserLayoutStore store = new RDBMDistributedLayoutStore();

                    // The first argument should be a valid username...
                    String uName = (args[0]);
                    System.out.print("Exporting layout for user '" + uName + "'...");
                    int uId = DlmLayoutPublisher.lookupUserId(uName);
                    IPerson usr = PersonFactory.createGuestPerson();
                    usr.setAttribute(IPerson.USERNAME, uName);
                    usr.setID(uId);

                    // Construct the layout manager...
                    UserProfile prf = new UserProfile(PROFILE_ID, "User Profile for " + uName, "User Profile", LAYOUT_ID, STYLESHEET_ID, THEME_ID);
                    LocaleManager lm = new LocaleManager(usr);
                    prf.setLocaleManager(lm);
                    IUserLayoutManager dlm = ((TransientUserLayoutManagerWrapper) UserLayoutManagerFactory
                                            .getUserLayoutManager(usr, prf)).getOriginalLayoutManager();

                    // Retrieve the layout...
                    StructureStylesheetUserPreferences ssup = store.getStructureStylesheetUserPreferences(usr, PROFILE_ID, STYLESHEET_ID);
                    IUserLayout layout = dlm.getUserLayout();
                    String rootId = layout.getRootId();
                    IUserLayoutNodeDescription root = layout.getNodeDescription(rootId);

                    // Set up the Document...
                    Document doc = DocumentFactory.getNewDocument();
                    Element layoutElement = doc.createElement("layout");
                    doc.appendChild(layoutElement);
                    layoutElement.setAttribute("user", uName);
                    Element rootFolderElement = doc.createElement("root-folder");
                    layoutElement.appendChild(rootFolderElement);

                    // Analyze the layout...
                    populateChildren(rootFolderElement, (IUserLayoutFolderDescription) root, dlm, ssup);

                    // Write to the indicated file...
                    // JAXP seralizing
                    TransformerFactory xformFactory 
                      = TransformerFactory.newInstance();
                    Transformer idTransform = xformFactory.newTransformer();
                    Source input = new DOMSource(doc);
                    Result output = new StreamResult(new FileOutputStream(args[1]));
                    idTransform.setOutputProperty(OutputKeys.INDENT,"yes");
                   	idTransform.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
                    idTransform.transform(input, output);       
                    
                } catch (Throwable t) {
                    log.error("The exporter tool terminated unexpectedly.", t);
                    System.out.println("The exporter tool terminated unexpectedly.");
                    t.printStackTrace(System.out);
                    System.exit(7);
                }

                break;

            default:<commit_msg>UP-1501: fixed type-o<commit_after>/* Copyright 2006 The JA-SIG Collaborative.  All rights reserved.
*  See license distributed with this file and
*  available online at http://www.uportal.org/license.html
*/

package org.jasig.portal.layout.dlm.publisher;

import java.io.FileOutputStream;
import java.util.Enumeration;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;



import org.jasig.portal.PortalException;
import org.jasig.portal.StructureStylesheetUserPreferences;
import org.jasig.portal.UserProfile;
import org.jasig.portal.i18n.LocaleManager;
import org.jasig.portal.layout.IUserLayout;
import org.jasig.portal.layout.IUserLayoutManager;
import org.jasig.portal.layout.IUserLayoutStore;
import org.jasig.portal.layout.TransientUserLayoutManagerWrapper;
import org.jasig.portal.layout.UserLayoutManagerFactory;
import org.jasig.portal.layout.dlm.RDBMDistributedLayoutStore;
import org.jasig.portal.layout.node.IUserLayoutChannelDescription;
import org.jasig.portal.layout.node.IUserLayoutFolderDescription;
import org.jasig.portal.layout.node.IUserLayoutNodeDescription;
import org.jasig.portal.layout.node.UserLayoutFolderDescription;
import org.jasig.portal.security.IPerson;
import org.jasig.portal.security.PersonFactory;
import org.jasig.portal.utils.DocumentFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class DlmLayoutExporter {

    // Static Members.
    private static final Log log = LogFactory.getLog(DlmLayoutExporter.class);
    private static final int PROFILE_ID = 1;
    private static final int LAYOUT_ID = 1;
    private static final int STYLESHEET_ID = 4;
    private static final int THEME_ID = 3;

    public static void main(String[] args) {

        // PrintWriter out = new PrintWriter(System.out);
        log.info("DLM Layout Exporter Tool");
        log.info("");

        switch (args.length) {
            case 2:

                try {

                    // Set up the layout store...
                    IUserLayoutStore store = new RDBMDistributedLayoutStore();

                    // The first argument should be a valid username...
                    String uName = (args[0]);
                    System.out.print("Exporting layout for user '" + uName + "'...");
                    int uId = DlmLayoutPublisher.lookupUserId(uName);
                    IPerson usr = PersonFactory.createGuestPerson();
                    usr.setAttribute(IPerson.USERNAME, uName);
                    usr.setID(uId);

                    // Construct the layout manager...
                    UserProfile prf = new UserProfile(PROFILE_ID, "User Profile for " + uName, "User Profile", LAYOUT_ID, STYLESHEET_ID, THEME_ID);
                    LocaleManager lm = new LocaleManager(usr);
                    prf.setLocaleManager(lm);
                    IUserLayoutManager dlm = ((TransientUserLayoutManagerWrapper) UserLayoutManagerFactory
                                            .getUserLayoutManager(usr, prf)).getOriginalLayoutManager();

                    // Retrieve the layout...
                    StructureStylesheetUserPreferences ssup = store.getStructureStylesheetUserPreferences(usr, PROFILE_ID, STYLESHEET_ID);
                    IUserLayout layout = dlm.getUserLayout();
                    String rootId = layout.getRootId();
                    IUserLayoutNodeDescription root = layout.getNodeDescription(rootId);

                    // Set up the Document...
                    Document doc = DocumentFactory.getNewDocument();
                    Element layoutElement = doc.createElement("layout");
                    doc.appendChild(layoutElement);
                    layoutElement.setAttribute("user", uName);
                    Element rootFolderElement = doc.createElement("root-folder");
                    layoutElement.appendChild(rootFolderElement);

                    // Analyze the layout...
                    populateChildren(rootFolderElement, (IUserLayoutFolderDescription) root, dlm, ssup);

                    // Write to the indicated file...
                    // JAXP serializing
                    TransformerFactory xformFactory 
                      = TransformerFactory.newInstance();
                    Transformer idTransform = xformFactory.newTransformer();
                    Source input = new DOMSource(doc);
                    Result output = new StreamResult(new FileOutputStream(args[1]));
                    idTransform.setOutputProperty(OutputKeys.INDENT,"yes");
                   	idTransform.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
                    idTransform.transform(input, output);       
                    
                } catch (Throwable t) {
                    log.error("The exporter tool terminated unexpectedly.", t);
                    System.out.println("The exporter tool terminated unexpectedly.");
                    t.printStackTrace(System.out);
                    System.exit(7);
                }

                break;

            default:
{'fraction_non_alphanumeric': 0.09017998694395225, 'fraction_numerical': 0.003543784388697193, 'mean_word_length': 2.262549437176757, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '375552', 'n_tokens_mistral': 2802, 'n_tokens_neox': 2677, 'n_words': 571}