List of usage examples for org.dom4j Element elements
List<Element> elements(QName qName);
From source file:com.jswiff.xml.RecordXMLReader.java
License:Open Source License
private static MorphGradient readMorphGradient(Element parentElement) { Element element = parentElement.element("morphgradient"); boolean focal = false; if (element == null) { element = getElement("focalmorphgradient", parentElement); focal = true;/*ww w .ja v a2 s. c o m*/ } List recordElements = element.elements("morphgradrecord"); int arrayLength = recordElements.size(); MorphGradRecord[] records = new MorphGradRecord[arrayLength]; for (int i = 0; i < arrayLength; i++) { Element recordElement = (Element) recordElements.get(i); Element start = getElement("start", recordElement); short startRatio = getShortAttribute("ratio", start); RGBA startColor = readRGBA(getElement("color", start)); Element end = getElement("end", recordElement); short endRatio = getShortAttribute("ratio", end); RGBA endColor = readRGBA(getElement("color", end)); records[i] = new MorphGradRecord(startRatio, startColor, endRatio, endColor); } MorphGradient morphGradient; if (focal) { double startFocalpointratio = getDoubleAttribute("startfocalpointratio", element); double endfocalpointratio = getDoubleAttribute("endfocalpointratio", element); morphGradient = new FocalMorphGradient(records, startFocalpointratio, endfocalpointratio); } else { morphGradient = new MorphGradient(records); } morphGradient.setInterpolationMethod(readInterpolationMethod(element)); morphGradient.setSpreadMethod(readSpreadMethod(element)); return morphGradient; }
From source file:com.liferay.alloy.tools.builder.base.BaseBuilder.java
License:Open Source License
protected List<Component> getAllComponents() throws Exception { DocumentFactory factory = SAXReaderUtil.getDocumentFactory(); Document doc = factory.createDocument(); String taglibsXML = "<components></components>"; Document taglibsDoc = SAXReaderUtil .read(new InputSource(new ByteArrayInputStream(taglibsXML.getBytes("utf-8")))); Element root = taglibsDoc.getRootElement(); for (Document currentDoc : getComponentDefinitionDocs()) { currentDoc = _getExtendedDocument(currentDoc); Element currentRoot = currentDoc.getRootElement(); String defaultPackage = currentRoot.attributeValue("short-name"); List<Element> extComponentNodes = currentRoot.elements("component"); for (Element extComponent : extComponentNodes) { String extComponentPackage = Convert.toString(extComponent.attributeValue("package"), defaultPackage);//from ww w. ja v a2s . co m extComponent.addAttribute("package", extComponentPackage); } Element authors = currentRoot.element("author"); List<Element> components = currentRoot.elements("component"); for (Element component : components) { Element copy = component.createCopy(); Element componentAuthors = copy.element("authors"); if ((authors != null) && (componentAuthors == null)) { copy.add(authors.createCopy()); } root.add(copy); } List<org.dom4j.Attribute> attributes = currentRoot.attributes(); for (org.dom4j.Attribute attribute : attributes) { root.addAttribute(attribute.getName(), attribute.getValue()); } } doc.add(root.createCopy()); return getComponents(doc); }
From source file:com.liferay.alloy.tools.builder.base.BaseBuilder.java
License:Open Source License
protected Document mergeXMLAttributes(Document doc1, Document doc2) { Element doc2Root = doc2.getRootElement(); Element doc1Root = doc1.getRootElement(); Element docRoot = doc2Root.createCopy(); docRoot.clearContent();// w w w. j a v a2s .co m if (doc1Root != null) { Iterator<Object> attributesIterator = doc1Root.attributeIterator(); while (attributesIterator.hasNext()) { org.dom4j.Attribute attribute = (org.dom4j.Attribute) attributesIterator.next(); if (attribute.getName().equals("extends")) { continue; } docRoot.addAttribute(attribute.getName(), attribute.getValue()); } Element descriptionElement = doc1Root.element("description"); if (descriptionElement != null) { docRoot.add(descriptionElement.createCopy()); } } DocumentFactory factory = SAXReaderUtil.getDocumentFactory(); Document doc = factory.createDocument(); doc.setRootElement(docRoot); List<Element> doc2Components = doc2Root.elements(_COMPONENT); for (Element doc2Component : doc2Components) { Element component = doc2Component.createCopy(); String name = doc2Component.attributeValue("name"); Element doc1Component = getComponentNode(doc1, name); if (doc1Component != null) { Element doc1ComponentDescriptionElement = doc1Component.element("description"); if (doc1ComponentDescriptionElement != null) { Element descriptionElement = component.element("description"); if (descriptionElement != null) { component.remove(descriptionElement); } component.add(doc1ComponentDescriptionElement.createCopy()); } Iterator<Object> attributesIterator = doc1Component.attributeIterator(); while (attributesIterator.hasNext()) { org.dom4j.Attribute attribute = (org.dom4j.Attribute) attributesIterator.next(); component.addAttribute(attribute.getName(), attribute.getValue()); } Element doc1AttributesNode = doc1Component.element(_ATTRIBUTES); Element attributesNode = component.element(_ATTRIBUTES); if ((doc1AttributesNode != null) && (attributesNode != null)) { List<Element> doc1Attributes = doc1AttributesNode.elements(_ATTRIBUTE); List<Element> attributes = attributesNode.elements(_ATTRIBUTE); for (Element doc1Attribute : doc1Attributes) { Element attribute = getElementByName(attributes, doc1Attribute.elementText("name")); if (attribute != null) { attributesNode.remove(attribute); } attributesNode.add(doc1Attribute.createCopy()); } } Element doc1EventsNode = doc1Component.element(_EVENTS); Element eventsNode = component.element(_EVENTS); if ((doc1EventsNode != null) && (eventsNode != null)) { List<Element> doc1Events = doc1EventsNode.elements(_EVENT); List<Element> events = eventsNode.elements(_EVENT); for (Element doc1Event : doc1Events) { Element event = getElementByName(events, doc1Event.elementText("name")); if (event != null) { eventsNode.add(event); } eventsNode.add(doc1Event.createCopy()); } } } doc.getRootElement().add(component); } if (doc1Root != null) { List<Element> doc1Components = doc1Root.elements(_COMPONENT); for (Element doc1Component : doc1Components) { Element component = doc1Component.createCopy(); String name = doc1Component.attributeValue("name"); Element doc2Component = getComponentNode(doc2, name); if (doc2Component == null) { doc.getRootElement().add(component); } } } return doc; }
From source file:com.liferay.alloy.tools.builder.faces.FacesBuilder.java
License:Open Source License
@Override protected List<Component> getComponents(Document doc) throws Exception { Element root = doc.getRootElement(); Map<String, Component> facesComponentsMap = new HashMap<>(); String defaultYUIRendererParentClass = root.attributeValue("defaultYUIRendererParentClass"); String defaultSince = root.attributeValue("defaultSince"); List<Element> allComponentNodes = root.elements("component"); for (Element node : allComponentNodes) { FacesComponent facesComponent = new FacesComponent(); facesComponent.initialize(node, _COMPONENTS_PACKAGE, defaultYUIRendererParentClass, defaultSince); facesComponentsMap.put(facesComponent.getName(), facesComponent); }//w w w. ja v a2s . c o m List<Component> facesComponents = new ArrayList<>(facesComponentsMap.values()); for (Component facesComponent : facesComponents) { recursivelyAddExtensionAttributesAndEvents(facesComponent, facesComponentsMap); } return facesComponents; }
From source file:com.liferay.alloy.tools.builder.taglib.TagBuilder.java
License:Open Source License
@Override protected List<Component> getComponents(Document doc) throws Exception { Element root = doc.getRootElement(); List<Component> components = new ArrayList<Component>(); String defaultPackage = root.attributeValue("short-name"); List<Element> allComponentNodes = root.elements("component"); for (Element node : allComponentNodes) { TagComponent tagComponent = new TagComponent(); tagComponent.initialize(node, defaultPackage); components.add(tagComponent);/*from w w w .j a v a2s.c o m*/ } return components; }
From source file:com.liferay.alloy.tools.model.Component.java
License:Open Source License
public void initialize(Element componentElement, String defaultPackage) { String name = componentElement.attributeValue("name"); setName(name);//from ww w . j a v a2 s . co m Element descriptionElement = componentElement.element("description"); String description = StringPool.EMPTY; if (descriptionElement != null) { description = Convert.toString(descriptionElement.getText()); } setDescription(description); Element authorsElement = componentElement.element("authors"); if (authorsElement != null) { List<String> authors = new ArrayList<String>(); List<Element> authorElementsList = authorsElement.elements("author"); for (Element authorElement : authorElementsList) { authors.add(authorElement.getText()); } _authors = authors.toArray(new String[authors.size()]); } if (_authors == null) { _authors = _DEFAULT_AUTHORS; } _alloyComponent = Convert.toBoolean(componentElement.attributeValue("alloyComponent"), true); _bodyContent = Convert.toBoolean(componentElement.attributeValue("bodyContent"), false); _componentInterface = Convert.toString(componentElement.attributeValue("componentInterface"), null); String extendsTagsString = Convert.toString(componentElement.attributeValue("extendsTags"), null); if (extendsTagsString == null) { _extendsTags = null; } else { _extendsTags = extendsTagsString.split(StringPool.SPACE); } _module = Convert.toString(componentElement.attributeValue("module"), null); _package = Convert.toString(componentElement.attributeValue("package"), defaultPackage); _parentClass = Convert.toString(componentElement.attributeValue("parentClass"), null); boolean generateJava = Convert.toBoolean(componentElement.attributeValue("generateJava"), true); setGenerateJava(generateJava); Element attributesElement = componentElement.element("attributes"); _attributes = new ArrayList<Attribute>(); if (attributesElement != null) { List<Element> attributeElementsList = attributesElement.elements("attribute"); _attributes.addAll(getAttributesFromElements(attributeElementsList)); } Element eventsElement = componentElement.element("events"); _events = new ArrayList<Event>(); if (eventsElement != null) { List<Element> eventElementsList = eventsElement.elements("event"); _events.addAll(getEventsFromElements(eventElementsList)); } }
From source file:com.liferay.maven.plugins.ThemeMergeMojo.java
License:Open Source License
protected void doExecute() throws Exception { workDir = new File(workDir, "liferay-theme"); if (!workDir.exists()) { workDir.mkdirs();//from w w w .jav a2 s . com } if (Validator.isNotNull(parentTheme)) { if (parentTheme.indexOf(":") > 0) { String[] parentThemeArray = parentTheme.split(":"); parentThemeArtifactGroupId = parentThemeArray[0]; parentThemeArtifactId = parentThemeArray[1]; parentThemeArtifactVersion = parentThemeArray[2]; parentThemeId = null; } else { parentThemeId = parentTheme; } } getLog().info("Parent theme group ID " + parentThemeArtifactGroupId); getLog().info("Parent theme artifact ID " + parentThemeArtifactId); getLog().info("Parent theme version " + parentThemeArtifactVersion); getLog().info("Parent theme ID " + parentThemeId); String[] excludes = null; String[] includes = null; boolean portalTheme = false; if (parentThemeArtifactGroupId.equals("com.liferay.portal") && parentThemeArtifactId.equals("portal-web")) { portalTheme = true; } if (!portalTheme) { Dependency dependency = createDependency(parentThemeArtifactGroupId, parentThemeArtifactId, parentThemeArtifactVersion, "", "war"); Artifact artifact = resolveArtifact(dependency); UnArchiver unArchiver = archiverManager.getUnArchiver(artifact.getFile()); unArchiver.setDestDirectory(workDir); unArchiver.setSourceFile(artifact.getFile()); IncludeExcludeFileSelector includeExcludeFileSelector = new IncludeExcludeFileSelector(); includeExcludeFileSelector.setExcludes(excludes); includeExcludeFileSelector.setIncludes(includes); unArchiver.setFileSelectors(new FileSelector[] { includeExcludeFileSelector }); unArchiver.extract(); } File liferayLookAndFeelXml = new File(webappSourceDir, "WEB-INF/liferay-look-and-feel.xml"); if (liferayLookAndFeelXml.exists()) { Document document = SAXReaderUtil.read(liferayLookAndFeelXml, false); Element rootElement = document.getRootElement(); List<Element> themeElements = rootElement.elements("theme"); for (Element themeElement : themeElements) { String id = themeElement.attributeValue("id"); if (Validator.isNotNull(themeId) && !themeId.equals(id)) { continue; } Theme targetTheme = readTheme(themeElement); if (portalTheme) { mergePortalTheme(targetTheme); } else { File sourceLiferayLookAndFeelXml = new File(workDir, "WEB-INF/liferay-look-and-feel.xml"); Theme sourceTheme = readTheme(parentThemeId, sourceLiferayLookAndFeelXml); mergeTheme(sourceTheme, targetTheme); } } } else { String id = PortalUtil.getJsSafePortletId(project.getArtifactId()); Theme targetTheme = readTheme(id, null); if (portalTheme) { mergePortalTheme(targetTheme); } else { File sourceLiferayLookAndFeelXml = new File(workDir, "WEB-INF/liferay-look-and-feel.xml"); Theme sourceTheme = readTheme(parentThemeId, sourceLiferayLookAndFeelXml); mergeTheme(sourceTheme, targetTheme); } } }
From source file:com.liferay.maven.plugins.ThemeMergeMojo.java
License:Open Source License
protected Theme readTheme(String themeId, File liferayLookAndFeelXml) throws Exception { if ((liferayLookAndFeelXml != null) && liferayLookAndFeelXml.exists()) { Document document = SAXReaderUtil.read(liferayLookAndFeelXml, false); Element rootElement = document.getRootElement(); List<Element> themeElements = rootElement.elements("theme"); for (Element themeElement : themeElements) { String id = themeElement.attributeValue("id"); if (Validator.isNotNull(themeId) && !themeId.equals(id)) { continue; }//from www . j a v a 2s .co m return readTheme(themeElement); } } Theme theme = new Theme(themeId); theme.setCssPath("/css"); theme.setImagesPath("/images"); theme.setJavaScriptPath("/js"); theme.setRootPath("/"); theme.setTemplateExtension(themeType); theme.setTemplatesPath("/templates"); return theme; }
From source file:com.liferay.petra.log4j.Log4JUtil.java
License:Open Source License
public static void configureLog4J(URL url) { if (url == null) { return;//from w w w . java2 s.c om } String urlContent = _getURLContent(url); if (urlContent == null) { return; } // See LPS-6029, LPS-8865, and LPS-24280 DOMConfigurator domConfigurator = new DOMConfigurator(); domConfigurator.doConfigure(new UnsyncStringReader(urlContent), LogManager.getLoggerRepository()); try { SAXReader saxReader = new SAXReader(); saxReader.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) { if (systemId.endsWith("log4j.dtd")) { return new InputSource(DOMConfigurator.class.getResourceAsStream("log4j.dtd")); } return null; } }); Document document = saxReader.read(new UnsyncStringReader(urlContent), url.toExternalForm()); Element rootElement = document.getRootElement(); List<Element> categoryElements = rootElement.elements("category"); for (Element categoryElement : categoryElements) { String name = categoryElement.attributeValue("name"); Element priorityElement = categoryElement.element("priority"); String priority = priorityElement.attributeValue("value"); java.util.logging.Logger jdkLogger = java.util.logging.Logger.getLogger(name); jdkLogger.setLevel(_getJdkLevel(priority)); } } catch (Exception e) { _logger.error(e, e); } }
From source file:com.liferay.portal.ejb.PortletManagerImpl.java
License:Open Source License
private Set _readPortletXML(String servletContextName, String xml, Map portletsPool) throws DocumentException, IOException { Set portletIds = new HashSet(); if (xml == null) { return portletIds; }/* w w w .j a va2 s . com*/ /*EntityResolver resolver = new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) { InputStream is = getClass().getClassLoader().getResourceAsStream( "com/liferay/portal/resources/portlet-app_1_0.xsd"); return new InputSource(is); } };*/ 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); } return portletIds; }