Examples of LSSerializer


Examples of org.w3c.dom.ls.LSSerializer

      DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
      DOMImplementationLS domImplementation = (DOMImplementationLS) registry.getDOMImplementation("LS");
      Writer stringWriter = new StringWriter();
      LSOutput formattedOutput = domImplementation.createLSOutput();
      formattedOutput.setCharacterStream(stringWriter);
      LSSerializer domSerializer = domImplementation.createLSSerializer();
      domSerializer.getDomConfig().setParameter("format-pretty-print", true);
      // Set this to true if the declaration is needed to be in the output.
      domSerializer.getDomConfig().setParameter("xml-declaration", keepXmlDeclaration);
      domSerializer.write(document, formattedOutput);
      return stringWriter.toString();
    } catch (Exception e) {
      throw new RuntimeException(FORMAT_ERROR, e);
    }
  }
View Full Code Here

Examples of org.w3c.dom.ls.LSSerializer

            }
        }
        LSOutput output = impl.createLSOutput();
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        output.setByteStream(byteArrayOutputStream);
        LSSerializer writer = impl.createLSSerializer();
        writer.write(doc, output);
        byte[] buf = byteArrayOutputStream.toByteArray();
        return new ByteArrayInputStream(buf);
    }
View Full Code Here

Examples of org.w3c.dom.ls.LSSerializer

      TypeOracle typeOracle, JClassType type, Writer out)
      throws UnableToCompleteException {
    logger = logger.branch(TreeLogger.DEBUG, "Building gadget manifest", null);

    Document d;
    LSSerializer serializer;
    LSOutput output;

    // Initialize the XML document
    try {
      DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
      DOMImplementation impl = registry.getDOMImplementation("Core 3.0");
      d = impl.createDocument(null, null, null);
      DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS",
          "3.0");
      output = implLS.createLSOutput();
      output.setCharacterStream(out);
      serializer = implLS.createLSSerializer();
    } catch (ClassNotFoundException e) {
      logger.log(TreeLogger.ERROR, "Could not create document", e);
      throw new UnableToCompleteException();
    } catch (IllegalAccessException e) {
      logger.log(TreeLogger.ERROR, "Could not create document", e);
      throw new UnableToCompleteException();
    } catch (InstantiationException e) {
      logger.log(TreeLogger.ERROR, "Could not create document", e);
      throw new UnableToCompleteException();
    }

    // Root elements
    Element module = (Element) d.appendChild(d.createElement("Module"));

    Element modulePrefs = (Element) module.appendChild(d.createElement("ModulePrefs"));

    addInjectedModulePrefs(logger, type, modulePrefs);

    // Write out the ModulePrefs tag
    ModulePrefs prefs = type.getAnnotation(ModulePrefs.class);
    if (prefs != null) {
      GadgetUtils.writeAnnotationToElement(logger, prefs, modulePrefs,
          "requirements", "locales");
      GadgetUtils.writeRequirementsToElement(logger, d, modulePrefs,
          prefs.requirements());
      GadgetUtils.writeLocalesToElement(logger, d, modulePrefs, prefs.locales());

    }

    // Write out the UserPref tags
    JClassType preferenceType = typeOracle.findType(Preference.class.getName().replace(
        '$', '.'));
    assert preferenceType != null;

    JClassType prefsType = GadgetUtils.getUserPrefsType(logger, typeOracle,
        type);
    for (JMethod m : prefsType.getOverridableMethods()) {
      Element userPref = (Element) module.appendChild(d.createElement("UserPref"));
      configurePreferenceElement(logger, d, userPref, preferenceType, m);
    }

    // Add required features to the manifest
    // <require feature="someFeature" />
    for (JClassType currentClass = type; currentClass != null; currentClass = currentClass.getSuperclass()) {
      for (JClassType interfaceType : currentClass.getImplementedInterfaces()) {
        FeatureName name = interfaceType.getAnnotation(FeatureName.class);
        if (name != null) {
          for (String feature : name.value()) {
            // Skip features defined to be implicitly available in the container
            if (FeatureName.INTRINSIC.equals(feature)) {
              continue;
            }
            Element require = (Element) modulePrefs.appendChild(d.createElement("Require"));
            require.setAttribute("feature", feature);
          }
          GadgetUtils.writeRequirementsToElement(logger, d, modulePrefs,
              name.requirements());
        }
      }
    }

    // Generate and append the Content section(s).
    for (Element contentSection : createContentSections(logger, type,
        typeOracle, d)) {
      module.appendChild(contentSection);
    }
    serializer.write(d, output);
  }
View Full Code Here

Examples of org.w3c.dom.ls.LSSerializer

            impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
        }
        LSOutput output = impl.createLSOutput();
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        output.setByteStream(bout);
        LSSerializer writer = impl.createLSSerializer();
        writer.write(node, output);
   
        return bout.toByteArray();
    }
View Full Code Here

Examples of org.w3c.dom.ls.LSSerializer

            impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
        }
        LSOutput output = impl.createLSOutput();
        RawByteArrayOutputStream bout = new RawByteArrayOutputStream();
        output.setByteStream(bout);
        LSSerializer writer = impl.createLSSerializer();
        writer.write(node, output);

        return new ByteArrayInputStream(bout.getBytes(), 0, bout.size());
    }
View Full Code Here

Examples of org.w3c.dom.ls.LSSerializer

            }
        }
        LSOutput output = impl.createLSOutput();
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        output.setByteStream(byteArrayOutputStream);
        LSSerializer writer = impl.createLSSerializer();
        writer.write(doc, output);
        byte[] buf = byteArrayOutputStream.toByteArray();
        return new ByteArrayInputStream(buf);
    }
View Full Code Here

Examples of org.w3c.dom.ls.LSSerializer

        data.nsContext = ns;
    }
   
    public void serialize(OutputStream os, Node node, Format format) throws XMLException {
        try {
          LSSerializer ser = createLSSerializer(format);
          LSOutput out = domImplementationLS.createLSOutput();
          out.setByteStream(os);
          ser.write(node,out);
        } catch(Exception e) {
            throw new XMLException(e,"Error while converting XML document to string"); // $NLS-AbstractXercesDriver.ErrorwhileconvertingXMLdocumentto-1$
        }
    }
View Full Code Here

Examples of org.w3c.dom.ls.LSSerializer

        }
    }

    public void serialize(Writer w, Node node, Format format) throws XMLException {
        try {
          LSSerializer ser = createLSSerializer(format);
          LSOutput out = domImplementationLS.createLSOutput();
          out.setCharacterStream(w);
          ser.write(node,out);
        } catch(Exception e) {
            throw new XMLException(e,"Error while converting XML document to string"); // $NLS-AbstractXercesDriver.ErrorwhileconvertingXMLdocumentto.1-1$
        }
    }
View Full Code Here

Examples of org.w3c.dom.ls.LSSerializer

            throw new XMLException(e,"Error while converting XML document to string"); // $NLS-AbstractXercesDriver.ErrorwhileconvertingXMLdocumentto.1-1$
        }
    }

    private LSSerializer createLSSerializer(Format format) {
      LSSerializer ser = domImplementationLS.createLSSerializer();
      DOMConfiguration c = ser.getDomConfig();
      c.setParameter("format-pretty-print", format.indent!=0); //$NON-NLS-1$
      c.setParameter("xml-declaration", !format.xmlDecl); //$NON-NLS-1$
      return ser;
    }
View Full Code Here

Examples of org.w3c.dom.ls.LSSerializer

      return prettyFormat(input, 4);
 
 
  public static String getStringFromDoc(org.w3c.dom.Document doc)    {
      DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
      LSSerializer lsSerializer = domImplementation.createLSSerializer();
      String xml = lsSerializer.writeToString(doc);
      xml = prettyFormat(xml);
      return xml;   
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.