public static EDLController createEDLController(
     EDocLiteAssociation edlAssociation,
     EDLGlobalConfig edlGlobalConfig,
     DocumentRouteHeaderValue document) {
   EDLController edlController = createEDLController(edlAssociation, edlGlobalConfig);
   try {
     Document defaultDom = edlController.getDefaultDOM();
     Document documentDom = XmlHelper.readXml(document.getDocContent());
     // get the data node and import it into our default DOM
     Element documentData = (Element) documentDom.getElementsByTagName(EDLXmlUtils.DATA_E).item(0);
     if (documentData != null) {
       Element defaultDomEDL = EDLXmlUtils.getEDLContent(defaultDom, false);
       Element defaultDomData =
           (Element) defaultDomEDL.getElementsByTagName(EDLXmlUtils.DATA_E).item(0);
       defaultDomEDL.replaceChild(defaultDom.importNode(documentData, true), defaultDomData);
     }
     if (LOG.isDebugEnabled()) {
       LOG.debug(
           "Created default Node from document id "
               + document.getDocumentId()
               + " content "
               + XmlJotter.jotNode(defaultDom));
     }
   } catch (Exception e) {
     throw new WorkflowRuntimeException(
         "Problems creating controller for EDL "
             + edlAssociation.getEdlName()
             + " document "
             + document.getDocumentId(),
         e);
   }
   return edlController;
 }
示例#2
0
 @Override
 public void apply(Element e) {
   if (e.getTagName().equals("property")) {
     Element parent = (Element) e.getParentNode();
     if (parent != null && parent.getTagName().equals("ndbx")) {
       Attr name = e.getAttributeNode("name");
       Attr value = e.getAttributeNode("value");
       if (name != null && name.getValue().equals("oscPort")) {
         if (value != null) {
           Element device = e.getOwnerDocument().createElement("device");
           device.setAttribute("name", "osc1");
           device.setAttribute("type", "osc");
           Element portProperty = e.getOwnerDocument().createElement("property");
           portProperty.setAttribute("name", "port");
           portProperty.setAttribute("value", value.getValue());
           device.appendChild(portProperty);
           Element autostartProperty = e.getOwnerDocument().createElement("property");
           autostartProperty.setAttribute("name", "autostart");
           autostartProperty.setAttribute("value", "true");
           device.appendChild(autostartProperty);
           parent.replaceChild(device, e);
         } else {
           parent.removeChild(e);
         }
       }
     }
   }
 }
  public void signAssertion(Document samlDocument) throws ProcessingException {
    Element originalAssertionElement =
        org.keycloak.saml.common.util.DocumentUtil.getChildElement(
            samlDocument.getDocumentElement(),
            new QName(
                JBossSAMLURIConstants.ASSERTION_NSURI.get(), JBossSAMLConstants.ASSERTION.get()));
    if (originalAssertionElement == null) return;
    Node clonedAssertionElement = originalAssertionElement.cloneNode(true);
    Document temporaryDocument;

    try {
      temporaryDocument = org.keycloak.saml.common.util.DocumentUtil.createDocument();
    } catch (ConfigurationException e) {
      throw new ProcessingException(e);
    }

    temporaryDocument.adoptNode(clonedAssertionElement);
    temporaryDocument.appendChild(clonedAssertionElement);

    signDocument(temporaryDocument);

    samlDocument.adoptNode(clonedAssertionElement);

    Element parentNode = (Element) originalAssertionElement.getParentNode();

    parentNode.replaceChild(clonedAssertionElement, originalAssertionElement);
  }
  private IStatus updateVaadinLiferayPortletXMLTo62(IDOMDocument document) {
    Element rootElement = document.getDocumentElement();

    NodeList portletNodes = rootElement.getElementsByTagName("portlet");

    if (portletNodes.getLength() > 1) {
      Element lastPortletElement = (Element) portletNodes.item(portletNodes.getLength() - 1);

      Node rnpNode =
          NodeUtil.appendChildElement(
              lastPortletElement, "requires-namespaced-parameters", "false");
      Node ajaxNode = NodeUtil.appendChildElement(lastPortletElement, "ajaxable", "false");
      Node hpcNode = lastPortletElement.getElementsByTagName("header-portlet-css").item(0);
      Node fpjNode = lastPortletElement.getElementsByTagName("footer-portlet-javascript").item(0);

      lastPortletElement.replaceChild(rnpNode, hpcNode);
      lastPortletElement.replaceChild(ajaxNode, fpjNode);
    }

    return Status.OK_STATUS;
  }
 private void convertToEdge(Element element) {
   Element parent = (Element) element.getParentNode();
   Element newElement = element.getOwnerDocument().createElement("edge");
   parent.replaceChild(newElement, element);
   NamedNodeMap attributes = element.getAttributes();
   for (int i = 0; i < attributes.getLength(); i++) {
     newElement.setAttributeNode((Attr) attributes.item(i).cloneNode(true));
   }
   NodeList nodeList = element.getChildNodes();
   for (int i = 0; i < nodeList.getLength(); i++) {
     newElement.appendChild(nodeList.item(i).cloneNode(true));
   }
   convertChildrenToEdge(newElement);
 }
示例#6
0
  protected Document applyChangesInAccessRights(
      Document docExistingAccessRights,
      Map<String, ExtendedMap> removedAccessRights,
      Map<String, ExtendedMap> modifiedAccessRights,
      Map<String, ExtendedMap> addedAccessRights) {

    // We have to make a clone of this hashtable, because we may have to remove some elements
    // and we don't want to affect this on the original hashtable.
    addedAccessRights = new HashMap<String, ExtendedMap>(addedAccessRights);

    // ("removedAccessRights = " + removedAccessRights);
    // ("modifiedAccessRights = " + modifiedAccessRights);
    // ("addedAccessRights = " + addedAccessRights);

    Element elExistingAccessRights = docExistingAccessRights.getDocumentElement();

    // ("antall accessrights: " + elExistingAccessRights.getChildNodes().getLength());
    // Loop thru existing accessrights and check if there is anyone to remove or modify
    Element curAccessRight = (Element) elExistingAccessRights.getFirstChild();
    while (curAccessRight != null) {

      String groupKey = curAccessRight.getAttribute("groupkey");
      // ("checking accessright, groupkey = " + groupKey);

      boolean remove = removedAccessRights.containsKey(groupKey);
      boolean modify = modifiedAccessRights.containsKey(groupKey);
      boolean add = addedAccessRights.containsKey(groupKey);
      boolean overwrite = (modify || add);

      // Remove accessright
      if (remove) {

        // ("removing accessright, groupkey = " + groupKey);
        curAccessRight = XMLTool.removeChildFromParent(elExistingAccessRights, curAccessRight);
      }
      // Overwrite accessright
      else if (overwrite) {

        ExtendedMap params;
        if (modify) {
          params = modifiedAccessRights.get(groupKey);
          // ("modifying/overwriting accessright, groupkey = " + groupKey);
        } else // add == true:
        {
          params = addedAccessRights.get(groupKey);
          // ("adding/overwriting accessright, groupkey = " + groupKey);
        }

        Document docNewAccessRight = XMLTool.createDocument("foo");
        Element elNewAccessRight =
            buildAccessRightElement(
                docNewAccessRight, docNewAccessRight.getDocumentElement(), groupKey, params);

        Element imported = (Element) docExistingAccessRights.importNode(elNewAccessRight, true);
        elExistingAccessRights.replaceChild(imported, curAccessRight);
        curAccessRight = imported;

        // Hvis vi overskriver eksisterende rettighet i stedet for å legge til, fordi den finnes fra
        // før
        // må vi fjerne rettigheten fra addedAccessRights, slik at vi ikke legger til den to ganger.
        if (add) {
          // ("Found an accessright that we wanted to add, that existed - we overwrite it
          // inseated, and removes the groupkey ("+groupKey+")from the addAccessRights hashtable so
          // that it
          // want be added later");
          addedAccessRights.remove(groupKey);
        }

        //
        curAccessRight = (Element) curAccessRight.getNextSibling();
      } else {
        curAccessRight = (Element) curAccessRight.getNextSibling();
      }
    }
    // Add new accessrights
    for (Object addedAccessRightKey : addedAccessRights.keySet()) {
      String currentGroupKey = (String) addedAccessRightKey;

      // ("adding new accessright, groupkey = " + currentGroupKey);

      ExtendedMap params = addedAccessRights.get(currentGroupKey);
      Document docNewAccessRight = XMLTool.createDocument("foo");
      Element elNewAccessRight =
          buildAccessRightElement(
              docNewAccessRight, docNewAccessRight.getDocumentElement(), currentGroupKey, params);

      elExistingAccessRights.appendChild(
          docExistingAccessRights.importNode(elNewAccessRight, true));
    }

    return docExistingAccessRights;
  }
示例#7
0
  /**
   * Create a document in using the XConfiguration-*.xml found in SCI/modules/MODULE_NAME/etc/
   *
   * @return the built document
   */
  public static Document createDocument() {
    DocumentBuilder docBuilder;
    DocumentBuilderFactory factory;
    Document mainDoc = getDefaultDocument();
    if (mainDoc == null) {
      return null;
    }

    Element root = mainDoc.getDocumentElement();

    factory = ScilabDocumentBuilderFactory.newInstance();

    try {
      docBuilder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException pce) {
      System.err.println("Cannot create a XML DocumentBuilder:\n" + pce);
      return null;
    }

    List<File> etcs = getEtcDir();
    for (File etc : etcs) {
      File[] xmls =
          etc.listFiles(
              new FilenameFilter() {
                public boolean accept(File dir, String name) {
                  return name.endsWith(".xml") && name.startsWith("XConfiguration-");
                }
              });
      for (File xml : xmls) {
        try {
          Document doc = docBuilder.parse(xml);
          if (xml.getName().equals("XConfiguration-general.xml")) {
            try {
              XPath xp = xpathFactory.newXPath();
              NodeList nodes =
                  (NodeList)
                      xp.compile(
                              "//shortcuts/body/actions/action-folder/action[contains(@key, 'OSSCKEY')]")
                          .evaluate(doc, XPathConstants.NODESET);
              for (int i = 0; i < nodes.getLength(); i++) {
                Element e = (Element) nodes.item(i);
                e.setAttribute(
                    "key",
                    e.getAttribute("key").replace("OSSCKEY", ScilabKeyStroke.getOSMetaKey()));
              }
            } catch (XPathExpressionException e) {
              System.err.println(e);
            }
          }
          Node node = mainDoc.importNode(doc.getDocumentElement(), true);
          NodeList list = root.getElementsByTagName(node.getNodeName());
          if (list.getLength() != 0) {
            root.replaceChild(node, list.item(0));
          }
        } catch (SAXException se) {
          System.err.println(ERROR_READ + xml.getName());
        } catch (IOException ioe) {
          System.err.println(ERROR_READ + xml.getName());
        }
      }
    }

    return mainDoc;
  }