Package com.dotcms.repackage.org.dom4j

Examples of com.dotcms.repackage.org.dom4j.Element


    SAXReader reader = new SAXReader();
    //reader.setEntityResolver(resolver);

    Document doc = reader.read(new StringReader(xml));

    Element root = doc.getRootElement();

    Set userAttributes = new HashSet();

    Iterator itr1 = root.elements("user-attribute").iterator();

    while (itr1.hasNext()) {
      Element userAttribute = (Element)itr1.next();

      String name = userAttribute.elementText("name");

      userAttributes.add(name);
    }

    itr1 = root.elements("portlet").iterator();

    while (itr1.hasNext()) {
      Element portlet = (Element)itr1.next();

      String portletId = portlet.elementText("portlet-name");
      if (servletContextName != null) {
        portletId =
          servletContextName + PortletConfigImpl.WAR_SEPARATOR +
          portletId;
      }

      portletIds.add(portletId);

      Portlet portletModel = (Portlet)portletsPool.get(portletId);
      if (portletModel == null) {
        portletModel = new Portlet(
          new PortletPK(portletId, _SHARED_KEY, _SHARED_KEY));

        portletsPool.put(portletId, portletModel);
      }

      if (servletContextName != null) {
        portletModel.setWARFile(true);
      }

      portletModel.setPortletClass(portlet.elementText("portlet-class"));

      Iterator itr2 = portlet.elements("init-param").iterator();

      while (itr2.hasNext()) {
        Element initParam = (Element)itr2.next();

        portletModel.getInitParams().put(
          initParam.elementText("name"),
          initParam.elementText("value"));
      }

      Element expirationCache = portlet.element("expiration-cache");
      if (expirationCache != null) {
        portletModel.setExpCache(new Integer(GetterUtil.getInteger(
          expirationCache.getText())));
      }

      itr2 = portlet.elements("supports").iterator();

      while (itr2.hasNext()) {
        Element supports = (Element)itr2.next();

        String mimeType = supports.elementText("mime-type");

        Iterator itr3 = supports.elements("portlet-mode").iterator();

        while (itr3.hasNext()) {
          Element portletMode = (Element)itr3.next();

          Set mimeTypeModes =
            (Set)portletModel.getPortletModes().get(mimeType);

          if (mimeTypeModes == null) {
            mimeTypeModes = new HashSet();

            portletModel.getPortletModes().put(
              mimeType, mimeTypeModes);
          }

          mimeTypeModes.add(portletMode.getTextTrim().toLowerCase());
        }
      }

      Set supportedLocales = portletModel.getSupportedLocales();

      supportedLocales.add(Locale.getDefault().getLanguage());

      itr2 = portlet.elements("supported-locale").iterator();

      while (itr2.hasNext()) {
        Element supportedLocaleEl = (Element)itr2.next();

        String supportedLocale = supportedLocaleEl.getText();

        supportedLocales.add(supportedLocale);
      }

      portletModel.setResourceBundle(
        portlet.elementText("resource-bundle"));

      Element portletInfo = portlet.element("portlet-info");

      String portletInfoTitle = null;
      String portletInfoShortTitle = null;
      String portletInfoKeyWords = null;

      if (portletInfo != null) {
        portletInfoTitle = portletInfo.elementText("title");
        portletInfoShortTitle = portletInfo.elementText("short-title");
        portletInfoKeyWords = portletInfo.elementText("keywords");
      }

      portletModel.setPortletInfo(new PortletInfo(
        portletInfoTitle, portletInfoShortTitle, portletInfoKeyWords));

      Element portletPreferences = portlet.element("portlet-preferences");

      String defaultPreferences = null;
      String prefsValidator = null;

      if (portletPreferences != null) {
        Element prefsValidatorEl =
          portletPreferences.element("preferences-validator");

        String prefsValidatorName = null;

        if (prefsValidatorEl != null) {
          prefsValidator = prefsValidatorEl.getText();

          portletPreferences.remove(prefsValidatorEl);
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        XMLWriter writer = new XMLWriter(
          baos, OutputFormat.createCompactFormat());

        writer.write(portletPreferences);

        defaultPreferences = baos.toString();
      }

      portletModel.setDefaultPreferences(defaultPreferences);
      portletModel.setPreferencesValidator(prefsValidator);

      if (!portletModel.isWARFile() &&
        Validator.isNotNull(prefsValidator) &&
        GetterUtil.getBoolean(PropsUtil.get(
          PropsUtil.PREFERENCE_VALIDATE_ON_STARTUP))) {

        try {
          PreferencesValidator prefsValidatorObj =
            PortalUtil.getPreferencesValidator(portletModel);

          prefsValidatorObj.validate(
            PortletPreferencesSerializer.fromDefaultXML(
              defaultPreferences));
        }
        catch (Exception e) {
          _log.warn(
            "Portlet with the name " + portletId +
              " does not have valid default preferences");
        }
      }

      List roles = new ArrayList();

      itr2 = portlet.elements("security-role-ref").iterator();

      while (itr2.hasNext()) {
        Element role = (Element)itr2.next();

        roles.add(role.elementText("role-name"));
      }

      portletModel.setRolesArray((String[])roles.toArray(new String[0]));

      portletModel.getUserAttributes().addAll(userAttributes);
View Full Code Here


    Set portletIds = new HashSet();

    Iterator itr1 = doc.getRootElement().elements("category").iterator();

    while (itr1.hasNext()) {
      Element category = (Element)itr1.next();

      String name = category.attributeValue("name");

      List portlets = new ArrayList();

      Iterator itr2 = category.elements("portlet").iterator();

      while (itr2.hasNext()) {
        Element portlet = (Element)itr2.next();

        String portletId = portlet.attributeValue("id");
        if (servletContextName != null) {
          portletId =
            servletContextName + PortletConfigImpl.WAR_SEPARATOR +
            portletId;
        }

        portletIds.add(portletId);

        String status = portlet.attributeValue("status");

        portlets.add(new KeyValuePair(portletId, status));
      }

      if (portlets.size() > 0) {
        categories.put(name, portlets);
      }
    }

    // Portlets that do not belong to any categories should default to the
    // Undefined category

    List undefinedPortlets = new ArrayList();

    itr1 = _getPortletsPool().values().iterator();

    while (itr1.hasNext()) {
      Portlet portlet = (Portlet)itr1.next();

      String portletId = portlet.getPortletId();

      if ((servletContextName != null) && (portlet.isWARFile()) &&
        (portletId.startsWith(servletContextName) &&
        (!portletIds.contains(portletId)))) {

        undefinedPortlets.add(new KeyValuePair(portletId, null));
      }
      else if ((servletContextName == null) && (!portlet.isWARFile()) &&
           (!portletIds.contains(portletId))) {

        undefinedPortlets.add(new KeyValuePair(portletId, null));
      }
    }
View Full Code Here

    SAXReader reader = new SAXReader();
    reader.setEntityResolver( null );

    Document doc = reader.read(new StringReader(xml));

    Element root = doc.getRootElement();

    Map customUserAttributes = new HashMap();

    Iterator itr = root.elements("custom-user-attribute").iterator();

    while (itr.hasNext()) {
      Element customUserAttribute = (Element)itr.next();

      String name = customUserAttribute.attributeValue("name");
      String customClass = customUserAttribute.attributeValue(
        "custom-class");

      customUserAttributes.put(name, customClass);
    }

    itr = root.elements("portlet").iterator();

    while (itr.hasNext()) {
      Element portlet = (Element)itr.next();

      String portletId = portlet.attributeValue("id");
      if (servletContextName != null) {
        portletId =
          servletContextName + PortletConfigImpl.WAR_SEPARATOR +
          portletId;
      }

      liferayPortletIds.add(portletId);

      Portlet portletModel = (Portlet)portletsPool.get(portletId);

      if (portletModel != null) {
        portletModel.setStrutsPath(GetterUtil.get(
          portlet.attributeValue("struts-path"),
          portletModel.getStrutsPath()));
        portletModel.setIndexerClass(GetterUtil.get(
          portlet.attributeValue("indexer-class"),
          portletModel.getIndexerClass()));
        portletModel.setSchedulerClass(GetterUtil.get(
          portlet.attributeValue("scheduler-class"),
          portletModel.getSchedulerClass()));
        portletModel.setPreferencesSharingType(GetterUtil.get(
          portlet.attributeValue("preferences-sharing-type"),
          portletModel.getPreferencesSharingType()));
        portletModel.setUseDefaultTemplate(GetterUtil.get(
          portlet.attributeValue("use-default-template"),
          portletModel.isUseDefaultTemplate()));
        portletModel.setShowPortletAccessDenied(GetterUtil.get(
          portlet.attributeValue("show-portlet-access-denied"),
          portletModel.isShowPortletAccessDenied()));
        portletModel.setShowPortletInactive(GetterUtil.get(
          portlet.attributeValue("show-portlet-inactive"),
          portletModel.isShowPortletInactive()));
        portletModel.setRestoreCurrentView(GetterUtil.get(
          portlet.attributeValue("restore-current-view"),
          portletModel.isRestoreCurrentView()));
        portletModel.setNs4Compatible(GetterUtil.get(
          portlet.attributeValue("ns-4-compatible"),
          portletModel.isNs4Compatible()));
        portletModel.setNarrow(GetterUtil.get(
          portlet.attributeValue("narrow"),
          portletModel.isNarrow()));
        portletModel.setActive(GetterUtil.get(
          portlet.attributeValue("active"),
          portletModel.isActive()));
        portletModel.setInclude(GetterUtil.get(
          portlet.attributeValue("include"),
          portletModel.isInclude()));

        portletModel.getCustomUserAttributes().putAll(
          customUserAttributes);
      }
View Full Code Here

   */
  public XmlTool getParent() {
    if (isEmpty()) {
      return null;
    }
    Element parent = node().getParent();
    if (parent == null) {
      return null;
    }
    return new XmlTool(parent);
  }
View Full Code Here

    if (size() == 1) {
      return getParent();
    }
    List<Node> parents = new ArrayList<Node>(size());
    for (Node n : nodes) {
      Element parent = n.getParent();
      if (parent != null && !parents.contains(parent)) {
        parents.add(parent);
      }
    }
    if (parents.isEmpty()) {
View Full Code Here

    @Override
    public void testFinished ( Description description ) throws Exception {

        long time = System.currentTimeMillis() - t1;

        Element currentTestcase = root.addElement( "testcase" );
        currentTestcase.addAttribute( "time", formatTime( time ) );
        currentTestcase.addAttribute( "classname", description.getClassName() );
        currentTestcase.addAttribute( "name", description.getMethodName() );
        if ( currentFailureNode != null ) {
            currentTestcase.add( currentFailureNode );
            currentFailureNode = null;
        }
    }
View Full Code Here

        currentFailureNode = createFailure( elementName, failure );
    }

    private Element createFailure ( String elementName, Failure failure ) {

        final Element element = DocumentHelper.createElement( elementName );
        element.addAttribute( "message", failure.getMessage() );
        element.addAttribute( "type", failure.getException().getClass().getName() );
        element.addText( failure.getTrace() );
        return element;
    }
View Full Code Here

*
*/
public class ElementComparator implements Comparator {

  public int compare(Object obj1, Object obj2) {
    Element el1 = (Element)obj1;
    Element el2 = (Element)obj2;

    String el1Name = el1.getName();
    String el2Name = el2.getName();

    if (!el1Name.equals(el2Name)) {
      return el1Name.compareTo(el2Name);
    }

    String el1Text = el1.getTextTrim();
    String el2Text = el2.getTextTrim();

    if (!el1Text.equals(el2Text)) {
      return el1Text.compareTo(el2Text);
    }

    List el1Attrs = el1.attributes();
    List el2Attrs = el2.attributes();

    if (el1Attrs.size() < el2Attrs.size()) {
      return -1;
    }
    else if (el1Attrs.size() > el2Attrs.size()) {
      return 1;
    }

    for (int i = 0; i < el1Attrs.size(); i++) {
      Attribute attr = (Attribute)el1Attrs.get(i);

      int value = _compare(el2Attrs, attr, new AttributeComparator());

      if (value != 0) {
        return value;
      }
    }

    List el1Elements = el1.elements();
    List el2Elements = el2.elements();

    if (el1Elements.size() < el2Elements.size()) {
      return -1;
    }
    else if (el1Elements.size() > el2Elements.size()) {
      return 1;
    }

    for (int i = 0; i < el1Elements.size(); i++) {
      Element el = (Element)el1Elements.get(i);

      int value = _compare(el2Elements, el, new ElementComparator());

      if (value != 0) {
        return value;
View Full Code Here

  public XMLElementComparator(XMLDescriptor descriptor) {
    _descriptor = descriptor;
  }

  public int compare(Object obj1, Object obj2) {
    Element el1 = (Element)obj1;
    Element el2 = (Element)obj2;

    if (_descriptor.areEqual(el1, el2)) {
      return 0;
    }
    else {
View Full Code Here

    Document doc = reader.read(new File("classes/META-INF/ejb-jar.xml"));

    Iterator itr = doc.getRootElement().element("enterprise-beans").elements("session").iterator();

    while (itr.hasNext()) {
      Element entity = (Element)itr.next();

      sb.append("\t\t<session>\n");
      sb.append("\t\t\t<ejb-name>").append(entity.elementText("ejb-name")).append("</ejb-name>\n");

      if (entity.elementText("display-name").endsWith("LocalManagerEJB")) {
        sb.append("\t\t\t<bean-local-home-name>ejb/liferay/").append(entity.elementText("display-name")).append("Home</bean-local-home-name>\n");
      }
      else {
        sb.append("\t\t\t<bean-home-name>").append(entity.elementText("ejb-name")).append("</bean-home-name>\n");
      }

      sb.append("\t\t</session>\n");
    }
View Full Code Here

TOP

Related Classes of com.dotcms.repackage.org.dom4j.Element

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.